本文整理匯總了Golang中github.com/juju/juju/state.Machine.Units方法的典型用法代碼示例。如果您正苦於以下問題:Golang Machine.Units方法的具體用法?Golang Machine.Units怎麽用?Golang Machine.Units使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/juju/state.Machine
的用法示例。
在下文中一共展示了Machine.Units方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: machineTags
// machineTags returns machine-specific tags to set on the instance.
func (p *ProvisionerAPI) machineTags(m *state.Machine, jobs []multiwatcher.MachineJob) (map[string]string, error) {
// Names of all units deployed to the machine.
//
// TODO(axw) 2015-06-02 #1461358
// We need a worker that periodically updates
// instance tags with current deployment info.
units, err := m.Units()
if err != nil {
return nil, errors.Trace(err)
}
unitNames := make([]string, 0, len(units))
for _, unit := range units {
if !unit.IsPrincipal() {
continue
}
unitNames = append(unitNames, unit.Name())
}
sort.Strings(unitNames)
cfg, err := p.st.EnvironConfig()
if err != nil {
return nil, errors.Trace(err)
}
machineTags := instancecfg.InstanceTags(cfg, jobs)
if len(unitNames) > 0 {
machineTags[tags.JujuUnitsDeployed] = strings.Join(unitNames, " ")
}
return machineTags, nil
}
示例2: commonServiceInstances
// commonServiceInstances returns instances with
// services in common with the specified machine.
func commonServiceInstances(st *state.State, m *state.Machine) ([]instance.Id, error) {
units, err := m.Units()
if err != nil {
return nil, err
}
instanceIdSet := make(set.Strings)
for _, unit := range units {
if !unit.IsPrincipal() {
continue
}
instanceIds, err := state.ServiceInstances(st, unit.ApplicationName())
if err != nil {
return nil, err
}
for _, instanceId := range instanceIds {
instanceIdSet.Add(string(instanceId))
}
}
instanceIds := make([]instance.Id, instanceIdSet.Size())
// Sort values to simplify testing.
for i, instanceId := range instanceIdSet.SortedValues() {
instanceIds[i] = instance.Id(instanceId)
}
return instanceIds, nil
}
示例3: machineEndpointBindings
func (p *ProvisionerAPI) machineEndpointBindings(m *state.Machine) (map[string]string, error) {
units, err := m.Units()
if err != nil {
return nil, errors.Trace(err)
}
spacesNamesToProviderIds, err := p.allSpaceNamesToProviderIds()
if err != nil {
return nil, errors.Trace(err)
}
var combinedBindings map[string]string
processedServicesSet := set.NewStrings()
for _, unit := range units {
if !unit.IsPrincipal() {
continue
}
service, err := unit.Application()
if err != nil {
return nil, errors.Trace(err)
}
if processedServicesSet.Contains(service.Name()) {
// Already processed, skip it.
continue
}
bindings, err := service.EndpointBindings()
if err != nil {
return nil, errors.Trace(err)
}
processedServicesSet.Add(service.Name())
if len(bindings) == 0 {
continue
}
if combinedBindings == nil {
combinedBindings = make(map[string]string)
}
for endpoint, spaceName := range bindings {
if spaceName == "" {
// Skip unspecified bindings, as they won't affect the instance
// selected for provisioning.
continue
}
spaceProviderId, nameKnown := spacesNamesToProviderIds[spaceName]
if nameKnown {
combinedBindings[endpoint] = spaceProviderId
} else {
// Technically, this can't happen in practice, as we're
// validating the bindings during service deployment.
return nil, errors.Errorf("unknown space %q with no provider ID specified for endpoint %q", spaceName, endpoint)
}
}
}
return combinedBindings, nil
}