本文整理汇总了Golang中github.com/wallyworld/core/state.Service.Networks方法的典型用法代码示例。如果您正苦于以下问题:Golang Service.Networks方法的具体用法?Golang Service.Networks怎么用?Golang Service.Networks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/wallyworld/core/state.Service
的用法示例。
在下文中一共展示了Service.Networks方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: processService
func (context *statusContext) processService(service *state.Service) (status api.ServiceStatus) {
serviceCharmURL, _ := service.CharmURL()
status.Charm = serviceCharmURL.String()
status.Exposed = service.IsExposed()
status.Life = processLife(service)
latestCharm, ok := context.latestCharms[*serviceCharmURL.WithRevision(-1)]
if ok && latestCharm != serviceCharmURL.String() {
status.CanUpgradeTo = latestCharm
}
var err error
status.Relations, status.SubordinateTo, err = context.processRelations(service)
if err != nil {
status.Err = err
return
}
includeNetworks, excludeNetworks, err := service.Networks()
if err == nil {
status.Networks = api.NetworksSpecification{
Enabled: includeNetworks,
Disabled: excludeNetworks,
}
}
if service.IsPrincipal() {
status.Units = context.processUnits(context.units[service.Name()], serviceCharmURL.String())
}
return status
}
示例2: AddUnits
// AddUnits starts n units of the given service and allocates machines
// to them as necessary.
func AddUnits(st *state.State, svc *state.Service, n int, machineIdSpec string) ([]*state.Unit, error) {
units := make([]*state.Unit, n)
// Hard code for now till we implement a different approach.
policy := state.AssignCleanEmpty
// All units should have the same networks as the service.
includeNetworks, excludeNetworks, err := svc.Networks()
if err != nil {
return nil, fmt.Errorf("cannot get service %q networks: %v", svc.Name(), err)
}
// TODO what do we do if we fail half-way through this process?
for i := 0; i < n; i++ {
unit, err := svc.AddUnit()
if err != nil {
return nil, fmt.Errorf("cannot add unit %d/%d to service %q: %v", i+1, n, svc.Name(), err)
}
if machineIdSpec != "" {
if n != 1 {
return nil, fmt.Errorf("cannot add multiple units of service %q to a single machine", svc.Name())
}
// machineIdSpec may be an existing machine or container, eg 3/lxc/2
// or a new container on a machine, eg lxc:3
mid := machineIdSpec
var containerType instance.ContainerType
specParts := strings.SplitN(machineIdSpec, ":", 2)
if len(specParts) > 1 {
firstPart := specParts[0]
var err error
if containerType, err = instance.ParseContainerType(firstPart); err == nil {
mid = specParts[1]
} else {
mid = machineIdSpec
}
}
if !names.IsMachine(mid) {
return nil, fmt.Errorf("invalid force machine id %q", mid)
}
var err error
var m *state.Machine
// If a container is to be used, create it.
if containerType != "" {
// Create the new machine marked as dirty so that
// nothing else will grab it before we assign the unit to it.
template := state.MachineTemplate{
Series: unit.Series(),
Jobs: []state.MachineJob{state.JobHostUnits},
Dirty: true,
IncludeNetworks: includeNetworks,
ExcludeNetworks: excludeNetworks,
}
m, err = st.AddMachineInsideMachine(template, mid, containerType)
} else {
m, err = st.Machine(mid)
}
if err != nil {
return nil, fmt.Errorf("cannot assign unit %q to machine: %v", unit.Name(), err)
}
err = unit.AssignToMachine(m)
if err != nil {
return nil, err
}
} else if err := st.AssignUnit(unit, policy); err != nil {
return nil, err
}
units[i] = unit
}
return units, nil
}