本文整理汇总了Golang中github.com/wallyworld/core/instance.Instance类的典型用法代码示例。如果您正苦于以下问题:Golang Instance类的具体用法?Golang Instance怎么用?Golang Instance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Instance类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: handleBootstrapError
// handleBootstrapError cleans up after a failed bootstrap.
func handleBootstrapError(err error, ctx environs.BootstrapContext, inst instance.Instance, env environs.Environ) {
if err == nil {
return
}
logger.Errorf("bootstrap failed: %v", err)
ch := make(chan os.Signal, 1)
ctx.InterruptNotify(ch)
defer ctx.StopInterruptNotify(ch)
defer close(ch)
go func() {
for _ = range ch {
fmt.Fprintln(ctx.GetStderr(), "Cleaning up failed bootstrap")
}
}()
if inst != nil {
fmt.Fprintln(ctx.GetStderr(), "Stopping instance...")
if stoperr := env.StopInstances([]instance.Instance{inst}); stoperr != nil {
logger.Errorf("cannot stop failed bootstrap instance %q: %v", inst.Id(), stoperr)
} else {
// set to nil so we know we can safely delete the state file
inst = nil
}
}
// We only delete the bootstrap state file if either we didn't
// start an instance, or we managed to cleanly stop it.
if inst == nil {
if rmerr := bootstrap.DeleteStateFile(env.Storage()); rmerr != nil {
logger.Errorf("cannot delete bootstrap state file: %v", rmerr)
}
}
}
开发者ID:jameinel,项目名称:core,代码行数:34,代码来源:bootstrap.go
示例2: WaitDNSName
// WaitDNSName is an implementation that the providers can use. It builds on
// the provider's implementation of Instance.DNSName.
func WaitDNSName(inst instance.Instance) (string, error) {
for a := LongAttempt.Start(); a.Next(); {
name, err := inst.DNSName()
if err == nil || err != instance.ErrNoDNSName {
return name, err
}
}
return "", fmt.Errorf("timed out trying to get DNS address for %v", inst.Id())
}
开发者ID:jameinel,项目名称:core,代码行数:11,代码来源:polling.go
示例3: instInfo
// instInfo returns the instance info for the given id
// and instance. If inst is nil, it returns a not-found error.
func (*aggregator) instInfo(id instance.Id, inst instance.Instance) (instanceInfo, error) {
if inst == nil {
return instanceInfo{}, errors.NotFoundf("instance %v", id)
}
addr, err := inst.Addresses()
if err != nil {
return instanceInfo{}, err
}
return instanceInfo{
addr,
inst.Status(),
}, nil
}
开发者ID:jameinel,项目名称:core,代码行数:15,代码来源:aggregate.go
示例4: DestroyContainer
func (manager *containerManager) DestroyContainer(instance instance.Instance) error {
name := string(instance.Id())
kvmContainer := KvmObjectFactory.New(name)
if err := kvmContainer.Stop(); err != nil {
logger.Errorf("failed to stop kvm container: %v", err)
return err
}
return container.RemoveDirectory(name)
}
开发者ID:jameinel,项目名称:core,代码行数:9,代码来源:kvm.go
示例5: assertInstanceId
// assertInstanceId asserts that the machine has an instance id
// that matches that of the given instance. If the instance is nil,
// It asserts that the instance id is unset.
func assertInstanceId(c *gc.C, m *state.Machine, inst instance.Instance) {
var wantId, gotId instance.Id
var err error
if inst != nil {
wantId = inst.Id()
}
for a := waitAgent.Start(); a.Next(); {
err := m.Refresh()
c.Assert(err, gc.IsNil)
gotId, err = m.InstanceId()
if err != nil {
c.Assert(err, jc.Satisfies, state.IsNotProvisionedError)
if inst == nil {
return
}
continue
}
break
}
c.Assert(err, gc.IsNil)
c.Assert(gotId, gc.Equals, wantId)
}
开发者ID:jameinel,项目名称:core,代码行数:25,代码来源:livetests.go
示例6: assertPorts
// assertPorts retrieves the open ports of the instance and compares them
// to the expected.
func (s *FirewallerSuite) assertPorts(c *gc.C, inst instance.Instance, machineId string, expected []instance.Port) {
s.BackingState.StartSync()
start := time.Now()
for {
got, err := inst.Ports(machineId)
if err != nil {
c.Fatal(err)
return
}
instance.SortPorts(got)
instance.SortPorts(expected)
if reflect.DeepEqual(got, expected) {
c.Succeed()
return
}
if time.Since(start) > coretesting.LongWait {
c.Fatalf("timed out: expected %q; got %q", expected, got)
return
}
time.Sleep(coretesting.ShortWait)
}
}
开发者ID:jameinel,项目名称:core,代码行数:24,代码来源:firewaller_test.go
示例7: Bootstrap
// Bootstrap is a common implementation of the Bootstrap method defined on
// environs.Environ; we strongly recommend that this implementation be used
// when writing a new provider.
func Bootstrap(ctx environs.BootstrapContext, env environs.Environ, args environs.BootstrapParams) (err error) {
// TODO make safe in the case of racing Bootstraps
// If two Bootstraps are called concurrently, there's
// no way to make sure that only one succeeds.
var inst instance.Instance
defer func() { handleBootstrapError(err, ctx, inst, env) }()
// First thing, ensure we have tools otherwise there's no point.
selectedTools, err := EnsureBootstrapTools(ctx, env, config.PreferredSeries(env.Config()), args.Constraints.Arch)
if err != nil {
return err
}
// Get the bootstrap SSH client. Do this early, so we know
// not to bother with any of the below if we can't finish the job.
client := ssh.DefaultClient
if client == nil {
// This should never happen: if we don't have OpenSSH, then
// go.crypto/ssh should be used with an auto-generated key.
return fmt.Errorf("no SSH client available")
}
privateKey, err := GenerateSystemSSHKey(env)
if err != nil {
return err
}
machineConfig := environs.NewBootstrapMachineConfig(privateKey)
fmt.Fprintln(ctx.GetStderr(), "Launching instance")
inst, hw, _, err := env.StartInstance(environs.StartInstanceParams{
Constraints: args.Constraints,
Tools: selectedTools,
MachineConfig: machineConfig,
Placement: args.Placement,
})
if err != nil {
return fmt.Errorf("cannot start bootstrap instance: %v", err)
}
fmt.Fprintf(ctx.GetStderr(), " - %s\n", inst.Id())
machineConfig.InstanceId = inst.Id()
machineConfig.HardwareCharacteristics = hw
err = bootstrap.SaveState(
env.Storage(),
&bootstrap.BootstrapState{
StateInstances: []instance.Id{inst.Id()},
})
if err != nil {
return fmt.Errorf("cannot save state: %v", err)
}
return FinishBootstrap(ctx, client, inst, machineConfig)
}
开发者ID:jameinel,项目名称:core,代码行数:56,代码来源:bootstrap.go
示例8: DestroyContainer
func (manager *containerManager) DestroyContainer(instance instance.Instance) error {
start := time.Now()
name := string(instance.Id())
lxcContainer := LxcObjectFactory.New(name)
if useRestartDir() {
// Remove the autostart link.
if err := os.Remove(restartSymlink(name)); err != nil {
logger.Errorf("failed to remove restart symlink: %v", err)
return err
}
}
if err := lxcContainer.Destroy(); err != nil {
logger.Errorf("failed to destroy lxc container: %v", err)
return err
}
err := container.RemoveDirectory(name)
logger.Tracef("container %q stopped: %v", name, time.Now().Sub(start))
return err
}
开发者ID:jameinel,项目名称:core,代码行数:20,代码来源:lxc.go
示例9: lxcRemovedContainerDir
func (s *lxcBrokerSuite) lxcRemovedContainerDir(inst instance.Instance) string {
return filepath.Join(s.RemovedDir, string(inst.Id()))
}
开发者ID:jameinel,项目名称:core,代码行数:3,代码来源:lxc-broker_test.go
示例10: kvmContainerDir
func (s *kvmBrokerSuite) kvmContainerDir(inst instance.Instance) string {
return filepath.Join(s.ContainerDir, string(inst.Id()))
}
开发者ID:jameinel,项目名称:core,代码行数:3,代码来源:kvm-broker_test.go
注:本文中的github.com/wallyworld/core/instance.Instance类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论