Skip to content

Commit

Permalink
Implemented handler to getLxcList with Lxd_IP
Browse files Browse the repository at this point in the history
  • Loading branch information
vin0298 committed Aug 28, 2018
1 parent f764e58 commit d9d43aa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
11 changes: 6 additions & 5 deletions lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,21 @@ func (l *lxd) getLxdIDByName(db *sqlx.DB) error {
return nil
}

func (l *lxd) getLxdNameByID(db *sqlx.DB) string {
rows, err := db.Queryx("SELECT name FROM lxd WHERE id=$1", l.ID)
func (l *lxd) getLxdNameAndAddressByID(db *sqlx.DB) (string, string) {
rows, err := db.Queryx("SELECT name, address FROM lxd WHERE id=$1", l.ID)
if err != nil {
log.Error(err.Error())
return ""
return "", ""
}
defer rows.Close()

lxdData := lxd{}
if rows.Next() {
if err = rows.StructScan(&lxdData); err != nil {
log.Error(err.Error())
return ""
return "", ""
}
}
log.Infof("lxd name: %s", lxdData.Name)
return lxdData.Name
return lxdData.Address, lxdData.Name
}
3 changes: 3 additions & 0 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ func calculateMetrics(memResult, cpuResult, storageResult promResponse, scoringW
memoryScores := memResult.Data.Result
cpuScores := cpuResult.Data.Result

log.Infof("array length: %d", len(memoryScores))
for i := 0; i < len(memoryScores); i++ {
log.Infof("memoryScore arr: %s for i: %d", memoryScores[i], i)
log.Infof("cpuScore arr: %s for i: %d", cpuScores[i], i)
address := memoryScores[i].Metric.Instance
strMemScore := memoryScores[i].Value[1].(string)
strCpuScore := cpuScores[i].Value[1].(string)
Expand Down
5 changes: 3 additions & 2 deletions scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (s *scheduler) initialize(user, password, dbname, host, port, sslmode strin
s.Router.HandleFunc("/api/v1/lxc-services", s.createNewLxcServiceHandler).Methods("POST")
s.Router.HandleFunc("/api/v1/lxc-services/{lxdName}", s.getLxcServicesListHandler).Methods("GET")
s.Router.HandleFunc("/api/v1/lxc-services", s.updateLxcServicesStatusByIDHandler).Methods("PUT")
s.Router.HandleFunc("/api/v1/lxc-service/{lxcId}", s.getLxcServiceListByLxcIDHandler).Methods("GET")
s.Router.HandleFunc("/api/v1/lxc-services/lxc/{lxcId}", s.getLxcServiceListByLxcIDHandler).Methods("GET")
s.client = agentClient{}
s.metricsDB = prometheusMetricsDB{}

Expand Down Expand Up @@ -219,10 +219,11 @@ func (s *scheduler) createNewLxcServiceHandler(w http.ResponseWriter, r *http.Re
lxc := lxc{ID: newLxcService.LxcID}
lxd := lxd{ID: newLxcService.LxdID}
lxcName := lxc.getLxcNameByID(s.DB)
lxdName := lxd.getLxdNameByID(s.DB)
lxdAddress, lxdName := lxd.getLxdNameAndAddressByID(s.DB)

newLxcService.LxcName = lxcName
newLxcService.LxdName = lxdName
newLxcService.LxdAddress = lxdAddress
exist := newLxcService.checkIfLxcServiceExist(s.DB)
if !exist {
newLxcService.ID = uuid.New()
Expand Down

0 comments on commit d9d43aa

Please sign in to comment.