github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/pkg/providers/ukvm/ukvm_provider.go (about)

     1  package ukvm
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  
     7  	"github.com/solo-io/unik/pkg/config"
     8  	"github.com/solo-io/unik/pkg/state"
     9  )
    10  
    11  type UkvmProvider struct {
    12  	config config.Ukvm
    13  	state  state.State
    14  }
    15  
    16  func UkvmStateFile() string {
    17  	return filepath.Join(config.Internal.UnikHome, "ukvm/state.json")
    18  
    19  }
    20  func ukvmImagesDirectory() string {
    21  	return filepath.Join(config.Internal.UnikHome, "ukvm/images/")
    22  }
    23  
    24  func ukvmInstancesDirectory() string {
    25  	return filepath.Join(config.Internal.UnikHome, "ukvm/instances/")
    26  }
    27  
    28  func ukvmVolumesDirectory() string {
    29  	return filepath.Join(config.Internal.UnikHome, "ukvm/volumes/")
    30  }
    31  
    32  func NewUkvmProvider(config config.Ukvm) (*UkvmProvider, error) {
    33  
    34  	os.MkdirAll(ukvmImagesDirectory(), 0777)
    35  	os.MkdirAll(ukvmInstancesDirectory(), 0777)
    36  	os.MkdirAll(ukvmVolumesDirectory(), 0777)
    37  
    38  	p := &UkvmProvider{
    39  		config: config,
    40  		state:  state.NewBasicState(UkvmStateFile()),
    41  	}
    42  
    43  	return p, nil
    44  }
    45  
    46  func (p *UkvmProvider) WithState(state state.State) *UkvmProvider {
    47  	p.state = state
    48  	return p
    49  }
    50  func getImageDir(imageName string) string {
    51  	return filepath.Join(ukvmImagesDirectory(), imageName)
    52  }
    53  func getKernelPath(imageName string) string {
    54  	return filepath.Join(ukvmImagesDirectory(), imageName, "program.bin")
    55  }
    56  func getUkvmPath(imageName string) string {
    57  	return filepath.Join(ukvmImagesDirectory(), imageName, "ukvm-bin")
    58  }
    59  
    60  func getInstanceDir(instanceName string) string {
    61  	return filepath.Join(ukvmInstancesDirectory(), instanceName)
    62  }
    63  
    64  func getInstanceLogName(instanceName string) string {
    65  	return filepath.Join(ukvmInstancesDirectory(), instanceName, "stdout")
    66  }
    67  
    68  func getVolumePath(volumeName string) string {
    69  	return filepath.Join(ukvmVolumesDirectory(), volumeName, "data.img")
    70  }