Skip to content

Commit

Permalink
fix rootlb flavor (#71)
Browse files Browse the repository at this point in the history
* fix rootlb flavor

* style updates per review:
- add comment regarding OPENRC_URL
- go vet formatting for FlavorInfo init
- move GetCloudletSharedRootLBFlavor to rootlb.go
  • Loading branch information
jlmorris3827 authored Apr 3, 2019
1 parent 90d0f43 commit e986044
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
29 changes: 28 additions & 1 deletion crm-platforms/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package openstack

import (
"fmt"
"os"

"github.com/mobiledgex/edge-cloud-infra/mexos"
"github.com/mobiledgex/edge-cloud/cloud-resource-manager/platform/pc"
"github.com/mobiledgex/edge-cloud/cloudcommon"
"github.com/mobiledgex/edge-cloud/edgeproto"
"github.com/mobiledgex/edge-cloud/flavor"
"github.com/mobiledgex/edge-cloud/log"
)

Expand All @@ -23,6 +25,10 @@ func (s *Platform) Init(key *edgeproto.CloudletKey) error {
rootLBName := cloudcommon.GetRootLBFQDN(key)
log.DebugLog(log.DebugLevelMexos, "init openstack", "rootLB", rootLBName)

// OPENRC_URL is required for OpenStack, but optional in InitInfraCommon
if os.Getenv("OPENRC_URL") == "" {
return fmt.Errorf("Env OPENRC_URL not set")
}
if err := mexos.InitInfraCommon(); err != nil {
return err
}
Expand All @@ -35,6 +41,17 @@ func (s *Platform) Init(key *edgeproto.CloudletKey) error {
if err != nil || len(osflavors) == 0 {
return fmt.Errorf("failed to get flavors, %s", err.Error())
}
var finfo []*edgeproto.FlavorInfo
for _, f := range osflavors {
finfo = append(
finfo,
&edgeproto.FlavorInfo{
Name: f.Name,
Vcpus: uint64(f.VCPUs),
Ram: uint64(f.RAM),
Disk: uint64(f.Disk)},
)
}

// create rootLB
crmRootLB, cerr := mexos.NewRootLB(rootLBName)
Expand All @@ -48,8 +65,18 @@ func (s *Platform) Init(key *edgeproto.CloudletKey) error {
s.rootLB = crmRootLB
s.rootLBName = rootLBName

var sharedRootLBFlavor edgeproto.Flavor
err = mexos.GetCloudletSharedRootLBFlavor(&sharedRootLBFlavor)
if err != nil {
return fmt.Errorf("unable to get Shared RootLB Flavor: %v", err)
}
flavorName, err := flavor.GetClosestFlavor(finfo, sharedRootLBFlavor)
if err != nil {
return fmt.Errorf("unable to find closest flavor for Shared RootLB: %v", err)
}

log.DebugLog(log.DebugLevelMexos, "calling RunMEXAgentCloudletKey", "cloudletkeystr", key.GetKeyString())
err = mexos.RunMEXAgentCloudletKey(rootLBName, key.GetKeyString(), osflavors[0].Name)
err = mexos.RunMEXAgentCloudletKey(rootLBName, key.GetKeyString(), flavorName)
if err != nil {
return err
}
Expand Down
36 changes: 36 additions & 0 deletions mexos/rootlb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package mexos

import (
"fmt"
"os"
"strconv"
"time"

"github.com/mobiledgex/edge-cloud/edgeproto"
Expand Down Expand Up @@ -167,3 +169,37 @@ func WaitForRootLB(rootLB *MEXRootLB) error {

return nil
}

// GetCloudletSharedRootLBFlavor gets the flavor from defaults
// or environment variables
func GetCloudletSharedRootLBFlavor(flavor *edgeproto.Flavor) error {
ram := os.Getenv("MEX_SHARED_ROOTLB_RAM")
var err error
if ram != "" {
flavor.Ram, err = strconv.ParseUint(ram, 10, 64)
if err != nil {
return err
}
} else {
flavor.Ram = 4096
}
vcpus := os.Getenv("MEX_SHARED_ROOTLB_VCPUS")
if vcpus != "" {
flavor.Vcpus, err = strconv.ParseUint(vcpus, 10, 64)
if err != nil {
return err
}
} else {
flavor.Vcpus = 2
}
disk := os.Getenv("MEX_SHARED_ROOTLB_DISK")
if disk != "" {
flavor.Disk, err = strconv.ParseUint(disk, 10, 64)
if err != nil {
return err
}
} else {
flavor.Disk = 40
}
return nil
}

0 comments on commit e986044

Please sign in to comment.