示例#1
0
文件: scaleio.go 项目: luk5/rexray
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
}
示例#2
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
}