How to use NewConfig method of cloudapi Package

Best K6 code snippet using cloudapi.NewConfig

environ.go

Source:environ.go Github

copy

Full Screen

1// Copyright 2013 Joyent Inc.2// Licensed under the AGPLv3, see LICENCE file for details.3package joyent4import (5 "fmt"6 "strings"7 "sync"8 "github.com/joyent/gosdc/cloudapi"9 "github.com/juju/errors"10 "github.com/juju/juju/constraints"11 "github.com/juju/juju/environs"12 "github.com/juju/juju/environs/config"13 "github.com/juju/juju/environs/imagemetadata"14 "github.com/juju/juju/environs/simplestreams"15 "github.com/juju/juju/environs/tags"16 "github.com/juju/juju/instance"17 "github.com/juju/juju/provider/common"18)19// This file contains the core of the Joyent Environ implementation.20type joyentEnviron struct {21 name string22 compute *joyentCompute23 // supportedArchitectures caches the architectures24 // for which images can be instantiated.25 archLock sync.Mutex26 supportedArchitectures []string27 lock sync.Mutex // protects ecfg28 ecfg *environConfig29}30// newEnviron create a new Joyent environ instance from config.31func newEnviron(cfg *config.Config) (*joyentEnviron, error) {32 env := new(joyentEnviron)33 if err := env.SetConfig(cfg); err != nil {34 return nil, err35 }36 env.name = cfg.Name()37 var err error38 env.compute, err = newCompute(env.ecfg)39 if err != nil {40 return nil, err41 }42 return env, nil43}44func (env *joyentEnviron) SetName(envName string) {45 env.name = envName46}47func (*joyentEnviron) Provider() environs.EnvironProvider {48 return providerInstance49}50// PrecheckInstance is defined on the state.Prechecker interface.51func (env *joyentEnviron) PrecheckInstance(series string, cons constraints.Value, placement string) error {52 if placement != "" {53 return fmt.Errorf("unknown placement directive: %s", placement)54 }55 if !cons.HasInstanceType() {56 return nil57 }58 // Constraint has an instance-type constraint so let's see if it is valid.59 instanceTypes, err := env.listInstanceTypes()60 if err != nil {61 return err62 }63 for _, instanceType := range instanceTypes {64 if instanceType.Name == *cons.InstanceType {65 return nil66 }67 }68 return fmt.Errorf("invalid Joyent instance %q specified", *cons.InstanceType)69}70func (env *joyentEnviron) getSupportedArchitectures() ([]string, error) {71 env.archLock.Lock()72 defer env.archLock.Unlock()73 if env.supportedArchitectures != nil {74 return env.supportedArchitectures, nil75 }76 cfg := env.Ecfg()77 // Create a filter to get all images from our region and for the correct stream.78 cloudSpec := simplestreams.CloudSpec{79 Region: cfg.Region(),80 Endpoint: cfg.SdcUrl(),81 }82 imageConstraint := imagemetadata.NewImageConstraint(simplestreams.LookupParams{83 CloudSpec: cloudSpec,84 Stream: cfg.ImageStream(),85 })86 var err error87 env.supportedArchitectures, err = common.SupportedArchitectures(env, imageConstraint)88 return env.supportedArchitectures, err89}90func (env *joyentEnviron) SetConfig(cfg *config.Config) error {91 env.lock.Lock()92 defer env.lock.Unlock()93 ecfg, err := providerInstance.newConfig(cfg)94 if err != nil {95 return err96 }97 env.ecfg = ecfg98 return nil99}100func (env *joyentEnviron) Config() *config.Config {101 return env.Ecfg().Config102}103func (env *joyentEnviron) PrepareForBootstrap(ctx environs.BootstrapContext) error {104 if ctx.ShouldVerifyCredentials() {105 if err := verifyCredentials(env); err != nil {106 return errors.Trace(err)107 }108 }109 return nil110}111func (env *joyentEnviron) Bootstrap(ctx environs.BootstrapContext, args environs.BootstrapParams) (*environs.BootstrapResult, error) {112 return common.Bootstrap(ctx, env, args)113}114func (env *joyentEnviron) ControllerInstances(controllerUUID string) ([]instance.Id, error) {115 instanceIds := []instance.Id{}116 filter := cloudapi.NewFilter()117 filter.Set(tagKey("group"), "juju")118 filter.Set(tagKey(tags.JujuModel), controllerUUID)119 filter.Set(tagKey(tags.JujuIsController), "true")120 machines, err := env.compute.cloudapi.ListMachines(filter)121 if err != nil || len(machines) == 0 {122 return nil, environs.ErrNotBootstrapped123 }124 for _, m := range machines {125 if strings.EqualFold(m.State, "provisioning") || strings.EqualFold(m.State, "running") {126 copy := m127 ji := &joyentInstance{machine: &copy, env: env}128 instanceIds = append(instanceIds, ji.Id())129 }130 }131 return instanceIds, nil132}133func (env *joyentEnviron) Destroy() error {134 return errors.Trace(common.Destroy(env))135}136// DestroyController implements the Environ interface.137func (env *joyentEnviron) DestroyController(controllerUUID string) error {138 // TODO(wallyworld): destroy hosted model resources139 return env.Destroy()140}141func (env *joyentEnviron) Ecfg() *environConfig {142 env.lock.Lock()143 defer env.lock.Unlock()144 return env.ecfg145}146// MetadataLookupParams returns parameters which are used to query simplestreams metadata.147func (env *joyentEnviron) MetadataLookupParams(region string) (*simplestreams.MetadataLookupParams, error) {148 if region == "" {149 region = env.Ecfg().Region()150 }151 return &simplestreams.MetadataLookupParams{152 Series: config.PreferredSeries(env.Ecfg()),153 Region: region,154 Endpoint: env.Ecfg().sdcUrl(),155 Architectures: []string{"amd64", "armhf"},156 }, nil157}158// Region is specified in the HasRegion interface.159func (env *joyentEnviron) Region() (simplestreams.CloudSpec, error) {160 return simplestreams.CloudSpec{161 Region: env.Ecfg().Region(),162 Endpoint: env.Ecfg().sdcUrl(),163 }, nil164}...

