Commit 886a401f authored by Yann KAISER's avatar Yann KAISER
Browse files

Updated the CreateDisk function in resource_disk

parent f5464b34
......@@ -53,11 +53,21 @@ func resourceDisk() *schema.Resource {
}
}
func CreateDisk(vmName string, diskMap map[string]interface{}, m interface{}) (*vm.Disk, error) {
session := m.(*Client).ImageSession
func CreateDisk(vmName string, diskMap map[string]interface{}, session *image.Client) (*vm.Disk, error) {
if !diskMap["enabled"].(bool) {
return nil, nil
}
diskType := "IMAGE"
diskTypeValue, diskTypeHas := diskMap["type"]
if diskTypeHas {
diskType = diskTypeValue.(string)
}
disk := vm.Disk{
ImageDiskType: diskMap["type"].(string),
ImageDiskType: diskType,
Target: diskMap["target"].(string),
}
......@@ -94,8 +104,22 @@ func CreateDisk(vmName string, diskMap map[string]interface{}, m interface{}) (*
} else {
if v, ok := diskMap["image_id"]; ok {
disk.ImageID = v.(int)
_, err := session.FetchImage(&image.Request{
SpecificID: &disk.ImageID,
})
if err != nil {
return nil, err
}
} else if v, ok := diskMap["image_name"]; ok {
disk.Image = v.(string)
_, err := session.FetchImage(&image.Request{
SpecificName: &disk.Image,
})
if err != nil {
return nil, err
}
} else {
return nil, fmt.Errorf("You need to specify an image name for an IMAGE disk")
}
......
......@@ -218,7 +218,7 @@ func resourceVMCreate(d *schema.ResourceData, m interface{}) error {
var disk *vm.Disk
if imData == nil {
disk, err = CreateDisk(vmData.Name, diskMap, m)
disk, err = CreateDisk(vmData.Name, diskMap, imageSession)
if err != nil {
return err
}
......@@ -441,7 +441,7 @@ func resourceVMUpdate(d *schema.ResourceData, m interface{}) error {
var disk *vm.Disk
if imData == nil {
disk, err = CreateDisk(vmName, diskMap, m)
disk, err = CreateDisk(vmName, diskMap, imageSession)
if err != nil {
return err
}
......
......@@ -184,7 +184,7 @@ func resourceVMTemplateCreate(d *schema.ResourceData, m interface{}) error {
for _, diskRes := range diskSet.List() {
var diskMap = diskRes.(map[string]interface{})
disk, err := CreateDisk(d.Get("name").(string), diskMap, m)
disk, err := CreateDisk(d.Get("name").(string), diskMap, imageSession)
if err != nil {
return err
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment