Skip to content

Commit

Permalink
Add NetworkMapping section to importx options.
Browse files Browse the repository at this point in the history
Mapping could be specified by adding something like this
to the options json file:

    "NetworkMapping" : [{
        "name" : "net1",
        "network" : "VM Network"
    }]
  • Loading branch information
Vadim Egorov committed Jul 20, 2016
1 parent b5ee639 commit 223168f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
7 changes: 7 additions & 0 deletions govc/importx/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ type Property struct {
Spec *ovf.Property `json:",omitempty"`
}

type Network struct {
Name string
Network string
}

type Options struct {
AllDeploymentOptions []string `json:",omitempty"`
Deployment string
Expand All @@ -47,6 +52,8 @@ type Options struct {

PropertyMapping []Property `json:",omitempty"`

NetworkMapping []Network `json:",omitempty"`

PowerOn bool
InjectOvfEnv bool
WaitForIP bool
Expand Down
46 changes: 30 additions & 16 deletions govc/importx/ovf.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,35 @@ func (cmd *ovfx) Map(op []Property) (p []types.KeyValue) {
return
}

func (cmd *ovfx) NetworkMap(e *ovf.Envelope) (p []types.OvfNetworkMapping) {
finder, err := cmd.DatastoreFlag.Finder()
if err != nil {
return
}

networks := map[string]string{}

if e.Network != nil {
for _, net := range e.Network.Networks {
networks[net.Name] = net.Name
}
}

for _, net := range cmd.Options.NetworkMapping {
networks[net.Name] = net.Network
}

for src, dst := range networks {
if net, err := finder.Network(context.TODO(), dst); err == nil {
p = append(p, types.OvfNetworkMapping{
Name: src,
Network: net.Reference(),
})
}
}
return
}

func (cmd *ovfx) Import(fpath string) (*types.ManagedObjectReference, error) {
o, err := cmd.ReadOvf(fpath)
if err != nil {
Expand Down Expand Up @@ -215,22 +244,7 @@ func (cmd *ovfx) Import(fpath string) (*types.ManagedObjectReference, error) {
DeploymentOption: cmd.Options.Deployment,
Locale: "US"},
PropertyMapping: cmd.Map(cmd.Options.PropertyMapping),
}

if e.Network != nil {
finder, err := cmd.DatastoreFlag.Finder()
if err != nil {
return nil, err
}
for _, n := range e.Network.Networks {
if net, err := finder.Network(context.TODO(), n.Name); err == nil {
cisp.NetworkMapping = append(cisp.NetworkMapping,
types.OvfNetworkMapping{
Name: n.Name,
Network: net.Reference(),
})
}
}
NetworkMapping: cmd.NetworkMap(e),
}

m := object.NewOvfManager(cmd.Client)
Expand Down
7 changes: 7 additions & 0 deletions govc/importx/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ func (cmd *spec) Spec(fpath string) error {
WaitForIP: false,
InjectOvfEnv: false,
PropertyMapping: cmd.Map(e)}

if e.Network != nil {
for _, net := range e.Network.Networks {
o.NetworkMapping = append(o.NetworkMapping, Network{net.Name, ""})
}
}

if cmd.verbose {
o.AllDeploymentOptions = deploymentOptions
o.AllDiskProvisioningOptions = allDiskProvisioningOptions
Expand Down

0 comments on commit 223168f

Please sign in to comment.