How to use Add method of cloud Package

Best K6 code snippet using cloud.Add

JUFLOW.go

Source:JUFLOW.go Github

copy

Full Screen

...111 Doc: jujuDoc,112 MissingCallback: RunPlugin,113 UserAliasesFilename: osenv.JujuXDGDataHomePath("aliases"),114 })115 jcmd.AddHelpTopic("basics", "Basic Help Summary", usageHelp)116 registerCommands(jcmd, ctx) <============117 return jcmd118}119// TODO(ericsnow) Factor out the commands and aliases into a static120// registry that can be passed to the supercommand separately.121// registerCommands registers commands in the specified registry.122func registerCommands(r commandRegistry, ctx *cmd.Context) {123 // Creation commands.124 r.Register(newBootstrapCommand())125 r.Register(application.NewAddRelationCommand())126...127 // Manage clouds and credentials128 r.Register(cloud.NewUpdateCloudsCommand())129 r.Register(cloud.NewListCloudsCommand())130 r.Register(cloud.NewListRegionsCommand())131 r.Register(cloud.NewShowCloudCommand())132 r.Register(cloud.NewAddCloudCommand(&cloudToCommandAdapter{})) =====> juju/cmd/supercommand.go 133 func (c *SuperCommand) Register(subcmd Command)134 r.Register(cloud.NewRemoveCloudCommand())135 r.Register(cloud.NewListCredentialsCommand())136 r.Register(cloud.NewDetectCredentialsCommand())137 r.Register(cloud.NewSetDefaultRegionCommand())138 r.Register(cloud.NewSetDefaultCredentialCommand())139 r.Register(cloud.NewAddCredentialCommand())140 r.Register(cloud.NewRemoveCredentialCommand())141 r.Register(cloud.NewUpdateCredentialCommand())142type cloudToCommandAdapter struct{}143./cmd/juju/commands/main.go144type commandRegistry interface {145 Register(cmd.Command)146 RegisterSuperAlias(name, super, forName string, check cmd.DeprecationCheck)147 RegisterDeprecated(subcmd cmd.Command, check cmd.DeprecationCheck)148}149------------------------------------------------------------------------------150juju/juju/cmd/supercommand.go151 "github.com/juju/cmd"152// NewSuperCommand is like cmd.NewSuperCommand but153// it adds juju-specific functionality:154// - The default logging configuration is taken from the environment;155// - The version is configured to the current juju version;156// - The command emits a log message when a command runs.157func NewSuperCommand(p cmd.SuperCommandParams) *cmd.SuperCommand {158 p.Log = &cmd.Log{159 DefaultConfig: os.Getenv(osenv.JujuLoggingConfigEnvKey),160 }161 current := version.Binary{162 Number: jujuversion.Current,163 Arch: arch.HostArch(),164 Series: series.MustHostSeries(),165 }166 // p.Version should be a version.Binary, but juju/cmd does not167 // import juju/juju/version so this cannot happen. We have168 // tests to assert that this string value is correct.169 p.Version = current.String()170 p.NotifyRun = runNotifier171 return cmd.NewSuperCommand(p)172}173-----------------------------------------174juju/cmd/supercommand.go175// NewSuperCommand creates and initializes a new `SuperCommand`, and returns176// the fully initialized structure.177func NewSuperCommand(params SuperCommandParams) *SuperCommand {178 command := &SuperCommand{179 Name: params.Name,180 Purpose: params.Purpose,181 Doc: params.Doc,182 Log: params.Log,183 usagePrefix: params.UsagePrefix,184 missingCallback: params.MissingCallback,185 Aliases: params.Aliases,186 version: params.Version,187 notifyRun: params.NotifyRun,188 notifyHelp: params.NotifyHelp,189 userAliasesFilename: params.UserAliasesFilename,190 }191 command.init()192 return command193}194func (c *SuperCommand) init() {195 if c.subcmds != nil {196 return197 }198 c.help = &helpCommand{199 super: c,200 }201 c.help.init()202 c.subcmds = map[string]commandReference{203 "help": commandReference{command: c.help},204 }205 if c.version != "" {206 c.subcmds["version"] = commandReference{207 command: newVersionCommand(c.version),208 }209 }210 c.userAliases = ParseAliasFile(c.userAliasesFilename)211}212// SuperCommand is a Command that selects a subcommand and assumes its213// properties; any command line arguments that were not used in selecting214// the subcommand are passed down to it, and to Run a SuperCommand is to run215// its selected subcommand.216type SuperCommand struct {217 CommandBase218 Name string219 Purpose string220 Doc string221 Log *Log222 Aliases []string223 version string224 usagePrefix string225 userAliasesFilename string226 userAliases map[string][]string227 subcmds map[string]commandReference228 help *helpCommand229 commonflags *gnuflag.FlagSet230 flags *gnuflag.FlagSet231 action commandReference232 showHelp bool233 showDescription bool234 showVersion bool235 noAlias bool236 missingCallback MissingCallback237 notifyRun func(string)238 notifyHelp func([]string)239}240// SuperCommandParams provides a way to have default parameter to the241// `NewSuperCommand` call.242type SuperCommandParams struct {243 // UsagePrefix should be set when the SuperCommand is244 // actually a subcommand of some other SuperCommand;245 // if NotifyRun is called, it name will be prefixed accordingly,246 // unless UsagePrefix is identical to Name.247 UsagePrefix string248 // Notify, if not nil, is called when the SuperCommand249 // is about to run a sub-command.250 NotifyRun func(cmdName string)251 // NotifyHelp is called just before help is printed, with the252 // arguments received by the help command. This can be253 // used, for example, to load command information for external254 // "plugin" commands, so that their documentation will show up255 // in the help output.256 NotifyHelp func([]string)257 Name string258 Purpose string259 Doc string260 Log *Log261 MissingCallback MissingCallback262 Aliases []string263 Version string264 // UserAliasesFilename refers to the location of a file that contains265 // name = cmd [args...]266 // values, that is used to change default behaviour of commands in order267 // to add flags, or provide short cuts to longer commands.268 UserAliasesFilename string269}270vi juju/cmd/cmd.go271// CommandBase provides the default implementation for SetFlags, Init, and Help.272type CommandBase struct{}273------------------------------------------------------------------------------274vi ./juju/juju/cmd/juju/cloud/add.go275 "github.com/juju/cmd"276// AddCloudCommand is the command that allows you to add a cloud configuration277// for use with juju bootstrap.278type AddCloudCommand struct {279 cmd.CommandBase280 // Replace, if true, existing cloud information is overwritten.281 Replace bool282 // Cloud is the name fo the cloud to add.283 Cloud string284 // CloudFile is the name of the cloud YAML file.285 CloudFile string286 // Ping contains the logic for pinging a cloud endpoint to know whether or287 // not it really has a valid cloud of the same type as the provider. By288 // default it just calls the correct provider's Ping method.289 Ping func(p environs.EnvironProvider, endpoint string) error290 cloudMetadataStore CloudMetadataStore291}292// Info returns help information about the command.293func (c *AddCloudCommand) Info() *cmd.Info {294 return &cmd.Info{295 Name: "add-cloud",296 Args: "<cloud name> <cloud definition file>",297 Purpose: usageAddCloudSummary,298 Doc: usageAddCloudDetails,299 }300}301vi juju/cmd/cmd.go302// CommandBase provides the default implementation for SetFlags, Init, and Help.303type CommandBase struct{}304./cmd/juju/cloud/add.go305// NewAddCloudCommand returns a command to add cloud information.306func NewAddCloudCommand(cloudMetadataStore CloudMetadataStore) *AddCloudCommand {307 // Ping is provider.Ping except in tests where we don't actually want to308 // require a valid cloud.309 return &AddCloudCommand{310 cloudMetadataStore: cloudMetadataStore,311 Ping: func(p environs.EnvironProvider, endpoint string) error {312 return p.Ping(endpoint)313 },314 }315}316./cmd/juju/cloud/add.go317type CloudMetadataStore interface {318 ParseCloudMetadataFile(path string) (map[string]cloud.Cloud, error)319 ParseOneCloud(data []byte) (cloud.Cloud, error)320 PublicCloudMetadata(searchPaths ...string) (result map[string]cloud.Cloud, fallbackUsed bool, _ error)321 PersonalCloudMetadata() (map[string]cloud.Cloud, error)322 WritePersonalCloudMetadata(cloudsMap map[string]cloud.Cloud) error323}324==================================================================================325juju/cmd Register <===== juju/juju AddCloudCommand326juju/juju/cmd/juju/commands/main.go327func registerCommands(r commandRegistry, ctx *cmd.Context) {328...329 // Manage clouds and credentials330 r.Register(cloud.NewAddCloudCommand(&cloudToCommandAdapter{}))331juju/juju/cmd/juju/cloud/add.go332// NewAddCloudCommand returns a command to add cloud information.333func NewAddCloudCommand(cloudMetadataStore CloudMetadataStore) *AddCloudCommand {334 // Ping is provider.Ping except in tests where we don't actually want to335 // require a valid cloud.336 return &AddCloudCommand{337 cloudMetadataStore: cloudMetadataStore,338 Ping: func(p environs.EnvironProvider, endpoint string) error {339 return p.Ping(endpoint)340 },341 }342}343vi ./juju/juju/cmd/juju/cloud/add.go344 "github.com/juju/cmd"345// AddCloudCommand is the command that allows you to add a cloud configuration346// for use with juju bootstrap.347type AddCloudCommand struct {348 cmd.CommandBase <========== juju/cmd/cmd.go CommandBase struct349 // Replace, if true, existing cloud information is overwritten.350 Replace bool351 // Cloud is the name fo the cloud to add.352 Cloud string353 // CloudFile is the name of the cloud YAML file.354 CloudFile string355 // Ping contains the logic for pinging a cloud endpoint to know whether or356 // not it really has a valid cloud of the same type as the provider. By357 // default it just calls the correct provider's Ping method.358 Ping func(p environs.EnvironProvider, endpoint string) error359 cloudMetadataStore CloudMetadataStore360}361// Info returns help information about the command.362func (c *AddCloudCommand) Info() *cmd.Info {363 return &cmd.Info{364 Name: "add-cloud",365 Args: "<cloud name> <cloud definition file>",366 Purpose: usageAddCloudSummary,367 Doc: usageAddCloudDetails,368 }369}370====================================================================================371juju/cmd/cmd.go372// CommandBase provides the default implementation for SetFlags, Init, and Help.373type CommandBase struct{}374juju/cmd/supercommand.go375// Register makes a subcommand available for use on the command line. The376// command will be available via its own name, and via any supplied aliases.377func (c *SuperCommand) Register(subcmd Command) {378 info := subcmd.Info()379 c.insert(commandReference{name: info.Name, command: subcmd})380 for _, name := range info.Aliases {381 c.insert(commandReference{name: name, command: subcmd, alias: info.Name})382 }383}384juju/cmd/cmd.go385// Command is implemented by types that interpret command-line arguments.386type Command interface {387 // IsSuperCommand returns true if the command is a super command.388 IsSuperCommand() bool389 // Info returns information about the Command.390 Info() *Info391 // SetFlags adds command specific flags to the flag set.392 SetFlags(f *gnuflag.FlagSet)393 // Init initializes the Command before running.394 Init(args []string) error395 // Run will execute the Command as directed by the options and positional396 // arguments passed to Init.397 Run(ctx *Context) error <------------398 // AllowInterspersedFlags returns whether the command allows flag399 // arguments to be interspersed with non-flag arguments.400 AllowInterspersedFlags() bool401}402====================================================================================403vi ./juju/juju/cmd/juju/cloud/add.go404// AddCloudCommand is the command that allows you to add a cloud configuration405// for use with juju bootstrap.406type AddCloudCommand struct {407 cmd.CommandBase408 // Replace, if true, existing cloud information is overwritten.409 Replace bool410 // Cloud is the name fo the cloud to add.411 Cloud string412 // CloudFile is the name of the cloud YAML file.413 CloudFile string414 // Ping contains the logic for pinging a cloud endpoint to know whether or415 // not it really has a valid cloud of the same type as the provider. By416 // default it just calls the correct provider's Ping method.417 Ping func(p environs.EnvironProvider, endpoint string) error418 cloudMetadataStore CloudMetadataStore419}420juju/juju/cmd/juju/cloud/add.go421// Run executes the add cloud command, adding a cloud based on a passed-in yaml422// file or interactive queries.423func (c *AddCloudCommand) Run(ctxt *cmd.Context) error {424 if c.CloudFile == "" {425 return c.runInteractive(ctxt)426 }427 specifiedClouds, err := c.cloudMetadataStore.ParseCloudMetadataFile(c.CloudFile) <========== 1428 if err != nil {429 return err430 }431 if specifiedClouds == nil {432 return errors.New("no personal clouds are defined")433 }434 newCloud, ok := specifiedClouds[c.Cloud]435 if !ok {436 return errors.Errorf("cloud %q not found in file %q", c.Cloud, c.CloudFile)437 }438 // first validate cloud input439 data, err := ioutil.ReadFile(c.CloudFile)440 if err != nil {441 return errors.Trace(err)442 }443 if err = cloud.ValidateCloudSet([]byte(data)); err != nil {444 ctxt.Warningf(err.Error())445 }446 // validate cloud data447 provider, err := environs.Provider(newCloud.Type)448 if err != nil {449 return errors.Trace(err)450 }451 schemas := provider.CredentialSchemas()452 for _, authType := range newCloud.AuthTypes {453 if _, defined := schemas[authType]; !defined {454 return errors.NotSupportedf("auth type %q", authType)455 }456 }457 if err := c.verifyName(c.Cloud); err != nil {458 return errors.Trace(err)459 }460 return addCloud(c.cloudMetadataStore, newCloud)461}462====================================================================================463__1__464 specifiedClouds, err := c.cloudMetadataStore.ParseCloudMetadataFile(c.CloudFile)465vi ./juju/juju/cmd/juju/cloud/add.go466type CloudMetadataStore interface {467 ParseCloudMetadataFile(path string) (map[string]cloud.Cloud, error)468 ParseOneCloud(data []byte) (cloud.Cloud, error)469 PublicCloudMetadata(searchPaths ...string) (result map[string]cloud.Cloud, fallbackUsed bool, _ error)470 PersonalCloudMetadata() (map[string]cloud.Cloud, error)471 WritePersonalCloudMetadata(cloudsMap map[string]cloud.Cloud) error472}473vi ./juju/juju/cloud/personalclouds.go474import (475 "io/ioutil"476 "github.com/juju/juju/juju/osenv"477// ParseCloudMetadataFile loads any cloud metadata defined478// in the specified file.479func ParseCloudMetadataFile(file string) (map[string]Cloud, error) {480 data, err := ioutil.ReadFile(file)481 if err != nil {482 return nil, err483 }484 clouds, err := ParseCloudMetadata(data) <------485 if err != nil {486 return nil, err487 }488 return clouds, err489}490--------------------------------------------------------------491cat >> ~/maas.yaml << EOF492clouds:/493 maas:494 type: maas495 auth-types: [oauth1]496 endpoint: http://192.168.100.3/MAAS/497EOF498--------------------------------------------------------------499./cloud/clouds.go500 "gopkg.in/yaml.v2"501var defaultCloudDescription = map[string]string{502 "aws": "Amazon Web Services",503 "aws-china": "Amazon China",504 "aws-gov": "Amazon (USA Government)",505 "google": "Google Cloud Platform",506 "azure": "Microsoft Azure",507 "azure-china": "Microsoft Azure China",508 "rackspace": "Rackspace Cloud",509 "joyent": "Joyent Cloud",510 "cloudsigma": "CloudSigma Cloud",511 "lxd": "LXD Container Hypervisor",512 "maas": "Metal As A Service",513 "openstack": "Openstack Cloud",514 "oracle": "Oracle Compute Cloud Service",515}516// ParseCloudMetadata parses the given yaml bytes into Clouds metadata.517func ParseCloudMetadata(data []byte) (map[string]Cloud, error) {518 var metadata cloudSet519 if err := yaml.Unmarshal(data, &metadata); err != nil {520 return nil, errors.Annotate(err, "cannot unmarshal yaml cloud metadata")521 }522 // Translate to the exported type. For each cloud, we store523 // the first region for the cloud as its default region.524 clouds := make(map[string]Cloud)525 for name, cloud := range metadata.Clouds {526 details := cloudFromInternal(cloud)527 details.Name = name528 if details.Description == "" {529 var ok bool530 if details.Description, ok = defaultCloudDescription[name]; !ok {531 details.Description = defaultCloudDescription[cloud.Type]532 }533 }534 clouds[name] = details535 }536 return clouds, nil537}538func cloudFromInternal(in *cloud) Cloud {539 var regions []Region540 if len(in.Regions.Map) > 0 {541 for _, item := range in.Regions.Slice {542 name := fmt.Sprint(item.Key)543 r := in.Regions.Map[name]544 if r == nil {545 // r will be nil if none of the fields in546 // the YAML are set.547 regions = append(regions, Region{Name: name})548 } else {549 regions = append(regions, Region{550 name,551 r.Endpoint,552 r.IdentityEndpoint,553 r.StorageEndpoint,554 })555 }556 }557 }558 meta := Cloud{559 Name: in.Name,560 Type: in.Type,561 AuthTypes: in.AuthTypes,562 Endpoint: in.Endpoint,563 IdentityEndpoint: in.IdentityEndpoint,564 StorageEndpoint: in.StorageEndpoint,565 Regions: regions,566 Config: in.Config,567 RegionConfig: in.RegionConfig,568 Description: in.Description,569 }570 meta.denormaliseMetadata()571 return meta572}573meta574{575 "Name": "",576 "Type": "openstack",577 "Description": "",578 "AuthTypes": [579 "access-key",580 "userpass"581 ],582 "Endpoint": "",583 "IdentityEndpoint": "",584 "StorageEndpoint": "",585 "Regions": [586 {587 "Name": "reg1",588 "Endpoint": "https://openstack.example.com:35574/v3.0/",589 "IdentityEndpoint": "https://graph.windows.net",590 "StorageEndpoint": "https://core.windows.net"591 },592 {593 "Name": "reg2",594 "Endpoint": "https://openstack.example.com:35574/v3.0/",595 "IdentityEndpoint": "https://graph.windows.net",596 "StorageEndpoint": "https://core.windows.net"597 }598 ],599 "Config": null,600 "RegionConfig": null601}602import (603 "reflect"604 "strings"605)606func init() {607 RegisterStructTags(Cloud{}, Region{})608}609// RegisterStructTags ensures the yaml tags for the given structs are able to be used610// when parsing cloud metadata.611func RegisterStructTags(vals ...interface{}) {612 tags := mkTags(vals...)613 for k, v := range tags {614 tagsForType[k] = v615 }616}617func mkTags(vals ...interface{}) map[reflect.Type]map[string]int {618 typeMap := make(map[reflect.Type]map[string]int)619 for _, v := range vals {620 t := reflect.TypeOf(v)621 typeMap[t] = yamlTags(t)622 }623 return typeMap624}625// yamlTags returns a map from yaml tag to the field index for the string fields in the given type.626func yamlTags(t reflect.Type) map[string]int {627 if t.Kind() != reflect.Struct {628 panic(errors.Errorf("cannot get yaml tags on type %s", t))629 }630 tags := make(map[string]int)631 for i := 0; i < t.NumField(); i++ {632 f := t.Field(i)633 if f.Type != reflect.TypeOf("") {634 continue635 }636 if tag := f.Tag.Get("yaml"); tag != "" {637 if i := strings.Index(tag, ","); i >= 0 {638 tag = tag[0:i]639 }640 if tag == "-" {641 continue642 }643 if tag != "" {644 f.Name = tag645 }646 }647 tags[f.Name] = i648 }649 return tags650}651func (cloud Cloud) denormaliseMetadata() {652 for name, region := range cloud.Regions {653 r := region654 inherit(&r, &cloud)655 cloud.Regions[name] = r656 }657}658// inherit sets any blank fields in dst to their equivalent values in fields in src that have matching json tags.659// The dst parameter must be a pointer to a struct.660func inherit(dst, src interface{}) {661 for tag := range tags(dst) {662 setFieldByTag(dst, tag, fieldByTag(src, tag), false)663 }664}665type structTags map[reflect.Type]map[string]int666var tagsForType structTags = make(structTags)667// tags returns the field offsets for the JSON tags defined by the given value, which must be668// a struct or a pointer to a struct.669func tags(x interface{}) map[string]int {670 t := reflect.TypeOf(x)671 if t.Kind() == reflect.Ptr {672 t = t.Elem()673 }674 if t.Kind() != reflect.Struct {675 panic(errors.Errorf("expected struct, not %s", t))676 }677 if tagm := tagsForType[t]; tagm != nil {678 return tagm679 }680 panic(errors.Errorf("%s not found in type table", t))681}682// fieldByTag returns the value for the field in x with the given JSON tag, or "" if there is no such field.683func fieldByTag(x interface{}, tag string) string {684 tagm := tags(x)685 v := reflect.ValueOf(x)686 if v.Kind() == reflect.Ptr {687 v = v.Elem()688 }689 if i, ok := tagm[tag]; ok {690 return v.Field(i).Interface().(string)691 }692 return ""693}694// setFieldByTag sets the value for the field in x with the given JSON tag to val.695// The override parameter specifies whether the value will be set even if the original value is non-empty.696func setFieldByTag(x interface{}, tag, val string, override bool) {697 i, ok := tags(x)[tag]698 if !ok {699 return700 }701 v := reflect.ValueOf(x).Elem()702 f := v.Field(i)703 if override || f.Interface().(string) == "" {704 f.Set(reflect.ValueOf(val))705 }706}707// inherit sets any blank fields in dst to their equivalent values in fields in src that have matching json tags.708// The dst parameter must be a pointer to a struct.709func inherit(dst, src interface{}) {710 for tag := range tags(dst) {711 setFieldByTag(dst, tag, fieldByTag(src, tag), false)712 }713}714func (cloud Cloud) denormaliseMetadata() {715 for name, region := range cloud.Regions {716 r := region717 inherit(&r, &cloud)718 cloud.Regions[name] = r719 }720}721--------------------------------------------------------------722../../../gopkg.in/yaml.v2/yaml.go723func Unmarshal(in []byte, out interface{}) (err error) {724 return unmarshal(in, out, false)725}726--------------------------------------------------------------727./cloud/clouds.go728// cloudSet contains cloud definitions, used for marshalling and729// unmarshalling.730type cloudSet struct {731 // Clouds is a map of cloud definitions, keyed on cloud name.732 Clouds map[string]*cloud `yaml:"clouds"`733}734--------------------------------------------------------------735./cloud/clouds.go736// RegionConfig holds a map of regions and the attributes that serve as the737// region specific configuration options. This allows model inheritance to738// function, providing a place to store configuration for a specific region739// which is passed down to other models under the same controller.740type RegionConfig map[string]Attrs741// Attrs serves as a map to hold regions specific configuration attributes.742// This serves to reduce confusion over having a nested map, i.e.743// map[string]map[string]interface{}744type Attrs map[string]interface{}745// AuthType is the type of authentication used by the cloud.746type AuthType string747// AuthTypes is defined to allow sorting AuthType slices.748type AuthTypes []AuthType749--------------------------------------------------------------750./cloud/clouds.go751// cloud is equivalent to Cloud, for marshalling and unmarshalling.752type cloud struct {753 Name string `yaml:"name,omitempty"`754 Type string `yaml:"type"`755 Description string `yaml:"description,omitempty"`756 AuthTypes []AuthType `yaml:"auth-types,omitempty,flow"`757 Endpoint string `yaml:"endpoint,omitempty"`758 IdentityEndpoint string `yaml:"identity-endpoint,omitempty"`759 StorageEndpoint string `yaml:"storage-endpoint,omitempty"`760 Regions regions `yaml:"regions,omitempty"`761 Config map[string]interface{} `yaml:"config,omitempty"`762 RegionConfig RegionConfig `yaml:"region-config,omitempty"`763}764// regions is a collection of regions, either as a map and/or765// as a yaml.MapSlice.766//767// When marshalling, we populate the Slice field only. This is768// necessary for us to control the order of map items.769//770// When unmarshalling, we populate both Map and Slice. Map is771// populated to simplify conversion to Region objects. Slice772// is populated so we can identify the first map item, which773// becomes the default region for the cloud.774type regions struct {775 Map map[string]*region776 Slice yaml.MapSlice777}778// region is equivalent to Region, for marshalling and unmarshalling.779type region struct {780 Endpoint string `yaml:"endpoint,omitempty"`781 IdentityEndpoint string `yaml:"identity-endpoint,omitempty"`782 StorageEndpoint string `yaml:"storage-endpoint,omitempty"`783}784--------------------------------------------------------------785./cloud/clouds.go786// Cloud is a cloud definition.787type Cloud struct {788 // Name of the cloud.789 Name string790 // Type is the type of cloud, eg ec2, openstack etc.791 // This is one of the provider names registered with792 // environs.RegisterProvider.793 Type string794 // Description describes the type of cloud.795 Description string796 // AuthTypes are the authentication modes supported by the cloud.797 AuthTypes AuthTypes798 // Endpoint is the default endpoint for the cloud regions, may be799 // overridden by a region.800 Endpoint string801 // IdentityEndpoint is the default identity endpoint for the cloud802 // regions, may be overridden by a region.803 IdentityEndpoint string804 // StorageEndpoint is the default storage endpoint for the cloud805 // regions, may be overridden by a region.806 StorageEndpoint string807 // Regions are the regions available in the cloud.808 //809 // Regions is a slice, and not a map, because order is important.810 // The first region in the slice is the default region for the811 // cloud.812 Regions []Region813 // Config contains optional cloud-specific configuration to use814 // when bootstrapping Juju in this cloud. The cloud configuration815 // will be combined with Juju-generated, and user-supplied values;816 // user-supplied values taking precedence.817 Config map[string]interface{}818 // RegionConfig contains optional region specific configuration.819 // Like Config above, this will be combined with Juju-generated and user820 // supplied values; with user supplied values taking precedence.821 RegionConfig RegionConfig822}823--------------------------------------------------------------824./cloud/clouds.go825// Region is a cloud region.826type Region struct {827 // Name is the name of the region.828 Name string829 // Endpoint is the region's primary endpoint URL.830 Endpoint string831 // IdentityEndpoint is the region's identity endpoint URL.832 // If the cloud/region does not have an identity-specific833 // endpoint URL, this will be empty.834 IdentityEndpoint string835 // StorageEndpoint is the region's storage endpoint URL.836 // If the cloud/region does not have a storage-specific837 // endpoint URL, this will be empty.838 StorageEndpoint string839}840--------------------------------------------------------------841clouds:842 <cloud_name>:843 type: <type_of_cloud>844 auth-types: <[access-key, oauth, userpass]>845 regions:846 <region-name>:847 endpoint: <https://xxx.yyy.zzz:35574/v3.0/>848--------------------------------------------------------------849#####################################################################################################850__2__851juju/juju/cloud/clouds.go852// Cloud is a cloud definition.853type Cloud struct {854 // Name of the cloud.855 Name string856 // Type is the type of cloud, eg ec2, openstack etc.857 // This is one of the provider names registered with858 // environs.RegisterProvider.859 Type string860 // Description describes the type of cloud.861 Description string862 // AuthTypes are the authentication modes supported by the cloud.863 AuthTypes AuthTypes864 // Endpoint is the default endpoint for the cloud regions, may be865 // overridden by a region.866 Endpoint string867 // IdentityEndpoint is the default identity endpoint for the cloud868 // regions, may be overridden by a region.869 IdentityEndpoint string870 // StorageEndpoint is the default storage endpoint for the cloud871 // regions, may be overridden by a region.872 StorageEndpoint string873 // Regions are the regions available in the cloud.874 //875 // Regions is a slice, and not a map, because order is important.876 // The first region in the slice is the default region for the877 // cloud.878 Regions []Region879 // Config contains optional cloud-specific configuration to use880 // when bootstrapping Juju in this cloud. The cloud configuration881 // will be combined with Juju-generated, and user-supplied values;882 // user-supplied values taking precedence.883 Config map[string]interface{}884 // RegionConfig contains optional region specific configuration.885 // Like Config above, this will be combined with Juju-generated and user886 // supplied values; with user supplied values taking precedence.887 RegionConfig RegionConfig888}889juju/juju/cmd/juju/cloud/add.go890type CloudMetadataStore interface {891 ParseCloudMetadataFile(path string) (map[string]cloud.Cloud, error)892 ParseOneCloud(data []byte) (cloud.Cloud, error)893 PublicCloudMetadata(searchPaths ...string) (result map[string]cloud.Cloud, fallbackUsed bool, _ error)894 PersonalCloudMetadata() (map[string]cloud.Cloud, error)895 WritePersonalCloudMetadata(cloudsMap map[string]cloud.Cloud) error896}897// AddCloudCommand is the command that allows you to add a cloud configuration898// for use with juju bootstrap.899type AddCloudCommand struct {900 cmd.CommandBase901 // Replace, if true, existing cloud information is overwritten.902 Replace bool903 // Cloud is the name fo the cloud to add.904 Cloud string905 // CloudFile is the name of the cloud YAML file.906 CloudFile string907 // Ping contains the logic for pinging a cloud endpoint to know whether or908 // not it really has a valid cloud of the same type as the provider. By909 // default it just calls the correct provider's Ping method.910 Ping func(p environs.EnvironProvider, endpoint string) error911 cloudMetadataStore CloudMetadataStore912}913// Run executes the add cloud command, adding a cloud based on a passed-in yaml914// file or interactive queries.915func (c *AddCloudCommand) Run(ctxt *cmd.Context) error {916 if c.CloudFile == "" {917 return c.runInteractive(ctxt)918 }919 specifiedClouds, err := c.cloudMetadataStore.ParseCloudMetadataFile(c.CloudFile) <========== 1920 if err != nil {921 return err922 }923 if specifiedClouds == nil {924 return errors.New("no personal clouds are defined")925 }926 newCloud, ok := specifiedClouds[c.Cloud]927 if !ok {928 return errors.Errorf("cloud %q not found in file %q", c.Cloud, c.CloudFile)929 }...

