本文整理汇总了Golang中github.com/juju/cmd.Context.InterruptNotify方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.InterruptNotify方法的具体用法?Golang Context.InterruptNotify怎么用?Golang Context.InterruptNotify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/cmd.Context
的用法示例。
在下文中一共展示了Context.InterruptNotify方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleBootstrapError
// handleBootstrapError is called to clean up if bootstrap fails.
func handleBootstrapError(ctx *cmd.Context, err error, cleanup func()) {
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")
}
}()
cleanup()
}
示例2: handleBootstrapError
// handleBootstrapError is called to clean up if bootstrap fails.
func handleBootstrapError(ctx *cmd.Context, err error, cleanup func() error) {
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 err := cleanup(); err != nil {
logger.Errorf("error cleaning up: %v", err)
}
}
示例3: Run
// Run connects to the environment specified on the command line and bootstraps
// a juju in that environment if none already exists. If there is as yet no environments.yaml file,
// the user is informed how to create one.
func (c *BootstrapCommand) Run(ctx *cmd.Context) (resultErr error) {
bootstrapFuncs := getBootstrapFuncs()
if len(c.seriesOld) > 0 {
fmt.Fprintln(ctx.Stderr, "Use of --series is obsolete. --upload-tools now expands to all supported series of the same operating system.")
}
if len(c.Series) > 0 {
fmt.Fprintln(ctx.Stderr, "Use of --upload-series is obsolete. --upload-tools now expands to all supported series of the same operating system.")
}
envName := getEnvName(c)
if envName == "" {
return errors.Errorf("the name of the environment must be specified")
}
if err := checkProviderType(envName); errors.IsNotFound(err) {
// This error will get handled later.
} else if err != nil {
return errors.Trace(err)
}
environ, cleanup, err := environFromName(
ctx,
envName,
"Bootstrap",
bootstrapFuncs.EnsureNotBootstrapped,
)
// If we error out for any reason, clean up the environment.
defer func() {
if resultErr != nil && cleanup != nil {
if c.KeepBrokenEnvironment {
logger.Warningf("bootstrap failed but --keep-broken was specified so environment is not being destroyed.\n" +
"When you are finished diagnosing the problem, remember to run juju destroy-environment --force\n" +
"to clean up the environment.")
} else {
handleBootstrapError(ctx, resultErr, cleanup)
}
}
}()
// Handle any errors from environFromName(...).
if err != nil {
return errors.Annotatef(err, "there was an issue examining the environment")
}
// Check to see if this environment is already bootstrapped. If it
// is, we inform the user and exit early. If an error is returned
// but it is not that the environment is already bootstrapped,
// then we're in an unknown state.
if err := bootstrapFuncs.EnsureNotBootstrapped(environ); nil != err {
if environs.ErrAlreadyBootstrapped == err {
logger.Warningf("This juju environment is already bootstrapped. If you want to start a new Juju\nenvironment, first run juju destroy-environment to clean up, or switch to an\nalternative environment.")
return err
}
return errors.Annotatef(err, "cannot determine if environment is already bootstrapped.")
}
// Block interruption during bootstrap. Providers may also
// register for interrupt notification so they can exit early.
interrupted := make(chan os.Signal, 1)
defer close(interrupted)
ctx.InterruptNotify(interrupted)
defer ctx.StopInterruptNotify(interrupted)
go func() {
for _ = range interrupted {
ctx.Infof("Interrupt signalled: waiting for bootstrap to exit")
}
}()
// If --metadata-source is specified, override the default tools metadata source so
// SyncTools can use it, and also upload any image metadata.
var metadataDir string
if c.MetadataSource != "" {
metadataDir = ctx.AbsPath(c.MetadataSource)
}
// TODO (wallyworld): 2013-09-20 bug 1227931
// We can set a custom tools data source instead of doing an
// unnecessary upload.
if environ.Config().Type() == provider.Local {
c.UploadTools = true
}
err = bootstrapFuncs.Bootstrap(envcmd.BootstrapContext(ctx), environ, bootstrap.BootstrapParams{
Constraints: c.Constraints,
Placement: c.Placement,
UploadTools: c.UploadTools,
AgentVersion: c.AgentVersion,
MetadataDir: metadataDir,
})
if err != nil {
return errors.Annotate(err, "failed to bootstrap environment")
}
err = c.SetBootstrapEndpointAddress(environ)
if err != nil {
return errors.Annotate(err, "saving bootstrap endpoint address")
}
//.........这里部分代码省略.........
示例4: Run
// Run connects to the environment specified on the command line and bootstraps
// a juju in that environment if none already exists. If there is as yet no environments.yaml file,
// the user is informed how to create one.
func (c *BootstrapCommand) Run(ctx *cmd.Context) (resultErr error) {
bootstrapFuncs := getBootstrapFuncs()
if len(c.seriesOld) > 0 {
fmt.Fprintln(ctx.Stderr, "Use of --series is deprecated. Please use --upload-series instead.")
}
if c.ConnectionName() == "" {
return fmt.Errorf("the name of the environment must be specified")
}
environ, cleanup, err := environFromName(ctx, c.ConnectionName(), "Bootstrap")
if err != nil {
return errors.Annotatef(err, "there was an issue examining the environment")
}
// If we error out for any reason, clean up the environment.
defer func() {
if resultErr != nil {
cleanup()
}
}()
// We want to validate constraints early. However, if a custom image metadata
// source is specified, we can't validate the arch because that depends on what
// images metadata is to be uploaded. So we validate here if no custom metadata
// source is specified, and defer till later if not.
if c.MetadataSource == "" {
if err := validateConstraints(c.Constraints, environ); err != nil {
return err
}
}
// Check to see if this environment is already bootstrapped. If it
// is, we inform the user and exit early. If an error is returned
// but it is not that the environment is already bootstrapped,
// then we're in an unknown state.
if err := bootstrapFuncs.EnsureNotBootstrapped(environ); nil != err {
if environs.ErrAlreadyBootstrapped == err {
logger.Warningf("This juju environment is already bootstrapped. If you want to start a new Juju\nenvironment, first run juju destroy-environment to clean up, or switch to an\nalternative environment.")
return err
}
return errors.Annotatef(err, "cannot determine if environment is already bootstrapped.")
}
// Block interruption during bootstrap. Providers may also
// register for interrupt notification so they can exit early.
interrupted := make(chan os.Signal, 1)
defer close(interrupted)
ctx.InterruptNotify(interrupted)
defer ctx.StopInterruptNotify(interrupted)
go func() {
for _ = range interrupted {
ctx.Infof("Interrupt signalled: waiting for bootstrap to exit")
}
}()
// If --metadata-source is specified, override the default tools metadata source so
// SyncTools can use it, and also upload any image metadata.
if c.MetadataSource != "" {
metadataDir := ctx.AbsPath(c.MetadataSource)
if err := uploadCustomMetadata(metadataDir, environ); err != nil {
return err
}
if err := validateConstraints(c.Constraints, environ); err != nil {
return err
}
}
// TODO (wallyworld): 2013-09-20 bug 1227931
// We can set a custom tools data source instead of doing an
// unnecessary upload.
if environ.Config().Type() == provider.Local {
c.UploadTools = true
}
if c.UploadTools {
err = bootstrapFuncs.UploadTools(ctx, environ, c.Constraints.Arch, true, c.Series...)
if err != nil {
return err
}
}
return bootstrapFuncs.Bootstrap(ctx, environ, environs.BootstrapParams{
Constraints: c.Constraints,
Placement: c.Placement,
})
}
示例5: Run
// Run connects to the environment specified on the command line and bootstraps
// a juju in that environment if none already exists. If there is as yet no environments.yaml file,
// the user is informed how to create one.
func (c *bootstrapCommand) Run(ctx *cmd.Context) (resultErr error) {
bootstrapFuncs := getBootstrapFuncs()
envName := getModelName(c)
if envName == "" {
return errors.Errorf("the name of the model must be specified")
}
if err := checkProviderType(envName); errors.IsNotFound(err) {
// This error will get handled later.
} else if err != nil {
return errors.Trace(err)
}
environ, cleanup, err := environFromName(
ctx,
envName,
"Bootstrap",
bootstrapFuncs.EnsureNotBootstrapped,
)
// If we error out for any reason, clean up the environment.
defer func() {
if resultErr != nil && cleanup != nil {
if c.KeepBrokenEnvironment {
logger.Warningf("bootstrap failed but --keep-broken was specified so model is not being destroyed.\n" +
"When you are finished diagnosing the problem, remember to run juju destroy-model --force\n" +
"to clean up the model.")
} else {
handleBootstrapError(ctx, resultErr, cleanup)
}
}
}()
// Handle any errors from environFromName(...).
if err != nil {
return errors.Annotatef(err, "there was an issue examining the model")
}
// Check to see if this environment is already bootstrapped. If it
// is, we inform the user and exit early. If an error is returned
// but it is not that the environment is already bootstrapped,
// then we're in an unknown state.
if err := bootstrapFuncs.EnsureNotBootstrapped(environ); nil != err {
if environs.ErrAlreadyBootstrapped == err {
logger.Warningf("This juju model is already bootstrapped. If you want to start a new Juju\nmodel, first run juju destroy-model to clean up, or switch to an\nalternative model.")
return err
}
return errors.Annotatef(err, "cannot determine if model is already bootstrapped.")
}
// Block interruption during bootstrap. Providers may also
// register for interrupt notification so they can exit early.
interrupted := make(chan os.Signal, 1)
defer close(interrupted)
ctx.InterruptNotify(interrupted)
defer ctx.StopInterruptNotify(interrupted)
go func() {
for _ = range interrupted {
ctx.Infof("Interrupt signalled: waiting for bootstrap to exit")
}
}()
// If --metadata-source is specified, override the default tools metadata source so
// SyncTools can use it, and also upload any image metadata.
var metadataDir string
if c.MetadataSource != "" {
metadataDir = ctx.AbsPath(c.MetadataSource)
}
// Merge environ and bootstrap-specific constraints.
constraintsValidator, err := environ.ConstraintsValidator()
if err != nil {
return errors.Trace(err)
}
bootstrapConstraints, err := constraintsValidator.Merge(
c.Constraints, c.BootstrapConstraints,
)
if err != nil {
return errors.Trace(err)
}
logger.Infof("combined bootstrap constraints: %v", bootstrapConstraints)
err = bootstrapFuncs.Bootstrap(modelcmd.BootstrapContext(ctx), environ, bootstrap.BootstrapParams{
EnvironConstraints: c.Constraints,
BootstrapConstraints: bootstrapConstraints,
BootstrapSeries: c.BootstrapSeries,
BootstrapImage: c.BootstrapImage,
Placement: c.Placement,
UploadTools: c.UploadTools,
AgentVersion: c.AgentVersion,
MetadataDir: metadataDir,
})
if err != nil {
return errors.Annotate(err, "failed to bootstrap model")
}
err = c.SetBootstrapEndpointAddress(environ)
if err != nil {
//.........这里部分代码省略.........
示例6: Run
//.........这里部分代码省略.........
}
cloudRegion := c.Cloud
if region.Name != "" {
cloudRegion = fmt.Sprintf("%s/%s", cloudRegion, region.Name)
}
ctx.Infof(
"Creating Juju controller %q on %s",
c.controllerName, cloudRegion,
)
// If we error out for any reason, clean up the environment.
defer func() {
if resultErr != nil {
if c.KeepBrokenEnvironment {
logger.Warningf(`
bootstrap failed but --keep-broken was specified so model is not being destroyed.
When you are finished diagnosing the problem, remember to run juju destroy-model --force
to clean up the model.`[1:])
} else {
handleBootstrapError(ctx, resultErr, func() error {
return environsDestroy(
c.controllerName, environ, store,
)
})
}
}
}()
// Block interruption during bootstrap. Providers may also
// register for interrupt notification so they can exit early.
interrupted := make(chan os.Signal, 1)
defer close(interrupted)
ctx.InterruptNotify(interrupted)
defer ctx.StopInterruptNotify(interrupted)
go func() {
for _ = range interrupted {
ctx.Infof("Interrupt signalled: waiting for bootstrap to exit")
}
}()
// If --metadata-source is specified, override the default tools metadata source so
// SyncTools can use it, and also upload any image metadata.
var metadataDir string
if c.MetadataSource != "" {
metadataDir = ctx.AbsPath(c.MetadataSource)
}
// Merge environ and bootstrap-specific constraints.
constraintsValidator, err := environ.ConstraintsValidator()
if err != nil {
return errors.Trace(err)
}
bootstrapConstraints, err := constraintsValidator.Merge(
c.Constraints, c.BootstrapConstraints,
)
if err != nil {
return errors.Trace(err)
}
logger.Infof("combined bootstrap constraints: %v", bootstrapConstraints)
hostedModelConfig := map[string]interface{}{
"name": c.hostedModelName,
config.UUIDKey: hostedModelUUID.String(),
}
示例7: Run
//.........这里部分代码省略.........
}
cloudRegion := c.Cloud
if region.Name != "" {
cloudRegion = fmt.Sprintf("%s/%s", cloudRegion, region.Name)
}
ctx.Infof(
"Creating Juju controller %q on %s",
c.controllerName, cloudRegion,
)
// If we error out for any reason, clean up the environment.
defer func() {
if resultErr != nil {
if c.KeepBrokenEnvironment {
ctx.Infof(`
bootstrap failed but --keep-broken was specified so resources are not being destroyed.
When you have finished diagnosing the problem, remember to clean up the failed controller.
See `[1:] + "`juju kill-controller`" + `.`)
} else {
handleBootstrapError(ctx, resultErr, func() error {
return environsDestroy(
c.controllerName, environ, store,
)
})
}
}
}()
// Block interruption during bootstrap. Providers may also
// register for interrupt notification so they can exit early.
interrupted := make(chan os.Signal, 1)
defer close(interrupted)
ctx.InterruptNotify(interrupted)
defer ctx.StopInterruptNotify(interrupted)
go func() {
for _ = range interrupted {
ctx.Infof("Interrupt signalled: waiting for bootstrap to exit")
}
}()
// If --metadata-source is specified, override the default tools metadata source so
// SyncTools can use it, and also upload any image metadata.
var metadataDir string
if c.MetadataSource != "" {
metadataDir = ctx.AbsPath(c.MetadataSource)
}
// Merge environ and bootstrap-specific constraints.
constraintsValidator, err := environ.ConstraintsValidator()
if err != nil {
return errors.Trace(err)
}
bootstrapConstraints, err := constraintsValidator.Merge(
c.Constraints, c.BootstrapConstraints,
)
if err != nil {
return errors.Trace(err)
}
logger.Infof("combined bootstrap constraints: %v", bootstrapConstraints)
hostedModelConfig := map[string]interface{}{
"name": c.hostedModelName,
config.UUIDKey: hostedModelUUID.String(),
}
for k, v := range inheritedControllerAttrs {
示例8: Run
// Run connects to the environment specified on the command line and bootstraps
// a juju in that environment if none already exists. If there is as yet no environments.yaml file,
// the user is informed how to create one.
func (c *BootstrapCommand) Run(ctx *cmd.Context) (resultErr error) {
bootstrapFuncs := getBootstrapFuncs()
if len(c.seriesOld) > 0 {
fmt.Fprintln(ctx.Stderr, "Use of --series is deprecated. Please use --upload-series instead.")
}
environ, cleanup, err := environFromName(ctx, c.EnvName, &resultErr, "Bootstrap")
if err != nil {
return err
}
// We want to validate constraints early. However, if a custom image metadata
// source is specified, we can't validate the arch because that depends on what
// images metadata is to be uploaded. So we validate here if no custom metadata
// source is specified, and defer till later if not.
if c.MetadataSource == "" {
if err := validateConstraints(c.Constraints, environ); err != nil {
return err
}
}
defer cleanup()
if err := bootstrapFuncs.EnsureNotBootstrapped(environ); err != nil {
return err
}
// Block interruption during bootstrap. Providers may also
// register for interrupt notification so they can exit early.
interrupted := make(chan os.Signal, 1)
defer close(interrupted)
ctx.InterruptNotify(interrupted)
defer ctx.StopInterruptNotify(interrupted)
go func() {
for _ = range interrupted {
ctx.Infof("Interrupt signalled: waiting for bootstrap to exit")
}
}()
// If --metadata-source is specified, override the default tools metadata source so
// SyncTools can use it, and also upload any image metadata.
if c.MetadataSource != "" {
metadataDir := ctx.AbsPath(c.MetadataSource)
if err := uploadCustomMetadata(metadataDir, environ); err != nil {
return err
}
if err := validateConstraints(c.Constraints, environ); err != nil {
return err
}
}
// TODO (wallyworld): 2013-09-20 bug 1227931
// We can set a custom tools data source instead of doing an
// unnecessary upload.
if environ.Config().Type() == provider.Local {
c.UploadTools = true
}
if c.UploadTools {
err = bootstrapFuncs.UploadTools(ctx, environ, c.Constraints.Arch, true, c.Series...)
if err != nil {
return err
}
}
return bootstrapFuncs.Bootstrap(ctx, environ, environs.BootstrapParams{
Constraints: c.Constraints,
Placement: c.Placement,
})
}