Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Commit

Permalink
vms: add networks (-w) flag
Browse files Browse the repository at this point in the history
Change-Id: I28c52d28eb25412940b599d8bbf900ded7e76c69
  • Loading branch information
molteanu committed Apr 1, 2016
1 parent b1a4b1e commit d0ef304
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions photon/cli/command/vms.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/vmware/photon-controller-cli/Godeps/_workspace/src/github.com/codegangsta/cli"
"github.com/vmware/photon-controller-cli/Godeps/_workspace/src/github.com/vmware/photon-controller-go-sdk/photon"
"regexp"
)

// Creates a cli.Command for vm
Expand Down Expand Up @@ -76,6 +77,10 @@ func GetVMCommand() cli.Command {
Name: "affinities, a",
Usage: "VM Locality(kind id)",
},
cli.StringFlag{
Name: "networks, w",
Usage: "VM Networks(id1, id2)",
},
cli.StringFlag{
Name: "tenant, t",
Usage: "Tenant name",
Expand Down Expand Up @@ -333,6 +338,7 @@ func createVM(c *cli.Context) error {
affinities := c.String("affinities")
tenantName := c.String("tenant")
projectName := c.String("project")
networks := c.String("networks")

client.Esxclient, err = client.GetClient(c.GlobalIsSet("non-interactive"))
if err != nil {
Expand Down Expand Up @@ -390,13 +396,19 @@ func createVM(c *cli.Context) error {
return err
}

var networkList []string
if (len(networks) > 0) {
networkList = regexp.MustCompile(`\s*,\s*`).Split(networks, -1)
}

vmSpec := photon.VmCreateSpec{}
vmSpec.Name = name
vmSpec.Flavor = flavor
vmSpec.SourceImageID = imageID
vmSpec.AttachedDisks = disksList
vmSpec.Affinities = affinitiesList
vmSpec.Environment = environmentMap
vmSpec.Networks = networkList

if !c.GlobalIsSet("non-interactive") {
fmt.Printf("\nCreating VM: %s(%s)\n", vmSpec.Name, vmSpec.Flavor)
Expand Down
1 change: 1 addition & 0 deletions photon/cli/command/vms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func TestCreateDeleteVM(t *testing.T) {
set.String("tenant", "fake_tenant_name", "tenant name")
set.String("project", "fake_project_name", "project name")
set.String("environment", "vm:fake_environment", "environment")
set.String("network", "networkid1", "VM Network")
cxt := cli.NewContext(nil, set, globalCtx)

err = createVM(cxt)
Expand Down

0 comments on commit d0ef304

Please sign in to comment.