本文整理汇总了Golang中github.com/wallyworld/core/instance.Id函数的典型用法代码示例。如果您正苦于以下问题:Golang Id函数的具体用法?Golang Id怎么用?Golang Id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Id函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestInstances
func (s *environSuite) TestInstances(c *gc.C) {
var ids []instance.Id
instances, err := s.env.Instances(ids)
c.Assert(err, gc.Equals, environs.ErrNoInstances)
c.Assert(instances, gc.HasLen, 0)
ids = append(ids, manual.BootstrapInstanceId)
instances, err = s.env.Instances(ids)
c.Assert(err, gc.IsNil)
c.Assert(instances, gc.HasLen, 1)
c.Assert(instances[0], gc.NotNil)
ids = append(ids, manual.BootstrapInstanceId)
instances, err = s.env.Instances(ids)
c.Assert(err, gc.IsNil)
c.Assert(instances, gc.HasLen, 2)
c.Assert(instances[0], gc.NotNil)
c.Assert(instances[1], gc.NotNil)
ids = append(ids, instance.Id("invalid"))
instances, err = s.env.Instances(ids)
c.Assert(err, gc.Equals, environs.ErrPartialInstances)
c.Assert(instances, gc.HasLen, 3)
c.Assert(instances[0], gc.NotNil)
c.Assert(instances[1], gc.NotNil)
c.Assert(instances[2], gc.IsNil)
ids = []instance.Id{instance.Id("invalid")}
instances, err = s.env.Instances(ids)
c.Assert(err, gc.Equals, environs.ErrNoInstances)
c.Assert(instances, gc.HasLen, 1)
c.Assert(instances[0], gc.IsNil)
}
开发者ID:jameinel,项目名称:core,代码行数:34,代码来源:environ_test.go
示例2: TestGetSystemIdValues
func (*utilSuite) TestGetSystemIdValues(c *gc.C) {
instanceId1 := instance.Id("/MAAS/api/1.0/nodes/system_id1/")
instanceId2 := instance.Id("/MAAS/api/1.0/nodes/system_id2/")
instanceIds := []instance.Id{instanceId1, instanceId2}
values := getSystemIdValues(instanceIds)
c.Check(values["id"], gc.DeepEquals, []string{"system_id1", "system_id2"})
}
开发者ID:jameinel,项目名称:core,代码行数:9,代码来源:util_test.go
示例3: setUpManual
// setUpManual adds "manually provisioned" machines to state:
// one manager machine, and one non-manager.
func (s *destroyEnvironmentSuite) setUpManual(c *gc.C) (m0, m1 *state.Machine) {
m0, err := s.State.AddMachine("precise", state.JobManageEnviron)
c.Assert(err, gc.IsNil)
err = m0.SetProvisioned(instance.Id("manual:0"), "manual:0:fake_nonce", nil)
c.Assert(err, gc.IsNil)
m1, err = s.State.AddMachine("precise", state.JobHostUnits)
c.Assert(err, gc.IsNil)
err = m1.SetProvisioned(instance.Id("manual:1"), "manual:1:fake_nonce", nil)
c.Assert(err, gc.IsNil)
return m0, m1
}
开发者ID:jameinel,项目名称:core,代码行数:13,代码来源:destroy_test.go
示例4: TestCannotRecordStartedInstance
func (s *BootstrapSuite) TestCannotRecordStartedInstance(c *gc.C) {
innerStorage := newStorage(s, c)
stor := &mockStorage{Storage: innerStorage}
startInstance := func(
_ string, _ constraints.Value, _, _ []string, _ tools.List, _ *cloudinit.MachineConfig,
) (
instance.Instance, *instance.HardwareCharacteristics, []network.Info, error,
) {
stor.putErr = fmt.Errorf("suddenly a wild blah")
return &mockInstance{id: "i-blah"}, nil, nil, nil
}
var stopped []instance.Instance
stopInstances := func(instances []instance.Instance) error {
stopped = append(stopped, instances...)
return nil
}
env := &mockEnviron{
storage: stor,
startInstance: startInstance,
stopInstances: stopInstances,
config: configGetter(c),
}
ctx := coretesting.Context(c)
err := common.Bootstrap(ctx, env, environs.BootstrapParams{})
c.Assert(err, gc.ErrorMatches, "cannot save state: suddenly a wild blah")
c.Assert(stopped, gc.HasLen, 1)
c.Assert(stopped[0].Id(), gc.Equals, instance.Id("i-blah"))
}
开发者ID:jameinel,项目名称:core,代码行数:32,代码来源:bootstrap_test.go
示例5: restoreBootstrapMachine
func restoreBootstrapMachine(conn *juju.APIConn, backupFile string, creds credentials) (newInstId instance.Id, addr string, err error) {
addr, err = conn.State.Client().PublicAddress("0")
if err != nil {
return "", "", fmt.Errorf("cannot get public address of bootstrap machine: %v", err)
}
status, err := conn.State.Client().Status(nil)
if err != nil {
return "", "", fmt.Errorf("cannot get environment status: %v", err)
}
info, ok := status.Machines["0"]
if !ok {
return "", "", fmt.Errorf("cannot find bootstrap machine in status")
}
newInstId = instance.Id(info.InstanceId)
progress("copying backup file to bootstrap host")
if err := sendViaScp(backupFile, addr, "~/juju-backup.tgz"); err != nil {
return "", "", fmt.Errorf("cannot copy backup file to bootstrap instance: %v", err)
}
progress("updating bootstrap machine")
if err := runViaSsh(addr, updateBootstrapMachineScript(newInstId, creds)); err != nil {
return "", "", fmt.Errorf("update script failed: %v", err)
}
return newInstId, addr, nil
}
开发者ID:jameinel,项目名称:core,代码行数:25,代码来源:restore.go
示例6: countPolls
// countPolls sets up a machine loop with the given
// addresses and status to be returned from getInstanceInfo,
// waits for coretesting.ShortWait, and returns the
// number of times the instance is polled.
func countPolls(c *gc.C, addrs []instance.Address, instId, instStatus string, machineStatus params.Status) int {
count := int32(0)
getInstanceInfo := func(id instance.Id) (instanceInfo, error) {
c.Check(string(id), gc.Equals, instId)
atomic.AddInt32(&count, 1)
if addrs == nil {
return instanceInfo{}, fmt.Errorf("no instance addresses available")
}
return instanceInfo{addrs, instStatus}, nil
}
context := &testMachineContext{
getInstanceInfo: getInstanceInfo,
dyingc: make(chan struct{}),
}
m := &testMachine{
id: "99",
instanceId: instance.Id(instId),
refresh: func() error { return nil },
addresses: addrs,
life: state.Alive,
status: machineStatus,
}
died := make(chan machine)
go runMachine(context, m, nil, died)
time.Sleep(coretesting.ShortWait)
killMachineLoop(c, m, context.dyingc, died)
c.Assert(context.killAllErr, gc.Equals, nil)
return int(count)
}
开发者ID:jameinel,项目名称:core,代码行数:35,代码来源:machine_test.go
示例7: TestSinglePollWhenInstancInfoUnimplemented
func (s *machineSuite) TestSinglePollWhenInstancInfoUnimplemented(c *gc.C) {
s.PatchValue(&ShortPoll, 1*time.Millisecond)
s.PatchValue(&LongPoll, 1*time.Millisecond)
count := int32(0)
getInstanceInfo := func(id instance.Id) (instanceInfo, error) {
c.Check(id, gc.Equals, instance.Id("i1234"))
atomic.AddInt32(&count, 1)
return instanceInfo{}, errors.NotImplementedf("instance address")
}
context := &testMachineContext{
getInstanceInfo: getInstanceInfo,
dyingc: make(chan struct{}),
}
m := &testMachine{
id: "99",
instanceId: "i1234",
refresh: func() error { return nil },
life: state.Alive,
}
died := make(chan machine)
go runMachine(context, m, nil, died)
time.Sleep(coretesting.ShortWait)
killMachineLoop(c, m, context.dyingc, died)
c.Assert(context.killAllErr, gc.Equals, nil)
c.Assert(count, gc.Equals, int32(1))
}
开发者ID:jameinel,项目名称:core,代码行数:28,代码来源:machine_test.go
示例8: TestMachineConfig
func (s *machineConfigSuite) TestMachineConfig(c *gc.C) {
addrs := []instance.Address{instance.NewAddress("1.2.3.4", instance.NetworkUnknown)}
hc := instance.MustParseHardware("mem=4G arch=amd64")
apiParams := params.AddMachineParams{
Jobs: []params.MachineJob{params.JobHostUnits},
InstanceId: instance.Id("1234"),
Nonce: "foo",
HardwareCharacteristics: hc,
Addrs: addrs,
}
machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams})
c.Assert(err, gc.IsNil)
c.Assert(len(machines), gc.Equals, 1)
machineId := machines[0].Machine
machineConfig, err := client.MachineConfig(s.State, machineId, apiParams.Nonce, "")
c.Assert(err, gc.IsNil)
envConfig, err := s.State.EnvironConfig()
c.Assert(err, gc.IsNil)
env, err := environs.New(envConfig)
c.Assert(err, gc.IsNil)
stateInfo, apiInfo, err := env.StateInfo()
c.Assert(err, gc.IsNil)
c.Check(machineConfig.StateInfo.Addrs, gc.DeepEquals, stateInfo.Addrs)
c.Check(machineConfig.APIInfo.Addrs, gc.DeepEquals, apiInfo.Addrs)
c.Assert(machineConfig.Tools.URL, gc.Not(gc.Equals), "")
}
开发者ID:jameinel,项目名称:core,代码行数:28,代码来源:machineconfig_test.go
示例9: TestExtractSystemId
func (*utilSuite) TestExtractSystemId(c *gc.C) {
instanceId := instance.Id("/MAAS/api/1.0/nodes/system_id/")
systemId := extractSystemId(instanceId)
c.Check(systemId, gc.Equals, "system_id")
}
开发者ID:jameinel,项目名称:core,代码行数:7,代码来源:util_test.go
示例10: TestSetProvisioned
func (s *withoutStateServerSuite) TestSetProvisioned(c *gc.C) {
// Provision machine 0 first.
hwChars := instance.MustParseHardware("arch=i386", "mem=4G")
err := s.machines[0].SetProvisioned("i-am", "fake_nonce", &hwChars)
c.Assert(err, gc.IsNil)
args := params.SetProvisioned{Machines: []params.MachineSetProvisioned{
{Tag: s.machines[0].Tag(), InstanceId: "i-was", Nonce: "fake_nonce", Characteristics: nil},
{Tag: s.machines[1].Tag(), InstanceId: "i-will", Nonce: "fake_nonce", Characteristics: &hwChars},
{Tag: s.machines[2].Tag(), InstanceId: "i-am-too", Nonce: "fake", Characteristics: nil},
{Tag: "machine-42", InstanceId: "", Nonce: "", Characteristics: nil},
{Tag: "unit-foo-0", InstanceId: "", Nonce: "", Characteristics: nil},
{Tag: "service-bar", InstanceId: "", Nonce: "", Characteristics: nil},
}}
result, err := s.provisioner.SetProvisioned(args)
c.Assert(err, gc.IsNil)
c.Assert(result, gc.DeepEquals, params.ErrorResults{
Results: []params.ErrorResult{
{¶ms.Error{
Message: `cannot set instance data for machine "0": already set`,
}},
{nil},
{nil},
{apiservertesting.NotFoundError("machine 42")},
{apiservertesting.ErrUnauthorized},
{apiservertesting.ErrUnauthorized},
},
})
// Verify machine 1 and 2 were provisioned.
c.Assert(s.machines[1].Refresh(), gc.IsNil)
c.Assert(s.machines[2].Refresh(), gc.IsNil)
instanceId, err := s.machines[1].InstanceId()
c.Assert(err, gc.IsNil)
c.Check(instanceId, gc.Equals, instance.Id("i-will"))
instanceId, err = s.machines[2].InstanceId()
c.Assert(err, gc.IsNil)
c.Check(instanceId, gc.Equals, instance.Id("i-am-too"))
c.Check(s.machines[1].CheckProvisioned("fake_nonce"), jc.IsTrue)
c.Check(s.machines[2].CheckProvisioned("fake"), jc.IsTrue)
gotHardware, err := s.machines[1].HardwareCharacteristics()
c.Assert(err, gc.IsNil)
c.Check(gotHardware, gc.DeepEquals, &hwChars)
}
开发者ID:jameinel,项目名称:core,代码行数:45,代码来源:provisioner_test.go
示例11: TestString
func (s *instanceTest) TestString(c *gc.C) {
jsonValue := `{"hostname": "thethingintheplace", "system_id": "system_id", "test": "test"}`
obj := s.testMAASObject.TestServer.NewNode(jsonValue)
instance := &maasInstance{maasObject: &obj, environ: s.makeEnviron()}
hostname, err := instance.DNSName()
c.Assert(err, gc.IsNil)
expected := hostname + ":" + string(instance.Id())
c.Assert(fmt.Sprint(instance), gc.Equals, expected)
}
开发者ID:jameinel,项目名称:core,代码行数:9,代码来源:instance_test.go
示例12: TestCannotStopInstances
func (s *DestroySuite) TestCannotStopInstances(c *gc.C) {
env := &mockEnviron{
allInstances: func() ([]instance.Instance, error) {
return []instance.Instance{
&mockInstance{id: "one"},
&mockInstance{id: "another"},
}, nil
},
stopInstances: func(instances []instance.Instance) error {
c.Assert(instances, gc.HasLen, 2)
c.Assert(instances[0].Id(), gc.Equals, instance.Id("one"))
c.Assert(instances[1].Id(), gc.Equals, instance.Id("another"))
return fmt.Errorf("nah")
},
}
err := common.Destroy(env)
c.Assert(err, gc.ErrorMatches, "nah")
}
开发者ID:jameinel,项目名称:core,代码行数:18,代码来源:destroy_test.go
示例13: 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
}
开发者ID:jameinel,项目名称:core,代码行数:9,代码来源:kvm-broker_test.go
示例14: TestStringWithoutHostname
func (s *instanceTest) TestStringWithoutHostname(c *gc.C) {
// For good measure, test what happens if we don't have a hostname.
jsonValue := `{"system_id": "system_id", "test": "test"}`
obj := s.testMAASObject.TestServer.NewNode(jsonValue)
instance := &maasInstance{maasObject: &obj, environ: s.makeEnviron()}
_, err := instance.DNSName()
c.Assert(err, gc.NotNil)
expected := fmt.Sprintf("<DNSName failed: %q>", err) + ":" + string(instance.Id())
c.Assert(fmt.Sprint(instance), gc.Equals, expected)
}
开发者ID:jameinel,项目名称:core,代码行数:10,代码来源:instance_test.go
示例15: setUpSavedState
func (suite *StateSuite) setUpSavedState(c *gc.C, dataDir string) bootstrap.BootstrapState {
state := bootstrap.BootstrapState{
StateInstances: []instance.Id{instance.Id("an-instance-id")},
}
content, err := goyaml.Marshal(state)
c.Assert(err, gc.IsNil)
err = ioutil.WriteFile(filepath.Join(dataDir, bootstrap.StateFile), []byte(content), 0644)
c.Assert(err, gc.IsNil)
return state
}
开发者ID:jameinel,项目名称:core,代码行数:10,代码来源:state_test.go
示例16: TestInitializeEnvironment
func (s *BootstrapSuite) TestInitializeEnvironment(c *gc.C) {
hw := instance.MustParseHardware("arch=amd64 mem=8G")
machConf, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.envcfg, "--instance-id", string(s.instanceId), "--hardware", hw.String())
c.Assert(err, gc.IsNil)
err = cmd.Run(nil)
c.Assert(err, gc.IsNil)
c.Assert(s.fakeEnsureMongo.dataDir, gc.Equals, s.dataDir)
c.Assert(s.fakeEnsureMongo.initiateCount, gc.Equals, 1)
c.Assert(s.fakeEnsureMongo.ensureCount, gc.Equals, 1)
c.Assert(s.fakeEnsureMongo.dataDir, gc.Equals, s.dataDir)
c.Assert(s.fakeEnsureMongo.withHA, jc.IsTrue)
expectInfo, exists := machConf.StateServingInfo()
c.Assert(exists, jc.IsTrue)
c.Assert(expectInfo.SharedSecret, gc.Equals, "")
servingInfo := s.fakeEnsureMongo.info
c.Assert(len(servingInfo.SharedSecret), gc.Not(gc.Equals), 0)
servingInfo.SharedSecret = ""
c.Assert(servingInfo, jc.DeepEquals, expectInfo)
expectDialAddrs := []string{fmt.Sprintf("127.0.0.1:%d", expectInfo.StatePort)}
gotDialAddrs := s.fakeEnsureMongo.initiateParams.DialInfo.Addrs
c.Assert(gotDialAddrs, gc.DeepEquals, expectDialAddrs)
memberHost := fmt.Sprintf("%s:%d", s.bootstrapName, expectInfo.StatePort)
c.Assert(s.fakeEnsureMongo.initiateParams.MemberHostPort, gc.Equals, memberHost)
c.Assert(s.fakeEnsureMongo.initiateParams.User, gc.Equals, "")
c.Assert(s.fakeEnsureMongo.initiateParams.Password, gc.Equals, "")
st, err := state.Open(&state.Info{
Addrs: []string{testing.MgoServer.Addr()},
CACert: testing.CACert,
Password: testPasswordHash(),
}, state.DefaultDialOpts(), environs.NewStatePolicy())
c.Assert(err, gc.IsNil)
defer st.Close()
machines, err := st.AllMachines()
c.Assert(err, gc.IsNil)
c.Assert(machines, gc.HasLen, 1)
instid, err := machines[0].InstanceId()
c.Assert(err, gc.IsNil)
c.Assert(instid, gc.Equals, instance.Id(string(s.instanceId)))
stateHw, err := machines[0].HardwareCharacteristics()
c.Assert(err, gc.IsNil)
c.Assert(stateHw, gc.NotNil)
c.Assert(*stateHw, gc.DeepEquals, hw)
cons, err := st.EnvironConstraints()
c.Assert(err, gc.IsNil)
c.Assert(&cons, jc.Satisfies, constraints.IsEmpty)
}
开发者ID:jameinel,项目名称:core,代码行数:54,代码来源:bootstrap_test.go
示例17: StopInstances
// StopInstances shuts down the given instances.
func (broker *lxcBroker) StopInstances(instances []instance.Instance) error {
// TODO: potentially parallelise.
for _, instance := range instances {
lxcLogger.Infof("stopping lxc container for instance: %s", instance.Id())
if err := broker.manager.DestroyContainer(instance); err != nil {
lxcLogger.Errorf("container did not stop: %v", err)
return err
}
}
return nil
}
开发者ID:jameinel,项目名称:core,代码行数:12,代码来源:lxc-broker.go
示例18: TestInstancesReturnsErrorIfPartialInstances
func (suite *environSuite) TestInstancesReturnsErrorIfPartialInstances(c *gc.C) {
known := suite.addNode(allocatedNode)
suite.addNode(`{"system_id": "test2"}`)
unknown := instance.Id("unknown systemID")
instances, err := suite.makeEnviron().Instances([]instance.Id{known, unknown})
c.Check(err, gc.Equals, environs.ErrPartialInstances)
c.Assert(instances, gc.HasLen, 2)
c.Check(instances[0].Id(), gc.Equals, known)
c.Check(instances[1], gc.IsNil)
}
开发者ID:jameinel,项目名称:core,代码行数:11,代码来源:environ_whitebox_test.go
示例19: TestLoadStateIntegratesWithSaveState
func (suite *StateSuite) TestLoadStateIntegratesWithSaveState(c *gc.C) {
storage := suite.newStorage(c)
state := bootstrap.BootstrapState{
StateInstances: []instance.Id{instance.Id("an-instance-id")},
}
err := bootstrap.SaveState(storage, &state)
c.Assert(err, gc.IsNil)
storedState, err := bootstrap.LoadState(storage)
c.Assert(err, gc.IsNil)
c.Check(*storedState, gc.DeepEquals, state)
}
开发者ID:jameinel,项目名称:core,代码行数:12,代码来源:state_test.go
示例20: TestDestroyContainer
func (s *KVMSuite) TestDestroyContainer(c *gc.C) {
instance := containertesting.CreateContainer(c, s.manager, "1/lxc/0")
err := s.manager.DestroyContainer(instance)
c.Assert(err, gc.IsNil)
name := string(instance.Id())
// Check that the container dir is no longer in the container dir
c.Assert(filepath.Join(s.ContainerDir, name), jc.DoesNotExist)
// but instead, in the removed container dir
c.Assert(filepath.Join(s.RemovedDir, name), jc.IsDirectory)
}
开发者ID:jameinel,项目名称:core,代码行数:12,代码来源:kvm_test.go
注:本文中的github.com/wallyworld/core/instance.Id函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论