Skip to content

Commit

Permalink
caa: Move cloudTable into parent package
Browse files Browse the repository at this point in the history
Add AddCloud public function instead of directly updating
cloudTable and add init function for each provider

Signed-off-by: James Tumber <james.tumber@ibm.com>
  • Loading branch information
tumberino authored and bpradipt committed Dec 3, 2023
1 parent 5a77d63 commit 4ba026a
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/adaptor/cloud/aws/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ var awscfg Config

type Manager struct{}

func init() {
cloud.AddCloud("aws", &Manager{})
}

func (_ *Manager) ParseCmd(flags *flag.FlagSet) {

flags.StringVar(&awscfg.AccessKeyId, "aws-access-key-id", "", "Access Key ID, defaults to `AWS_ACCESS_KEY_ID`")
Expand Down
4 changes: 4 additions & 0 deletions pkg/adaptor/cloud/azure/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ var azurecfg Config

type Manager struct{}

func init() {
cloud.AddCloud("azure", &Manager{})
}

func (_ *Manager) ParseCmd(flags *flag.FlagSet) {
flags.StringVar(&azurecfg.ClientId, "clientid", "", "Client Id, defaults to `AZURE_CLIENT_ID`")
flags.StringVar(&azurecfg.ClientSecret, "secret", "", "Client Secret, defaults to `AZURE_CLIENT_SECRET`")
Expand Down
28 changes: 28 additions & 0 deletions pkg/adaptor/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"encoding/json"
"errors"
"flag"
"fmt"
"log"
"net"
Expand All @@ -32,6 +33,33 @@ const (

var logger = log.New(log.Writer(), "[adaptor/cloud] ", log.LstdFlags|log.Lmsgprefix)

type Cloud interface {
ParseCmd(flags *flag.FlagSet)
LoadEnv()
NewProvider() (Provider, error)
}

var cloudTable map[string]Cloud = make(map[string]Cloud)

func Get(name string) Cloud {
return cloudTable[name]
}

func AddCloud(name string, cloud Cloud) {
cloudTable[name] = cloud
}

func List() []string {

var list []string

for name := range cloudTable {
list = append(list, name)
}

return list
}

func (s *cloudService) addSandbox(sid sandboxID, sandbox *sandbox) error {

s.mutex.Lock()
Expand Down
4 changes: 4 additions & 0 deletions pkg/adaptor/cloud/ibmcloud-powervs/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ var ibmcloudPowerVSConfig Config

type Manager struct{}

func init() {
cloud.AddCloud("ibmcloud-powervs", &Manager{})
}

func (_ *Manager) ParseCmd(flags *flag.FlagSet) {

flags.StringVar(&ibmcloudPowerVSConfig.ApiKey, "api-key", "", "IBM Cloud API key, defaults to `IBMCLOUD_API_KEY`")
Expand Down
4 changes: 4 additions & 0 deletions pkg/adaptor/cloud/ibmcloud/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ var ibmcloudVPCConfig Config

type Manager struct{}

func init() {
cloud.AddCloud("ibmcloud", &Manager{})
}

func (*Manager) ParseCmd(flags *flag.FlagSet) {

flags.StringVar(&ibmcloudVPCConfig.ApiKey, "api-key", "", "IBM Cloud API key, defaults to `IBMCLOUD_API_KEY`")
Expand Down
4 changes: 4 additions & 0 deletions pkg/adaptor/cloud/libvirt/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const (
defaultFirmware = "/usr/share/edk2/ovmf/OVMF_CODE.fd"
)

func init() {
cloud.AddCloud("libvirt", &Manager{})
}

func (*Manager) ParseCmd(flags *flag.FlagSet) {

flags.StringVar(&libvirtcfg.URI, "uri", defaultURI, "libvirt URI")
Expand Down
4 changes: 4 additions & 0 deletions pkg/adaptor/cloud/vsphere/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ var vspherecfg Config

type Manager struct{}

func init() {
cloud.AddCloud("vsphere", &Manager{})
}

func (_ *Manager) ParseCmd(flags *flag.FlagSet) {

flags.StringVar(&vspherecfg.VcenterURL, "vcenter-url", "", "URL of vCenter instance to connect to")
Expand Down

0 comments on commit 4ba026a

Please sign in to comment.