Full Screen

Full Screen

cloud.go

Source:cloud.go Github

copy

Full Screen

...35func CreateTestRun(opts InspectOutput, instances int32, host, token string, log logr.Logger) (string, error) {36 if len(opts.External.Loadimpact.Name) < 1 {37 opts.External.Loadimpact.Name = "k6-operator-test"38 }39 cloudConfig := cloudapi.NewConfig()40 if opts.External.Loadimpact.ProjectID > 0 {41 cloudConfig.ProjectID = null.NewInt(opts.External.Loadimpact.ProjectID, true)42 }43 logger := &logrus.Logger{44 Out: os.Stdout,45 Formatter: new(logrus.TextFormatter),46 Hooks: make(logrus.LevelHooks),47 Level: logrus.InfoLevel,48 }49 if opts.Thresholds == nil {50 opts.Thresholds = make(map[string][]string)51 }52 if len(host) == 0 {53 host = cloudConfig.Host.String...

Full Screen

Full Screen

NewConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 provider, err := common.DefaultConfigProvider()4 if err != nil {5 fmt.Println("Error creating DefaultConfigProvider", err)6 }7 identityClient, err := identity.NewIdentityClientWithConfigurationProvider(provider)8 if err != nil {9 fmt.Println("Error creating identity client", err)10 }11 coreClient, err := core.NewComputeClientWithConfigurationProvider(provider)12 if err != nil {13 fmt.Println("Error creating core client", err)14 }15 tenancyID, err := provider.TenancyOCID()16 if err != nil {17 fmt.Println("Error getting tenancy OCID", err)18 }19 userID, err := provider.UserOCID()20 if err != nil {21 fmt.Println("Error getting user OCID", err)22 }23 fingerprint, err := provider.KeyFingerprint()24 if err != nil {25 fmt.Println("Error getting fingerprint", err)26 }27 privateKey, err := provider.PrivateRSAKey()28 if err != nil {29 fmt.Println("Error getting private key", err)30 }31 region, err := provider.Region()32 if err != nil {33 fmt.Println("Error getting region", err)34 }35 passphrase, err := provider.PassPhrase()36 if err != nil {37 fmt.Println("Error getting pass phrase", err)38 }39 tenancyName, err := provider.TenancyName()40 if err != nil {41 fmt.Println("Error getting tenancy name", err)42 }

Full Screen

Full Screen

NewConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 config := client.NewConfig("us-sw-1", auth.NewSSHAgentSigner)4 fmt.Println(config)5}6import (7func main() {8 config := client.NewConfig("us-sw-1", auth.NewSSHAgentSigner)9 fmt.Println(config)10}11import (12func main() {13 config := client.NewConfig("us-sw-1", auth.NewSSHAgentSigner)14 fmt.Println(config)15}16import (17func main() {18 config := client.NewConfig("us-sw-1", auth.NewSSHAgentSigner)19 fmt.Println(config)20}21import (22func main() {23 config := client.NewConfig("us-sw-1", auth.NewSSHAgentSigner)24 fmt.Println(config)25}26import (27func main() {28 config := client.NewConfig("us-sw-1", auth.NewSSHAgentSigner)29 fmt.Println(config)30}31import (32func main() {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful