github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/pkg/providers/xen/xen_provider.go (about) 1 package xen 2 3 import ( 4 "os" 5 "path/filepath" 6 7 "github.com/solo-io/unik/pkg/config" 8 "github.com/solo-io/unik/pkg/providers/xen/xenclient" 9 "github.com/solo-io/unik/pkg/state" 10 ) 11 12 type XenProvider struct { 13 state state.State 14 client *xenclient.XenClient 15 } 16 17 func XenStateFile() string { 18 return filepath.Join(config.Internal.UnikHome, "xen/state.json") 19 20 } 21 func xenImagesDirectory() string { 22 return filepath.Join(config.Internal.UnikHome, "xen/images/") 23 } 24 25 func xenInstancesDirectory() string { 26 return filepath.Join(config.Internal.UnikHome, "xen/instances/") 27 } 28 29 func xenVolumesDirectory() string { 30 return filepath.Join(config.Internal.UnikHome, "xen/volumes/") 31 } 32 33 func NewXenProvider(config config.Xen) (*XenProvider, error) { 34 35 os.MkdirAll(xenImagesDirectory(), 0777) 36 os.MkdirAll(xenInstancesDirectory(), 0777) 37 os.MkdirAll(xenVolumesDirectory(), 0777) 38 39 p := &XenProvider{ 40 state: state.NewBasicState(XenStateFile()), 41 client: &xenclient.XenClient{ 42 KernelPath: config.KernelPath, 43 XenBridge: config.XenBridge, 44 }, 45 } 46 47 /* 48 if err := p.deployInstanceListener(); err != nil { 49 return nil, errors.New("deploying xen instance listener", err) 50 } 51 */ 52 53 return p, nil 54 } 55 56 func (p *XenProvider) WithState(state state.State) *XenProvider { 57 p.state = state 58 return p 59 } 60 61 func getImagePath(imageName string) string { 62 return filepath.Join(xenImagesDirectory(), imageName, "boot.img") 63 } 64 65 func getInstanceDir(instanceName string) string { 66 return filepath.Join(xenInstancesDirectory(), instanceName) 67 } 68 69 func getVolumePath(volumeName string) string { 70 return filepath.Join(xenVolumesDirectory(), volumeName, "data.img") 71 }