Skip to content

Add support for Projects #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: increase-pod-affinity-leniency
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ var (
// client is the implementation of Interface.
type client struct {
*cloudstack.CloudStackClient
projectID string
}

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

return &client{csClient}
return &client{csClient, config.ProjectID}
}
2 changes: 2 additions & 0 deletions pkg/cloud/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Config struct {
APIKey string
SecretKey string
VerifySSL bool
ProjectID string
}

// csConfig wraps the config for the CloudStack cloud provider.
Expand Down Expand Up @@ -40,6 +41,7 @@ func ReadConfig(configFilePath string) (*Config, error) {
return &Config{
APIURL: cfg.Global.APIURL,
APIKey: cfg.Global.APIKey,
ProjectID: cfg.Global.ProjectID,
SecretKey: cfg.Global.SecretKey,
VerifySSL: !cfg.Global.SSLNoVerify,
}, nil
Expand Down
8 changes: 6 additions & 2 deletions pkg/cloud/vms.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ func (c *client) GetVMByID(ctx context.Context, vmID string) (*VM, error) {
logger := klog.FromContext(ctx)
p := c.VirtualMachine.NewListVirtualMachinesParams()
p.SetId(vmID)
if c.projectID != "" {
p.SetProjectid(c.projectID)
}
logger.V(2).Info("CloudStack API call", "command", "ListVirtualMachines", "params", map[string]string{
"id": vmID,
"id": vmID,
"projectID": c.projectID,
})
l, err := c.VirtualMachine.ListVirtualMachines(p)
if err != nil {
Expand All @@ -24,7 +28,7 @@ func (c *client) GetVMByID(ctx context.Context, vmID string) (*VM, error) {
return nil, ErrTooManyResults
}
vm := l.VirtualMachines[0]

logger.V(2).Info("Returning VM", "vmID", vm.Id, "zoneID", vm.Zoneid)
return &VM{
ID: vm.Id,
ZoneID: vm.Zoneid,
Expand Down
10 changes: 9 additions & 1 deletion pkg/cloud/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ func (c *client) GetVolumeByID(ctx context.Context, volumeID string) (*Volume, e
logger := klog.FromContext(ctx)
p := c.Volume.NewListVolumesParams()
p.SetId(volumeID)
if c.projectID != "" {
p.SetProjectid(c.projectID)
}
logger.V(2).Info("CloudStack API call", "command", "ListVolumes", "params", map[string]string{
"id": volumeID,
"id": volumeID,
"projectid": c.projectID,
})

return c.listVolumes(p)
Expand All @@ -66,11 +70,15 @@ func (c *client) CreateVolume(ctx context.Context, diskOfferingID, zoneID, name
p.SetZoneid(zoneID)
p.SetName(name)
p.SetSize(sizeInGB)
if c.projectID != "" {
p.SetProjectid(c.projectID)
}
logger.V(2).Info("CloudStack API call", "command", "CreateVolume", "params", map[string]string{
"diskofferingid": diskOfferingID,
"zoneid": zoneID,
"name": name,
"size": strconv.FormatInt(sizeInGB, 10),
"projectid": c.projectID,
})
vol, err := c.Volume.CreateVolume(p)
if err != nil {
Expand Down
Loading