本文整理汇总了Golang中github.com/juju/juju/juju.NewAPIClientFromName函数的典型用法代码示例。如果您正苦于以下问题:Golang NewAPIClientFromName函数的具体用法?Golang NewAPIClientFromName怎么用?Golang NewAPIClientFromName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewAPIClientFromName函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: SetUpTest
func (s *apiEnvironmentSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
var err error
s.client, err = juju.NewAPIClientFromName("", nil)
c.Assert(err, jc.ErrorIsNil)
c.Assert(s.client, gc.NotNil)
}
开发者ID:imoapps,项目名称:juju,代码行数:7,代码来源:api_environment_test.go
示例2: Run
func (c *DestroyEnvironmentCommand) Run(ctx *cmd.Context) (result error) {
store, err := configstore.Default()
if err != nil {
return fmt.Errorf("cannot open environment info storage: %v", err)
}
environ, err := environs.NewFromName(c.envName, store)
if err != nil {
if environs.IsEmptyConfig(err) {
// Delete the .jenv file and call it done.
ctx.Infof("removing empty environment file")
return environs.DestroyInfo(c.envName, store)
}
return err
}
if !c.assumeYes {
fmt.Fprintf(ctx.Stdout, destroyEnvMsg, environ.Name(), environ.Config().Type())
scanner := bufio.NewScanner(ctx.Stdin)
scanner.Scan()
err := scanner.Err()
if err != nil && err != io.EOF {
return fmt.Errorf("Environment destruction aborted: %s", err)
}
answer := strings.ToLower(scanner.Text())
if answer != "y" && answer != "yes" {
return errors.New("environment destruction aborted")
}
}
// If --force is supplied, then don't attempt to use the API.
// This is necessary to destroy broken environments, where the
// API server is inaccessible or faulty.
if !c.force {
defer func() {
if result == nil {
return
}
logger.Errorf(`failed to destroy environment %q
If the environment is unusable, then you may run
juju destroy-environment --force
to forcefully destroy the environment. Upon doing so, review
your environment provider console for any resources that need
to be cleaned up.
`, c.envName)
}()
apiclient, err := juju.NewAPIClientFromName(c.envName)
if err != nil {
return fmt.Errorf("cannot connect to API: %v", err)
}
defer apiclient.Close()
err = apiclient.DestroyEnvironment()
if err != nil && !params.IsCodeNotImplemented(err) {
return fmt.Errorf("destroying environment: %v", err)
}
}
return environs.Destroy(environ, store)
}
开发者ID:klyachin,项目名称:juju,代码行数:60,代码来源:destroyenvironment.go
示例3: Run
func (c *RemoveServiceCommand) Run(_ *cmd.Context) error {
client, err := juju.NewAPIClientFromName(c.EnvName)
if err != nil {
return err
}
defer client.Close()
return client.ServiceDestroy(c.ServiceName)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:8,代码来源:removeservice.go
示例4: Run
// Run resets the configuration of a service.
func (c *UnsetCommand) Run(ctx *cmd.Context) error {
apiclient, err := juju.NewAPIClientFromName(c.EnvName)
if err != nil {
return err
}
defer apiclient.Close()
return apiclient.ServiceUnset(c.ServiceName, c.Options)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:9,代码来源:unset.go
示例5: TestMultipleCloseOk
// TODO(jam): 2013-08-27 This should move somewhere in api.*
func (s *NewAPIClientSuite) TestMultipleCloseOk(c *gc.C) {
coretesting.MakeSampleJujuHome(c)
bootstrapEnv(c, "", defaultConfigStore(c))
client, _ := juju.NewAPIClientFromName("")
c.Assert(client.Close(), gc.IsNil)
c.Assert(client.Close(), gc.IsNil)
c.Assert(client.Close(), gc.IsNil)
}
开发者ID:klyachin,项目名称:juju,代码行数:9,代码来源:api_test.go
示例6: Run
func (c *ResolvedCommand) Run(_ *cmd.Context) error {
client, err := juju.NewAPIClientFromName(c.EnvName)
if err != nil {
return err
}
defer client.Close()
return client.Resolved(c.UnitName, c.Retry)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:8,代码来源:resolved.go
示例7: Run
// Run connects to the environment specified on the command line
// and calls EnsureAvailability.
func (c *EnsureAvailabilityCommand) Run(_ *cmd.Context) error {
client, err := juju.NewAPIClientFromName(c.EnvName)
if err != nil {
return err
}
defer client.Close()
return client.EnsureAvailability(c.NumStateServers, c.Constraints, c.Series)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:10,代码来源:ensureavailability.go
示例8: Run
// Run connects to the environment specified on the command line and destroys
// units therein.
func (c *RemoveUnitCommand) Run(_ *cmd.Context) error {
client, err := juju.NewAPIClientFromName(c.EnvName)
if err != nil {
return err
}
defer client.Close()
return client.DestroyServiceUnits(c.UnitNames...)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:10,代码来源:removeunit.go
示例9: Run
func (c *RemoveRelationCommand) Run(_ *cmd.Context) error {
client, err := juju.NewAPIClientFromName(c.EnvName)
if err != nil {
return err
}
defer client.Close()
return client.DestroyRelation(c.Endpoints...)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:8,代码来源:removerelation.go
示例10: Run
func (c *UnsetEnvironmentCommand) Run(ctx *cmd.Context) error {
client, err := juju.NewAPIClientFromName(c.EnvName)
if err != nil {
return err
}
defer client.Close()
return client.EnvironmentUnset(c.keys...)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:8,代码来源:environment.go
示例11: TestNameNotDefault
func (s *NewAPIClientSuite) TestNameNotDefault(c *gc.C) {
envName := coretesting.SampleCertName + "-2"
coretesting.WriteEnvironments(c, coretesting.MultipleEnvConfig, envName)
s.bootstrapEnv(c, envName, defaultConfigStore(c))
apiclient, err := juju.NewAPIClientFromName(envName)
c.Assert(err, jc.ErrorIsNil)
defer apiclient.Close()
assertEnvironmentName(c, apiclient, envName)
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:9,代码来源:api_test.go
示例12: Run
func (c *AddRelationCommand) Run(_ *cmd.Context) error {
client, err := juju.NewAPIClientFromName(c.EnvName)
if err != nil {
return err
}
defer client.Close()
_, err = client.AddRelation(c.Endpoints...)
return err
}
开发者ID:rogpeppe,项目名称:juju,代码行数:9,代码来源:addrelation.go
示例13: Run
// Run connects to the environment specified on the command line
// and calls AddServiceUnits for the given service.
func (c *AddUnitCommand) Run(_ *cmd.Context) error {
apiclient, err := juju.NewAPIClientFromName(c.EnvName)
if err != nil {
return err
}
defer apiclient.Close()
_, err = apiclient.AddServiceUnits(c.ServiceName, c.NumUnits, c.ToMachineSpec)
return err
}
开发者ID:rogpeppe,项目名称:juju,代码行数:12,代码来源:addunit.go
示例14: Run
func (c *RemoveMachineCommand) Run(_ *cmd.Context) error {
apiclient, err := juju.NewAPIClientFromName(c.EnvName)
if err != nil {
return err
}
defer apiclient.Close()
if c.Force {
return apiclient.ForceDestroyMachines(c.MachineIds...)
}
return apiclient.DestroyMachines(c.MachineIds...)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:11,代码来源:removemachine.go
示例15: ProvisionMachine
// ProvisionMachine provisions a machine agent to an existing host, via
// an SSH connection to the specified host. The host may optionally be preceded
// with a login username, as in [[email protected]]host.
//
// On successful completion, this function will return the id of the state.Machine
// that was entered into state.
func ProvisionMachine(args ProvisionMachineArgs) (machineId string, err error) {
client, err := juju.NewAPIClientFromName(args.EnvName)
if err != nil {
return "", err
}
defer func() {
if machineId != "" && err != nil {
logger.Errorf("provisioning failed, removing machine %v: %v", machineId, err)
if cleanupErr := client.DestroyMachines(machineId); cleanupErr != nil {
logger.Warningf("error cleaning up machine: %s", cleanupErr)
}
machineId = ""
}
client.Close()
}()
// Create the "ubuntu" user and initialise passwordless sudo. We populate
// the ubuntu user's authorized_keys file with the public keys in the current
// user's ~/.ssh directory. The authenticationworker will later update the
// ubuntu user's authorized_keys.
user, hostname := splitUserHost(args.Host)
authorizedKeys, err := config.ReadAuthorizedKeys("")
if err := InitUbuntuUser(hostname, user, authorizedKeys, args.Stdin, args.Stdout); err != nil {
return "", err
}
machineParams, err := gatherMachineParams(hostname)
if err != nil {
return "", err
}
// Inform Juju that the machine exists.
machineId, err = recordMachineInState(client, *machineParams)
if err != nil {
return "", err
}
provisioningScript, err := client.ProvisioningScript(params.ProvisioningScriptParams{
MachineId: machineId,
Nonce: machineParams.Nonce,
})
if err != nil {
return "", err
}
// Finally, provision the machine agent.
err = runProvisionScript(provisioningScript, hostname, args.Stderr)
if err != nil {
return machineId, err
}
logger.Infof("Provisioned machine %v", machineId)
return machineId, nil
}
开发者ID:rogpeppe,项目名称:juju,代码行数:60,代码来源:provisioner.go
示例16: Run
func (c *SetConstraintsCommand) Run(_ *cmd.Context) (err error) {
apiclient, err := juju.NewAPIClientFromName(c.EnvName)
if err != nil {
return err
}
defer apiclient.Close()
if c.ServiceName == "" {
return apiclient.SetEnvironmentConstraints(c.Constraints)
}
return apiclient.SetServiceConstraints(c.ServiceName, c.Constraints)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:11,代码来源:constraints.go
示例17: Run
func (c *RetryProvisioningCommand) Run(context *cmd.Context) error {
client, err := juju.NewAPIClientFromName(c.EnvName)
if err != nil {
return err
}
defer client.Close()
results, err := client.RetryProvisioning(c.Machines...)
if err != nil {
return err
}
for i, result := range results {
if result.Error != nil {
fmt.Fprintf(context.Stderr, "cannot retry provisioning %q: %v\n", c.Machines[i], result.Error)
}
}
return nil
}
开发者ID:rogpeppe,项目名称:juju,代码行数:17,代码来源:retryprovisioning.go
示例18: Run
// Run updates the configuration of a service.
func (c *SetCommand) Run(ctx *cmd.Context) error {
api, err := juju.NewAPIClientFromName(c.EnvName)
if err != nil {
return err
}
defer api.Close()
if c.SettingsYAML.Path != "" {
b, err := c.SettingsYAML.Read(ctx)
if err != nil {
return err
}
return api.ServiceSetYAML(c.ServiceName, string(b))
} else if len(c.SettingsStrings) == 0 {
return nil
}
return api.ServiceSet(c.ServiceName, c.SettingsStrings)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:19,代码来源:set.go
示例19: Run
// Run fetches the configuration of the service and formats
// the result as a YAML string.
func (c *GetCommand) Run(ctx *cmd.Context) error {
client, err := juju.NewAPIClientFromName(c.EnvName)
if err != nil {
return err
}
defer client.Close()
results, err := client.ServiceGet(c.ServiceName)
if err != nil {
return err
}
resultsMap := map[string]interface{}{
"service": results.Service,
"charm": results.Charm,
"settings": results.Config,
}
return c.out.Write(ctx, resultsMap)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:21,代码来源:get.go
示例20: TestNameDefault
func (s *NewAPIClientSuite) TestNameDefault(c *gc.C) {
coretesting.WriteEnvironments(c, coretesting.MultipleEnvConfig)
// The connection logic should not delay the config connection
// at all when there is no environment info available.
// Make sure of that by providing a suitably long delay
// and checking that the connection happens within that
// time.
s.PatchValue(juju.ProviderConnectDelay, coretesting.LongWait)
s.bootstrapEnv(c, coretesting.SampleEnvName, defaultConfigStore(c))
startTime := time.Now()
apiclient, err := juju.NewAPIClientFromName("")
c.Assert(err, jc.ErrorIsNil)
defer apiclient.Close()
c.Assert(time.Since(startTime), jc.LessThan, coretesting.LongWait)
// We should get the default sample environment if we ask for ""
assertEnvironmentName(c, apiclient, coretesting.SampleEnvName)
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:19,代码来源:api_test.go
注:本文中的github.com/juju/juju/juju.NewAPIClientFromName函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论