diff --git a/drivers/softlayer/driver.go b/drivers/softlayer/driver.go index 6cc313d3..46e9dc49 100644 --- a/drivers/softlayer/driver.go +++ b/drivers/softlayer/driver.go @@ -48,6 +48,8 @@ type deviceConfig struct { HourlyBilling bool LocalDisk bool PrivateNet bool + PublicVLAN int + PrivateVLAN int } func init() { @@ -182,6 +184,18 @@ func GetCreateFlags() []cli.Flag { Usage: "OS image for machine", Value: "UBUNTU_LATEST", }, + cli.IntFlag{ + EnvVar: "SOFTLAYER_PUBLIC_VLAN_ID", + Name: "softlayer-public-vlan-id", + Usage: "", + Value: 0, + }, + cli.IntFlag{ + EnvVar: "SOFTLAYER_PRIVATE_VLAN_ID", + Name: "softlayer-private-vlan-id", + Usage: "", + Value: 0, + }, } } @@ -200,6 +214,16 @@ func validateDeviceConfig(c *deviceConfig) error { return fmt.Errorf("Missing required setting - --softlayer-cpu") } + if c.PrivateNet && c.PublicVLAN > 0 { + return fmt.Errorf("Can not specify both --softlayer-private-net-only and --softlayer-public-vlan-id") + } + if c.PublicVLAN > 0 && c.PrivateVLAN == 0 { + return fmt.Errorf("Missing required setting - --softlayer-private-vlan-id (because --softlayer-public-vlan-id is specified)") + } + if c.PrivateVLAN > 0 && !c.PrivateNet && c.PublicVLAN == 0 { + return fmt.Errorf("Missing required setting - --softlayer-public-vlan-id (because --softlayer-private-vlan-id is specified)") + } + return nil } @@ -248,6 +272,8 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { HourlyBilling: flags.Bool("softlayer-hourly-billing"), Image: flags.String("softlayer-image"), Region: flags.String("softlayer-region"), + PublicVLAN: flags.Int("softlayer-public-vlan-id"), + PrivateVLAN: flags.Int("softlayer-private-vlan-id"), } return validateDeviceConfig(d.deviceConfig) } @@ -383,6 +409,8 @@ func (d *Driver) waitForSetupTransactions() { } func (d *Driver) Create() error { + spec := d.buildHostSpec() + log.Infof("Creating SSH key...") key, err := d.createSSHKey() if err != nil { @@ -392,7 +420,6 @@ func (d *Driver) Create() error { log.Infof("SSH key %s (%d) created in SoftLayer", key.Label, key.Id) d.SSHKeyID = key.Id - spec := d.buildHostSpec() spec.SshKeys = []*SshKey{key} id, err := d.getClient().VirtualGuest().Create(spec) @@ -422,6 +449,21 @@ func (d *Driver) buildHostSpec() *HostSpec { if d.deviceConfig.DiskSize > 0 { spec.BlockDevices = []BlockDevice{{Device: "0", DiskImage: DiskImage{Capacity: d.deviceConfig.DiskSize}}} } + if d.deviceConfig.PublicVLAN > 0 { + spec.PrimaryNetworkComponent = &NetworkComponent{ + NetworkVLAN: &NetworkVLAN{ + Id: d.deviceConfig.PublicVLAN, + }, + } + } + if d.deviceConfig.PrivateVLAN > 0 { + spec.PrimaryBackendNetworkComponent = &NetworkComponent{ + NetworkVLAN: &NetworkVLAN{ + Id: d.deviceConfig.PrivateVLAN, + }, + } + } + log.Debugf("Built host spec %#v", spec) return spec } diff --git a/drivers/softlayer/softlayer.go b/drivers/softlayer/softlayer.go index 3eaca9df..67b77e71 100644 --- a/drivers/softlayer/softlayer.go +++ b/drivers/softlayer/softlayer.go @@ -16,18 +16,28 @@ type Client struct { } type HostSpec struct { - Hostname string `json:"hostname"` - Domain string `json:"domain"` - Cpu int `json:"startCpus"` - Memory int `json:"maxMemory"` - Datacenter Datacenter `json:"datacenter"` - SshKeys []*SshKey `json:"sshKeys"` - BlockDevices []BlockDevice `json:"blockDevices"` - InstallScript string `json:"postInstallScriptUri"` - PrivateNetOnly bool `json:"privateNetworkOnlyFlag"` - Os string `json:"operatingSystemReferenceCode"` - HourlyBilling bool `json:"hourlyBillingFlag"` - LocalDisk bool `json:"localDiskFlag"` + Hostname string `json:"hostname"` + Domain string `json:"domain"` + Cpu int `json:"startCpus"` + Memory int `json:"maxMemory"` + Datacenter Datacenter `json:"datacenter"` + SshKeys []*SshKey `json:"sshKeys"` + BlockDevices []BlockDevice `json:"blockDevices"` + InstallScript string `json:"postInstallScriptUri"` + PrivateNetOnly bool `json:"privateNetworkOnlyFlag"` + Os string `json:"operatingSystemReferenceCode"` + HourlyBilling bool `json:"hourlyBillingFlag"` + LocalDisk bool `json:"localDiskFlag"` + PrimaryNetworkComponent *NetworkComponent `json:"primaryNetworkComponent,omitempty"` + PrimaryBackendNetworkComponent *NetworkComponent `json:"primaryBackendNetworkComponent,omitempty"` +} + +type NetworkComponent struct { + NetworkVLAN *NetworkVLAN `json:"networkVlan"` +} + +type NetworkVLAN struct { + Id int `json:"id"` } type SshKey struct {