Skip to content

Commit

Permalink
TASK SIO-5985 Add fields to create virtual server request.
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Neumyvakin committed Apr 23, 2024
1 parent 10243ac commit 62dca94
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
6 changes: 5 additions & 1 deletion additionalDisks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type AdditionalDiskCreateRequest struct {
OfferID int `json:"offer_id"`
}

type AdditionalDisk struct {
type Disk struct {
ID int `json:"id"`
IsPrimary bool `json:"is_primary"`
Name string `json:"name"`
Expand All @@ -17,3 +17,7 @@ type AdditionalDisk struct {
Storage Storage `json:"storage"`
Offer Offer `json:"offer,omitempty"`
}

type disksResponse struct {
Data []Disk `json:"data"`
}
19 changes: 14 additions & 5 deletions virtual_servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,19 @@ type VirtualServerCreateRequest struct {
FQDNs []string `json:"fqdns,omitempty"`
Password string `json:"password,omitempty"`
SSHKeys []int `json:"ssh_keys"`
PlanID int `json:"plan"`
PlanID int `json:"plan,omitempty"`
CustomPlan *Plan `json:"custom_plan,omitempty"`
ProjectID int `json:"project"`
LocationID int `json:"location"`
ComputeResourceID int `json:"compute_resource,omitempty"`
OSImageVersionID int `json:"os,omitempty"`
ApplicationID int `json:"application,omitempty"`
ApplicationData map[string]interface{} `json:"applicationData,omitempty"`
AdditionalDisks []AdditionalDiskCreateRequest `json:"additional_disks,omitempty"`
AdditionalIPCount int `json:"additional_ip_count,omitempty"`
AdditionalIPv6Count int `json:"additional_ipv6_count,omitempty"`
PrimaryIP *string `json:"primary_ip,omitempty"`
IPTypes []IPVersion `json:"ip_types,omitempty"`
AdditionalIPCount *int `json:"additional_ip_count,omitempty"`
AdditionalIPv6Count *int `json:"additional_ipv6_count,omitempty"`
}

// VirtualServerUpdateRequest represents available properties for updating an existing
Expand Down Expand Up @@ -237,14 +240,14 @@ func (s *VirtualServersService) Backup(ctx context.Context, id int) (Backup, err
return resp.Data, unmarshal(body, &resp)
}

type ViretualServerResizeRequest struct {
type VirtualServerResizeRequest struct {
PreserveDisk bool `json:"preserve_disk"`
PlanID int `json:"plan_id"`
BackupSettings *VirtualServerBackupSettings `json:"backup_settings,omitempty"`
}

// Resize resizes specified virtual server.
func (s *VirtualServersService) Resize(ctx context.Context, id int, data ViretualServerResizeRequest) (Task, error) {
func (s *VirtualServersService) Resize(ctx context.Context, id int, data VirtualServerResizeRequest) (Task, error) {
return s.client.asyncPost(ctx, fmt.Sprintf("servers/%d/resize", id), withBody(data))
}

Expand All @@ -258,3 +261,9 @@ func (s *VirtualServersService) SnapshotsCreate(ctx context.Context, vmID int, d
var resp snapshotResponse
return resp.Data, s.client.create(ctx, fmt.Sprintf("servers/%d/snapshots", vmID), data, &resp)
}

// Disks gets a list of disks for the specified virtual server.
func (s *VirtualServersService) Disks(ctx context.Context, id int) ([]Disk, error) {
var resp disksResponse
return resp.Data, s.client.get(ctx, fmt.Sprintf("servers/%d/disks", id), &resp)
}
2 changes: 1 addition & 1 deletion virtual_servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func TestVirtualServersService_Backup(t *testing.T) {
}

func TestVirtualServersService_resize(t *testing.T) {
data := ViretualServerResizeRequest{
data := VirtualServerResizeRequest{
PreserveDisk: true,
PlanID: 42,
BackupSettings: &VirtualServerBackupSettings{
Expand Down

0 comments on commit 62dca94

Please sign in to comment.