本文整理汇总了Golang中github.com/juju/names.NewVolumeTag函数的典型用法代码示例。如果您正苦于以下问题:Golang NewVolumeTag函数的具体用法?Golang NewVolumeTag怎么用?Golang NewVolumeTag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewVolumeTag函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestWatchEnvironVolumeAttachments
func (s *VolumeStateSuite) TestWatchEnvironVolumeAttachments(c *gc.C) {
service := s.setupMixedScopeStorageService(c, "block")
addUnit := func() {
u, err := service.AddUnit()
c.Assert(err, jc.ErrorIsNil)
err = s.State.AssignUnit(u, state.AssignCleanEmpty)
c.Assert(err, jc.ErrorIsNil)
}
addUnit()
w := s.State.WatchEnvironVolumeAttachments()
defer testing.AssertStop(c, w)
wc := testing.NewStringsWatcherC(c, s.State, w)
wc.AssertChangeInSingleEvent("0:0") // initial
wc.AssertNoChange()
addUnit()
wc.AssertChangeInSingleEvent("1:3")
wc.AssertNoChange()
err := s.State.DetachVolume(names.NewMachineTag("0"), names.NewVolumeTag("0"))
c.Assert(err, jc.ErrorIsNil)
wc.AssertChangeInSingleEvent("0:0") // dying
wc.AssertNoChange()
err = s.State.RemoveVolumeAttachment(names.NewMachineTag("0"), names.NewVolumeTag("0"))
c.Assert(err, jc.ErrorIsNil)
wc.AssertChangeInSingleEvent("0:0") // removed
wc.AssertNoChange()
}
示例2: TestRemoveVolumesMachineAgent
func (s *provisionerSuite) TestRemoveVolumesMachineAgent(c *gc.C) {
s.setupVolumes(c)
s.authorizer.EnvironManager = false
args := params.Entities{Entities: []params.Entity{
{"volume-0-0"}, {"volume-0-42"}, {"volume-42"},
{"volume-invalid"}, {"machine-0"},
}}
err := s.State.DetachVolume(names.NewMachineTag("0"), names.NewVolumeTag("0/0"))
c.Assert(err, jc.ErrorIsNil)
err = s.State.RemoveVolumeAttachment(names.NewMachineTag("0"), names.NewVolumeTag("0/0"))
c.Assert(err, jc.ErrorIsNil)
err = s.State.DestroyVolume(names.NewVolumeTag("0/0"))
c.Assert(err, jc.ErrorIsNil)
result, err := s.api.Remove(args)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, gc.DeepEquals, params.ErrorResults{
Results: []params.ErrorResult{
{Error: nil},
{Error: nil},
{Error: ¶ms.Error{Message: "permission denied", Code: "unauthorized access"}},
{Error: ¶ms.Error{Message: `"volume-invalid" is not a valid volume tag`}},
{Error: ¶ms.Error{Message: "permission denied", Code: "unauthorized access"}},
},
})
}
示例3: TestWatchMachineVolumeAttachments
func (s *VolumeStateSuite) TestWatchMachineVolumeAttachments(c *gc.C) {
service := s.setupMixedScopeStorageService(c, "block")
addUnit := func() {
u, err := service.AddUnit()
c.Assert(err, jc.ErrorIsNil)
err = s.State.AssignUnit(u, state.AssignCleanEmpty)
c.Assert(err, jc.ErrorIsNil)
}
addUnit()
w := s.State.WatchMachineVolumeAttachments(names.NewMachineTag("0"))
defer testing.AssertStop(c, w)
wc := testing.NewStringsWatcherC(c, s.State, w)
wc.AssertChangeInSingleEvent("0:0", "0:0/1", "0:0/2") // initial
wc.AssertNoChange()
addUnit()
// no change, since we're only interested in the one machine.
wc.AssertNoChange()
err := s.State.DetachVolume(names.NewMachineTag("0"), names.NewVolumeTag("0"))
c.Assert(err, jc.ErrorIsNil)
wc.AssertChangeInSingleEvent("0:0") // dying
wc.AssertNoChange()
err = s.State.RemoveVolumeAttachment(names.NewMachineTag("0"), names.NewVolumeTag("0"))
c.Assert(err, jc.ErrorIsNil)
wc.AssertChangeInSingleEvent("0:0") // removed
wc.AssertNoChange()
// TODO(axw) respond to changes to the same machine when we support
// dynamic storage and/or placement.
}
示例4: SetUpTest
func (s *volumeSourceSuite) SetUpTest(c *gc.C) {
s.BaseSuite.SetUpTest(c)
s.provider = gce.GCEStorageProvider()
var err error
s.source, err = s.provider.VolumeSource(s.BaseSuite.Config, &storage.Config{})
c.Check(err, jc.ErrorIsNil)
inst := gce.NewInstance(s.BaseInstance, s.Env)
vTag := names.NewVolumeTag("0")
mTag := names.NewMachineTag("0")
s.instId = inst.Id()
s.attachmentParams = &storage.VolumeAttachmentParams{
AttachmentParams: storage.AttachmentParams{
Provider: "gce",
Machine: mTag,
InstanceId: s.instId,
},
VolumeId: s.BaseDisk.Name,
Volume: names.NewVolumeTag("0"),
}
s.params = []storage.VolumeParams{{
Tag: vTag,
Size: 1024,
Provider: "gce",
Attachment: s.attachmentParams,
}}
}
示例5: TestCreateVolumes
func (s *loopSuite) TestCreateVolumes(c *gc.C) {
source, _ := s.loopVolumeSource(c)
s.commands.expect("fallocate", "-l", "2MiB", filepath.Join(s.storageDir, "volume-0"))
volumes, volumeAttachments, err := source.CreateVolumes([]storage.VolumeParams{{
Tag: names.NewVolumeTag("0"),
Size: 2,
Attachment: &storage.VolumeAttachmentParams{
AttachmentParams: storage.AttachmentParams{
Machine: names.NewMachineTag("1"),
InstanceId: "instance-id",
},
},
}})
c.Assert(err, jc.ErrorIsNil)
c.Assert(volumes, gc.HasLen, 1)
// volume attachments always deferred to AttachVolumes
c.Assert(volumeAttachments, gc.HasLen, 0)
c.Assert(volumes[0], gc.Equals, storage.Volume{
names.NewVolumeTag("0"),
storage.VolumeInfo{
VolumeId: "volume-0",
Size: 2,
},
})
}
示例6: assertCreateVolumes
func (s *ebsVolumeSuite) assertCreateVolumes(c *gc.C, vs storage.VolumeSource, instanceId string) {
vols, err := s.createVolumes(vs, instanceId)
c.Assert(err, jc.ErrorIsNil)
c.Assert(vols, gc.HasLen, 3)
c.Assert(vols, jc.SameContents, []storage.Volume{{
names.NewVolumeTag("0"),
storage.VolumeInfo{
Size: 10240,
VolumeId: "vol-0",
Persistent: true,
},
}, {
names.NewVolumeTag("1"),
storage.VolumeInfo{
Size: 20480,
VolumeId: "vol-1",
Persistent: true,
},
}, {
names.NewVolumeTag("2"),
storage.VolumeInfo{
Size: 30720,
VolumeId: "vol-2",
Persistent: false,
},
}})
ec2Client := ec2.StorageEC2(vs)
ec2Vols, err := ec2Client.Volumes(nil, nil)
c.Assert(err, jc.ErrorIsNil)
c.Assert(ec2Vols.Volumes, gc.HasLen, 3)
sortBySize(ec2Vols.Volumes)
c.Assert(ec2Vols.Volumes[0].Size, gc.Equals, 10)
c.Assert(ec2Vols.Volumes[1].Size, gc.Equals, 20)
c.Assert(ec2Vols.Volumes[2].Size, gc.Equals, 30)
}
示例7: TestDestroyVolumes
func (s *storageProvisionerSuite) TestDestroyVolumes(c *gc.C) {
provisionedVolume := names.NewVolumeTag("1")
unprovisionedVolume := names.NewVolumeTag("2")
volumeAccessor := newMockVolumeAccessor()
volumeAccessor.provisionVolume(provisionedVolume)
life := func(tags []names.Tag) ([]params.LifeResult, error) {
results := make([]params.LifeResult, len(tags))
for i := range results {
results[i].Life = params.Dead
}
return results, nil
}
destroyedChan := make(chan interface{}, 1)
s.provider.destroyVolumesFunc = func(volumeIds []string) []error {
destroyedChan <- volumeIds
return make([]error, len(volumeIds))
}
removedChan := make(chan interface{}, 1)
remove := func(tags []names.Tag) ([]params.ErrorResult, error) {
removedChan <- tags
return make([]params.ErrorResult, len(tags)), nil
}
args := &workerArgs{
volumes: volumeAccessor,
life: &mockLifecycleManager{
life: life,
remove: remove,
},
}
worker := newStorageProvisioner(c, args)
defer func() { c.Assert(worker.Wait(), gc.IsNil) }()
defer worker.Kill()
volumeAccessor.volumesWatcher.changes <- []string{
provisionedVolume.Id(),
unprovisionedVolume.Id(),
}
args.environ.watcher.changes <- struct{}{}
// Both volumes should be removed; the provisioned one
// should be deprovisioned first.
destroyed := waitChannel(c, destroyedChan, "waiting for volume to be deprovisioned")
assertNoEvent(c, destroyedChan, "volumes deprovisioned")
c.Assert(destroyed, jc.DeepEquals, []string{"vol-1"})
var removed []names.Tag
for len(removed) < 2 {
tags := waitChannel(c, removedChan, "waiting for volumes to be removed").([]names.Tag)
removed = append(removed, tags...)
}
c.Assert(removed, jc.SameContents, []names.Tag{provisionedVolume, unprovisionedVolume})
assertNoEvent(c, removedChan, "volumes removed")
}
示例8: TestParseVolumeTag
func (s *volumeSuite) TestParseVolumeTag(c *gc.C) {
assertParseVolumeTag(c, "volume-0", names.NewVolumeTag("0"))
assertParseVolumeTag(c, "volume-88", names.NewVolumeTag("88"))
assertParseVolumeTag(c, "volume-0-lxc-0-88", names.NewVolumeTag("0/lxc/0/88"))
assertParseVolumeTagInvalid(c, "", names.InvalidTagError("", ""))
assertParseVolumeTagInvalid(c, "one", names.InvalidTagError("one", ""))
assertParseVolumeTagInvalid(c, "volume-", names.InvalidTagError("volume-", names.VolumeTagKind))
assertParseVolumeTagInvalid(c, "machine-0", names.InvalidTagError("machine-0", names.VolumeTagKind))
}
示例9: createVolumes
func (s *ebsVolumeSuite) createVolumes(vs storage.VolumeSource, instanceId string) ([]storage.Volume, error) {
if instanceId == "" {
instanceId = s.srv.ec2srv.NewInstances(1, "m1.medium", imageId, ec2test.Running, nil)[0]
}
volume0 := names.NewVolumeTag("0")
volume1 := names.NewVolumeTag("1")
volume2 := names.NewVolumeTag("2")
params := []storage.VolumeParams{{
Tag: volume0,
Size: 10 * 1000,
Provider: ec2.EBS_ProviderType,
Attributes: map[string]interface{}{
"persistent": true,
"volume-type": "io1",
"iops": 100,
},
Attachment: &storage.VolumeAttachmentParams{
AttachmentParams: storage.AttachmentParams{
InstanceId: instance.Id(instanceId),
},
},
ResourceTags: map[string]string{
tags.JujuEnv: s.TestConfig["uuid"].(string),
},
}, {
Tag: volume1,
Size: 20 * 1000,
Provider: ec2.EBS_ProviderType,
Attributes: map[string]interface{}{
"persistent": true,
},
Attachment: &storage.VolumeAttachmentParams{
AttachmentParams: storage.AttachmentParams{
InstanceId: instance.Id(instanceId),
},
},
ResourceTags: map[string]string{
tags.JujuEnv: "something-else",
},
}, {
Tag: volume2,
Size: 30 * 1000,
Provider: ec2.EBS_ProviderType,
ResourceTags: map[string]string{
"abc": "123",
},
Attachment: &storage.VolumeAttachmentParams{
AttachmentParams: storage.AttachmentParams{
InstanceId: instance.Id(instanceId),
},
},
}}
vols, _, err := vs.CreateVolumes(params)
return vols, err
}
示例10: TestInstanceVolumesOldMass
func (s *volumeSuite) TestInstanceVolumesOldMass(c *gc.C) {
obj := s.testMAASObject.TestServer.NewNode(`{"system_id": "node0"}`)
instance := maasInstance{&obj}
volumes, attachments, err := instance.volumes(names.NewMachineTag("1"), []names.VolumeTag{
names.NewVolumeTag("1"),
names.NewVolumeTag("2"),
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(volumes, gc.HasLen, 0)
c.Assert(attachments, gc.HasLen, 0)
}
示例11: TestParseVolumeAttachmentId
func (s *VolumeStateSuite) TestParseVolumeAttachmentId(c *gc.C) {
assertValid := func(id string, m names.MachineTag, v names.VolumeTag) {
machineTag, volumeTag, err := state.ParseVolumeAttachmentId(id)
c.Assert(err, jc.ErrorIsNil)
c.Assert(machineTag, gc.Equals, m)
c.Assert(volumeTag, gc.Equals, v)
}
assertValid("0:0", names.NewMachineTag("0"), names.NewVolumeTag("0"))
assertValid("0:0/1", names.NewMachineTag("0"), names.NewVolumeTag("0/1"))
assertValid("0/lxc/0:1", names.NewMachineTag("0/lxc/0"), names.NewVolumeTag("1"))
}
示例12: TestDetachVolumes
func (s *cinderVolumeSourceSuite) TestDetachVolumes(c *gc.C) {
const mockServerId2 = mockServerId + "2"
var numListCalls, numDetachCalls int
mockAdapter := &mockAdapter{
listVolumeAttachments: func(serverId string) ([]nova.VolumeAttachment, error) {
numListCalls++
if serverId == mockServerId2 {
// no attachments
return nil, nil
}
c.Check(serverId, gc.Equals, mockServerId)
return []nova.VolumeAttachment{{
Id: mockVolId,
VolumeId: mockVolId,
ServerId: mockServerId,
Device: "/dev/sda",
}}, nil
},
detachVolume: func(serverId, volId string) error {
numDetachCalls++
c.Check(serverId, gc.Equals, mockServerId)
c.Check(volId, gc.Equals, mockVolId)
return nil
},
}
volSource := openstack.NewCinderVolumeSource(mockAdapter)
errs, err := volSource.DetachVolumes([]storage.VolumeAttachmentParams{{
Volume: names.NewVolumeTag("123"),
VolumeId: mockVolId,
AttachmentParams: storage.AttachmentParams{
Machine: names.NewMachineTag("0"),
InstanceId: mockServerId,
},
}, {
Volume: names.NewVolumeTag("42"),
VolumeId: "42",
AttachmentParams: storage.AttachmentParams{
Machine: names.NewMachineTag("0"),
InstanceId: mockServerId2,
},
}})
c.Assert(err, jc.ErrorIsNil)
c.Assert(errs, jc.DeepEquals, []error{nil, nil})
// DetachVolume should only be called for existing attachments.
mockAdapter.CheckCalls(c, []gitjujutesting.StubCall{{
"ListVolumeAttachments", []interface{}{mockServerId},
}, {
"DetachVolume", []interface{}{mockServerId, mockVolId},
}, {
"ListVolumeAttachments", []interface{}{mockServerId2},
}})
}
示例13: testAttachFilesystems
func (s *managedfsSuite) testAttachFilesystems(c *gc.C, readOnly, reattach bool) {
const testMountPoint = "/in/the/place"
source := s.initSource(c)
cmd := s.commands.expect("df", "--output=source", filepath.Dir(testMountPoint))
cmd.respond("headers\n/same/as/rootfs", nil)
cmd = s.commands.expect("df", "--output=source", testMountPoint)
if reattach {
cmd.respond("headers\n/different/to/rootfs", nil)
} else {
cmd.respond("headers\n/same/as/rootfs", nil)
var args []string
if readOnly {
args = append(args, "-o", "ro")
}
args = append(args, "/dev/sda1", testMountPoint)
s.commands.expect("mount", args...)
}
s.blockDevices[names.NewVolumeTag("0")] = storage.BlockDevice{
DeviceName: "sda",
HardwareId: "capncrunch",
Size: 2,
}
s.filesystems[names.NewFilesystemTag("0/0")] = storage.Filesystem{
Tag: names.NewFilesystemTag("0/0"),
Volume: names.NewVolumeTag("0"),
}
results, err := source.AttachFilesystems([]storage.FilesystemAttachmentParams{{
Filesystem: names.NewFilesystemTag("0/0"),
FilesystemId: "filesystem-0-0",
AttachmentParams: storage.AttachmentParams{
Machine: names.NewMachineTag("0"),
InstanceId: "inst-ance",
ReadOnly: readOnly,
},
Path: testMountPoint,
}})
c.Assert(err, jc.ErrorIsNil)
c.Assert(results, jc.DeepEquals, []storage.AttachFilesystemsResult{{
FilesystemAttachment: &storage.FilesystemAttachment{
names.NewFilesystemTag("0/0"),
names.NewMachineTag("0"),
storage.FilesystemAttachmentInfo{
Path: testMountPoint,
ReadOnly: readOnly,
},
},
}})
}
示例14: TestWatchMachineVolumeAttachments
func (s *VolumeStateSuite) TestWatchMachineVolumeAttachments(c *gc.C) {
service := s.setupMixedScopeStorageService(c, "block")
addUnit := func(to *state.Machine) (u *state.Unit, m *state.Machine) {
var err error
u, err = service.AddUnit()
c.Assert(err, jc.ErrorIsNil)
if to != nil {
err = u.AssignToMachine(to)
c.Assert(err, jc.ErrorIsNil)
return u, to
}
err = s.State.AssignUnit(u, state.AssignCleanEmpty)
c.Assert(err, jc.ErrorIsNil)
mid, err := u.AssignedMachineId()
c.Assert(err, jc.ErrorIsNil)
m, err = s.State.Machine(mid)
c.Assert(err, jc.ErrorIsNil)
return u, m
}
_, m0 := addUnit(nil)
w := s.State.WatchMachineVolumeAttachments(names.NewMachineTag("0"))
defer testing.AssertStop(c, w)
wc := testing.NewStringsWatcherC(c, s.State, w)
wc.AssertChangeInSingleEvent("0:0/1", "0:0/2") // initial
wc.AssertNoChange()
addUnit(nil)
// no change, since we're only interested in the one machine.
wc.AssertNoChange()
err := s.State.DetachVolume(names.NewMachineTag("0"), names.NewVolumeTag("0"))
c.Assert(err, jc.ErrorIsNil)
// no change, since we're only interested in attachments of
// machine-scoped volumes.
wc.AssertNoChange()
err = s.State.DetachVolume(names.NewMachineTag("0"), names.NewVolumeTag("0/1"))
c.Assert(err, jc.ErrorIsNil)
wc.AssertChangeInSingleEvent("0:0/1") // dying
wc.AssertNoChange()
err = s.State.RemoveVolumeAttachment(names.NewMachineTag("0"), names.NewVolumeTag("0/1"))
c.Assert(err, jc.ErrorIsNil)
wc.AssertChangeInSingleEvent("0:0/1") // removed
wc.AssertNoChange()
addUnit(m0)
wc.AssertChangeInSingleEvent("0:0/7", "0:0/8") // added
}
示例15: TestEnsureDead
func (s *provisionerSuite) TestEnsureDead(c *gc.C) {
s.setupVolumes(c)
args := params.Entities{Entities: []params.Entity{{"volume-0-0"}, {"volume-1"}, {"volume-42"}}}
result, err := s.api.EnsureDead(args)
c.Assert(err, jc.ErrorIsNil)
// TODO(wallyworld) - this test will be updated when EnsureDead is supported
c.Assert(result, gc.DeepEquals, params.ErrorResults{
Results: []params.ErrorResult{
{Error: common.ServerError(common.NotSupportedError(names.NewVolumeTag("0/0"), "ensuring death"))},
{Error: common.ServerError(common.NotSupportedError(names.NewVolumeTag("1"), "ensuring death"))},
{Error: common.ServerError(errors.NotFoundf(`volume "42"`))},
},
})
}