Beispiel #1
0
// ParseVolumeAttachmentId parses a string as a volume attachment ID,
// returning the machine and volume components.
func ParseVolumeAttachmentId(id string) (names.MachineTag, names.VolumeTag, error) {
	fields := strings.SplitN(id, ":", 2)
	if len(fields) != 2 || !names.IsValidMachine(fields[0]) || !names.IsValidVolume(fields[1]) {
		return names.MachineTag{}, names.VolumeTag{}, errors.Errorf("invalid volume attachment ID %q", id)
	}
	machineTag := names.NewMachineTag(fields[0])
	volumeTag := names.NewVolumeTag(fields[1])
	return machineTag, volumeTag, nil
}
Beispiel #2
0
func assertVolumeNameInvalid(c *gc.C, name string) {
	c.Assert(names.IsValidVolume(name), gc.Equals, false)
	testVolumeTag := func() { names.NewVolumeTag(name) }
	expect := fmt.Sprintf("%q is not a valid volume ID", name)
	c.Assert(testVolumeTag, gc.PanicMatches, expect)
}
Beispiel #3
0
func assertVolumeNameValid(c *gc.C, name string) {
	c.Assert(names.IsValidVolume(name), gc.Equals, true)
	names.NewVolumeTag(name)
}