Skip to content

Commit 8cb8b80

Browse files
committed
Merge branch 'support-projects' of https://github.com/shapeblue/cloudstack-csi-driver into add-volume-snapshot-support
2 parents 14a77fd + 5126c4a commit 8cb8b80

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
@@ -75,11 +75,12 @@ var (
7575
// client is the implementation of Interface.
7676
type client struct {
7777
*cloudstack.CloudStackClient
78+
projectID string
7879
}
7980

8081
// New creates a new cloud connector, given its configuration.
8182
func New(config *Config) Interface {
8283
csClient := cloudstack.NewAsyncClient(config.APIURL, config.APIKey, config.SecretKey, config.VerifySSL)
8384

84-
return &client{csClient}
85+
return &client{csClient, config.ProjectID}
8586
}

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
@@ -43,8 +43,12 @@ func (c *client) GetVolumeByID(ctx context.Context, volumeID string) (*Volume, e
4343
logger := klog.FromContext(ctx)
4444
p := c.Volume.NewListVolumesParams()
4545
p.SetId(volumeID)
46+
if c.projectID != "" {
47+
p.SetProjectid(c.projectID)
48+
}
4649
logger.V(2).Info("CloudStack API call", "command", "ListVolumes", "params", map[string]string{
47-
"id": volumeID,
50+
"id": volumeID,
51+
"projectid": c.projectID,
4852
})
4953

5054
return c.listVolumes(p)
@@ -68,11 +72,15 @@ func (c *client) CreateVolume(ctx context.Context, diskOfferingID, zoneID, name
6872
p.SetZoneid(zoneID)
6973
p.SetName(name)
7074
p.SetSize(sizeInGB)
75+
if c.projectID != "" {
76+
p.SetProjectid(c.projectID)
77+
}
7178
logger.V(2).Info("CloudStack API call", "command", "CreateVolume", "params", map[string]string{
7279
"diskofferingid": diskOfferingID,
7380
"zoneid": zoneID,
7481
"name": name,
7582
"size": strconv.FormatInt(sizeInGB, 10),
83+
"projectid": c.projectID,
7684
})
7785
vol, err := c.Volume.CreateVolume(p)
7886
if err != nil {

0 commit comments

Comments
 (0)