Skip to content

Commit e07d09b

Browse files
committed
add additional apis to the vm service
1 parent 5365469 commit e07d09b

4 files changed

Lines changed: 302 additions & 0 deletions

File tree

cloudstack/VirtualMachineService.go

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ type VirtualMachineServiceIface interface {
104104
GetVMScheduleByID(id string, virtualmachineid string, opts ...OptionFunc) (*VMSchedule, int, error)
105105
DeleteVMSchedule(p *DeleteVMScheduleParams) (*DeleteVMScheduleResponse, error)
106106
NewDeleteVMScheduleParams(virtualmachineid string) *DeleteVMScheduleParams
107+
AssignVirtualMachineToBackupOffering(p *AssignVirtualMachineToBackupOfferingParams) (*AssignVirtualMachineToBackupOfferingResponse, error)
108+
NewAssignVirtualMachineToBackupOfferingParams(backupofferingid string, virtualmachineid string) *AssignVirtualMachineToBackupOfferingParams
109+
RemoveVirtualMachineFromBackupOffering(p *RemoveVirtualMachineFromBackupOfferingParams) (*RemoveVirtualMachineFromBackupOfferingResponse, error)
110+
NewRemoveVirtualMachineFromBackupOfferingParams(virtualmachineid string) *RemoveVirtualMachineFromBackupOfferingParams
107111
}
108112

