本文整理汇总了Golang中github.com/maximilien/softlayer-go/softlayer.Client类的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: WaitForVirtualGuest
func WaitForVirtualGuest(softLayerClient sl.Client, virtualGuestId int, targetState string, timeout, pollingInterval time.Duration) error {
virtualGuestService, err := softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return bosherr.WrapError(err, "Creating VirtualGuestService from SoftLayer client")
}
retryCount := 0
totalTime := time.Duration(0)
for totalTime < timeout {
vgPowerState, err := virtualGuestService.GetPowerState(virtualGuestId)
if err != nil {
if retryCount > MAX_RETRY_COUNT {
return bosherr.WrapError(err, "Getting active transactions from SoftLayer client")
} else {
retryCount += 1
continue
}
}
if vgPowerState.KeyName == targetState {
return nil
}
totalTime += pollingInterval
time.Sleep(pollingInterval)
}
return bosherr.Errorf("Waiting for virtual guest with ID '%d' to have be in state '%s'", virtualGuestId, targetState)
}
示例2: WaitForVirtualGuestToTargetState
func WaitForVirtualGuestToTargetState(softLayerClient sl.Client, virtualGuestId int, targetState string, logger boshlog.Logger) error {
virtualGuestService, err := softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return bosherr.WrapError(err, "Creating VirtualGuestService from SoftLayer client")
}
getTargetStateRetryable := boshretry.NewRetryable(
func() (bool, error) {
vgPowerState, err := virtualGuestService.GetPowerState(virtualGuestId)
if err != nil {
return false, bosherr.WrapErrorf(err, "Getting PowerState from vitrual guest %d", virtualGuestId)
} else {
if strings.Contains(vgPowerState.KeyName, targetState) {
return false, nil
}
return true, nil
}
})
timeService := clock.NewClock()
timeoutRetryStrategy := boshretry.NewTimeoutRetryStrategy(TIMEOUT, POLLING_INTERVAL, getTargetStateRetryable, timeService, logger)
err = timeoutRetryStrategy.Try()
if err != nil {
return bosherr.Errorf("Waiting for virtual guest with ID '%d' to have be in state '%s'", virtualGuestId, targetState)
}
return nil
}
示例3: WaitForVirtualGuestToHaveNoRunningTransaction
func WaitForVirtualGuestToHaveNoRunningTransaction(softLayerClient sl.Client, virtualGuestId int, logger boshlog.Logger) error {
virtualGuestService, err := softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return bosherr.WrapError(err, "Creating VirtualGuestService from SoftLayer client")
}
totalTime := time.Duration(0)
for totalTime < TIMEOUT {
activeTransactions, err := virtualGuestService.GetActiveTransactions(virtualGuestId)
if err != nil {
return bosherr.WrapErrorf(err, "Getting active transaction against vitrual guest %d", virtualGuestId)
}
if len(activeTransactions) == 0 {
return nil
}
totalTime += POLLING_INTERVAL
time.Sleep(POLLING_INTERVAL)
}
return bosherr.Errorf("Waiting for virtual guest with ID '%d' to have no active transactions", virtualGuestId)
}
示例4: WaitForVirtualGuestToHaveNoRunningTransactions
func WaitForVirtualGuestToHaveNoRunningTransactions(softLayerClient sl.Client, virtualGuestId int, timeout, pollingInterval time.Duration) error {
virtualGuestService, err := softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return bosherr.WrapError(err, "Creating VirtualGuestService from SoftLayer client")
}
retryCount := 0
totalTime := time.Duration(0)
for totalTime < timeout {
activeTransactions, err := virtualGuestService.GetActiveTransactions(virtualGuestId)
if err != nil {
if retryCount > MAX_RETRY_COUNT {
return bosherr.WrapError(err, "Getting active transactions from SoftLayer client")
} else {
retryCount += 1
continue
}
}
if len(activeTransactions) == 0 {
return nil
}
totalTime += pollingInterval
time.Sleep(pollingInterval)
}
return bosherr.Errorf("Waiting for virtual guest with ID '%d' to have no active transactions", virtualGuestId)
}
示例5: AttachEphemeralDiskToVirtualGuest
func AttachEphemeralDiskToVirtualGuest(softLayerClient sl.Client, virtualGuestId int, diskSize int, logger boshlog.Logger) error {
err := WaitForVirtualGuestLastCompleteTransaction(softLayerClient, virtualGuestId, "Service Setup")
if err != nil {
return bosherr.WrapErrorf(err, "Waiting for VirtualGuest `%d` has Service Setup transaction complete", virtualGuestId)
}
err = WaitForVirtualGuestToHaveNoRunningTransactions(softLayerClient, virtualGuestId)
if err != nil {
return bosherr.WrapErrorf(err, "Waiting for VirtualGuest `%d` to have no pending transactions", virtualGuestId)
}
service, err := softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return bosherr.WrapErrorf(err, "Attaching ephemeral disk to VirtualGuest `%d`", virtualGuestId)
}
err = service.AttachEphemeralDisk(virtualGuestId, diskSize)
if err != nil {
return bosherr.WrapErrorf(err, "Attaching ephemeral disk to VirtualGuest `%d`", virtualGuestId)
}
err = WaitForVirtualGuestToHaveRunningTransaction(softLayerClient, virtualGuestId, logger)
if err != nil {
return bosherr.WrapErrorf(err, "Waiting for VirtualGuest `%d` to launch transaction", virtualGuestId)
}
err = WaitForVirtualGuestLastCompleteTransaction(softLayerClient, virtualGuestId, "Cloud Instance Upgrade")
if err != nil {
return bosherr.WrapErrorf(err, "Waiting for VirtualGuest `%d` has Cloud Instance Upgrade transaction complete", virtualGuestId)
}
return nil
}
示例6: WaitForVirtualGuestIsNotPingable
func WaitForVirtualGuestIsNotPingable(softLayerClient sl.Client, virtualGuestId int, logger boshlog.Logger) error {
virtualGuestService, err := softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return bosherr.WrapError(err, "Creating VirtualGuestService from SoftLayer client")
}
checkPingableRetryable := boshretry.NewRetryable(
func() (bool, error) {
state, err := virtualGuestService.IsPingable(virtualGuestId)
if err != nil {
return false, bosherr.WrapErrorf(err, "Checking pingable against vitrual guest %d", virtualGuestId)
} else {
return state, nil
}
})
timeService := clock.NewClock()
timeoutRetryStrategy := boshretry.NewTimeoutRetryStrategy(TIMEOUT, POLLING_INTERVAL, checkPingableRetryable, timeService, logger)
err = timeoutRetryStrategy.Try()
if err != nil {
return bosherr.Errorf("Waiting for virtual guest with ID '%d' is not pingable", virtualGuestId)
}
return nil
}
示例7: postCheckActiveTransactionsForOSReload
func (vm SoftLayerVM) postCheckActiveTransactionsForOSReload(softLayerClient sl.Client) error {
virtualGuestService, err := softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return bosherr.WrapError(err, "Creating VirtualGuestService from SoftLayer client")
}
totalTime := time.Duration(0)
for totalTime < bslcommon.TIMEOUT {
activeTransactions, err := virtualGuestService.GetActiveTransactions(vm.ID())
if err != nil {
return bosherr.WrapError(err, "Getting active transactions from SoftLayer client")
}
if len(activeTransactions) > 0 {
vm.logger.Info(SOFTLAYER_VM_OS_RELOAD_TAG, "OS Reload transaction started")
break
}
totalTime += bslcommon.POLLING_INTERVAL
time.Sleep(bslcommon.POLLING_INTERVAL)
}
if totalTime >= bslcommon.TIMEOUT {
return errors.New(fmt.Sprintf("Waiting for OS Reload transaction to start TIME OUT!"))
}
err = bslcommon.WaitForVirtualGuest(vm.softLayerClient, vm.ID(), "RUNNING")
if err != nil {
return bosherr.WrapError(err, fmt.Sprintf("PowerOn failed with VirtualGuest id %d", vm.ID()))
}
vm.logger.Info(SOFTLAYER_VM_OS_RELOAD_TAG, fmt.Sprintf("The virtual guest %d is powered on", vm.ID()))
return nil
}
示例8: WaitForVirtualGuestToHaveNoRunningTransaction
func WaitForVirtualGuestToHaveNoRunningTransaction(softLayerClient sl.Client, virtualGuestId int, logger boshlog.Logger) error {
virtualGuestService, err := softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return bosherr.WrapError(err, "Creating VirtualGuestService from SoftLayer client")
}
runningTransactionsRetryable := boshretry.NewRetryable(
func() (bool, error) {
activeTransactions, err := virtualGuestService.GetActiveTransactions(virtualGuestId)
if err != nil {
return false, bosherr.WrapErrorf(err, "Getting active transaction against vitrual guest %d", virtualGuestId)
} else {
if len(activeTransactions) == 0 {
return false, nil
}
return true, nil
}
})
timeService := clock.NewClock()
timeoutRetryStrategy := boshretry.NewTimeoutRetryStrategy(TIMEOUT, POLLING_INTERVAL, runningTransactionsRetryable, timeService, logger)
err = timeoutRetryStrategy.Try()
if err != nil {
return bosherr.Errorf("Waiting for virtual guest with ID '%d' to have no active transactions", virtualGuestId)
}
return nil
}
示例9: WaitForVirtualGuestUpgradeComplete
func WaitForVirtualGuestUpgradeComplete(softLayerClient sl.Client, virtualGuestId int) error {
virtualGuestService, err := softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return bosherr.WrapError(err, "Creating VirtualGuestService from SoftLayer client")
}
totalTime := time.Duration(0)
for totalTime < TIMEOUT {
lastTransaction, err := virtualGuestService.GetLastTransaction(virtualGuestId)
if err != nil {
return bosherr.WrapErrorf(err, "Getting Last Complete Transaction for virtual guest with ID '%d'", virtualGuestId)
}
if strings.Contains(lastTransaction.TransactionGroup.Name, "Cloud Migrate") && strings.Contains(lastTransaction.TransactionStatus.FriendlyName, "Complete") {
return nil
}
if strings.Contains(lastTransaction.TransactionGroup.Name, "Cloud Instance Upgrade") && strings.Contains(lastTransaction.TransactionStatus.FriendlyName, "Complete") {
return nil
}
totalTime += POLLING_INTERVAL
time.Sleep(POLLING_INTERVAL)
}
return bosherr.Errorf("Waiting for virtual guest with ID '%d' to update complete", virtualGuestId)
}
示例10: GetObjectDetailsOnVirtualGuest
func GetObjectDetailsOnVirtualGuest(softLayerClient sl.Client, virtualGuestId int) (datatypes.SoftLayer_Virtual_Guest, error) {
virtualGuestService, err := softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return datatypes.SoftLayer_Virtual_Guest{}, bosherr.WrapError(err, "Cannot get softlayer virtual guest service.")
}
virtualGuest, err := virtualGuestService.GetObject(virtualGuestId)
if err != nil {
return datatypes.SoftLayer_Virtual_Guest{}, bosherr.WrapErrorf(err, "Cannot get virtual guest with id: %d", virtualGuestId)
}
return virtualGuest, nil
}
示例11: ConfigureMetadataDiskOnVirtualGuest
func ConfigureMetadataDiskOnVirtualGuest(softLayerClient sl.Client, virtualGuestId int) error {
virtualGuestService, err := softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return bosherr.WrapError(err, "Creating VirtualGuestService from SoftLayer client")
}
_, err = virtualGuestService.ConfigureMetadataDisk(virtualGuestId)
if err != nil {
return bosherr.WrapError(err, fmt.Sprintf("Configuring metadata on VirtualGuest `%d`", virtualGuestId))
}
return nil
}
示例12: GetObjectDetailsOnStorage
func GetObjectDetailsOnStorage(softLayerClient sl.Client, volumeId int) (datatypes.SoftLayer_Network_Storage, error) {
networkStorageService, err := softLayerClient.GetSoftLayer_Network_Storage_Service()
if err != nil {
return datatypes.SoftLayer_Network_Storage{}, bosherr.WrapError(err, "Cannot get network storage service.")
}
volume, err := networkStorageService.GetIscsiVolume(volumeId)
if err != nil {
return datatypes.SoftLayer_Network_Storage{}, bosherr.WrapErrorf(err, "Cannot get iSCSI volume with id: %d", volumeId)
}
return volume, nil
}
示例13: AttachEphemeralDiskToVirtualGuest
func AttachEphemeralDiskToVirtualGuest(softLayerClient sl.Client, virtualGuestId int, diskSize int, logger boshlog.Logger) error {
err := WaitForVirtualGuestLastCompleteTransaction(softLayerClient, virtualGuestId, "Service Setup")
if err != nil {
return bosherr.WrapErrorf(err, "Waiting for VirtualGuest `%d` has Service Setup transaction complete", virtualGuestId)
}
err = WaitForVirtualGuestToHaveNoRunningTransactions(softLayerClient, virtualGuestId)
if err != nil {
return bosherr.WrapErrorf(err, "Waiting for VirtualGuest `%d` to have no pending transactions", virtualGuestId)
}
service, err := softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return bosherr.WrapErrorf(err, "Attaching ephemeral disk to VirtualGuest `%d`", virtualGuestId)
}
receipt, err := service.AttachEphemeralDisk(virtualGuestId, diskSize)
if err != nil {
if !strings.Contains(err.Error(), "HTTP error code") {
return err
}
}
if receipt.OrderId == 0 {
return nil
}
err = WaitForVirtualGuestToHaveRunningTransaction(softLayerClient, virtualGuestId, logger)
if err != nil {
return bosherr.WrapErrorf(err, "Waiting for VirtualGuest `%d` to launch transaction", virtualGuestId)
}
err = WaitForVirtualGuestToHaveNoRunningTransaction(softLayerClient, virtualGuestId, logger)
if err != nil {
return bosherr.WrapErrorf(err, "Waiting for VirtualGuest `%d` no transcation in progress", virtualGuestId)
}
err = WaitForVirtualGuestUpgradeComplete(softLayerClient, virtualGuestId)
if err != nil {
return bosherr.WrapErrorf(err, "Waiting for VirtualGuest `%d` upgrade complete", virtualGuestId)
}
err = WaitForVirtualGuest(softLayerClient, virtualGuestId, "RUNNING")
if err != nil {
return bosherr.WrapErrorf(err, "Waiting for VirtualGuest `%d`", virtualGuestId)
}
return nil
}
示例14: SetMetadataOnVirtualGuest
func SetMetadataOnVirtualGuest(softLayerClient sl.Client, virtualGuestId int, metadata string) error {
virtualGuestService, err := softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return bosherr.WrapError(err, "Creating VirtualGuestService from SoftLayer client")
}
success, err := virtualGuestService.SetMetadata(virtualGuestId, metadata)
if err != nil {
return bosherr.WrapError(err, fmt.Sprintf("Setting metadata on VirtualGuest `%d`", virtualGuestId))
}
if !success {
return bosherr.WrapError(err, fmt.Sprintf("Failed to set metadata on VirtualGuest `%d`", virtualGuestId))
}
return nil
}
示例15: WaitForVirtualGuest
func WaitForVirtualGuest(softLayerClient sl.Client, virtualGuestId int, targetState string) error {
virtualGuestService, err := softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return bosherr.WrapError(err, "Creating VirtualGuestService from SoftLayer client")
}
totalTime := time.Duration(0)
for totalTime < TIMEOUT {
vgPowerState, err := virtualGuestService.GetPowerState(virtualGuestId)
if err != nil {
return bosherr.WrapErrorf(err, "Getting Power State for virtual guest with ID '%d'", virtualGuestId)
}
if strings.Contains(vgPowerState.KeyName, targetState) {
return nil
}
totalTime += POLLING_INTERVAL
time.Sleep(POLLING_INTERVAL)
}
return bosherr.Errorf("Waiting for virtual guest with ID '%d' to have be in state '%s'", virtualGuestId, targetState)
}