func (c SoftLayerCreator) Create(agentID string, stemcell bslcstem.Stemcell, cloudProps VMCloudProperties, networks Networks, env Environment) (VM, error) { virtualGuestTemplate := sldatatypes.SoftLayer_Virtual_Guest_Template{ Hostname: agentID, Domain: cloudProps.Domain, StartCpus: cloudProps.StartCpus, MaxMemory: cloudProps.MaxMemory, Datacenter: sldatatypes.Datacenter{ Name: cloudProps.Datacenter.Name, }, BlockDeviceTemplateGroup: &sldatatypes.BlockDeviceTemplateGroup{ GlobalIdentifier: stemcell.Uuid(), }, SshKeys: cloudProps.SshKeys, HourlyBillingFlag: true, // Needed for ephemeral disk LocalDiskFlag: true, } virtualGuestService, err := c.softLayerClient.GetSoftLayer_Virtual_Guest_Service() if err != nil { return SoftLayerVM{}, bosherr.WrapError(err, "Creating VirtualGuestService from SoftLayer client") } virtualGuest, err := virtualGuestService.CreateObject(virtualGuestTemplate) if err != nil { return SoftLayerVM{}, bosherr.WrapError(err, "Creating VirtualGuest from SoftLayer client") } //TODO: need to find or ensure the name for the ephemeral disk for SoftLayer VG disks := DisksSpec{Ephemeral: "/dev/xvdc"} agentEnv := NewAgentEnvForVM(agentID, strconv.Itoa(virtualGuest.Id), networks, disks, env, c.agentOptions) metadata, err := json.Marshal(agentEnv) if err != nil { return SoftLayerVM{}, bosherr.WrapError(err, "Marshalling agent environment metadata") } err = bslcommon.ConfigureMetadataOnVirtualGuest(c.softLayerClient, virtualGuest.Id, string(metadata), bslcommon.TIMEOUT, bslcommon.POLLING_INTERVAL) if err != nil { return SoftLayerVM{}, bosherr.WrapError(err, fmt.Sprintf("Configuring metadata on VirtualGuest `%d`", virtualGuest.Id)) } err = bslcommon.AttachEphemeralDiskToVirtualGuest(c.softLayerClient, virtualGuest.Id, cloudProps.EphemeralDiskSize, bslcommon.TIMEOUT, bslcommon.POLLING_INTERVAL) if err != nil { return SoftLayerVM{}, bosherr.WrapError(err, fmt.Sprintf("Attaching ephemeral disk to VirtualGuest `%d`", virtualGuest.Id)) } agentEnvService := c.agentEnvServiceFactory.New(virtualGuest.Id) vm := NewSoftLayerVM(virtualGuest.Id, c.softLayerClient, util.GetSshClient(), agentEnvService, c.logger) return vm, nil }
func (f SoftLayerFinder) Find(vmID int) (VM, bool, error) { virtualGuestService, err := f.softLayerClient.GetSoftLayer_Virtual_Guest_Service() if err != nil { return SoftLayerVM{}, false, bosherr.WrapError(err, "Creating SoftLayer Virtual Guest Service from client") } virtualGuest, err := virtualGuestService.GetObject(vmID) if err != nil { return SoftLayerVM{}, false, bosherr.WrapErrorf(err, "Finding SoftLayer Virtual Guest with id `%d`", vmID) } vm, found := SoftLayerVM{}, true if virtualGuest.Id == vmID { vm = NewSoftLayerVM(vmID, f.softLayerClient, util.GetSshClient(), f.agentEnvServiceFactory.New(vmID), f.logger) } else { found = false } return vm, found, nil }