Esempio n. 1
0
func NewSolidFireDriverFromConfig(c *sfapi.Config) SolidFireDriver {
	var tenantID int64

	client, _ := sfapi.NewFromConfig("")
	req := sfapi.GetAccountByNameRequest{
		Name: c.TenantName,
	}

	account, err := client.GetAccountByName(&req)
	if err != nil {
		req := sfapi.AddAccountRequest{
			Username: c.TenantName,
		}
		tenantID, err = client.AddAccount(&req)
		if err != nil {
			log.Fatal("Failed to initialize solidfire driver while creating tenant: ", err)
		}
	} else {
		tenantID = account.AccountID
	}

	baseMountPoint := "/var/lib/solidfire/mount"
	if c.MountPoint != "" {
		baseMountPoint = c.MountPoint
	}

	iscsiInterface := "default"
	if c.InitiatorIFace != "" {
		iscsiInterface = c.InitiatorIFace
	}

	if c.Types != nil {
		client.VolumeTypes = c.Types
	}

	defaultVolSize := int64(1)
	if c.DefaultVolSz != 0 {
		defaultVolSize = c.DefaultVolSz
	}

	_, err = os.Lstat(baseMountPoint)
	if os.IsNotExist(err) {
		if err := os.MkdirAll(baseMountPoint, 0755); err != nil {
			log.Fatal("Failed to create Mount directory during driver init: %v", err)
		}
	}

	d := SolidFireDriver{
		TenantID:       tenantID,
		Client:         client,
		Mutex:          &sync.Mutex{},
		DefaultVolSz:   defaultVolSize,
		MountPoint:     c.MountPoint,
		InitiatorIFace: iscsiInterface,
	}
	log.Debugf("Driver initialized with the following settings:\n%+v\n", d)
	log.Info("Succesfuly initialized SolidFire Docker driver")
	return d
}
Esempio n. 2
0
func initClient(c *cli.Context) error {
	cfgFile := c.GlobalString("config")
	if cfgFile != "" {
		client, _ = sfapi.NewFromConfig(cfgFile)
		conf, _ := sfapi.ProcessConfig(cfgFile)
		client.Config = &conf
	} else {
		client, _ = sfapi.New()
	}
	updateLogLevel(c)
	return nil
}
Esempio n. 3
0
func New(cfgFile string) SolidFireDriver {
	var tenantID int64
	client, _ := sfapi.NewFromConfig(cfgFile)

	req := sfapi.GetAccountByNameRequest{
		Name: client.DefaultTenantName,
	}
	account, err := client.GetAccountByName(&req)
	if err != nil {
		req := sfapi.AddAccountRequest{
			Username: client.DefaultTenantName,
		}
		actID, err := client.AddAccount(&req)
		if err != nil {
			log.Fatalf("Failed init, unable to create Tenant (%s): %+v", client.DefaultTenantName, err)
		}
		tenantID = actID
		log.Debug("Set tenantID: ", tenantID)
	} else {
		tenantID = account.AccountID
		log.Debug("Set tenantID: ", tenantID)
	}
	baseMountPoint := "/var/lib/solidfire/mount"
	if client.Config.MountPoint != "" {
		baseMountPoint = client.Config.MountPoint
	}

	iscsiInterface := "default"
	if client.Config.InitiatorIFace != "" {
		iscsiInterface = client.Config.InitiatorIFace
	}

	_, err = os.Lstat(baseMountPoint)
	if os.IsNotExist(err) {
		if err := os.MkdirAll(baseMountPoint, 0755); err != nil {
			log.Fatal("Failed to create Mount directory during driver init: %v", err)
		}
	}

	d := SolidFireDriver{
		TenantID:       tenantID,
		Client:         client,
		Mutex:          &sync.Mutex{},
		DefaultVolSz:   client.DefaultVolSize,
		MountPoint:     client.Config.MountPoint,
		InitiatorIFace: iscsiInterface,
	}
	return d
}