Skip to content

Commit

Permalink
flavor clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
bobmex committed Nov 6, 2018
1 parent a204800 commit 70b8c75
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
31 changes: 20 additions & 11 deletions openstack-prov/oscliapi/mex.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ import (
// These are platform specific custom vars

var eMEXLargeImageName = os.Getenv("MEX_LARGE_IMAGE") // "mobiledgex-16.04-2"
var eMEXLargeFlavor = os.Getenv("MEX_LARGE_FLAVOR") // "m4.large"
var eMEXUserData = os.Getenv("MEX_USERDATA") // "/home/bob/userdata.txt"
var eMEXDir = os.Getenv("MEX_DIR")
var eMEXSubnetSeed = 100 // XXX
var eMEXSubnetLimit = 250 // XXX
var defaultImage = "mobiledgex-16.04-2"
var defaultFlavor = "m4.large"
var defaultFlavor = "x1.medium"

const (
k8smasterRole = "k8s-master"
Expand All @@ -44,18 +43,14 @@ func init() {
if eMEXLargeImageName == "" {
eMEXLargeImageName = defaultImage
}
if eMEXLargeFlavor == "" {
eMEXLargeFlavor = defaultFlavor
}
hm := os.Getenv("HOME")
if eMEXDir == "" {
eMEXDir = hm + "/.mobiledgex"
}
if eMEXUserData == "" {
eMEXUserData = eMEXDir + "/userdata.txt"
}
log.DebugLog(log.DebugLevelMexos, "mex init environment", "MEX_LARGE_IMAGE", eMEXLargeImageName, "MEX_LARGE_FLAVOR",
eMEXLargeFlavor, "MEX_USERDATA", eMEXUserData, "MEX_DIR", eMEXDir)
log.DebugLog(log.DebugLevelMexos, "mex init environment", "MEX_LARGE_IMAGE", eMEXLargeImageName, "MEX_USERDATA", eMEXUserData, "MEX_DIR", eMEXDir)
}

//CreateFlavorMEXVM creates basic KVM for mobiledgex applications
Expand All @@ -81,9 +76,8 @@ func CreateFlavorMEXVM(name, image, flavor, netID, userdata, role, edgeproxy, sk
image = eMEXLargeImageName
}
if flavor == "" {
flavor = eMEXLargeFlavor
return fmt.Errorf("Missing platform flavor")
}

if userdata == "" {
userdata = eMEXUserData
}
Expand Down Expand Up @@ -113,7 +107,7 @@ func CreateFlavorMEXVM(name, image, flavor, netID, userdata, role, edgeproxy, sk
props = append(props, "tags="+tags)
props = append(props, "tenant="+tenant)
opts.Properties = props
log.DebugLog(log.DebugLevelMexos, "create flavor MEX KVM", "server opts", opts)
log.DebugLog(log.DebugLevelMexos, "create flavor MEX KVM", "flavor", flavor, "server opts", opts)
err = CreateServer(opts)
if err != nil {
log.DebugLog(log.DebugLevelMexos, "error creating flavor MEX KVM", "server opts", opts)
Expand All @@ -122,6 +116,17 @@ func CreateFlavorMEXVM(name, image, flavor, netID, userdata, role, edgeproxy, sk
return nil
}

func GetFlavorTag(tags string) (string, error) {
for _, t := range strings.Split(tags, ",") {
if strings.HasPrefix(t, "m4.") { // XXX platform specific
return t, nil
}
}
//flavor not specified, use default
log.DebugLog(log.DebugLevelMexos, "no flavor in tags, using default flavor", "default flavor", defaultFlavor)
return defaultFlavor, nil
}

//CreateMEXKVM is easier way to create a MEX app capable KVM
// role can be k8s-master, k8s-node, or something else
func CreateMEXKVM(name, role, netSpec, tags, tenant string, id int) error {
Expand Down Expand Up @@ -375,9 +380,13 @@ func CreateMEXKVM(name, role, netSpec, tags, tenant string, id int) error {
}
log.DebugLog(log.DebugLevelMexos, "creating a new kvm", "name", name, "skipk8s", skipk8s, "masterip", masterIP,
"privnet", privNet, "privrouterip", privRouterIP, "tags", tags, "tenant", tenant)
platformFlavor, err := GetFlavorTag(tags)
if err != nil {
return fmt.Errorf("cannot get flavor from tags '%s'", tags)
}
err = CreateFlavorMEXVM(name,
eMEXLargeImageName,
eMEXLargeFlavor,
platformFlavor,
netID, // either external-net or internal-net,v4-fixed-ip=X.X.X.X
eMEXUserData,
role, // k8s-master,k8s-node,something else
Expand Down
22 changes: 13 additions & 9 deletions openstack-prov/oscliapi/mex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package oscli

import (
"fmt"
"github.com/rs/xid"
//"github.com/rs/xid"
"os"
"strings"
"testing"
Expand All @@ -19,8 +19,9 @@ func TestCreateMEXAgent(t *testing.T) {
if mexTestInfra1 == "" {
return
}
guid := xid.New()
agentName = "mex-agent-test-" + guid.String()
//guid := xid.New()
//agentName = "mex-agent-test-" + guid.String()
agentName = "mex-agent-test-1"

// XXX 10.101.X.X/24 is not used. Just place-holder for now.
// id 1 is not used either. DHCP is used.
Expand Down Expand Up @@ -67,8 +68,9 @@ func TestCreateKubernetesMaster(t *testing.T) {
if mexTestInfra1 == "" {
return
}
guid := xid.New()
masterName = "mex-" + roleMaster + "-" + guid.String()
//guid := xid.New()
//masterName = "mex-" + roleMaster + "-" + guid.String()
masterName = "mex-" + roleMaster + "-1"
//Master always has X.X.X.2
err := CreateMEXKVM(masterName, roleMaster, "priv-subnet,mex-k8s-net1,10.101.X.0/24", test1Tags, tenant, 1)
if err != nil {
Expand All @@ -85,8 +87,9 @@ func TestCreateKubernetesNode1(t *testing.T) {
if mexTestInfra1 == "" {
return
}
guid := xid.New()
node1Name = "mex-" + roleNode1 + "-" + guid.String()
//guid := xid.New()
//node1Name = "mex-" + roleNode1 + "-" + guid.String()
node1Name = "mex-" + roleNode1 + "-1"
err := CreateMEXKVM(node1Name, roleNode1, "priv-subnet,mex-k8s-net-1,10.101.X.0/24", test1Tags, tenant, 1)
if err != nil {
t.Errorf("can't create kubernetes node 1, %v", err)
Expand All @@ -101,8 +104,9 @@ func TestCreateKubernetesNode2(t *testing.T) {
if mexTestInfra1 == "" {
return
}
guid := xid.New()
node2Name = "mex-" + roleNode2 + "-" + guid.String()
//guid := xid.New()
//node2Name = "mex-" + roleNode2 + "-" + guid.String()
node2Name = "mex-" + roleNode2 + "-1"
err := CreateMEXKVM(node2Name, roleNode2, "priv-subnet,mex-k8s-net-1,10.101.X.0/24", test1Tags, tenant, 2)
if err != nil {
t.Errorf("can't create kubernetes node 2, %v", err)
Expand Down

0 comments on commit 70b8c75

Please sign in to comment.