github.com/didip/deis@v1.4.1/deisctl/client/client.go (about) 1 package client 2 3 import ( 4 "errors" 5 6 "github.com/deis/deis/deisctl/backend" 7 "github.com/deis/deis/deisctl/backend/fleet" 8 "github.com/deis/deis/deisctl/cmd" 9 ) 10 11 // DeisCtlClient manages Deis components, configuration, and related tasks. 12 type DeisCtlClient interface { 13 Config(argv []string) error 14 Install(argv []string) error 15 Journal(argv []string) error 16 List(argv []string) error 17 RefreshUnits(argv []string) error 18 Restart(argv []string) error 19 Scale(argv []string) error 20 Start(argv []string) error 21 Status(argv []string) error 22 Stop(argv []string) error 23 Uninstall(argv []string) error 24 } 25 26 // Client uses a backend to implement the DeisCtlClient interface. 27 type Client struct { 28 Backend backend.Backend 29 } 30 31 // NewClient returns a Client using the requested backend. 32 // The only backend currently supported is "fleet". 33 func NewClient(requestedBackend string) (*Client, error) { 34 var backend backend.Backend 35 36 if requestedBackend == "" { 37 requestedBackend = "fleet" 38 } 39 40 switch requestedBackend { 41 case "fleet": 42 b, err := fleet.NewClient() 43 if err != nil { 44 return nil, err 45 } 46 backend = b 47 default: 48 return nil, errors.New("invalid backend") 49 } 50 return &Client{Backend: backend}, nil 51 } 52 53 // Config gets or sets a configuration value from the cluster. 54 // 55 // A configuration value is stored and retrieved from a key/value store (in this case, etcd) 56 // at /deis/<component>/<config>. Configuration values are typically used for component-level 57 // configuration, such as enabling TLS for the routers. 58 func (c *Client) Config(argv []string) error { 59 return cmd.Config(argv) 60 } 61 62 // Install loads the definitions of components from local unit files. 63 // After Install, the components will be available to Start. 64 func (c *Client) Install(argv []string) error { 65 return cmd.Install(argv, c.Backend) 66 } 67 68 // Journal prints log output for the specified components. 69 func (c *Client) Journal(argv []string) error { 70 return cmd.Journal(argv, c.Backend) 71 } 72 73 // List prints a summary of installed components. 74 func (c *Client) List(argv []string) error { 75 return cmd.ListUnits(argv, c.Backend) 76 } 77 78 // RefreshUnits overwrites local unit files with those requested. 79 func (c *Client) RefreshUnits(argv []string) error { 80 return cmd.RefreshUnits(argv) 81 } 82 83 // Restart stops and then starts components. 84 func (c *Client) Restart(argv []string) error { 85 return cmd.Restart(argv, c.Backend) 86 } 87 88 // Scale grows or shrinks the number of running components. 89 func (c *Client) Scale(argv []string) error { 90 return cmd.Scale(argv, c.Backend) 91 } 92 93 // Start activates the specified components. 94 func (c *Client) Start(argv []string) error { 95 return cmd.Start(argv, c.Backend) 96 } 97 98 // Status prints the current status of components. 99 func (c *Client) Status(argv []string) error { 100 return cmd.Status(argv, c.Backend) 101 } 102 103 // Stop deactivates the specified components. 104 func (c *Client) Stop(argv []string) error { 105 return cmd.Stop(argv, c.Backend) 106 } 107 108 // Uninstall unloads the definitions of the specified components. 109 // After Uninstall, the components will be unavailable until Install is called. 110 func (c *Client) Uninstall(argv []string) error { 111 return cmd.Uninstall(argv, c.Backend) 112 }