This repository has been archived by the owner on Jul 6, 2022. It is now read-only.
/
provision.go
83 lines (80 loc) · 1.8 KB
/
provision.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
package main
import (
"fmt"
"time"
"github.com/Azure/open-service-broker-azure/pkg/client"
log "github.com/Sirupsen/logrus"
"github.com/urfave/cli"
)
func provision(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)
serviceID := c.String(flagServiceID)
if serviceID == "" {
return fmt.Errorf("--%s is a required flag", flagServiceID)
}
planID := c.String(flagPlanID)
if planID == "" {
return fmt.Errorf("--%s is a required flag", flagPlanID)
}
params, err := parseParams(c)
if err != nil {
return err
}
instanceID, err := client.Provision(
useSSL,
skipCertValidation,
host,
port,
username,
password,
serviceID,
planID,
params,
)
if err != nil {
log.Fatal(err)
}
fmt.Printf("\nProvisioning 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.OperationProvisioning,
)
if err != nil {
return fmt.Errorf("error polling for provisioning status: %s", err)
}
switch result {
case client.OperationStateInProgress:
fmt.Print(".")
case client.OperationStateSucceeded:
fmt.Printf(
"\n\nService instance %s has been successfully provisioned\n\n",
instanceID,
)
return nil
case client.OperationStateFailed:
return fmt.Errorf(
"Provisioning service instance %s has failed",
instanceID,
)
default:
return fmt.Errorf("Unrecognized operation status: %s", result)
}
}
}
return nil
}