本文整理汇总了Golang中github.com/juju/names.MachineTag类的典型用法代码示例。如果您正苦于以下问题:Golang MachineTag类的具体用法?Golang MachineTag怎么用?Golang MachineTag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MachineTag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: MachineVolumeAttachments
// MachineVolumeAttachments returns all of the VolumeAttachments for the
// specified machine.
func (st *State) MachineVolumeAttachments(machine names.MachineTag) ([]VolumeAttachment, error) {
attachments, err := st.volumeAttachments(bson.D{{"machineid", machine.Id()}})
if err != nil {
return nil, errors.Annotatef(err, "getting volume attachments for machine %q", machine.Id())
}
return attachments, nil
}
示例2: MachineFilesystemAttachments
// MachineFilesystemAttachments returns all of the FilesystemAttachments for the
// specified machine.
func (st *State) MachineFilesystemAttachments(machine names.MachineTag) ([]FilesystemAttachment, error) {
attachments, err := st.filesystemAttachments(bson.D{{"machineid", machine.Id()}})
if err != nil {
return nil, errors.Annotatef(err, "getting filesystem attachments for machine %q", machine.Id())
}
return attachments, nil
}
示例3: assertMachineStorageRefs
// assertMachineStorageRefs ensures that the specified machine's set of volume
// and filesystem references corresponds exactly to the volume and filesystem
// attachments that relate to the machine.
func assertMachineStorageRefs(c *gc.C, st *state.State, m names.MachineTag) {
machines, closer := state.GetRawCollection(st, state.MachinesC)
defer closer()
var doc struct {
Volumes []string `bson:"volumes,omitempty"`
Filesystems []string `bson:"filesystems,omitempty"`
}
err := machines.FindId(state.DocID(st, m.Id())).One(&doc)
c.Assert(err, jc.ErrorIsNil)
have := make(set.Tags)
for _, v := range doc.Volumes {
have.Add(names.NewVolumeTag(v))
}
for _, f := range doc.Filesystems {
have.Add(names.NewFilesystemTag(f))
}
expect := make(set.Tags)
volumeAttachments, err := st.MachineVolumeAttachments(m)
c.Assert(err, jc.ErrorIsNil)
for _, a := range volumeAttachments {
expect.Add(a.Volume())
}
filesystemAttachments, err := st.MachineFilesystemAttachments(m)
c.Assert(err, jc.ErrorIsNil)
for _, a := range filesystemAttachments {
expect.Add(a.Filesystem())
}
c.Assert(have, jc.DeepEquals, expect)
}
示例4: removeMachineFilesystemsOps
// removeMachineFilesystemsOps returns txn.Ops to remove non-persistent filesystems
// attached to the specified machine. This is used when the given machine is
// being removed from state.
func (st *State) removeMachineFilesystemsOps(machine names.MachineTag) ([]txn.Op, error) {
attachments, err := st.MachineFilesystemAttachments(machine)
if err != nil {
return nil, errors.Trace(err)
}
ops := make([]txn.Op, 0, len(attachments))
for _, a := range attachments {
filesystemTag := a.Filesystem()
// When removing the machine, there should only remain
// non-persistent storage. This will be implicitly
// removed when the machine is removed, so we do not
// use removeFilesystemAttachmentOps or removeFilesystemOps,
// which track and update related documents.
ops = append(ops, txn.Op{
C: filesystemAttachmentsC,
Id: filesystemAttachmentId(machine.Id(), filesystemTag.Id()),
Assert: txn.DocExists,
Remove: true,
})
canRemove, err := isFilesystemInherentlyMachineBound(st, filesystemTag)
if err != nil {
return nil, errors.Trace(err)
}
if !canRemove {
return nil, errors.Errorf("machine has non-machine bound filesystem %v", filesystemTag.Id())
}
ops = append(ops, txn.Op{
C: filesystemsC,
Id: filesystemTag.Id(),
Assert: txn.DocExists,
Remove: true,
})
}
return ops, nil
}
示例5: AllMachinePorts
// AllMachinePorts returns all port ranges currently open on the given
// machine, mapped to the tags of the unit that opened them and the
// relation that applies.
func (st *State) AllMachinePorts(machineTag names.MachineTag) (map[network.PortRange]params.RelationUnit, error) {
if st.BestAPIVersion() < 1 {
// AllMachinePorts() was introduced in UniterAPIV1.
return nil, errors.NotImplementedf("AllMachinePorts() (need V1+)")
}
var results params.MachinePortsResults
args := params.Entities{
Entities: []params.Entity{{Tag: machineTag.String()}},
}
err := st.facade.FacadeCall("AllMachinePorts", args, &results)
if err != nil {
return nil, err
}
if len(results.Results) != 1 {
return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return nil, result.Error
}
portsMap := make(map[network.PortRange]params.RelationUnit)
for _, ports := range result.Ports {
portRange := ports.PortRange.NetworkPortRange()
portsMap[portRange] = params.RelationUnit{
Unit: ports.UnitTag,
Relation: ports.RelationTag,
}
}
return portsMap, nil
}
示例6: refreshMachine
// refreshMachine refreshes the specified machine's instance ID. If it is set,
// then the machine watcher is stopped and pending entities' parameters are
// updated. If the machine is not provisioned yet, this method is a no-op.
func refreshMachine(ctx *context, tag names.MachineTag) error {
w, ok := ctx.machines[tag]
if !ok {
return errors.Errorf("machine %s is not being watched", tag.Id())
}
stopAndRemove := func() error {
if err := w.stop(); err != nil {
return errors.Annotate(err, "stopping machine watcher")
}
delete(ctx.machines, tag)
return nil
}
results, err := ctx.machineAccessor.InstanceIds([]names.MachineTag{tag})
if err != nil {
return errors.Annotate(err, "getting machine instance ID")
}
if err := results[0].Error; err != nil {
if params.IsCodeNotProvisioned(err) {
return nil
} else if params.IsCodeNotFound(err) {
// Machine is gone, so stop watching.
return stopAndRemove()
}
return errors.Annotate(err, "getting machine instance ID")
}
machineProvisioned(ctx, tag, instance.Id(results[0].Result))
// machine provisioning is the only thing we care about;
// stop the watcher.
return stopAndRemove()
}
示例7: WatchMachine
func (s stateShim) WatchMachine(tag names.MachineTag) (state.NotifyWatcher, error) {
m, err := s.Machine(tag.Id())
if err != nil {
return nil, errors.Trace(err)
}
return m.Watch(), nil
}
示例8: MachineInstanceId
func (s stateShim) MachineInstanceId(tag names.MachineTag) (instance.Id, error) {
m, err := s.Machine(tag.Id())
if err != nil {
return "", errors.Trace(err)
}
return m.InstanceId()
}
示例9: detachFilesystemOps
func detachFilesystemOps(m names.MachineTag, f names.FilesystemTag) []txn.Op {
return []txn.Op{{
C: filesystemAttachmentsC,
Id: filesystemAttachmentId(m.Id(), f.Id()),
Assert: isAliveDoc,
Update: bson.D{{"$set", bson.D{{"life", Dying}}}},
}}
}
示例10: detachVolumeOps
func detachVolumeOps(m names.MachineTag, v names.VolumeTag) []txn.Op {
return []txn.Op{{
C: volumeAttachmentsC,
Id: volumeAttachmentId(m.Id(), v.Id()),
Assert: isAliveDoc,
Update: bson.D{{"$set", bson.D{{"life", Dying}}}},
}}
}
示例11: ReleaseContainerAddresses
// ReleaseContainerAddresses releases a static IP address allocated to a
// container.
func (st *State) ReleaseContainerAddresses(containerTag names.MachineTag) (err error) {
defer errors.DeferredAnnotatef(&err, "cannot release static addresses for %q", containerTag.Id())
var result params.ErrorResults
args := params.Entities{
Entities: []params.Entity{{Tag: containerTag.String()}},
}
if err := st.facade.FacadeCall("ReleaseContainerAddresses", args, &result); err != nil {
return err
}
return result.OneError()
}
示例12: GetSSHHostKeys
// GetSSHHostKeys retrieves the SSH host keys stored for an entity.
///
// NOTE: Currently only machines are supported. This can be
// generalised to take other tag types later, if and when we need it.
func (st *State) GetSSHHostKeys(tag names.MachineTag) (SSHHostKeys, error) {
coll, closer := st.getCollection(sshHostKeysC)
defer closer()
var doc sshHostKeysDoc
err := coll.FindId(machineGlobalKey(tag.Id())).One(&doc)
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("SSH host keys for %s", tag)
} else if err != nil {
return nil, errors.Annotate(err, "SSH host key lookup failed")
}
return SSHHostKeys(doc.Keys), nil
}
示例13: FilesystemAttachment
// FilesystemAttachment returns the FilesystemAttachment corresponding to
// the specified filesystem and machine.
func (st *State) FilesystemAttachment(machine names.MachineTag, filesystem names.FilesystemTag) (FilesystemAttachment, error) {
coll, cleanup := st.getCollection(filesystemAttachmentsC)
defer cleanup()
var att filesystemAttachment
err := coll.FindId(filesystemAttachmentId(machine.Id(), filesystem.Id())).One(&att.doc)
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("filesystem %q on machine %q", filesystem.Id(), machine.Id())
} else if err != nil {
return nil, errors.Annotatef(err, "getting filesystem %q on machine %q", filesystem.Id(), machine.Id())
}
return &att, nil
}
示例14: prepareOrGetContainerInterfaceInfo
// prepareOrGetContainerInterfaceInfo returns the necessary information to
// configure network interfaces of a container with allocated static
// IP addresses.
//
// TODO(dimitern): Before we start using this, we need to rename both
// the method and the network.InterfaceInfo type to be called
// InterfaceConfig.
func (st *State) prepareOrGetContainerInterfaceInfo(
containerTag names.MachineTag, allocateNewAddress bool) (
[]network.InterfaceInfo, error) {
var result params.MachineNetworkConfigResults
args := params.Entities{
Entities: []params.Entity{{Tag: containerTag.String()}},
}
facadeName := ""
if allocateNewAddress {
facadeName = "PrepareContainerInterfaceInfo"
} else {
facadeName = "GetContainerInterfaceInfo"
}
if err := st.facade.FacadeCall(facadeName, args, &result); err != nil {
return nil, err
}
if len(result.Results) != 1 {
return nil, errors.Errorf("expected 1 result, got %d", len(result.Results))
}
if err := result.Results[0].Error; err != nil {
return nil, err
}
ifaceInfo := make([]network.InterfaceInfo, len(result.Results[0].Config))
for i, cfg := range result.Results[0].Config {
ifaceInfo[i] = network.InterfaceInfo{
DeviceIndex: cfg.DeviceIndex,
MACAddress: cfg.MACAddress,
CIDR: cfg.CIDR,
MTU: cfg.MTU,
ProviderId: network.Id(cfg.ProviderId),
ProviderSubnetId: network.Id(cfg.ProviderSubnetId),
ProviderSpaceId: network.Id(cfg.ProviderSpaceId),
ProviderVLANId: network.Id(cfg.ProviderVLANId),
ProviderAddressId: network.Id(cfg.ProviderAddressId),
VLANTag: cfg.VLANTag,
InterfaceName: cfg.InterfaceName,
ParentInterfaceName: cfg.ParentInterfaceName,
InterfaceType: network.InterfaceType(cfg.InterfaceType),
Disabled: cfg.Disabled,
NoAutoStart: cfg.NoAutoStart,
ConfigType: network.InterfaceConfigType(cfg.ConfigType),
Address: network.NewAddress(cfg.Address),
DNSServers: network.NewAddresses(cfg.DNSServers...),
DNSSearchDomains: cfg.DNSSearchDomains,
GatewayAddress: network.NewAddress(cfg.GatewayAddress),
}
}
return ifaceInfo, nil
}
示例15: NewAPI
// NewAPI returns a new API client for the Singular facade. It exposes methods
// for claiming and observing administration responsibility for the apiCaller's
// model, on behalf of the supplied controller machine.
func NewAPI(apiCaller base.APICaller, controllerTag names.MachineTag) (*API, error) {
controllerId := controllerTag.Id()
if !names.IsValidMachine(controllerId) {
return nil, errors.NotValidf("controller tag")
}
modelTag, err := apiCaller.ModelTag()
if err != nil {
return nil, errors.Trace(err)
}
facadeCaller := base.NewFacadeCaller(apiCaller, "Singular")
return &API{
modelTag: modelTag,
controllerTag: controllerTag,
facadeCaller: facadeCaller,
}, nil
}