func (d SolidFireDriver) Create(r volume.Request) volume.Response { log.Infof("Create volume %s on %s\n", r.Name, "solidfire") d.Mutex.Lock() defer d.Mutex.Unlock() var req sfapi.CreateVolumeRequest var qos sfapi.QoS var vsz int64 log.Debugf("GetVolumeByName: %s, %d", r.Name, d.TenantID) log.Debugf("Options passed in to create: %+v", r.Options) v, err := d.Client.GetVolumeByName(r.Name, d.TenantID) if err == nil && v.VolumeID != 0 { log.Infof("Found existing Volume by Name: %s", r.Name) return volume.Response{} } formatOpts(r) log.Debugf("Options after conversion: %+v", r.Options) if r.Options["size"] != "" { s, _ := strconv.ParseInt(r.Options["size"], 10, 64) log.Info("Received size request in Create: ", s) vsz = int64(units.GiB) * s } else { // NOTE(jdg): We need to cleanup the conversions and such when we read // in from the config file, it's sort of ugly. BUT, just remember that // when we pull the value from d.DefaultVolSz it's already been // multiplied vsz = d.DefaultVolSz log.Info("Creating with default size of: ", vsz) } if r.Options["qos"] != "" { iops := strings.Split(r.Options["qos"], ",") qos.MinIOPS, _ = strconv.ParseInt(iops[0], 10, 64) qos.MaxIOPS, _ = strconv.ParseInt(iops[1], 10, 64) qos.BurstIOPS, _ = strconv.ParseInt(iops[2], 10, 64) req.Qos = qos log.Infof("Received qos r.Options in Create: %+v", req.Qos) } if r.Options["type"] != "" { for _, t := range *d.Client.VolumeTypes { if strings.EqualFold(t.Type, r.Options["type"]) { req.Qos = t.QOS log.Infof("Received Type r.Options in Create and set QoS: %+v", req.Qos) break } } } req.TotalSize = vsz req.AccountID = d.TenantID req.Name = r.Name _, err = d.Client.CreateVolume(&req) if err != nil { return volume.Response{Err: err.Error()} } return volume.Response{} }
func cmdVolumeCreate(c *cli.Context) { var req sfapi.CreateVolumeRequest var qos sfapi.QoS req.Name = c.Args().First() sz := int64(0) if c.String("size") == "" && client.DefaultVolSize != 0 { sz = client.DefaultVolSize } else if c.String("size") != "" { sz, _ = units.ParseStrictBytes(c.String("size")) } else { fmt.Println("You must specify size for volumeCreate") return } account := int64(0) if c.String("account") == "" && client.DefaultAccountID != 0 { account = client.DefaultAccountID } else if c.String("account") != "" { account, _ = strconv.ParseInt(c.String("account"), 10, 64) } else { fmt.Println("You must specify an account for volumeCreate") return } req.TotalSize = sz req.AccountID = account if c.String("qos") != "" { iops := strings.Split(c.String("qos"), ",") qos.MinIOPS, _ = strconv.ParseInt(iops[0], 10, 64) qos.MaxIOPS, _ = strconv.ParseInt(iops[2], 10, 64) qos.BurstIOPS, _ = strconv.ParseInt(iops[2], 10, 64) req.Qos = qos } else if c.String("type") != "" { for _, t := range *client.Config.Types { if t.Type == c.String("type") { req.Qos = t.QOS } } } else { } v, err := client.CreateVolume(&req) if err != nil { fmt.Println("Error creating volume: ", err) } fmt.Println("-------------------------------------------") fmt.Println("Succesfully Created Volume:") fmt.Println("-------------------------------------------") fmt.Println("ID: ", v.VolumeID) fmt.Println("Name: ", v.Name) fmt.Println("Size (GiB): ", v.TotalSize/int64(units.GiB)) fmt.Println("QoS : ", "minIOPS:", v.Qos.MinIOPS, "maxIOPS:", v.Qos.MaxIOPS, "burstIOPS:", v.Qos.BurstIOPS) fmt.Println("Account: ", v.AccountID) fmt.Println("-------------------------------------------") if c.String("vag") != "" { vagID, _ := strconv.ParseInt(c.String("vag"), 10, 64) var volIDs []int64 volIDs = append(volIDs, v.VolumeID) err := client.AddVolumeToAccessGroup(vagID, volIDs) if err != nil { fmt.Printf("Failed to add volume to VAG ID: %d\n", vagID) return } fmt.Printf("Succesfully added volume to VAG ID: %d\n", vagID) } return }