예제 #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
}
예제 #2
0
파일: volume_test.go 프로젝트: juju/names
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)
}
예제 #3
0
파일: volume_test.go 프로젝트: juju/names
func assertVolumeNameValid(c *gc.C, name string) {
	c.Assert(names.IsValidVolume(name), gc.Equals, true)
	names.NewVolumeTag(name)
}