コード例 #1
1
func getVolumeAttachments(computeClient *gophercloud.ServiceClient, d *schema.ResourceData) error {
	var attachments []volumeattach.VolumeAttachment

	err := volumeattach.List(computeClient, d.Id()).EachPage(func(page pagination.Page) (bool, error) {
		actual, err := volumeattach.ExtractVolumeAttachments(page)
		if err != nil {
			return false, err
		}

		attachments = actual
		return true, nil
	})

	if err != nil {
		return err
	}

	vols := make([]map[string]interface{}, len(attachments))
	for i, attachment := range attachments {
		vols[i] = make(map[string]interface{})
		vols[i]["id"] = attachment.ID
		vols[i]["volume_id"] = attachment.VolumeID
		vols[i]["device"] = attachment.Device
	}
	log.Printf("[INFO] Volume attachments: %v", vols)
	d.Set("volume", vols)

	return nil
}
コード例 #2
0
func testAccCheckComputeV2InstanceVolumeAttachment(
	instance *servers.Server, volume *volumes.Volume) resource.TestCheckFunc {
	return func(s *terraform.State) error {
		var attachments []volumeattach.VolumeAttachment

		config := testAccProvider.Meta().(*Config)
		computeClient, err := config.computeV2Client(OS_REGION_NAME)
		if err != nil {
			return err
		}
		err = volumeattach.List(computeClient, instance.ID).EachPage(func(page pagination.Page) (bool, error) {
			actual, err := volumeattach.ExtractVolumeAttachments(page)
			if err != nil {
				return false, fmt.Errorf("Unable to lookup attachment: %s", err)
			}

			attachments = actual
			return true, nil
		})

		for _, attachment := range attachments {
			if attachment.VolumeID == volume.ID {
				return nil
			}
		}

		return fmt.Errorf("Volume not found: %s", volume.ID)
	}
}
コード例 #3
0
func testAccCheckComputeV2InstanceBootVolumeAttachment(
	instance *servers.Server) resource.TestCheckFunc {
	return func(s *terraform.State) error {
		var attachments []volumeattach.VolumeAttachment

		config := testAccProvider.Meta().(*Config)
		computeClient, err := config.computeV2Client(OS_REGION_NAME)
		if err != nil {
			return err
		}
		err = volumeattach.List(computeClient, instance.ID).EachPage(func(page pagination.Page) (bool, error) {
			actual, err := volumeattach.ExtractVolumeAttachments(page)
			if err != nil {
				return false, fmt.Errorf("Unable to lookup attachment: %s", err)
			}

			attachments = actual
			return true, nil
		})

		if len(attachments) == 1 {
			return nil
		}

		return fmt.Errorf("No attached volume found.")
	}
}
コード例 #4
0
ファイル: storage.go プロジェクト: bkeyoumarsi/rexray
func (driver *Driver) getBlockDevices(instanceID string) ([]volumeattach.VolumeAttachment, error) {
	// volumes := volumeattach.Get(driver.Client, driver.InstanceID, "")
	allPages, err := volumeattach.List(driver.Client, driver.InstanceID).AllPages()

	// volumeAttachments, err := volumes.VolumeAttachmentResult.ExtractAll()
	volumeAttachments, err := volumeattach.ExtractVolumeAttachments(allPages)
	if err != nil {
		return []volumeattach.VolumeAttachment{}, fmt.Errorf("Error: %v", err)
	}

	return volumeAttachments, nil

}
コード例 #5
0
ファイル: storage.go プロジェクト: robnolen/rexray
func (driver *Driver) getBlockDevices(instanceID string) ([]volumeattach.VolumeAttachment, error) {
	// volumes := volumeattach.Get(driver.Client, driver.InstanceID, "")
	allPages, err := volumeattach.List(driver.Client, driver.InstanceID).AllPages()

	// volumeAttachments, err := volumes.VolumeAttachmentResult.ExtractAll()
	volumeAttachments, err := volumeattach.ExtractVolumeAttachments(allPages)
	if err != nil {
		return []volumeattach.VolumeAttachment{},
			errors.WithFieldsE(eff(errors.Fields{
				"instanceId": instanceID}),
				"error extracting volume attachments", err)
	}

	return volumeAttachments, nil

}
コード例 #6
0
func getVolumeAttachments(computeClient *gophercloud.ServiceClient, serverId string) ([]volumeattach.VolumeAttachment, error) {
	var attachments []volumeattach.VolumeAttachment
	err := volumeattach.List(computeClient, serverId).EachPage(func(page pagination.Page) (bool, error) {
		actual, err := volumeattach.ExtractVolumeAttachments(page)
		if err != nil {
			return false, err
		}

		attachments = actual
		return true, nil
	})

	if err != nil {
		return nil, err
	}

	return attachments, nil
}
コード例 #7
0
func getVolumeAttachments(computeClient *gophercloud.ServiceClient, d *schema.ResourceData) error {
	var attachments []volumeattach.VolumeAttachment

	err := volumeattach.List(computeClient, d.Id()).EachPage(func(page pagination.Page) (bool, error) {
		actual, err := volumeattach.ExtractVolumeAttachments(page)
		if err != nil {
			return false, err
		}

		attachments = actual
		return true, nil
	})

	if err != nil {
		return err
	}

	var vols []map[string]interface{}
	for _, attachment := range attachments {
		// ignore the volume if it is attached as a root device
		rootDevFound := false
		for _, rootDev := range []string{"/dev/vda", "/dev/xda", "/dev/sda", "/dev/xvda"} {
			if attachment.Device == rootDev {
				rootDevFound = true
			}
		}

		if rootDevFound {
			continue
		}

		vol := make(map[string]interface{})
		vol["id"] = attachment.ID
		vol["volume_id"] = attachment.VolumeID
		vol["device"] = attachment.Device
		vols = append(vols, vol)
	}
	log.Printf("[INFO] Volume attachments: %v", vols)
	d.Set("volume", vols)

	return nil
}
func testAccCheckComputeV2InstanceVolumeDetached(instance *servers.Server, volume_id string) resource.TestCheckFunc {
	return func(s *terraform.State) error {
		var attachments []volumeattach.VolumeAttachment

		rs, ok := s.RootModule().Resources[volume_id]
		if !ok {
			return fmt.Errorf("Not found: %s", volume_id)
		}

		if rs.Primary.ID == "" {
			return fmt.Errorf("No ID is set")
		}

		config := testAccProvider.Meta().(*Config)
		computeClient, err := config.computeV2Client(OS_REGION_NAME)
		if err != nil {
			return err
		}
		err = volumeattach.List(computeClient, instance.ID).EachPage(func(page pagination.Page) (bool, error) {
			actual, err := volumeattach.ExtractVolumeAttachments(page)
			if err != nil {
				return false, fmt.Errorf("Unable to lookup attachment: %s", err)
			}

			attachments = actual
			return true, nil
		})

		for _, attachment := range attachments {
			if attachment.VolumeID == rs.Primary.ID {
				return fmt.Errorf("Volume is still attached.")
			}
		}

		return nil
	}
}
コード例 #9
0
func getVolumeAttachments(computeClient *gophercloud.ServiceClient, d *schema.ResourceData) error {
	var vols []map[string]interface{}

	allPages, err := volumeattach.List(computeClient, d.Id()).AllPages()
	if err != nil {
		return err
	}

	allVolumeAttachments, err := volumeattach.ExtractVolumeAttachments(allPages)
	if err != nil {
		return err
	}

	if v, ok := d.GetOk("volume"); ok {
		volumes := v.(*schema.Set).List()
		for _, volume := range volumes {
			if volumeMap, ok := volume.(map[string]interface{}); ok {
				if v, ok := volumeMap["volume_id"].(string); ok {
					for _, volumeAttachment := range allVolumeAttachments {
						if v == volumeAttachment.ID {
							vol := make(map[string]interface{})
							vol["id"] = volumeAttachment.ID
							vol["volume_id"] = volumeAttachment.VolumeID
							vol["device"] = volumeAttachment.Device
							vols = append(vols, vol)
						}
					}
				}
			}
		}
	}

	log.Printf("[INFO] Volume attachments: %v", vols)
	d.Set("volume", vols)

	return nil
}
コード例 #10
0
ファイル: delegate.go プロジェクト: 40a/bootkube
// List returns a Pager that allows you to iterate over a collection of VolumeAttachments.
func List(client *gophercloud.ServiceClient, serverID string) pagination.Pager {
	return os.List(client, serverID)
}