本文整理汇总了Golang中launchpad/net/juju-core/instance.Id函数的典型用法代码示例。如果您正苦于以下问题:Golang Id函数的具体用法?Golang Id怎么用?Golang Id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Id函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestGetSystemIdValues
func (s *UtilSuite) TestGetSystemIdValues(c *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"], DeepEquals, []string{"system_id1", "system_id2"})
}
示例2: TestAllInstances
func (suite *EnvironSuite) TestAllInstances(c *C) {
env := makeEnviron(c)
prefix := env.getEnvPrefix()
services := []gwacl.HostedServiceDescriptor{{ServiceName: "deployment-in-another-env"}, {ServiceName: prefix + "deployment-1"}, {ServiceName: prefix + "deployment-2"}}
requests := patchWithServiceListResponse(c, services)
instances, err := env.AllInstances()
c.Assert(err, IsNil)
c.Check(len(instances), Equals, 2)
c.Check(instances[0].Id(), Equals, instance.Id(prefix+"deployment-1"))
c.Check(instances[1].Id(), Equals, instance.Id(prefix+"deployment-2"))
c.Check(len(*requests), Equals, 1)
}
示例3: checkStopInstances
// checkStopInstances checks that an instance has been stopped.
func (s *CommonProvisionerSuite) checkStopInstances(c *C, instances ...instance.Instance) {
s.State.StartSync()
instanceIds := set.NewStrings()
for _, instance := range instances {
instanceIds.Add(string(instance.Id()))
}
// Continue checking for stop instance calls until all the instances we
// are waiting on to finish, actually finish, or we time out.
for !instanceIds.IsEmpty() {
select {
case o := <-s.op:
switch o := o.(type) {
case dummy.OpStopInstances:
for _, stoppedInstance := range o.Instances {
instanceIds.Remove(string(stoppedInstance.Id()))
}
default:
c.Fatalf("unexpected operation %#v", o)
return
}
case <-time.After(2 * time.Second):
c.Fatalf("provisioner did not stop an instance")
return
}
}
}
示例4: TestStartInstance
func (s *lxcBrokerSuite) TestStartInstance(c *C) {
machineId := "1/lxc/0"
lxc := s.startInstance(c, machineId)
c.Assert(lxc.Id(), Equals, instance.Id("juju-machine-1-lxc-0"))
c.Assert(s.lxcContainerDir(lxc), IsDirectory)
s.assertInstances(c, lxc)
}
示例5: TestInitializeEnvironment
func (s *BootstrapSuite) TestInitializeEnvironment(c *C) {
_, cmd, err := s.initBootstrapCommand(c, "--env-config", testConfig)
c.Assert(err, IsNil)
err = cmd.Run(nil)
c.Assert(err, IsNil)
st, err := state.Open(&state.Info{
Addrs: []string{testing.MgoAddr},
CACert: []byte(testing.CACert),
Password: testPasswordHash(),
}, state.DefaultDialOpts())
c.Assert(err, IsNil)
defer st.Close()
machines, err := st.AllMachines()
c.Assert(err, IsNil)
c.Assert(machines, HasLen, 1)
instid, err := machines[0].InstanceId()
c.Assert(err, IsNil)
c.Assert(instid, Equals, instance.Id("dummy.instance.id"))
cons, err := st.EnvironConstraints()
c.Assert(err, IsNil)
c.Assert(cons, DeepEquals, constraints.Value{})
}
示例6: Destroy
func (e *environ) Destroy(ensureInsts []instance.Instance) error {
log.Infof("environs/openstack: destroying environment %q", e.name)
insts, err := e.AllInstances()
if err != nil {
return fmt.Errorf("cannot get instances: %v", err)
}
found := make(map[instance.Id]bool)
var ids []instance.Id
for _, inst := range insts {
ids = append(ids, inst.Id())
found[inst.Id()] = true
}
// Add any instances we've been told about but haven't yet shown
// up in the instance list.
for _, inst := range ensureInsts {
id := instance.Id(inst.(*openstackInstance).Id())
if !found[id] {
ids = append(ids, id)
found[id] = true
}
}
err = e.terminateInstances(ids)
if err != nil {
return err
}
return e.Storage().RemoveAll()
}
示例7: TestExtractSystemId
func (s *UtilSuite) TestExtractSystemId(c *C) {
instanceId := instance.Id("/MAAS/api/1.0/nodes/system_id/")
systemId := extractSystemId(instanceId)
c.Check(systemId, Equals, "system_id")
}
示例8: TestInstancesReturnsErrorIfPartialInstances
func (suite *EnvironSuite) TestInstancesReturnsErrorIfPartialInstances(c *C) {
input1 := `{"system_id": "test"}`
node1 := suite.testMAASObject.TestServer.NewNode(input1)
resourceURI1, _ := node1.GetField("resource_uri")
input2 := `{"system_id": "test2"}`
suite.testMAASObject.TestServer.NewNode(input2)
instanceId1 := instance.Id(resourceURI1)
instanceId2 := instance.Id("unknown systemID")
instanceIds := []instance.Id{instanceId1, instanceId2}
instances, err := suite.environ.Instances(instanceIds)
c.Check(err, Equals, environs.ErrPartialInstances)
c.Check(len(instances), Equals, 1)
c.Check(string(instances[0].Id()), Equals, resourceURI1)
}
示例9: expectStarted
func (s *lxcProvisionerSuite) expectStarted(c *gc.C, machine *state.Machine) string {
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
}
示例10: TestInstancesReturnsFilteredList
func (suite *EnvironSuite) TestInstancesReturnsFilteredList(c *C) {
services := []gwacl.HostedServiceDescriptor{{ServiceName: "deployment-1"}, {ServiceName: "deployment-2"}}
requests := patchWithServiceListResponse(c, services)
env := makeEnviron(c)
instances, err := env.Instances([]instance.Id{"deployment-1"})
c.Assert(err, IsNil)
c.Check(len(instances), Equals, 1)
c.Check(instances[0].Id(), Equals, instance.Id("deployment-1"))
c.Check(len(*requests), Equals, 1)
}
示例11: TestInstancesReturnsPartialInstancesIfSomeInstancesAreNotFound
func (suite *EnvironSuite) TestInstancesReturnsPartialInstancesIfSomeInstancesAreNotFound(c *C) {
services := []gwacl.HostedServiceDescriptor{{ServiceName: "deployment-1"}, {ServiceName: "deployment-2"}}
requests := patchWithServiceListResponse(c, services)
env := makeEnviron(c)
instances, err := env.Instances([]instance.Id{"deployment-1", "unknown-deployment"})
c.Assert(err, Equals, environs.ErrPartialInstances)
c.Check(len(instances), Equals, 1)
c.Check(instances[0].Id(), Equals, instance.Id("deployment-1"))
c.Check(len(*requests), Equals, 1)
}
示例12: Run
// Run initializes state for an environment.
func (c *BootstrapCommand) Run(_ *cmd.Context) error {
if err := c.Conf.read("bootstrap"); err != nil {
return err
}
cfg, err := config.New(c.EnvConfig)
if err != nil {
return err
}
// There is no entity that's created at init time.
c.Conf.StateInfo.Tag = ""
st, err := state.Initialize(c.Conf.StateInfo, cfg, state.DefaultDialOpts())
if err != nil {
return err
}
defer st.Close()
if err := environs.BootstrapUsers(st, cfg, c.Conf.OldPassword); err != nil {
return err
}
// TODO(fwereade): we need to be able to customize machine jobs,
// not just hardcode these values; in particular, JobHostUnits
// on a machine, like this one, that is running JobManageEnviron
// (not to mention the actual state server itself...) will allow
// a malicious or compromised unit to trivially access to the
// user's environment credentials. However, given that this point
// is currently moot (see Upgrader in this package), the pseudo-
// local provider mode (in which everything is deployed with
// `--to 0`) offers enough value to enough people that
// JobHostUnits is currently always enabled. This will one day
// have to change, but it's strictly less important than fixing
// Upgrader, and it's a capability we'll always want to have
// available for the aforementioned use case.
jobs := []state.MachineJob{
state.JobManageEnviron, state.JobManageState, state.JobHostUnits,
}
data, err := ioutil.ReadFile(providerStateURLFile)
if err != nil {
return fmt.Errorf("cannot read provider-state-url file: %v", err)
}
stateInfoURL := strings.Split(string(data), "\n")[0]
bsState, err := environs.LoadStateFromURL(stateInfoURL)
if err != nil {
return fmt.Errorf("cannot load state from URL %q (read from %q): %v", stateInfoURL, providerStateURLFile, err)
}
instId := bsState.StateInstances[0]
var characteristics instance.HardwareCharacteristics
if len(bsState.Characteristics) > 0 {
characteristics = bsState.Characteristics[0]
}
return environs.ConfigureBootstrapMachine(st, c.Constraints, c.Conf.DataDir, jobs, instance.Id(instId), characteristics)
}
示例13: 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.StopContainer(instance); err != nil {
lxcLogger.Errorf("container did not stop: %v", err)
return err
}
}
return nil
}
示例14: setupSavedState
func (suite *StateSuite) setupSavedState(c *C, storage environs.Storage) environs.BootstrapState {
arch := "amd64"
state := environs.BootstrapState{
StateInstances: []instance.Id{instance.Id("an-instance-id")},
Characteristics: []instance.HardwareCharacteristics{{Arch: &arch}}}
content, err := goyaml.Marshal(state)
c.Assert(err, IsNil)
err = storage.Put(environs.StateFile, ioutil.NopCloser(bytes.NewReader(content)), int64(len(content)))
c.Assert(err, IsNil)
return state
}
示例15: TestStartInstance
func (s *lxcBrokerSuite) TestStartInstance(c *gc.C) {
machineId := "1/lxc/0"
lxc := s.startInstance(c, machineId)
c.Assert(lxc.Id(), gc.Equals, instance.Id("juju-machine-1-lxc-0"))
c.Assert(s.lxcContainerDir(lxc), jc.IsDirectory)
s.assertInstances(c, lxc)
// Uses default network config
lxcConfContents, err := ioutil.ReadFile(filepath.Join(s.ContainerDir, string(lxc.Id()), "lxc.conf"))
c.Assert(err, gc.IsNil)
c.Assert(string(lxcConfContents), jc.Contains, "lxc.network.type = veth")
c.Assert(string(lxcConfContents), jc.Contains, "lxc.network.link = lxcbr0")
}