本文整理汇总了Golang中github.com/juju/juju/state.Machine类的典型用法代码示例。如果您正苦于以下问题:Golang Machine类的具体用法?Golang Machine怎么用?Golang Machine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Machine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: buildMachineMatcherShims
func buildMachineMatcherShims(m *state.Machine, patterns []string) (shims []closurePredicate, _ error) {
// Look at machine status.
statusInfo, err := m.Status()
if err != nil {
return nil, err
}
shims = append(shims, func() (bool, bool, error) { return matchAgentStatus(patterns, statusInfo.Status) })
// Look at machine addresses. WARNING: Avoid the temptation to
// bring the append into the loop. The value we would close over
// will continue to change after the closure is created, and we'd
// only examine the last element of the loop for all closures.
var addrs []string
for _, a := range m.Addresses() {
addrs = append(addrs, a.Value)
}
shims = append(shims, func() (bool, bool, error) { return matchSubnet(patterns, addrs...) })
// If the machine hosts a unit that matches any of the given
// criteria, consider the machine a match as well.
unitShims, err := buildShimsForUnit(m.Units, patterns...)
if err != nil {
return nil, err
}
shims = append(shims, unitShims...)
// Units may be able to match the pattern. Ultimately defer to
// that logic, and guard against breaking the predicate-chain.
if len(unitShims) <= 0 {
shims = append(shims, func() (bool, bool, error) { return false, true, nil })
}
return
}
示例2: 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
}
示例3: getProvisioningInfo
func getProvisioningInfo(m *state.Machine) (*params.ProvisioningInfo, error) {
cons, err := m.Constraints()
if err != nil {
return nil, err
}
// 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.
networks, err := m.RequestedNetworks()
if err != nil {
return nil, err
}
var jobs []params.MachineJob
for _, job := range m.Jobs() {
jobs = append(jobs, job.ToParams())
}
return ¶ms.ProvisioningInfo{
Constraints: cons,
Series: m.Series(),
Placement: m.Placement(),
Networks: networks,
Jobs: jobs,
}, nil
}
示例4: 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
}
示例5: getOneMachineProviderNetworkConfig
func (api *MachinerAPI) getOneMachineProviderNetworkConfig(m *state.Machine) ([]params.NetworkConfig, error) {
instId, err := m.InstanceId()
if err != nil {
return nil, errors.Trace(err)
}
netEnviron, err := networkingcommon.NetworkingEnvironFromModelConfig(
stateenvirons.EnvironConfigGetter{api.st},
)
if errors.IsNotSupported(err) {
logger.Infof("not updating provider network config: %v", err)
return nil, nil
} else if err != nil {
return nil, errors.Annotate(err, "cannot get provider network config")
}
interfaceInfos, err := netEnviron.NetworkInterfaces(instId)
if err != nil {
return nil, errors.Annotatef(err, "cannot get network interfaces of %q", instId)
}
if len(interfaceInfos) == 0 {
logger.Infof("not updating provider network config: no interfaces returned")
return nil, nil
}
providerConfig := networkingcommon.NetworkConfigFromInterfaceInfo(interfaceInfos)
logger.Tracef("provider network config instance %q: %+v", instId, providerConfig)
return providerConfig, nil
}
示例6: expectStarted
func (s *lxcProvisionerSuite) expectStarted(c *gc.C, machine *state.Machine) string {
// This check in particular leads to tests just hanging
// indefinitely quite often on i386.
coretesting.SkipIfI386(c, "lp:1425569")
var event mock.Event
s.State.StartSync()
select {
case event = <-s.events:
c.Assert(event.Action, gc.Equals, mock.Created)
argsSet := set.NewStrings(event.TemplateArgs...)
c.Assert(argsSet.Contains("imageURL"), jc.IsTrue)
case <-time.After(coretesting.LongWait):
c.Fatalf("timeout while waiting the mock container to get created")
}
select {
case event = <-s.events:
c.Assert(event.Action, gc.Equals, mock.Started)
err := machine.Refresh()
c.Assert(err, jc.ErrorIsNil)
case <-time.After(coretesting.LongWait):
c.Fatalf("timeout while waiting the mock container to start")
}
s.waitInstanceId(c, machine, instance.Id(event.InstanceId))
return event.InstanceId
}
示例7: newAgent
// newAgent returns a new MachineAgent instance
func (s *commonMachineSuite) newAgent(c *gc.C, m *state.Machine) *MachineAgent {
a := &MachineAgent{}
s.initAgent(c, a, "--machine-id", m.Id())
err := a.ReadConfig(m.Tag().String())
c.Assert(err, gc.IsNil)
return a
}
示例8: 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
}
示例9: constructImageConstraint
// constructImageConstraint returns model-specific criteria used to look for image metadata.
func (p *ProvisionerAPI) constructImageConstraint(m *state.Machine) (*imagemetadata.ImageConstraint, environs.Environ, error) {
// If we can determine current region,
// we want only metadata specific to this region.
cloud, env, err := p.obtainEnvCloudConfig()
if err != nil {
return nil, nil, errors.Trace(err)
}
lookup := simplestreams.LookupParams{
Series: []string{m.Series()},
Stream: env.Config().ImageStream(),
}
mcons, err := m.Constraints()
if err != nil {
return nil, nil, errors.Annotatef(err, "cannot get machine constraints for machine %v", m.MachineTag().Id())
}
if mcons.Arch != nil {
lookup.Arches = []string{*mcons.Arch}
}
if cloud != nil {
lookup.CloudSpec = *cloud
}
return imagemetadata.NewImageConstraint(lookup), env, nil
}
示例10: primeAgentWithMachine
func (s *commonMachineSuite) primeAgentWithMachine(c *gc.C, m *state.Machine, vers version.Binary) (*state.Machine, agent.ConfigSetterWriter, *tools.Tools) {
pinger, err := m.SetAgentPresence()
c.Assert(err, jc.ErrorIsNil)
s.AddCleanup(func(c *gc.C) {
c.Assert(worker.Stop(pinger), jc.ErrorIsNil)
})
return s.configureMachine(c, m.Id(), vers)
}
示例11: assertAssignUnit
func (s *assignCleanSuite) assertAssignUnit(c *gc.C, expectedMachine *state.Machine) {
unit, err := s.wordpress.AddUnit()
c.Assert(err, jc.ErrorIsNil)
reusedMachine, err := s.assignUnit(unit)
c.Assert(err, jc.ErrorIsNil)
c.Assert(reusedMachine.Id(), gc.Equals, expectedMachine.Id())
c.Assert(reusedMachine.Clean(), jc.IsFalse)
}
示例12: expectStarted
func (s *kvmProvisionerSuite) expectStarted(c *gc.C, machine *state.Machine) string {
s.State.StartSync()
event := s.nextEvent(c)
c.Assert(event.Action, gc.Equals, mock.Started)
err := machine.Refresh()
c.Assert(err, jc.ErrorIsNil)
s.waitInstanceId(c, machine, instance.Id(event.InstanceId))
return event.InstanceId
}
示例13: assertRetryProvisioning
func (s *clientSuite) assertRetryProvisioning(c *gc.C, machine *state.Machine) {
_, err := s.APIState.Client().RetryProvisioning(machine.Tag().(names.MachineTag))
c.Assert(err, jc.ErrorIsNil)
statusInfo, err := machine.Status()
c.Assert(err, jc.ErrorIsNil)
c.Assert(statusInfo.Status, gc.Equals, status.Error)
c.Assert(statusInfo.Message, gc.Equals, "error")
c.Assert(statusInfo.Data["transient"], jc.IsTrue)
}
示例14: 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
}
示例15: runMachineUpdate
// runMachineUpdate connects via ssh to the machine and runs the update script.
func runMachineUpdate(machine *state.Machine, sshArg string) error {
addr, err := machine.PublicAddress()
if err != nil {
if network.IsNoAddress(err) {
return errors.Annotatef(err, "no appropriate public address found")
}
return errors.Trace(err)
}
return runViaSSH(addr.Value, sshArg)
}