本文整理汇总了Golang中github.com/scaleway/scaleway-cli/pkg/api.ScalewayAPI类的典型用法代码示例。如果您正苦于以下问题:Golang ScalewayAPI类的具体用法?Golang ScalewayAPI怎么用?Golang ScalewayAPI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ScalewayAPI类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: deleteRunningServer
// deleteRunningServer terminates the server and waits until it is removed.
func deleteRunningServer(scaleway *api.ScalewayAPI, server *api.ScalewayServer) error {
err := scaleway.PostServerAction(server.Identifier, "terminate")
if err != nil {
if serr, ok := err.(api.ScalewayAPIError); ok {
if serr.StatusCode == 404 {
return nil
}
}
return err
}
return resource.Retry(20*time.Minute, func() *resource.RetryError {
_, err := scaleway.GetServer(server.Identifier)
if err == nil {
return resource.RetryableError(fmt.Errorf("Waiting for server %q to be deleted", server.Identifier))
}
if serr, ok := err.(api.ScalewayAPIError); ok {
if serr.StatusCode == 404 {
return nil
}
}
return resource.RetryableError(err)
})
}
开发者ID:ryane,项目名称:terraform,代码行数:30,代码来源:helpers.go
示例2: waitForServerState
func waitForServerState(scaleway *api.ScalewayAPI, serverID, targetState string) error {
pending := []string{}
for _, state := range allStates {
if state != targetState {
pending = append(pending, state)
}
}
stateConf := &resource.StateChangeConf{
Pending: pending,
Target: []string{targetState},
Refresh: func() (interface{}, string, error) {
s, err := scaleway.GetServer(serverID)
if err == nil {
return 42, s.State, nil
}
if serr, ok := err.(api.ScalewayAPIError); ok {
if serr.StatusCode == 404 {
return 42, "stopped", nil
}
}
return 42, s.State, err
},
Timeout: 60 * time.Minute,
MinTimeout: 5 * time.Second,
Delay: 5 * time.Second,
}
_, err := stateConf.WaitForState()
return err
}
开发者ID:hashicorp,项目名称:terraform,代码行数:32,代码来源:helpers.go
示例3: DetachIP
// DetachIP detaches an IP from a server
func DetachIP(s *api.ScalewayAPI, ipID string) error {
var update struct {
Address string `json:"address"`
ID string `json:"id"`
Organization string `json:"organization"`
}
ip, err := s.GetIP(ipID)
if err != nil {
return err
}
update.Address = ip.IP.Address
update.ID = ip.IP.ID
update.Organization = ip.IP.Organization
resp, err := s.PutResponse(api.ComputeAPI, fmt.Sprintf("ips/%s", ipID), update)
if err != nil {
return err
}
if resp.StatusCode != http.StatusOK {
return err
}
resp.Body.Close()
return nil
}
开发者ID:Originate,项目名称:terraform,代码行数:26,代码来源:helpers.go
示例4: deleteStoppedServer
// deleteStoppedServer needs to cleanup attached root volumes. this is not done
// automatically by Scaleway
func deleteStoppedServer(scaleway *api.ScalewayAPI, server *api.ScalewayServer) error {
if err := scaleway.DeleteServer(server.Identifier); err != nil {
return err
}
if rootVolume, ok := server.Volumes["0"]; ok {
if err := scaleway.DeleteVolume(rootVolume.Identifier); err != nil {
return err
}
}
return nil
}
开发者ID:ryane,项目名称:terraform,代码行数:14,代码来源:helpers.go
示例5: UpdateScwApiBootscripts
func UpdateScwApiBootscripts(Api *api.ScalewayAPI, cache *Cache) {
for {
logrus.Infof("Fetching bootscripts from the Api...")
bootscripts, err := Api.GetBootscripts()
if err != nil {
logrus.Errorf("Failed to retrieve bootscripts list from the Api: %v", err)
} else {
cache.Api.Bootscripts = bootscripts
logrus.Infof("Bootscripts fetched: %d bootscripts", len(*bootscripts))
}
time.Sleep(5 * time.Minute)
}
}
开发者ID:scaleway,项目名称:devhub,代码行数:13,代码来源:cron.go
示例6: UpdateScwApiImages
func UpdateScwApiImages(Api *api.ScalewayAPI, cache *Cache) {
for {
logrus.Infof("Fetching images from the Api...")
images, err := Api.GetImages()
if err != nil {
logrus.Errorf("Failed to retrieve images list from the Api: %v", err)
} else {
cache.Api.Images = images
logrus.Infof("Images fetched: %d images", len(*images))
cache.MapImages()
}
time.Sleep(5 * time.Minute)
}
}
开发者ID:scaleway,项目名称:devhub,代码行数:14,代码来源:cron.go
示例7: deleteServerSafe
func deleteServerSafe(s *api.ScalewayAPI, serverID string) error {
server, err := s.GetServer(serverID)
if err != nil {
return err
}
if server.State != "stopped" {
if err := s.PostServerAction(serverID, "poweroff"); err != nil {
return err
}
if err := waitForServerState(s, serverID, "stopped"); err != nil {
return err
}
}
if err := s.DeleteServer(serverID); err != nil {
return err
}
if rootVolume, ok := server.Volumes["0"]; ok {
if err := s.DeleteVolume(rootVolume.Identifier); err != nil {
return err
}
}
return nil
}
开发者ID:mhlias,项目名称:terraform,代码行数:26,代码来源:helpers.go
示例8: deleteRunningServer
// deleteRunningServer terminates the server and waits until it is removed.
func deleteRunningServer(scaleway *api.ScalewayAPI, server *api.ScalewayServer) error {
err := scaleway.PostServerAction(server.Identifier, "terminate")
if err != nil {
if serr, ok := err.(api.ScalewayAPIError); ok {
if serr.StatusCode == 404 {
return nil
}
}
return err
}
return waitForServerState(scaleway, server.Identifier, "stopped")
}
开发者ID:hashicorp,项目名称:terraform,代码行数:16,代码来源:helpers.go
示例9: waitForServerState
func waitForServerState(scaleway *api.ScalewayAPI, serverID, targetState string) error {
return resource.Retry(20*time.Minute, func() *resource.RetryError {
s, err := scaleway.GetServer(serverID)
if err != nil {
return resource.NonRetryableError(err)
}
if s.State != targetState {
return resource.RetryableError(fmt.Errorf("Waiting for server to enter %q state", targetState))
}
return nil
})
}
开发者ID:paultyng,项目名称:terraform,代码行数:15,代码来源:helpers.go
示例10: waitForServerState
func waitForServerState(s *api.ScalewayAPI, serverID string, targetState string) error {
var server *api.ScalewayServer
var err error
var currentState string
for {
server, err = s.GetServer(serverID)
if err != nil {
return err
}
if currentState != server.State {
log.Printf("[DEBUG] Server changed state to %q\n", server.State)
currentState = server.State
}
if server.State == targetState {
break
}
time.Sleep(1 * time.Second)
}
return nil
}
开发者ID:mhlias,项目名称:terraform,代码行数:23,代码来源:helpers.go
示例11: uploadSSHKeys
// uploadSSHKeys uploads an SSH Key
func uploadSSHKeys(apiConnection *api.ScalewayAPI, newKey string) {
user, err := apiConnection.GetUser()
if err != nil {
logrus.Errorf("Unable to contact ScalewayAPI: %s", err)
} else {
user.SSHPublicKeys = append(user.SSHPublicKeys, api.ScalewayKeyDefinition{Key: strings.Trim(newKey, "\n")})
SSHKeys := api.ScalewayUserPatchSSHKeyDefinition{
SSHPublicKeys: user.SSHPublicKeys,
}
userID, err := apiConnection.GetUserID()
if err != nil {
logrus.Errorf("Unable to get userID: %s", err)
} else {
if err = apiConnection.PatchUserSSHKey(userID, SSHKeys); err != nil {
logrus.Errorf("Unable to patch SSHkey: %v", err)
}
}
}
}
开发者ID:ebfe,项目名称:scaleway-cli,代码行数:22,代码来源:login.go
示例12: runUserdata
func runUserdata(cmd *Command, args []string) error {
if userdataHelp {
return cmd.PrintUsage()
}
if len(args) < 1 {
return cmd.PrintShortUsage()
}
ctx := cmd.GetContext(args)
var Api *api.ScalewayAPI
var err error
var serverID string
if args[0] == "local" {
Api, err = api.NewScalewayAPI("", "", "", "")
if err != nil {
return err
}
Api.EnableMetadataAPI()
} else {
if ctx.API == nil {
return fmt.Errorf("You need to login first: 'scw login'")
}
serverID = ctx.API.GetServerID(args[0])
Api = ctx.API
}
switch len(args) {
case 1:
// List userdata
res, err := Api.GetUserdatas(serverID)
if err != nil {
return err
}
for _, key := range res.UserData {
fmt.Fprintln(ctx.Stdout, key)
}
default:
parts := strings.Split(args[1], "=")
key := parts[0]
switch len(parts) {
case 1:
// Get userdatas
res, err := Api.GetUserdata(serverID, key)
if err != nil {
return err
}
fmt.Fprintf(ctx.Stdout, "%s\n", res.String())
default:
value := parts[1]
if value != "" {
// Set userdata
err := Api.PatchUserdata(serverID, key, []byte(value))
if err != nil {
return err
}
fmt.Fprintln(ctx.Stdout, key)
} else {
// Delete userdata
err := Api.DeleteUserdata(serverID, key)
if err != nil {
return err
}
}
}
}
return nil
}
开发者ID:meyskens,项目名称:scaleway-cli,代码行数:68,代码来源:x_userdata.go
示例13: runUserdata
func runUserdata(cmd *Command, args []string) error {
if userdataHelp {
return cmd.PrintUsage()
}
if len(args) < 1 {
return cmd.PrintShortUsage()
}
metadata := false
ctx := cmd.GetContext(args)
var API *api.ScalewayAPI
var err error
var serverID string
if args[0] == "local" {
API, err = api.NewScalewayAPI("", "", scwversion.UserAgent(), *flRegion)
if err != nil {
return err
}
metadata = true
} else {
if ctx.API == nil {
return fmt.Errorf("You need to login first: 'scw login'")
}
serverID, err = ctx.API.GetServerID(args[0])
if err != nil {
return err
}
API = ctx.API
}
switch len(args) {
case 1:
// List userdata
res, errGetUserdata := API.GetUserdatas(serverID, metadata)
if errGetUserdata != nil {
return errGetUserdata
}
for _, key := range res.UserData {
fmt.Fprintln(ctx.Stdout, key)
}
default:
parts := strings.Split(args[1], "=")
key := parts[0]
switch len(parts) {
case 1:
// Get userdatas
res, errGetUserdata := API.GetUserdata(serverID, key, metadata)
if errGetUserdata != nil {
return errGetUserdata
}
fmt.Fprintf(ctx.Stdout, "%s\n", res.String())
default:
value := args[1][len(parts[0])+1:]
if value != "" {
var data []byte
// Set userdata
if value[0] == '@' {
if len(value) > 1 && value[1] == '~' {
home, err := config.GetHomeDir()
if err != nil {
return err
}
value = "@" + home + value[2:]
}
data, err = ioutil.ReadFile(value[1:])
if err != nil {
return err
}
} else {
data = []byte(value)
}
err := API.PatchUserdata(serverID, key, data, metadata)
if err != nil {
return err
}
fmt.Fprintln(ctx.Stdout, key)
} else {
// Delete userdata
err := API.DeleteUserdata(serverID, key, metadata)
if err != nil {
return err
}
}
}
}
return nil
}
开发者ID:QuentinPerez,项目名称:scaleway-cli,代码行数:86,代码来源:x_userdata.go
示例14: SetupLogger
func SetupLogger(s *api.ScalewayAPI) {
s.Logger = NewCliLogger(s)
}
开发者ID:QuentinPerez,项目名称:scaleway-cli,代码行数:3,代码来源:clilogger.go
注:本文中的github.com/scaleway/scaleway-cli/pkg/api.ScalewayAPI类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论