本文整理汇总了Golang中github.com/juju/names.ParseMachineTag函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseMachineTag函数的具体用法?Golang ParseMachineTag怎么用?Golang ParseMachineTag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ParseMachineTag函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetMachineActiveNetworks
// GetMachineActiveNetworks returns the tags of the all networks the
// each given machine has open ports on.
func (f *FirewallerAPI) GetMachineActiveNetworks(args params.Entities) (params.StringsResults, error) {
result := params.StringsResults{
Results: make([]params.StringsResult, len(args.Entities)),
}
canAccess, err := f.accessMachine()
if err != nil {
return params.StringsResults{}, err
}
for i, entity := range args.Entities {
machineTag, err := names.ParseMachineTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := f.getMachine(canAccess, machineTag)
if err != nil {
result.Results[i].Error = common.ServerError(err)
continue
}
ports, err := machine.AllPorts()
if err != nil {
result.Results[i].Error = common.ServerError(err)
continue
}
for _, port := range ports {
networkTag := names.NewNetworkTag(port.NetworkName()).String()
result.Results[i].Result = append(result.Results[i].Result, networkTag)
}
}
return result, nil
}
示例2: SetInstanceInfo
// SetInstanceInfo sets the provider specific machine id, nonce,
// metadata and network info for each given machine. Once set, the
// instance id cannot be changed.
func (p *ProvisionerAPI) SetInstanceInfo(args params.InstancesInfo) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Machines)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
for i, arg := range args.Machines {
tag, err := names.ParseMachineTag(arg.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := p.getMachine(canAccess, tag)
if err == nil {
var networks []state.NetworkInfo
var interfaces []state.NetworkInterfaceInfo
networks, interfaces, err = networkParamsToStateParams(arg.Networks, arg.Interfaces)
if err == nil {
err = machine.SetInstanceInfo(
arg.InstanceId, arg.Nonce, arg.Characteristics,
networks, interfaces)
}
if err != nil {
// Give the user more context about the error.
err = fmt.Errorf("aborted instance %q: %v", arg.InstanceId, err)
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例3: SetMachineBlockDevices
func (d *DiskManagerAPI) SetMachineBlockDevices(args params.SetMachineBlockDevices) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.MachineBlockDevices)),
}
canAccess, err := d.getAuthFunc()
if err != nil {
return result, err
}
for i, arg := range args.MachineBlockDevices {
tag, err := names.ParseMachineTag(arg.Machine)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
if !canAccess(tag) {
err = common.ErrPerm
} else {
// TODO(axw) create volumes for block devices without matching
// volumes, if and only if the block device has a serial. Under
// the assumption of unique (to a machine) serial IDs, this
// gives us a guaranteed *persistently* unique way of identifying
// the volume.
//
// NOTE: we must predicate the above on there being no unprovisioned
// volume attachments for the machine, otherwise we would have
// a race between the volume attachment info being recorded and
// the diskmanager publishing block devices and erroneously creating
// volumes.
err = d.st.SetMachineBlockDevices(tag.Id(), stateBlockDeviceInfo(arg.BlockDevices))
// TODO(axw) set volume/filesystem attachment info.
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例4: getMachineForSettingNetworkConfig
func (api *MachinerAPI) getMachineForSettingNetworkConfig(machineTag string) (*state.Machine, error) {
canModify, err := api.getCanModify()
if err != nil {
return nil, errors.Trace(err)
}
tag, err := names.ParseMachineTag(machineTag)
if err != nil {
return nil, errors.Trace(err)
}
if !canModify(tag) {
return nil, errors.Trace(common.ErrPerm)
}
m, err := api.getMachine(tag)
if errors.IsNotFound(err) {
return nil, errors.Trace(common.ErrPerm)
} else if err != nil {
return nil, errors.Trace(err)
}
if m.IsContainer() {
logger.Warningf("not updating network config for container %q", m.Id())
}
return m, nil
}
示例5: SetSupportedContainers
// SetSupportedContainers updates the list of containers supported by the machines passed in args.
func (p *ProvisionerAPI) SetSupportedContainers(args params.MachineContainersParams) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Params)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
for i, arg := range args.Params {
tag, err := names.ParseMachineTag(arg.MachineTag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := p.getMachine(canAccess, tag)
if err != nil {
result.Results[i].Error = common.ServerError(err)
continue
}
if len(arg.ContainerTypes) == 0 {
err = machine.SupportsNoContainers()
} else {
err = machine.SetSupportedContainers(arg.ContainerTypes)
}
if err != nil {
result.Results[i].Error = common.ServerError(err)
}
}
return result, nil
}
示例6: InstanceStatus
// InstanceStatus returns the instance status for each given entity.
// Only machine tags are accepted.
func (p *ProvisionerAPI) InstanceStatus(args params.Entities) (params.StatusResults, error) {
result := params.StatusResults{
Results: make([]params.StatusResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
logger.Errorf("failed to get an authorisation function: %v", err)
return result, errors.Trace(err)
}
for i, arg := range args.Entities {
mTag, err := names.ParseMachineTag(arg.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(err)
continue
}
machine, err := p.getMachine(canAccess, mTag)
if err == nil {
var statusInfo status.StatusInfo
statusInfo, err = machine.InstanceStatus()
result.Results[i].Status = statusInfo.Status
result.Results[i].Info = statusInfo.Message
result.Results[i].Data = statusInfo.Data
result.Results[i].Since = statusInfo.Since
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例7: Constraints
// Constraints returns the constraints for each given machine entity.
func (p *ProvisionerAPI) Constraints(args params.Entities) (params.ConstraintsResults, error) {
result := params.ConstraintsResults{
Results: make([]params.ConstraintsResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
for i, entity := range args.Entities {
tag, err := names.ParseMachineTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := p.getMachine(canAccess, tag)
if err == nil {
var cons constraints.Value
cons, err = machine.Constraints()
if err == nil {
result.Results[i].Constraints = cons
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例8: DistributionGroup
// DistributionGroup returns, for each given machine entity,
// a slice of instance.Ids that belong to the same distribution
// group as that machine. This information may be used to
// distribute instances for high availability.
func (p *ProvisionerAPI) DistributionGroup(args params.Entities) (params.DistributionGroupResults, error) {
result := params.DistributionGroupResults{
Results: make([]params.DistributionGroupResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
for i, entity := range args.Entities {
tag, err := names.ParseMachineTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := p.getMachine(canAccess, tag)
if err == nil {
// If the machine is an environment manager, return
// environment manager instances. Otherwise, return
// instances with services in common with the machine
// being provisioned.
if machine.IsManager() {
result.Results[i].Result, err = environManagerInstances(p.st)
} else {
result.Results[i].Result, err = commonServiceInstances(p.st, machine)
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例9: API2Payload
// API2Payload converts an API Payload info struct into
// a payload.FullPayloadInfo struct.
func API2Payload(apiInfo Payload) (payload.FullPayloadInfo, error) {
labels := make([]string, len(apiInfo.Labels))
copy(labels, apiInfo.Labels)
var unit, machine string
var empty payload.FullPayloadInfo
if apiInfo.Unit != "" {
tag, err := names.ParseUnitTag(apiInfo.Unit)
if err != nil {
return empty, errors.Trace(err)
}
unit = tag.Id()
}
if apiInfo.Machine != "" {
tag, err := names.ParseMachineTag(apiInfo.Machine)
if err != nil {
return empty, errors.Trace(err)
}
machine = tag.Id()
}
return payload.FullPayloadInfo{
Payload: payload.Payload{
PayloadClass: charm.PayloadClass{
Name: apiInfo.Class,
Type: apiInfo.Type,
},
ID: apiInfo.ID,
Status: apiInfo.Status,
Labels: labels,
Unit: unit,
},
Machine: machine,
}, nil
}
示例10: RequestedNetworks
// RequestedNetworks returns the requested networks for each given
// machine entity. Each entry in both lists is returned with its
// provider specific id.
func (p *ProvisionerAPI) RequestedNetworks(args params.Entities) (params.RequestedNetworksResults, error) {
result := params.RequestedNetworksResults{
Results: make([]params.RequestedNetworkResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
for i, entity := range args.Entities {
tag, err := names.ParseMachineTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := p.getMachine(canAccess, tag)
if err == nil {
var networks []string
networks, err = machine.RequestedNetworks()
if err == nil {
// TODO(dimitern) For now, since network names and
// provider ids are the same, we return what we got
// from state. In the future, when networks can be
// added before provisioning, we should convert both
// slices from juju network names to provider-specific
// ids before returning them.
result.Results[i].Networks = networks
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例11: WatchBlockDevices
// WatchBlockDevices watches for changes to the specified machines' block devices.
func (s *StorageProvisionerAPI) WatchBlockDevices(args params.Entities) (params.NotifyWatchResults, error) {
canAccess, err := s.getBlockDevicesAuthFunc()
if err != nil {
return params.NotifyWatchResults{}, common.ServerError(common.ErrPerm)
}
results := params.NotifyWatchResults{
Results: make([]params.NotifyWatchResult, len(args.Entities)),
}
one := func(arg params.Entity) (string, error) {
machineTag, err := names.ParseMachineTag(arg.Tag)
if err != nil {
return "", err
}
if !canAccess(machineTag) {
return "", common.ErrPerm
}
w := s.st.WatchBlockDevices(machineTag)
if _, ok := <-w.Changes(); ok {
return s.resources.Register(w), nil
}
return "", watcher.EnsureErr(w)
}
for i, arg := range args.Entities {
var result params.NotifyWatchResult
id, err := one(arg)
if err != nil {
result.Error = common.ServerError(err)
} else {
result.NotifyWatcherId = id
}
results.Results[i] = result
}
return results, nil
}
示例12: maybeReleaseContainerAddresses
func maybeReleaseContainerAddresses(
api APICalls,
instanceID instance.Id,
namespace string,
log loggo.Logger,
) {
if environs.AddressAllocationEnabled() {
// The addresser worker will take care of the addresses.
return
}
// If we're not using addressable containers, we might still have used MAAS
// 1.8+ device to register the container when provisioning. In that case we
// need to attempt releasing the device, but ignore a NotSupported error
// (when we're not using MAAS 1.8+).
namespacePrefix := fmt.Sprintf("%s-", namespace)
tagString := strings.TrimPrefix(string(instanceID), namespacePrefix)
containerTag, err := names.ParseMachineTag(tagString)
if err != nil {
// Not a reason to cause StopInstances to fail though..
log.Warningf("unexpected container tag %q: %v", instanceID, err)
return
}
err = api.ReleaseContainerAddresses(containerTag)
switch {
case err == nil:
log.Infof("released all addresses for container %q", containerTag.Id())
case errors.IsNotSupported(err):
log.Warningf("not releasing all addresses for container %q: %v", containerTag.Id(), err)
default:
log.Warningf(
"unexpected error trying to release container %q addreses: %v",
containerTag.Id(), err,
)
}
}
示例13: SetMachineAddresses
func (api *MachinerAPI) SetMachineAddresses(args params.SetMachinesAddresses) (params.ErrorResults, error) {
results := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.MachineAddresses)),
}
canModify, err := api.getCanModify()
if err != nil {
return results, err
}
for i, arg := range args.MachineAddresses {
tag, err := names.ParseMachineTag(arg.Tag)
if err != nil {
results.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
err = common.ErrPerm
if canModify(tag) {
var m *state.Machine
m, err = api.getMachine(tag)
if err == nil {
err = m.SetMachineAddresses(arg.Addresses...)
} else if errors.IsNotFound(err) {
err = common.ErrPerm
}
}
results.Results[i].Error = common.ServerError(err)
}
return results, nil
}
示例14: prepareContainerAccessEnvironment
// prepareContainerAccessEnvironment retrieves the environment, host machine, and access
// for working with containers.
func (p *ProvisionerAPI) prepareContainerAccessEnvironment() (environs.NetworkingEnviron, *state.Machine, common.AuthFunc, error) {
cfg, err := p.st.EnvironConfig()
if err != nil {
return nil, nil, nil, errors.Annotate(err, "failed to get environment config")
}
environ, err := environs.New(cfg)
if err != nil {
return nil, nil, nil, errors.Annotate(err, "failed to construct an environment from config")
}
netEnviron, supported := environs.SupportsNetworking(environ)
if !supported {
// " not supported" will be appended to the message below.
return nil, nil, nil, errors.NotSupportedf("environment %q networking", cfg.Name())
}
canAccess, err := p.getAuthFunc()
if err != nil {
return nil, nil, nil, errors.Annotate(err, "cannot authenticate request")
}
hostAuthTag := p.authorizer.GetAuthTag()
if hostAuthTag == nil {
return nil, nil, nil, errors.Errorf("authenticated entity tag is nil")
}
hostTag, err := names.ParseMachineTag(hostAuthTag.String())
if err != nil {
return nil, nil, nil, errors.Trace(err)
}
host, err := p.getMachine(canAccess, hostTag)
if err != nil {
return nil, nil, nil, errors.Trace(err)
}
return netEnviron, host, canAccess, nil
}
示例15: constructStartInstanceParams
func constructStartInstanceParams(
machine *apiprovisioner.Machine,
instanceConfig *instancecfg.InstanceConfig,
provisioningInfo *params.ProvisioningInfo,
possibleTools coretools.List,
) (environs.StartInstanceParams, error) {
volumes := make([]storage.VolumeParams, len(provisioningInfo.Volumes))
for i, v := range provisioningInfo.Volumes {
volumeTag, err := names.ParseVolumeTag(v.VolumeTag)
if err != nil {
return environs.StartInstanceParams{}, errors.Trace(err)
}
if v.Attachment == nil {
return environs.StartInstanceParams{}, errors.Errorf("volume params missing attachment")
}
machineTag, err := names.ParseMachineTag(v.Attachment.MachineTag)
if err != nil {
return environs.StartInstanceParams{}, errors.Trace(err)
}
if machineTag != machine.Tag() {
return environs.StartInstanceParams{}, errors.Errorf("volume attachment params has invalid machine tag")
}
if v.Attachment.InstanceId != "" {
return environs.StartInstanceParams{}, errors.Errorf("volume attachment params specifies instance ID")
}
volumes[i] = storage.VolumeParams{
volumeTag,
v.Size,
storage.ProviderType(v.Provider),
v.Attributes,
v.Tags,
&storage.VolumeAttachmentParams{
AttachmentParams: storage.AttachmentParams{
Machine: machineTag,
ReadOnly: v.Attachment.ReadOnly,
},
Volume: volumeTag,
},
}
}
var subnetsToZones map[network.Id][]string
if provisioningInfo.SubnetsToZones != nil {
// Convert subnet provider ids from string to network.Id.
subnetsToZones = make(map[network.Id][]string, len(provisioningInfo.SubnetsToZones))
for providerId, zones := range provisioningInfo.SubnetsToZones {
subnetsToZones[network.Id(providerId)] = zones
}
}
return environs.StartInstanceParams{
Constraints: provisioningInfo.Constraints,
Tools: possibleTools,
InstanceConfig: instanceConfig,
Placement: provisioningInfo.Placement,
DistributionGroup: machine.DistributionGroup,
Volumes: volumes,
SubnetsToZones: subnetsToZones,
}, nil
}