This repository has been archived by the owner on Jul 12, 2018. It is now read-only.
/
photon-cli.go
74 lines (61 loc) · 2.33 KB
/
photon-cli.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
package photoncli
import (
"errors"
"gopkg.in/urfave/cli.v2"
"github.com/enaml-ops/omg-cli/plugins/products/bosh-init"
"github.com/enaml-ops/omg-cli/plugins/products/bosh-init/enaml-gen/photoncpi"
"github.com/enaml-ops/omg-cli/utils"
"github.com/enaml-ops/pluginlib/pcli"
"github.com/xchapter7x/lo"
)
func GetFlags() []pcli.Flag {
boshdefaults := boshinit.NewPhotonBoshBase()
boshFlags := boshinit.BoshFlags(boshdefaults)
photonFlags := []pcli.Flag{
pcli.CreateStringFlag("photon-target", "photon api endpoint http://PHOTON_CTRL_IP:9000"),
pcli.CreateStringFlag("photon-user", "api admin user"),
pcli.CreateStringFlag("photon-password", "api admin pass"),
pcli.CreateBoolTFlag("photon-ignore-cert", "setting ignore cert or not"),
pcli.CreateStringFlag("photon-project-id", "the photon project id"),
pcli.CreateStringFlag("photon-machine-type", "photon instance type name", "core-200"),
pcli.CreateStringFlag("photon-network-id", "the network-id to deploy your bosh onto (THIS IS NOT THE NETWORK NAME)"),
}
boshFlags = append(boshFlags, photonFlags...)
return boshFlags
}
func GetAction(boshInitDeploy func(string)) func(c *cli.Context) error {
return func(c *cli.Context) (e error) {
var boshBase *boshinit.BoshBase
var err error
if boshBase, err = boshinit.NewBoshBase(c); err != nil {
lo.G.Error(err.Error())
return err
}
lo.G.Debug("Got boshbase", boshBase)
if err = utils.CheckRequired(c, "photon-target", "photon-project-id", "photon-network-id"); err != nil {
lo.G.Error(err.Error())
return err
}
user := c.IsSet("photon-user")
pass := c.IsSet("photon-password")
if user != pass {
lo.G.Error("--photon-user and --photon-password must be specified together")
return errors.New("--photon-user and --photon-password must be specified together")
}
provider := boshinit.NewPhotonIaaSProvider(&boshinit.PhotonBoshInitConfig{
Photon: photoncpi.Photon{
Target: c.String("photon-target"),
User: c.String("photon-user"),
Password: c.String("photon-password"),
IgnoreCert: c.Bool("photon-ignore-cert"),
Project: c.String("photon-project-id"),
},
NetworkName: c.String("photon-network-id"),
MachineType: c.String("photon-machine-type"),
}, boshBase)
if err = boshBase.HandleDeployment(provider, boshInitDeploy); err != nil {
return err
}
return nil
}
}