github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/pkg/providers/openstack/openstack_provider.go (about) 1 package openstack 2 3 import ( 4 "github.com/sirupsen/logrus" 5 "path/filepath" 6 7 "github.com/solo-io/unik/pkg/config" 8 "github.com/solo-io/unik/pkg/state" 9 "github.com/rackspace/gophercloud" 10 ) 11 12 type OpenstackProvider struct { 13 config config.Openstack 14 state state.State 15 } 16 17 func OpenstackStateFile() string { 18 return filepath.Join(config.Internal.UnikHome, "openstack/state.json") 19 } 20 21 func NewOpenstackProvider(config config.Openstack) (*OpenstackProvider, error) { 22 logrus.Infof("openstack state file: %s", OpenstackStateFile()) 23 p := &OpenstackProvider{ 24 config: config, 25 state: state.NewBasicState(OpenstackStateFile()), 26 } 27 28 return p, nil 29 } 30 31 func (p *OpenstackProvider) WithState(state state.State) *OpenstackProvider { 32 p.state = state 33 return p 34 } 35 36 func (p *OpenstackProvider) newClientNova() (*gophercloud.ServiceClient, error) { 37 handle, err := getHandle(p.config) 38 if err != nil { 39 return nil, err 40 } 41 client, err := getNovaClient(handle) 42 if err != nil { 43 return nil, err 44 } 45 return client, nil 46 } 47 48 func (p *OpenstackProvider) newClientGlance() (*gophercloud.ServiceClient, error) { 49 handle, err := getHandle(p.config) 50 if err != nil { 51 return nil, err 52 } 53 client, err := getGlanceClient(handle) 54 if err != nil { 55 return nil, err 56 } 57 return client, nil 58 }