NewGohanClientCLI GohanClientCLI constructor
(opts *GohanClientCLIOpts)
| 190 | |
| 191 | // NewGohanClientCLI GohanClientCLI constructor |
| 192 | func NewGohanClientCLI(opts *GohanClientCLIOpts) (*GohanClientCLI, error) { |
| 193 | gohanClientCLI := GohanClientCLI{ |
| 194 | opts: opts, |
| 195 | } |
| 196 | setUpLogging(gohanClientCLI.opts.logLevel) |
| 197 | |
| 198 | provider, err := getProviderClient() |
| 199 | if err != nil { |
| 200 | return nil, err |
| 201 | } |
| 202 | gohanClientCLI.provider = provider |
| 203 | |
| 204 | if opts.authTokenID != "" { |
| 205 | gohanClientCLI.provider.TokenID = opts.authTokenID |
| 206 | } |
| 207 | |
| 208 | if opts.gohanEndpointURL == "" { |
| 209 | gohanEndpointURL, err := gohanClientCLI.getGohanEndpointURL(provider) |
| 210 | if err != nil { |
| 211 | return nil, err |
| 212 | } |
| 213 | gohanClientCLI.opts.gohanEndpointURL = gohanEndpointURL |
| 214 | } |
| 215 | |
| 216 | var schemas []*schema.Schema |
| 217 | if gohanClientCLI.opts.cacheSchemas { |
| 218 | schemas, err = gohanClientCLI.getCachedSchemas() |
| 219 | } else { |
| 220 | schemas, err = gohanClientCLI.getSchemas() |
| 221 | } |
| 222 | if err != nil { |
| 223 | return nil, err |
| 224 | } |
| 225 | gohanClientCLI.schemas = schemas |
| 226 | if gohanClientCLI.opts.cacheSchemas { |
| 227 | err := gohanClientCLI.setCachedSchemas() |
| 228 | if err != nil { |
| 229 | return nil, fmt.Errorf("Error caching schemas: %v", err) |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | gohanClientCLI.commands = gohanClientCLI.getCommands() |
| 234 | |
| 235 | return &gohanClientCLI, nil |
| 236 | } |
| 237 | |
| 238 | func getProviderClient() (*gophercloud.ProviderClient, error) { |
| 239 | opts, err := openstack.AuthOptionsFromEnv() |
no test coverage detected