This repository has been archived by the owner on Jul 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 99
/
update.go
84 lines (81 loc) · 1.82 KB
/
update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"fmt"
"time"
"github.com/Azure/open-service-broker-azure/pkg/client"
log "github.com/Sirupsen/logrus"
"github.com/urfave/cli"
)
func update(c *cli.Context) error {
useSSL := c.GlobalBool(flagSSL)
skipCertValidation := c.GlobalBool(flagInsecure)
host := c.GlobalString(flagHost)
port := c.GlobalInt(flagPort)
username := c.GlobalString(flagUsername)
password := c.GlobalString(flagPassword)
instanceID := c.String(flagInstanceID)
if instanceID == "" {
return fmt.Errorf("--%s is a required flag", flagInstanceID)
}
serviceID := c.String(flagServiceID)
if serviceID == "" {
return fmt.Errorf("--%s is a required flag", flagServiceID)
}
planID := c.String(flagPlanID)
params, err := parseParams(c)
if err != nil {
return err
}
if err := client.Update(
useSSL,
skipCertValidation,
host,
port,
username,
password,
instanceID,
serviceID,
planID,
params,
); err != nil {
log.Fatal(err)
}
fmt.Printf("\nUpdating service instance %s\n\n", instanceID)
if c.Bool(flagPoll) {
ticker := time.NewTicker(time.Second * 5)
defer ticker.Stop()
for range ticker.C {
result, err := client.Poll(
useSSL,
skipCertValidation,
host,
port,
username,
password,
instanceID,
client.OperationUpdating,
)
if err != nil {
return fmt.Errorf("error polling for updating status: %s", err)
}
switch result {
case client.OperationStateInProgress:
fmt.Print(".")
case client.OperationStateSucceeded:
fmt.Printf(
"\n\nService instance %s has been successfully updated\n\n",
instanceID,
)
return nil
case client.OperationStateFailed:
return fmt.Errorf(
"Updating service instance %s has failed",
instanceID,
)
default:
return fmt.Errorf("Unrecognized operation status: %s", result)
}
}
}
return nil
}