109113
type AddNicToVirtualMachineParams struct {
@@ -14365,3 +14369,217 @@ func (r *DeleteVMScheduleResponse) UnmarshalJSON(b []byte) error {
1436514369
type alias DeleteVMScheduleResponse
1436614370
return json.Unmarshal(b, (*alias)(r))
1436714371
}
14372+
14373+
type AssignVirtualMachineToBackupOfferingParams struct {
14374+
p map[string]interface{}
14375+
}
14376+
14377+
func (p *AssignVirtualMachineToBackupOfferingParams) toURLValues() url.Values {
14378+
u := url.Values{}
14379+
if p.p == nil {
14380+
return u
14381+
}
14382+
if v, found := p.p["backupofferingid"]; found {
14383+
u.Set("backupofferingid", v.(string))
14384+
}
14385+
if v, found := p.p["virtualmachineid"]; found {
14386+
u.Set("virtualmachineid", v.(string))
14387+
}
14388+
return u
14389+
}
14390+
14391+
func (p *AssignVirtualMachineToBackupOfferingParams) SetBackupofferingid(v string) {
14392+
if p.p == nil {
14393+
p.p = make(map[string]interface{})
14394+
}
14395+
p.p["backupofferingid"] = v
14396+
}
14397+
14398+
func (p *AssignVirtualMachineToBackupOfferingParams) ResetBackupofferingid() {
14399+
if p.p != nil && p.p["backupofferingid"] != nil {
14400+
delete(p.p, "backupofferingid")
14401+
}
14402+
}
14403+
14404+
func (p *AssignVirtualMachineToBackupOfferingParams) GetBackupofferingid() (string, bool) {
14405+
if p.p == nil {
14406+
p.p = make(map[string]interface{})
14407+
}
14408+
value, ok := p.p["backupofferingid"].(string)
14409+
return value, ok
14410+
}
14411+
14412+
func (p *AssignVirtualMachineToBackupOfferingParams) SetVirtualmachineid(v string) {
14413+
if p.p == nil {
14414+
p.p = make(map[string]interface{})
14415+
}
14416+
p.p["virtualmachineid"] = v
14417+
}
14418+
14419+
func (p *AssignVirtualMachineToBackupOfferingParams) ResetVirtualmachineid() {
14420+
if p.p != nil && p.p["virtualmachineid"] != nil {
14421+
delete(p.p, "virtualmachineid")
14422+
}
14423+
}
14424+
14425+
func (p *AssignVirtualMachineToBackupOfferingParams) GetVirtualmachineid() (string, bool) {
14426+
if p.p == nil {
14427+
p.p = make(map[string]interface{})
14428+
}
14429+
value, ok := p.p["virtualmachineid"].(string)
14430+
return value, ok
14431+
}
14432+
14433+
// You should always use this function to get a new AssignVirtualMachineToBackupOfferingParams instance,
14434+
// as then you are sure you have configured all required params
14435+
func (s *VirtualMachineService) NewAssignVirtualMachineToBackupOfferingParams(backupofferingid string, virtualmachineid string) *AssignVirtualMachineToBackupOfferingParams {
14436+
p := &AssignVirtualMachineToBackupOfferingParams{}
14437+
p.p = make(map[string]interface{})
14438+
p.p["backupofferingid"] = backupofferingid
14439+
p.p["virtualmachineid"] = virtualmachineid
14440+
return p
14441+
}
14442+
14443+
// Assigns a VM to a backup offering
14444+
func (s *VirtualMachineService) AssignVirtualMachineToBackupOffering(p *AssignVirtualMachineToBackupOfferingParams) (*AssignVirtualMachineToBackupOfferingResponse, error) {
14445+
resp, err := s.cs.newPostRequest("assignVirtualMachineToBackupOffering", p.toURLValues())
14446+
if err != nil {
14447+
return nil, err
14448+
}
14449+
14450+
var r AssignVirtualMachineToBackupOfferingResponse
14451+
if err := json.Unmarshal(resp, &r); err != nil {
14452+
return nil, err
14453+
}
14454+
14455+
// If we have a async client, we need to wait for the async result
14456+
if s.cs.async {
14457+
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
14458+
if err != nil {
14459+
if err == AsyncTimeoutErr {
14460+
return &r, err
14461+
}
14462+
return nil, err
14463+
}
14464+
14465+
if err := json.Unmarshal(b, &r); err != nil {
14466+
return nil, err
14467+
}
14468+
}
14469+
14470+
return &r, nil
14471+
}
14472+
14473+
type AssignVirtualMachineToBackupOfferingResponse struct {
14474+
Displaytext string `json:"displaytext"`
14475+
JobID string `json:"jobid"`
14476+
Jobstatus int `json:"jobstatus"`
14477+
Success bool `json:"success"`
14478+
}
14479+
14480+
type RemoveVirtualMachineFromBackupOfferingParams struct {
14481+
p map[string]interface{}
14482+
}
14483+
14484+
func (p *RemoveVirtualMachineFromBackupOfferingParams) toURLValues() url.Values {
14485+
u := url.Values{}
14486+
if p.p == nil {
14487+
return u
14488+
}
14489+
if v, found := p.p["forced"]; found {
14490+
vv := strconv.FormatBool(v.(bool))
14491+
u.Set("forced", vv)
14492+
}
14493+
if v, found := p.p["virtualmachineid"]; found {
14494+
u.Set("virtualmachineid", v.(string))
14495+
}
14496+
return u
14497+
}
14498+
14499+
func (p *RemoveVirtualMachineFromBackupOfferingParams) SetForced(v bool) {
14500+
if p.p == nil {
14501+
p.p = make(map[string]interface{})
14502+
}
14503+
p.p["forced"] = v
14504+
}
14505+
14506+
func (p *RemoveVirtualMachineFromBackupOfferingParams) ResetForced() {
14507+
if p.p != nil && p.p["forced"] != nil {
14508+
delete(p.p, "forced")
14509+
}
14510+
}
14511+
14512+
func (p *RemoveVirtualMachineFromBackupOfferingParams) GetForced() (bool, bool) {
14513+
if p.p == nil {
14514+
p.p = make(map[string]interface{})
14515+
}
14516+
value, ok := p.p["forced"].(bool)
14517+
return value, ok
14518+
}
14519+
14520+
func (p *RemoveVirtualMachineFromBackupOfferingParams) SetVirtualmachineid(v string) {
14521+
if p.p == nil {
14522+
p.p = make(map[string]interface{})
14523+
}
14524+
p.p["virtualmachineid"] = v
14525+
}
14526+
14527+
func (p *RemoveVirtualMachineFromBackupOfferingParams) ResetVirtualmachineid() {
14528+
if p.p != nil && p.p["virtualmachineid"] != nil {
14529+
delete(p.p, "virtualmachineid")
14530+
}
14531+
}
14532+
14533+
func (p *RemoveVirtualMachineFromBackupOfferingParams) GetVirtualmachineid() (string, bool) {
14534+
if p.p == nil {
14535+
p.p = make(map[string]interface{})
14536+
}
14537+
value, ok := p.p["virtualmachineid"].(string)
14538+
return value, ok
14539+
}
14540+
14541+
// You should always use this function to get a new RemoveVirtualMachineFromBackupOfferingParams instance,
14542+
// as then you are sure you have configured all required params
14543+
func (s *VirtualMachineService) NewRemoveVirtualMachineFromBackupOfferingParams(virtualmachineid string) *RemoveVirtualMachineFromBackupOfferingParams {
14544+
p := &RemoveVirtualMachineFromBackupOfferingParams{}
14545+
p.p = make(map[string]interface{})
14546+
p.p["virtualmachineid"] = virtualmachineid
14547+
return p
14548+
}
14549+
14550+
// Removes a VM from any existing backup offering
14551+
func (s *VirtualMachineService) RemoveVirtualMachineFromBackupOffering(p *RemoveVirtualMachineFromBackupOfferingParams) (*RemoveVirtualMachineFromBackupOfferingResponse, error) {
14552+
resp, err := s.cs.newPostRequest("removeVirtualMachineFromBackupOffering", p.toURLValues())
14553+
if err != nil {
14554+
return nil, err
14555+
}
14556+
14557+
var r RemoveVirtualMachineFromBackupOfferingResponse
14558+
if err := json.Unmarshal(resp, &r); err != nil {
14559+
return nil, err
14560+
}
14561+
14562+
// If we have a async client, we need to wait for the async result
14563+
if s.cs.async {
14564+
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
14565+
if err != nil {
14566+
if err == AsyncTimeoutErr {
14567+
return &r, err
14568+
}
14569+
return nil, err
14570+
}
14571+
14572+
if err := json.Unmarshal(b, &r); err != nil {
14573+
return nil, err
14574+
}
14575+
}
14576+
14577+
return &r, nil
14578+
}
14579+
14580+
type RemoveVirtualMachineFromBackupOfferingResponse struct {
14581+
Displaytext string `json:"displaytext"`
14582+
JobID string `json:"jobid"`
14583+
Jobstatus int `json:"jobstatus"`
14584+
Success bool `json:"success"`
14585+
}

cloudstack/VirtualMachineService_mock.go

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generate/layout.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ var layout = apiInfo{
141141
"updateVMSchedule",
142142
"listVMSchedule",
143143
"deleteVMSchedule",
144+
"assignVirtualMachineToBackupOffering",
145+
"removeVirtualMachineFromBackupOffering",
144146
},
145147
"VPNService": {
146148
"addVpnUser",

test/VirtualMachineService_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,4 +494,28 @@ func TestVirtualMachineService(t *testing.T) {
494494
}
495495
t.Run("DeleteVMSchedule", testdeleteVMSchedule)
496496

497+
testassignVirtualMachineToBackupOffering := func(t *testing.T) {
498+
if _, ok := response["assignVirtualMachineToBackupOffering"]; !ok {
499+
t.Skipf("Skipping as no json response is provided in testdata")
500+
}
501+
p := client.VirtualMachine.NewAssignVirtualMachineToBackupOfferingParams("backupofferingid", "virtualmachineid")
502+
_, err := client.VirtualMachine.AssignVirtualMachineToBackupOffering(p)
503+
if err != nil {
504+
t.Errorf(err.Error())
505+
}
506+
}
507+
t.Run("AssignVirtualMachineToBackupOffering", testassignVirtualMachineToBackupOffering)
508+
509+
testremoveVirtualMachineFromBackupOffering := func(t *testing.T) {
510+
if _, ok := response["removeVirtualMachineFromBackupOffering"]; !ok {
511+
t.Skipf("Skipping as no json response is provided in testdata")
512+
}
513+
p := client.VirtualMachine.NewRemoveVirtualMachineFromBackupOfferingParams("virtualmachineid")
514+
_, err := client.VirtualMachine.RemoveVirtualMachineFromBackupOffering(p)
515+
if err != nil {
516+
t.Errorf(err.Error())
517+
}
518+
}
519+
t.Run("RemoveVirtualMachineFromBackupOffering", testremoveVirtualMachineFromBackupOffering)
520+
497521
}

0 commit comments

Comments
 (0)