Skip to content

Commit 5126c4a

Browse files
committed
Add support for Projects
1 parent fad82ed commit 5126c4a

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

pkg/cloud/cloud.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ var (
5555
// client is the implementation of Interface.
5656
type client struct {
5757
*cloudstack.CloudStackClient
58+
projectID string
5859
}
5960

6061
// New creates a new cloud connector, given its configuration.
6162
func New(config *Config) Interface {
6263
csClient := cloudstack.NewAsyncClient(config.APIURL, config.APIKey, config.SecretKey, config.VerifySSL)
6364

64-
return &client{csClient}
65+
return &client{csClient, config.ProjectID}
6566
}

pkg/cloud/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Config struct {
1212
APIKey string
1313
SecretKey string
1414
VerifySSL bool
15+
ProjectID string
1516
}
1617

1718
// csConfig wraps the config for the CloudStack cloud provider.
@@ -40,6 +41,7 @@ func ReadConfig(configFilePath string) (*Config, error) {
4041
return &Config{
4142
APIURL: cfg.Global.APIURL,
4243
APIKey: cfg.Global.APIKey,
44+
ProjectID: cfg.Global.ProjectID,
4345
SecretKey: cfg.Global.SecretKey,
4446
VerifySSL: !cfg.Global.SSLNoVerify,
4547
}, nil

pkg/cloud/vms.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ func (c *client) GetVMByID(ctx context.Context, vmID string) (*VM, error) {
1010
logger := klog.FromContext(ctx)
1111
p := c.VirtualMachine.NewListVirtualMachinesParams()
1212
p.SetId(vmID)
13+
if c.projectID != "" {
14+
p.SetProjectid(c.projectID)
15+
}
1316
logger.V(2).Info("CloudStack API call", "command", "ListVirtualMachines", "params", map[string]string{
14-
"id": vmID,
17+
"id": vmID,
18+
"projectID": c.projectID,
1519
})
1620
l, err := c.VirtualMachine.ListVirtualMachines(p)
1721
if err != nil {
@@ -24,7 +28,7 @@ func (c *client) GetVMByID(ctx context.Context, vmID string) (*VM, error) {
2428
return nil, ErrTooManyResults
2529
}
2630
vm := l.VirtualMachines[0]
27-
31+
logger.V(2).Info("Returning VM", "vmID", vm.Id, "zoneID", vm.Zoneid)
2832
return &VM{
2933
ID: vm.Id,
3034
ZoneID: vm.Zoneid,

pkg/cloud/volumes.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ func (c *client) GetVolumeByID(ctx context.Context, volumeID string) (*Volume, e
4141
logger := klog.FromContext(ctx)
4242
p := c.Volume.NewListVolumesParams()
4343
p.SetId(volumeID)
44+
if c.projectID != "" {
45+
p.SetProjectid(c.projectID)
46+
}
4447
logger.V(2).Info("CloudStack API call", "command", "ListVolumes", "params", map[string]string{
45-
"id": volumeID,
48+
"id": volumeID,
49+
"projectid": c.projectID,
4650
})
4751

4852
return c.listVolumes(p)
@@ -66,11 +70,15 @@ func (c *client) CreateVolume(ctx context.Context, diskOfferingID, zoneID, name
6670
p.SetZoneid(zoneID)
6771
p.SetName(name)
6872
p.SetSize(sizeInGB)
73+
if c.projectID != "" {
74+
p.SetProjectid(c.projectID)
75+
}
6976
logger.V(2).Info("CloudStack API call", "command", "CreateVolume", "params", map[string]string{
7077
"diskofferingid": diskOfferingID,
7178
"zoneid": zoneID,
7279
"name": name,
7380
"size": strconv.FormatInt(sizeInGB, 10),
81+
"projectid": c.projectID,
7482
})
7583
vol, err := c.Volume.CreateVolume(p)
7684
if err != nil {

0 commit comments

Comments
 (0)