Example #1
0
func Init() (storagedriver.Driver, error) {

	var (
		username             = os.Getenv("GOSCALEIO_USERNAME")
		password             = os.Getenv("GOSCALEIO_PASSWORD")
		endpoint             = os.Getenv("GOSCALEIO_ENDPOINT")
		systemID             = os.Getenv("GOSCALEIO_SYSTEMID")
		systemName           = os.Getenv("GOSCALEIO_SYSTEM")
		protectionDomainID   = os.Getenv("GOSCALEIO_PROTECTIONDOMAINID")
		protectionDomainName = os.Getenv("GOSCALEIO_PROTECTIONDOMAIN")
		storagePoolID        = os.Getenv("GOSCALEIO_STORAGEPOOLID")
		storagePoolName      = os.Getenv("GOSCALEIO_STORAGEPOOL")
	)

	client, err := goscaleio.NewClient()
	if err != nil {
		return nil, fmt.Errorf("%s: %s", storagedriver.ErrDriverInstanceDiscovery, err)
	}

	_, err = client.Authenticate(&goscaleio.ConfigConnect{endpoint, username, password})
	if err != nil {
		return nil, fmt.Errorf("%s: %s", storagedriver.ErrDriverInstanceDiscovery, err)
	}

	system, err := client.FindSystem(systemID, systemName, "")
	if err != nil {
		return nil, fmt.Errorf("%s: %s", storagedriver.ErrDriverInstanceDiscovery, err)
	}

	pd, err := system.FindProtectionDomain(protectionDomainID, protectionDomainName, "")
	if err != nil {
		return nil, fmt.Errorf("%s: %s", storagedriver.ErrDriverInstanceDiscovery, err)
	}

	protectionDomain := goscaleio.NewProtectionDomain(client)
	protectionDomain.ProtectionDomain = pd

	sp, err := protectionDomain.FindStoragePool(storagePoolID, storagePoolName, "")
	if err != nil {
		return nil, fmt.Errorf("%s: %s", storagedriver.ErrDriverInstanceDiscovery, err)
	}

	storagePool := goscaleio.NewStoragePool(client)
	storagePool.StoragePool = sp

	sdcguid, err := goscaleio.GetSdcLocalGUID()
	if err != nil {
		return nil, fmt.Errorf("%s: %s", storagedriver.ErrDriverInstanceDiscovery, err)
	}

	sdc, err := system.FindSdc("SdcGuid", strings.ToUpper(sdcguid))
	if err != nil {
		return nil, fmt.Errorf("%s: %s", storagedriver.ErrDriverInstanceDiscovery, err)
	}

	driver := &Driver{
		Client:           client,
		System:           system,
		ProtectionDomain: protectionDomain,
		StoragePool:      storagePool,
		Sdc:              sdc,
	}

	if os.Getenv("REXRAY_DEBUG") == "true" {
		log.Println("Storage Driver Initialized: " + providerName)
	}

	return driver, nil
}
Example #2
0
func (d *driver) Init(r *core.RexRay) error {
	d.r = r

	fields := eff(map[string]interface{}{
		"endpoint": d.endpoint(),
		"insecure": d.insecure(),
		"useCerts": d.useCerts(),
	})

	var err error

	if d.client, err = goscaleio.NewClientWithArgs(
		d.endpoint(),
		d.insecure(),
		d.useCerts()); err != nil {
		return goof.WithFieldsE(fields, "error constructing new client", err)
	}

	if _, err := d.client.Authenticate(
		&goscaleio.ConfigConnect{
			d.endpoint(),
			d.userName(),
			d.password()}); err != nil {
		fields["userName"] = d.userName()
		if d.password() != "" {
			fields["password"] = "******"
		}
		return goof.WithFieldsE(fields, "error authenticating", err)
	}

	if d.system, err = d.client.FindSystem(
		d.systemID(),
		d.systemName(), ""); err != nil {
		fields["systemId"] = d.systemID()
		fields["systemName"] = d.systemName()
		return goof.WithFieldsE(fields, "error finding system", err)
	}

	var pd *types.ProtectionDomain
	if pd, err = d.system.FindProtectionDomain(
		d.protectionDomainID(),
		d.protectionDomainName(), ""); err != nil {
		fields["domainId"] = d.protectionDomainID()
		fields["domainName"] = d.protectionDomainName()
		return goof.WithFieldsE(fields,
			"error finding protection domain", err)
	}
	d.protectionDomain = goscaleio.NewProtectionDomain(d.client)
	d.protectionDomain.ProtectionDomain = pd

	var sp *types.StoragePool
	if sp, err = d.protectionDomain.FindStoragePool(
		d.storagePoolID(),
		d.storagePoolName(), ""); err != nil {
		fields["storagePoolId"] = d.storagePoolID()
		fields["storagePoolName"] = d.storagePoolName()
		return goof.WithFieldsE(fields, "error finding storage pool", err)
	}
	d.storagePool = goscaleio.NewStoragePool(d.client)
	d.storagePool.StoragePool = sp

	var sdcGUID string
	if sdcGUID, err = goscaleio.GetSdcLocalGUID(); err != nil {
		return goof.WithFieldsE(fields, "error getting sdc local guid", err)
	}

	if d.sdc, err = d.system.FindSdc(
		"SdcGuid",
		strings.ToUpper(sdcGUID)); err != nil {
		fields["sdcGuid"] = sdcGUID
		return goof.WithFieldsE(fields, "error finding sdc", err)
	}

	log.WithField("provider", providerName).Info("storage driver initialized")

	return nil
}
Example #3
0
func Init(cfg *config.Config) (storage.Driver, error) {

	fields := eff(map[string]interface{}{
		"endpoint": cfg.ScaleIoEndpoint,
		"insecure": cfg.ScaleIoInsecure,
		"useCerts": cfg.ScaleIoUseCerts,
	})

	client, err := goscaleio.NewClientWithArgs(
		cfg.ScaleIoEndpoint,
		cfg.ScaleIoInsecure,
		cfg.ScaleIoUseCerts)

	if err != nil {
		return nil, errors.WithFieldsE(fields,
			"error constructing new client", err)
	}

	_, err = client.Authenticate(&goscaleio.ConfigConnect{
		cfg.ScaleIoEndpoint, cfg.ScaleIoUserName, cfg.ScaleIoPassword})
	if err != nil {
		fields["userName"] = cfg.ScaleIoUserName
		if cfg.ScaleIoPassword != "" {
			fields["password"] = "******"
		}
		return nil, errors.WithFieldsE(fields,
			"error authenticating", err)
	}

	system, err := client.FindSystem(
		cfg.ScaleIoSystemId, cfg.ScaleIoSystemName, "")
	if err != nil {
		fields["systemId"] = cfg.ScaleIoSystemId
		fields["systemName"] = cfg.ScaleIoSystemName
		return nil, errors.WithFieldsE(fields,
			"error finding system", err)
	}

	pd, err := system.FindProtectionDomain(
		cfg.ScaleIoProtectionDomainId, cfg.ScaleIoProtectionDomainName, "")
	if err != nil {
		fields["domainId"] = cfg.ScaleIoProtectionDomainId
		fields["domainName"] = cfg.ScaleIoProtectionDomainName
		return nil, errors.WithFieldsE(fields,
			"error finding protection domain", err)
	}

	protectionDomain := goscaleio.NewProtectionDomain(client)
	protectionDomain.ProtectionDomain = pd

	sp, err := protectionDomain.FindStoragePool(
		cfg.ScaleIoStoragePoolId, cfg.ScaleIoStoragePoolName, "")
	if err != nil {
		fields["storagePoolId"] = cfg.ScaleIoStoragePoolId
		fields["storagePoolName"] = cfg.ScaleIoStoragePoolName
		return nil, errors.WithFieldsE(fields,
			"error finding storage pool", err)
	}

	storagePool := goscaleio.NewStoragePool(client)
	storagePool.StoragePool = sp

	sdcguid, err := goscaleio.GetSdcLocalGUID()
	if err != nil {
		return nil, errors.WithFieldsE(fields,
			"error getting sdc local guid", err)
	}

	sdc, err := system.FindSdc("SdcGuid", strings.ToUpper(sdcguid))
	if err != nil {
		fields["sdcGuid"] = sdcguid
		return nil, errors.WithFieldsE(fields,
			"error finding sdc", err)
	}

	driver := &Driver{
		Client:           client,
		System:           system,
		ProtectionDomain: protectionDomain,
		StoragePool:      storagePool,
		Sdc:              sdc,
	}

	log.WithField("providerName", ProviderName).Debug(
		"storage driver initialized")

	return driver, nil
}