本文整理匯總了Golang中github.com/emccode/rexray/core/errors.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: prefixToMountUnmount
func (d *driver) prefixToMountUnmount(
volumeName,
volumeID string) ([]*core.Volume, []*core.VolumeAttachment, *core.Instance, error) {
if volumeName == "" && volumeID == "" {
return nil, nil, nil, errors.New("Missing volume name or ID")
}
var instance *core.Instance
var err error
if instance, err = d.getInstance(); err != nil {
return nil, nil, nil, err
}
var vols []*core.Volume
if vols, err = d.r.Storage.GetVolume(volumeID, volumeName); err != nil {
return nil, nil, nil, err
}
switch {
case len(vols) == 0:
return nil, nil, nil, errors.New("No volumes returned by name")
case len(vols) > 1:
return nil, nil, nil, errors.New("Multiple volumes returned by name")
}
var volAttachments []*core.VolumeAttachment
if volAttachments, err = d.r.Storage.GetVolumeAttach(
vols[0].VolumeID, instance.InstanceID); err != nil {
return nil, nil, nil, err
}
return vols, volAttachments, instance, nil
}
示例2: NetworkName
// NetworkName will return relevant information about how a volume can be discovered on an OS
func (d *driver) NetworkName(volumeName, instanceID string) (string, error) {
log.WithFields(log.Fields{
"volumeName": volumeName,
"instanceID": instanceID,
"driverName": d.Name()}).Info("returning network name")
volumes, err := d.r.Storage.GetVolume("", volumeName)
if err != nil {
return "", err
}
switch {
case len(volumes) == 0:
return "", errors.New("No volumes returned by name")
case len(volumes) > 1:
return "", errors.New("Multiple volumes returned by name")
}
volumeAttachment, err := d.r.Storage.GetVolumeAttach(
volumes[0].VolumeID, instanceID)
if err != nil {
return "", err
}
if len(volumeAttachment) == 0 {
return "", errors.New("Volume not attached")
}
volumes, err = d.r.Storage.GetVolume("", volumeName)
if err != nil {
return "", err
}
return volumes[0].NetworkName, nil
}
示例3: Key
// Key adds a key to the registration.
//
// The first vararg argument is the yaml name of the key, using a '.' as
// the nested separator. If the second two arguments are omitted they will be
// generated from the first argument. The second argument is the explicit name
// of the flag bound to this key. The third argument is the explicit name of
// the environment variable bound to thie key.
func (r *Registration) Key(
keyType KeyType,
short string,
defVal interface{},
description string,
keys ...string) {
if keys == nil {
panic(errors.New("keys is nil"))
}
lk := len(keys)
if lk == 0 {
panic(errors.New("len(keys) == 0"))
}
kn := keys[0]
rk := ®Key{
keyType: keyType,
short: short,
desc: description,
defVal: defVal,
keyName: keys[0],
}
if lk < 2 {
kp := strings.Split(kn, ".")
for x, s := range kp {
if x == 0 {
var buff []byte
b := bytes.NewBuffer(buff)
for y, r := range s {
if y == 0 {
b.WriteRune(unicode.ToLower(r))
} else {
b.WriteRune(r)
}
}
kp[x] = b.String()
} else {
kp[x] = strings.Title(s)
}
}
rk.flagName = strings.Join(kp, "")
}
if lk < 3 {
kp := strings.Split(kn, ".")
for x, s := range kp {
kp[x] = strings.ToUpper(s)
}
rk.envVarName = strings.Join(kp, "_")
}
r.keys = append(r.keys, rk)
}
示例4: Path
// Path returns the mounted path of the volume
func (d *driver) Path(volumeName, volumeID string) (string, error) {
log.WithFields(log.Fields{
"volumeName": volumeName,
"volumeID": volumeID,
"driverName": d.Name()}).Info("getting path to volume")
if volumeName == "" && volumeID == "" {
return "", errors.New("Missing volume name or ID")
}
instances, err := d.r.Storage.GetInstances()
if err != nil {
return "", err
}
switch {
case len(instances) == 0:
return "", errors.New("No instances")
case len(instances) > 1:
return "", errors.New("Too many instances returned, limit the storagedrivers")
}
volumes, err := d.r.Storage.GetVolume(volumeID, volumeName)
if err != nil {
return "", err
}
switch {
case len(volumes) == 0:
return "", errors.New("No volumes returned by name")
case len(volumes) > 1:
return "", errors.New("Multiple volumes returned by name")
}
volumeAttachment, err := d.r.Storage.GetVolumeAttach(volumes[0].VolumeID, instances[0].InstanceID)
if err != nil {
return "", err
}
if len(volumeAttachment) == 0 {
return "", nil
}
mounts, err := d.r.OS.GetMounts(volumeAttachment[0].DeviceName, "")
if err != nil {
return "", err
}
if len(mounts) == 0 {
return "", nil
}
return mounts[0].Mountpoint, nil
}
示例5: getVolumeMountPath
func getVolumeMountPath(name string) (string, error) {
if name == "" {
return "", errors.New("Missing volume name")
}
return fmt.Sprintf("%s/%s", mountDirectoryPath, name), nil
}
示例6: CopySnapshot
func (d *driver) CopySnapshot(
runAsync bool,
volumeID, snapshotID,
snapshotName, destinationSnapshotName,
destinationRegion string) (*core.Snapshot, error) {
return nil, errors.New("This driver does not implement CopySnapshot")
}
示例7: getLunMaps
func (d *xtremIODriver) getLunMaps(initiatorName, volumeID string) (xtio.Refs, error) {
if initiatorName == "" {
return nil, errors.New("Missing initiatorName")
}
initiatorGroup, err := d.client.GetInitiatorGroup("", initiatorName)
if err != nil {
return nil, err
}
lunMaps, err := d.client.GetLunMaps()
if err != nil {
return nil, err
}
var refs xtio.Refs
for _, ref := range lunMaps {
idents := strings.Split(ref.Name, "_")
if len(idents) < 3 {
continue
} else if strconv.Itoa(initiatorGroup.Index) == idents[1] && volumeID == idents[0] {
refs = append(refs, ref)
}
}
return refs, nil
}
示例8: getInstance
func (d *driver) getInstance() (*core.Instance, error) {
instances, err := d.r.Storage.GetInstances()
if err != nil {
return nil, err
}
switch {
case len(instances) == 0:
return nil, errors.New("No instances")
case len(instances) > 1:
return nil,
errors.New("Too many instances returned, limit the storagedrivers")
}
return instances[0], nil
}
示例9: Remove
// Remove will remove a remote volume
func (d *driver) Remove(volumeName string) error {
log.WithFields(log.Fields{
"volumeName": volumeName,
"driverName": d.Name()}).Info("removing volume")
if volumeName == "" {
return errors.New("Missing volume name")
}
instances, err := d.r.Storage.GetInstances()
if err != nil {
return err
}
switch {
case len(instances) == 0:
return errors.New("No instances")
case len(instances) > 1:
return errors.New("Too many instances returned, limit the storagedrivers")
}
volumes, err := d.r.Storage.GetVolume("", volumeName)
if err != nil {
return err
}
switch {
case len(volumes) == 0:
return errors.New("No volumes returned by name")
case len(volumes) > 1:
return errors.New("Multiple volumes returned by name")
}
err = d.Unmount("", volumes[0].VolumeID)
if err != nil {
return err
}
err = d.r.Storage.RemoveVolume(volumes[0].VolumeID)
if err != nil {
return err
}
return nil
}
示例10: createGetInstance
func (d *driver) createGetInstance() error {
var err error
var instances []*core.Instance
if instances, err = d.r.Storage.GetInstances(); err != nil {
return err
}
switch {
case len(instances) == 0:
return errors.New("No instances")
case len(instances) > 1:
return errors.New(
"Too many instances returned, limit the storagedrivers")
}
return nil
}
示例11: ReadConfig
// ReadConfig reads a configuration stream into the current config instance
func (c *Config) ReadConfig(in io.Reader) error {
if in == nil {
return errors.New("config reader is nil")
}
c.v.ReadConfigNoNil(in)
return nil
}
示例12: getIQN
func getIQN() (string, error) {
data, err := ioutil.ReadFile("/etc/iscsi/initiatorname.iscsi")
if err != nil {
return "", err
}
result := string(data)
lines := strings.Split(result, "\n")
for _, line := range lines {
split := strings.Split(line, "=")
if split[0] == "InitiatorName" {
return split[1], nil
}
}
return "", errors.New("IQN not found")
}
示例13: ReadConfig
// ReadConfig reads a configuration stream into the current config instance
func (c *Config) ReadConfig(in io.Reader) error {
if in == nil {
return errors.New("config reader is nil")
}
c.Viper.ReadConfigNoNil(in)
c.Viper.Unmarshal(&c.secureConfig)
c.Viper.Unmarshal(&c.plainTextConfig)
for key := range keys {
c.updateFlag(key, c.GlobalFlags)
c.updateFlag(key, c.AdditionalFlags)
}
return nil
}
示例14: GetDeviceNextAvailable
func (d *driver) GetDeviceNextAvailable() (string, error) {
letters := []string{
"a", "b", "c", "d", "e", "f", "g", "h",
"i", "j", "k", "l", "m", "n", "o", "p"}
blockDeviceNames := make(map[string]bool)
blockDeviceMapping, err := d.GetVolumeMapping()
if err != nil {
return "", err
}
for _, blockDevice := range blockDeviceMapping {
re, _ := regexp.Compile(`^/dev/xvd([a-z])`)
res := re.FindStringSubmatch(blockDevice.DeviceName)
if len(res) > 0 {
blockDeviceNames[res[1]] = true
}
}
localDevices, err := getLocalDevices()
if err != nil {
return "", err
}
for _, localDevice := range localDevices {
re, _ := regexp.Compile(`^xvd([a-z])`)
res := re.FindStringSubmatch(localDevice)
if len(res) > 0 {
blockDeviceNames[res[1]] = true
}
}
for _, letter := range letters {
if !blockDeviceNames[letter] {
nextDeviceName := "/dev/xvd" + letter
log.Println("Got next device name: " + nextDeviceName)
return nextDeviceName, nil
}
}
return "", errors.New("No available device")
}
示例15: AttachVolume
func (d *driver) AttachVolume(
runAsync bool,
volumeID, instanceID string) ([]*core.VolumeAttachment, error) {
if instanceID == "" {
instanceID = d.currentInstanceId
}
instance, err := d.GetInstance()
if err != nil {
return nil, err
}
instanceID = instance.Name
log.WithField("provider", providerName).Debugf("AttachVolume %s %s", volumeID, instance.Name)
query := d.client.Disks.List(d.project, d.zone)
query.Filter(fmt.Sprintf("name eq %s", volumeID))
disks, err := query.Do()
if err != nil {
return nil, err
}
if len(disks.Items) != 1 {
return nil, errors.New("No available device")
}
disk := &compute.AttachedDisk{
AutoDelete: false,
Boot: false,
Source: disks.Items[0].SelfLink,
}
operation, err := d.client.Instances.AttachDisk(d.project, d.zone, instanceID, disk).Do()
if err != nil {
return nil, err
}
if !runAsync {
err := d.waitUntilOperationIsFinished(operation)
if err != nil {
return nil, err
}
}
return d.GetVolumeAttach(volumeID, instanceID)
}