本文整理汇总了Golang中github.com/wallyworld/core/state.Machine类的典型用法代码示例。如果您正苦于以下问题:Golang Machine类的具体用法?Golang Machine怎么用?Golang Machine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Machine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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())
c.Assert(err, gc.IsNil)
return a
}
示例2: runMachineUpdate
// runMachineUpdate connects via ssh to the machine and runs the update script
func runMachineUpdate(m *state.Machine, sshArg string) error {
progress("updating machine: %v\n", m)
addr := instance.SelectPublicAddress(m.Addresses())
if addr == "" {
return fmt.Errorf("no appropriate public address found")
}
return runViaSsh(addr, sshArg)
}
示例3: assertAssignUnit
func (s *assignCleanSuite) assertAssignUnit(c *gc.C, expectedMachine *state.Machine) {
unit, err := s.wordpress.AddUnit()
c.Assert(err, gc.IsNil)
reusedMachine, err := s.assignUnit(unit)
c.Assert(err, gc.IsNil)
c.Assert(reusedMachine.Id(), gc.Equals, expectedMachine.Id())
c.Assert(reusedMachine.Clean(), jc.IsFalse)
}
示例4: expectStarted
func (s *kvmProvisionerSuite) expectStarted(c *gc.C, machine *state.Machine) string {
s.State.StartSync()
event := <-s.events
c.Assert(event.Action, gc.Equals, mock.Started)
err := machine.Refresh()
c.Assert(err, gc.IsNil)
s.waitInstanceId(c, machine, instance.Id(event.InstanceId))
return event.InstanceId
}
示例5: waitRemoved
// waitRemoved waits for the supplied machine to be removed from state.
func (s *CommonProvisionerSuite) waitRemoved(c *gc.C, m *state.Machine) {
s.waitMachine(c, m, func() bool {
err := m.Refresh()
if errors.IsNotFound(err) {
return true
}
c.Assert(err, gc.IsNil)
c.Logf("machine %v is still %s", m, m.Life())
return false
})
}
示例6: waitInstanceId
// waitInstanceId waits until the supplied machine has an instance id, then
// asserts it is as expected.
func (s *CommonProvisionerSuite) waitInstanceId(c *gc.C, m *state.Machine, expect instance.Id) {
s.waitHardwareCharacteristics(c, m, func() bool {
if actual, err := m.InstanceId(); err == nil {
c.Assert(actual, gc.Equals, expect)
return true
} else if !state.IsNotProvisionedError(err) {
// We don't expect any errors.
panic(err)
}
c.Logf("machine %v is still unprovisioned", m)
return false
})
}
示例7: checkStartInstanceCustom
func (s *CommonProvisionerSuite) checkStartInstanceCustom(c *gc.C, m *state.Machine, secret string, cons constraints.Value, includeNetworks, excludeNetworks []string, networkInfo []network.Info, waitInstanceId bool) (inst instance.Instance) {
s.BackingState.StartSync()
for {
select {
case o := <-s.op:
switch o := o.(type) {
case dummy.OpStartInstance:
inst = o.Instance
if waitInstanceId {
s.waitInstanceId(c, m, inst.Id())
}
// Check the instance was started with the expected params.
c.Assert(o.MachineId, gc.Equals, m.Id())
nonceParts := strings.SplitN(o.MachineNonce, ":", 2)
c.Assert(nonceParts, gc.HasLen, 2)
c.Assert(nonceParts[0], gc.Equals, names.MachineTag("0"))
c.Assert(nonceParts[1], jc.Satisfies, utils.IsValidUUIDString)
c.Assert(o.Secret, gc.Equals, secret)
c.Assert(o.IncludeNetworks, jc.DeepEquals, includeNetworks)
c.Assert(o.ExcludeNetworks, jc.DeepEquals, excludeNetworks)
c.Assert(o.NetworkInfo, jc.DeepEquals, networkInfo)
// All provisioned machines in this test suite have
// their hardware characteristics attributes set to
// the same values as the constraints due to the dummy
// environment being used.
if !constraints.IsEmpty(&cons) {
c.Assert(o.Constraints, gc.DeepEquals, cons)
hc, err := m.HardwareCharacteristics()
c.Assert(err, gc.IsNil)
c.Assert(*hc, gc.DeepEquals, instance.HardwareCharacteristics{
Arch: cons.Arch,
Mem: cons.Mem,
RootDisk: cons.RootDisk,
CpuCores: cons.CpuCores,
CpuPower: cons.CpuPower,
Tags: cons.Tags,
})
}
return
default:
c.Logf("ignoring unexpected operation %#v", o)
}
case <-time.After(2 * time.Second):
c.Fatalf("provisioner did not start an instance")
return
}
}
return
}
示例8: setFakeMachineAddresses
func (s *commonMachineSuite) setFakeMachineAddresses(c *gc.C, machine *state.Machine) {
addrs := []instance.Address{
instance.NewAddress("0.1.2.3", instance.NetworkUnknown),
}
err := machine.SetAddresses(addrs...)
c.Assert(err, gc.IsNil)
// Set the addresses in the environ instance as well so that if the instance poller
// runs it won't overwrite them.
instId, err := machine.InstanceId()
c.Assert(err, gc.IsNil)
insts, err := s.Conn.Environ.Instances([]instance.Id{instId})
c.Assert(err, gc.IsNil)
dummy.SetInstanceAddresses(insts[0], addrs)
}
示例9: remoteParamsForMachine
// remoteParamsForMachine returns a filled in RemoteExec instance
// based on the machine, command and timeout params. If the machine
// does not have an internal address, the Host is empty. This is caught
// by the function that actually tries to execute the command.
func remoteParamsForMachine(machine *state.Machine, command string, timeout time.Duration) *RemoteExec {
// magic boolean parameters are bad :-(
address := instance.SelectInternalAddress(machine.Addresses(), false)
execParams := &RemoteExec{
ExecParams: ssh.ExecParams{
Command: command,
Timeout: timeout,
},
MachineId: machine.Id(),
}
if address != "" {
execParams.Host = fmt.Sprintf("[email protected]%s", address)
}
return execParams
}
示例10: newMachineToolWaiter
func newMachineToolWaiter(m *state.Machine) *toolsWaiter {
w := m.Watch()
waiter := &toolsWaiter{
changes: make(chan struct{}, 1),
watcher: w,
tooler: m,
}
go func() {
for _ = range w.Changes() {
waiter.changes <- struct{}{}
}
close(waiter.changes)
}()
return waiter
}
示例11: assertStartInstance
func (t *LiveTests) assertStartInstance(c *gc.C, m *state.Machine) {
// Wait for machine to get an instance id.
for a := waitAgent.Start(); a.Next(); {
err := m.Refresh()
c.Assert(err, gc.IsNil)
instId, err := m.InstanceId()
if err != nil {
c.Assert(err, jc.Satisfies, state.IsNotProvisionedError)
continue
}
_, err = t.Env.Instances([]instance.Id{instId})
c.Assert(err, gc.IsNil)
return
}
c.Fatalf("provisioner failed to start machine after %v", waitAgent.Total)
}
示例12: waitMachineStatus
func (s *MachinerSuite) waitMachineStatus(c *gc.C, m *state.Machine, expectStatus params.Status) {
timeout := time.After(worstCase)
for {
select {
case <-timeout:
c.Fatalf("timeout while waiting for machine status to change")
case <-time.After(10 * time.Millisecond):
status, _, _, err := m.Status()
c.Assert(err, gc.IsNil)
if status != expectStatus {
c.Logf("machine %q status is %s, still waiting", m, status)
continue
}
return
}
}
}
示例13: 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
}
var instanceIdSet set.Strings
for _, unit := range units {
if !unit.IsPrincipal() {
continue
}
service, err := unit.Service()
if err != nil {
return nil, err
}
allUnits, err := service.AllUnits()
if err != nil {
return nil, err
}
for _, unit := range allUnits {
machineId, err := unit.AssignedMachineId()
if state.IsNotAssigned(err) {
continue
} else if err != nil {
return nil, err
}
machine, err := st.Machine(machineId)
if err != nil {
return nil, err
}
instanceId, err := machine.InstanceId()
if err == nil {
instanceIdSet.Add(string(instanceId))
} else if state.IsNotProvisionedError(err) {
continue
} else {
return nil, err
}
}
}
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
}
示例14: waitHardwareCharacteristics
func (s *CommonProvisionerSuite) waitHardwareCharacteristics(c *gc.C, m *state.Machine, check func() bool) {
w := m.WatchHardwareCharacteristics()
defer stop(c, w)
timeout := time.After(coretesting.LongWait)
resync := time.After(0)
for {
select {
case <-w.Changes():
if check() {
return
}
case <-resync:
resync = time.After(coretesting.ShortWait)
s.BackingState.StartSync()
case <-timeout:
c.Fatalf("hardware characteristics for machine %v wait timed out", m)
}
}
}
示例15: assertContainerProvisionerStarted
func (s *ContainerSetupSuite) assertContainerProvisionerStarted(
c *gc.C, host *state.Machine, ctype instance.ContainerType) {
// A stub worker callback to record what happens.
provisionerStarted := false
startProvisionerWorker := func(runner worker.Runner, containerType instance.ContainerType,
pr *apiprovisioner.State, cfg agent.Config, broker environs.InstanceBroker) error {
c.Assert(containerType, gc.Equals, ctype)
c.Assert(cfg.Tag(), gc.Equals, host.Tag())
provisionerStarted = true
return nil
}
s.PatchValue(&provisioner.StartProvisioner, startProvisionerWorker)
s.createContainer(c, host, ctype)
// Consume the apt command used to initialise the container.
<-s.aptCmdChan
// the container worker should have created the provisioner
c.Assert(provisionerStarted, jc.IsTrue)
}