Full Screen

Full Screen

add_test.go

Source:add_test.go Github

copy

Full Screen

...15}16var _ = gc.Suite(&addSuite{})17func (s *addSuite) SetUpTest(c *gc.C) {18 origHome := osenv.SetJujuXDGDataHome(c.MkDir())19 s.AddCleanup(func(*gc.C) { osenv.SetJujuXDGDataHome(origHome) })20}21func (s *addSuite) TestAddBadArgs(c *gc.C) {22 addCmd := cloud.NewAddCloudCommand()23 _, err := testing.RunCommand(c, addCmd)24 c.Assert(err, gc.ErrorMatches, "Usage: juju add-cloud <cloud-name> <cloud.yaml>")25 _, err = testing.RunCommand(c, addCmd, "cloud", "cloud.yaml", "extra")26 c.Assert(err, gc.ErrorMatches, `unrecognized args: \["extra"\]`)27}28func (s *addSuite) createTestCloudData(c *gc.C) string {29 current := `30clouds:31 homestack:32 type: openstack33 auth-types: [userpass, access-key]34 endpoint: http://homestack35 regions:36 london:37 endpoint: http://london/1.038`[1:]39 err := ioutil.WriteFile(osenv.JujuXDGDataHomePath("clouds.yaml"), []byte(current), 0600)40 c.Assert(err, jc.ErrorIsNil)41 sourceDir := c.MkDir()42 sourceFile := filepath.Join(sourceDir, "someclouds.yaml")43 source := `44clouds:45 homestack:46 type: openstack47 auth-types: [userpass, access-key]48 endpoint: http://homestack49 regions:50 london:51 endpoint: http://london/1.052 new-york:53 endpoint: http://newyork/1.054 garage-maas:55 type: mass56 auth-types: [oauth]57 endpoint: http://garagemaas58`[1:]59 err = ioutil.WriteFile(sourceFile, []byte(source), 0600)60 c.Assert(err, jc.ErrorIsNil)61 return sourceFile62}63func (s *addSuite) TestAddBadFilename(c *gc.C) {64 addCmd := cloud.NewAddCloudCommand()65 _, err := testing.RunCommand(c, addCmd, "cloud", "somefile.yaml")66 c.Assert(err, gc.ErrorMatches, "open somefile.yaml: .*")67}68func (s *addSuite) TestAddBadCloudName(c *gc.C) {69 sourceFile := s.createTestCloudData(c)70 addCmd := cloud.NewAddCloudCommand()71 _, err := testing.RunCommand(c, addCmd, "cloud", sourceFile)72 c.Assert(err, gc.ErrorMatches, `cloud "cloud" not found in file .*`)73}74func (s *addSuite) TestAddExisting(c *gc.C) {75 sourceFile := s.createTestCloudData(c)76 _, err := testing.RunCommand(c, cloud.NewAddCloudCommand(), "homestack", sourceFile)77 c.Assert(err, gc.ErrorMatches, `cloud called \"homestack\" already exists; use --replace to replace this existing cloud`)78}79func (s *addSuite) TestAddExistingReplace(c *gc.C) {80 sourceFile := s.createTestCloudData(c)81 _, err := testing.RunCommand(c, cloud.NewAddCloudCommand(), "homestack", sourceFile, "--replace")82 c.Assert(err, jc.ErrorIsNil)83 data, err := ioutil.ReadFile(osenv.JujuXDGDataHomePath("clouds.yaml"))84 c.Assert(string(data), gc.Equals, `85clouds:86 homestack:87 type: openstack88 auth-types: [userpass, access-key]89 endpoint: http://homestack90 regions:91 london:92 endpoint: http://london/1.093 new-york:94 endpoint: http://newyork/1.095`[1:])96}97func (s *addSuite) TestAddNew(c *gc.C) {98 sourceFile := s.createTestCloudData(c)99 _, err := testing.RunCommand(c, cloud.NewAddCloudCommand(), "garage-maas", sourceFile)100 c.Assert(err, jc.ErrorIsNil)101 data, err := ioutil.ReadFile(osenv.JujuXDGDataHomePath("clouds.yaml"))102 c.Assert(string(data), gc.Equals, `103clouds:104 garage-maas:105 type: mass106 auth-types: [oauth]107 endpoint: http://garagemaas108 homestack:109 type: openstack110 auth-types: [userpass, access-key]111 endpoint: http://homestack112 regions:113 london:...

Full Screen

Full Screen

add.go

Source:add.go Github

copy

Full Screen

...34Example:35 juju add-cloud homestack personal-clouds.yaml36 juju add-cloud homestack personal-clouds.yaml --replace37`38// NewAddCloudCommand returns a command to add cloud information.39func NewAddCloudCommand() cmd.Command {40 return &addCloudCommand{}41}42func (c *addCloudCommand) Info() *cmd.Info {43 return &cmd.Info{44 Name: "add-cloud",45 Purpose: "adds a named cloud definition to the list of those which can run Juju workloads",46 Doc: addCloudDoc,47 }48}49func (c *addCloudCommand) SetFlags(f *gnuflag.FlagSet) {50 f.BoolVar(&c.Replace, "replace", false, "overwrite any existing cloud information")51}52func (c *addCloudCommand) Init(args []string) (err error) {53 if len(args) < 2 {...

Full Screen

Full Screen

Add

Using AI Code Generation

copy

Full Screen

1func main() {2 cloud := Cloud{}3 cloud.Add(2, 3)4}5func main() {6 cloud := Cloud{}7 cloud.Add(2, 3)8}9func main() {10 cloud := Cloud{}11 cloud.Add(2, 3)12}13func main() {14 cloud := Cloud{}15 cloud.Add(2, 3)16}17import (18func main() {19 cloud := cloud.Cloud{}20 cloud.Add(2, 3)21 fmt.Println(cloud.Sum)22}23type Cloud struct {24}25func (c *Cloud) Add(a, b int) {26}27import (28func main() {29 cloud := cloud.Cloud{}30 cloud.Add(2, 3)31 fmt.Println(cloud.Sum)

Full Screen

Full Screen

Add

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main(){3 c = Add(a, b)4 fmt.Printf("The sum of a and b is %d5}6import "fmt"7func main(){8 c = Add(a, b)9 fmt.Printf("The sum of a and b is %d10}11import "fmt"12func main(){13 c = Add(a, b)14 fmt.Printf("The sum of a and b is %d15}16import "fmt"17func main(){18 c = Add(a, b)19 fmt.Printf("The sum of a and b is %d20}21import "fmt"22func main(){23 c = Add(a, b)24 fmt.Printf("The sum of a and b is %d25}26import "fmt"27func main(){28 c = Add(a, b)29 fmt.Printf("The sum of a and b is %d30}31import "fmt"32func main(){33 c = Add(a, b)34 fmt.Printf("The sum of a and b is %d

Full Screen

Full Screen

Add

Using AI Code Generation

copy

Full Screen

1import "fmt"2type cloud struct {3}4func (c *cloud) Add() {5 fmt.Println("Add method of cloud")6}7func main() {8 c := &cloud{name: "AWS"}9 c.Add()10}

Full Screen

Full Screen

Add

Using AI Code Generation

copy

Full Screen

1import (2type Cloud struct {3}4func (c Cloud) Add(a, b int) int {5}6func main() {7 fmt.Println(c.Add(1, 2))8}9import (10type Cloud struct {11}12func (c *Cloud) Add(a, b int) int {13}14func main() {15 fmt.Println(c.Add(1, 2))16}

Full Screen

Full Screen

Add

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(stringutil.Reverse("!oG ,olleH"))4 fmt.Println(stringutil.MyName)5}6import (7func main() {8 fmt.Println(icomefromalaska.Add(2, 3))9}10import (11func main() {12 fmt.Println(icomefromalaska.Add(2, 3))13}14import (15func main() {16 fmt.Println(icomefromalaska.Add(2, 3))17}18import (19func main() {20 fmt.Println(icomefromalaska.Add(2, 3))21}22import (23func main() {24 fmt.Println(icomefromalaska.Add(2, 3))25}26import (27func main() {28 fmt.Println(icomefromalaska.Add(2, 3))29}30import (31func main() {32 fmt.Println(icomefromalaska.Add(2, 3))33}34import (

Full Screen

Full Screen

Add

Using AI Code Generation

copy

Full Screen

1func main() {2 obj := cloud{}3 obj.Add(10, 20)4}5func main() {6 obj := cloud2{}7 obj.Add(10, 20)8}9type cloudinterface interface {10 Add(int, int)11}12type cloud struct {13}14func (obj cloud) Add(a int, b int) {15 fmt.Println(a + b)16}17type cloud2 struct {18}19func (obj cloud2) Add(a int, b int) {20 fmt.Println(a + b)21}22func main() {23 obj := cloud{}24 obj.Add(10, 20)25 obj2 := cloud2{}26 obj2.Add(10, 20)27}

Full Screen

Full Screen

Add

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 cloud := Cloud{4 }5 fmt.Println("Cloud radius is:", cloud.Radius)6 fmt.Println("Cloud perimeter is:", cloud.Perimeter())7 fmt.Println("Cloud area is:", cloud.Area())8}9import (10type Cloud struct {11}12func (c Cloud) Perimeter() float64 {13}14func (c Cloud) Area() float64 {15}16import (17func main() {18 cloud := Cloud{19 }20 fmt.Println("Cloud radius is:", cloud.Radius)21 fmt.Println("Cloud perimeter is:", cloud.Perimeter())22 fmt.Println("Cloud area is:", cloud.Area())23}24import (25type Cloud struct {26}27func (c Cloud) Perimeter() float64 {28}29func (c Cloud) Area() float64 {30}31import (32func main() {33 cloud := Cloud{34 }35 fmt.Println("Cloud radius is:", cloud.Radius)36 fmt.Println("Cloud perimeter is:", cloud.Perimeter())37 fmt.Println("Cloud area is:", cloud.Area())38}

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.

Run K6 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful