This is an automated email from the ASF dual-hosted git repository. pearl11594 pushed a commit to branch add-gpu-support in repository https://gitbox.apache.org/repos/asf/cloudstack-go.git
commit b352a8e909b01fdbdf944d4bfee44866c2e6f39a Author: Pearl Dsilva <pearl1...@gmail.com> AuthorDate: Mon Sep 22 16:32:57 2025 -0400 Add support for GPU apis --- cloudstack/GPUService.go | 2923 +++++++++++++++++++++++++++++++++++++++++ cloudstack/GPUService_mock.go | 641 +++++++++ cloudstack/cloudstack.go | 11 + generate/layout.go | 17 + test/GPUService_test.go | 239 ++++ 5 files changed, 3831 insertions(+) diff --git a/cloudstack/GPUService.go b/cloudstack/GPUService.go new file mode 100644 index 0000000..753f5cc --- /dev/null +++ b/cloudstack/GPUService.go @@ -0,0 +1,2923 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +package cloudstack + +import ( + "encoding/json" + "fmt" + "net/url" + "strconv" + "strings" +) + +type GPUServiceIface interface { + CreateGpuCard(p *CreateGpuCardParams) (*CreateGpuCardResponse, error) + NewCreateGpuCardParams(deviceid string, devicename string, name string, vendorid string, vendorname string) *CreateGpuCardParams + CreateGpuDevice(p *CreateGpuDeviceParams) (*CreateGpuDeviceResponse, error) + NewCreateGpuDeviceParams(busaddress string, gpucardid string, hostid string, vgpuprofileid string) *CreateGpuDeviceParams + CreateVgpuProfile(p *CreateVgpuProfileParams) (*CreateVgpuProfileResponse, error) + NewCreateVgpuProfileParams(gpucardid string, name string) *CreateVgpuProfileParams + DeleteGpuCard(p *DeleteGpuCardParams) (*DeleteGpuCardResponse, error) + NewDeleteGpuCardParams(id string) *DeleteGpuCardParams + DeleteGpuDevice(p *DeleteGpuDeviceParams) (*DeleteGpuDeviceResponse, error) + NewDeleteGpuDeviceParams(ids []string) *DeleteGpuDeviceParams + DeleteVgpuProfile(p *DeleteVgpuProfileParams) (*DeleteVgpuProfileResponse, error) + NewDeleteVgpuProfileParams(id string) *DeleteVgpuProfileParams + DiscoverGpuDevices(p *DiscoverGpuDevicesParams) (*DiscoverGpuDevicesResponse, error) + NewDiscoverGpuDevicesParams(id string) *DiscoverGpuDevicesParams + ListGpuCards(p *ListGpuCardsParams) (*ListGpuCardsResponse, error) + NewListGpuCardsParams() *ListGpuCardsParams + GetGpuCardID(keyword string, opts ...OptionFunc) (string, int, error) + GetGpuCardByName(name string, opts ...OptionFunc) (*GpuCard, int, error) + GetGpuCardByID(id string, opts ...OptionFunc) (*GpuCard, int, error) + ListGpuDevices(p *ListGpuDevicesParams) (*ListGpuDevicesResponse, error) + NewListGpuDevicesParams() *ListGpuDevicesParams + GetGpuDeviceByID(id string, opts ...OptionFunc) (*GpuDevice, int, error) + ListVgpuProfiles(p *ListVgpuProfilesParams) (*ListVgpuProfilesResponse, error) + NewListVgpuProfilesParams() *ListVgpuProfilesParams + GetVgpuProfileID(name string, opts ...OptionFunc) (string, int, error) + GetVgpuProfileByName(name string, opts ...OptionFunc) (*VgpuProfile, int, error) + GetVgpuProfileByID(id string, opts ...OptionFunc) (*VgpuProfile, int, error) + ManageGpuDevice(p *ManageGpuDeviceParams) (*ManageGpuDeviceResponse, error) + NewManageGpuDeviceParams(ids []string) *ManageGpuDeviceParams + UnmanageGpuDevice(p *UnmanageGpuDeviceParams) (*UnmanageGpuDeviceResponse, error) + NewUnmanageGpuDeviceParams(ids []string) *UnmanageGpuDeviceParams + UpdateGpuCard(p *UpdateGpuCardParams) (*UpdateGpuCardResponse, error) + NewUpdateGpuCardParams(id string) *UpdateGpuCardParams + UpdateGpuDevice(p *UpdateGpuDeviceParams) (*UpdateGpuDeviceResponse, error) + NewUpdateGpuDeviceParams(id string) *UpdateGpuDeviceParams + UpdateVgpuProfile(p *UpdateVgpuProfileParams) (*UpdateVgpuProfileResponse, error) + NewUpdateVgpuProfileParams(id string) *UpdateVgpuProfileParams +} + +type CreateGpuCardParams struct { + p map[string]interface{} +} + +func (p *CreateGpuCardParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["deviceid"]; found { + u.Set("deviceid", v.(string)) + } + if v, found := p.p["devicename"]; found { + u.Set("devicename", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["vendorid"]; found { + u.Set("vendorid", v.(string)) + } + if v, found := p.p["vendorname"]; found { + u.Set("vendorname", v.(string)) + } + if v, found := p.p["videoram"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("videoram", vv) + } + return u +} + +func (p *CreateGpuCardParams) SetDeviceid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["deviceid"] = v +} + +func (p *CreateGpuCardParams) ResetDeviceid() { + if p.p != nil && p.p["deviceid"] != nil { + delete(p.p, "deviceid") + } +} + +func (p *CreateGpuCardParams) GetDeviceid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["deviceid"].(string) + return value, ok +} + +func (p *CreateGpuCardParams) SetDevicename(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["devicename"] = v +} + +func (p *CreateGpuCardParams) ResetDevicename() { + if p.p != nil && p.p["devicename"] != nil { + delete(p.p, "devicename") + } +} + +func (p *CreateGpuCardParams) GetDevicename() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["devicename"].(string) + return value, ok +} + +func (p *CreateGpuCardParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v +} + +func (p *CreateGpuCardParams) ResetName() { + if p.p != nil && p.p["name"] != nil { + delete(p.p, "name") + } +} + +func (p *CreateGpuCardParams) GetName() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["name"].(string) + return value, ok +} + +func (p *CreateGpuCardParams) SetVendorid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vendorid"] = v +} + +func (p *CreateGpuCardParams) ResetVendorid() { + if p.p != nil && p.p["vendorid"] != nil { + delete(p.p, "vendorid") + } +} + +func (p *CreateGpuCardParams) GetVendorid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["vendorid"].(string) + return value, ok +} + +func (p *CreateGpuCardParams) SetVendorname(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vendorname"] = v +} + +func (p *CreateGpuCardParams) ResetVendorname() { + if p.p != nil && p.p["vendorname"] != nil { + delete(p.p, "vendorname") + } +} + +func (p *CreateGpuCardParams) GetVendorname() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["vendorname"].(string) + return value, ok +} + +func (p *CreateGpuCardParams) SetVideoram(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["videoram"] = v +} + +func (p *CreateGpuCardParams) ResetVideoram() { + if p.p != nil && p.p["videoram"] != nil { + delete(p.p, "videoram") + } +} + +func (p *CreateGpuCardParams) GetVideoram() (int64, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["videoram"].(int64) + return value, ok +} + +// You should always use this function to get a new CreateGpuCardParams instance, +// as then you are sure you have configured all required params +func (s *GPUService) NewCreateGpuCardParams(deviceid string, devicename string, name string, vendorid string, vendorname string) *CreateGpuCardParams { + p := &CreateGpuCardParams{} + p.p = make(map[string]interface{}) + p.p["deviceid"] = deviceid + p.p["devicename"] = devicename + p.p["name"] = name + p.p["vendorid"] = vendorid + p.p["vendorname"] = vendorname + return p +} + +// Creates a GPU card definition in the system +func (s *GPUService) CreateGpuCard(p *CreateGpuCardParams) (*CreateGpuCardResponse, error) { + resp, err := s.cs.newPostRequest("createGpuCard", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CreateGpuCardResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type CreateGpuCardResponse struct { + Deviceid string `json:"deviceid"` + Devicename string `json:"devicename"` + Id string `json:"id"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Name string `json:"name"` + Vendorid string `json:"vendorid"` + Vendorname string `json:"vendorname"` +} + +type CreateGpuDeviceParams struct { + p map[string]interface{} +} + +func (p *CreateGpuDeviceParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["busaddress"]; found { + u.Set("busaddress", v.(string)) + } + if v, found := p.p["gpucardid"]; found { + u.Set("gpucardid", v.(string)) + } + if v, found := p.p["hostid"]; found { + u.Set("hostid", v.(string)) + } + if v, found := p.p["numanode"]; found { + u.Set("numanode", v.(string)) + } + if v, found := p.p["parentgpudeviceid"]; found { + u.Set("parentgpudeviceid", v.(string)) + } + if v, found := p.p["type"]; found { + u.Set("type", v.(string)) + } + if v, found := p.p["vgpuprofileid"]; found { + u.Set("vgpuprofileid", v.(string)) + } + return u +} + +func (p *CreateGpuDeviceParams) SetBusaddress(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["busaddress"] = v +} + +func (p *CreateGpuDeviceParams) ResetBusaddress() { + if p.p != nil && p.p["busaddress"] != nil { + delete(p.p, "busaddress") + } +} + +func (p *CreateGpuDeviceParams) GetBusaddress() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["busaddress"].(string) + return value, ok +} + +func (p *CreateGpuDeviceParams) SetGpucardid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["gpucardid"] = v +} + +func (p *CreateGpuDeviceParams) ResetGpucardid() { + if p.p != nil && p.p["gpucardid"] != nil { + delete(p.p, "gpucardid") + } +} + +func (p *CreateGpuDeviceParams) GetGpucardid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["gpucardid"].(string) + return value, ok +} + +func (p *CreateGpuDeviceParams) SetHostid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hostid"] = v +} + +func (p *CreateGpuDeviceParams) ResetHostid() { + if p.p != nil && p.p["hostid"] != nil { + delete(p.p, "hostid") + } +} + +func (p *CreateGpuDeviceParams) GetHostid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["hostid"].(string) + return value, ok +} + +func (p *CreateGpuDeviceParams) SetNumanode(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["numanode"] = v +} + +func (p *CreateGpuDeviceParams) ResetNumanode() { + if p.p != nil && p.p["numanode"] != nil { + delete(p.p, "numanode") + } +} + +func (p *CreateGpuDeviceParams) GetNumanode() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["numanode"].(string) + return value, ok +} + +func (p *CreateGpuDeviceParams) SetParentgpudeviceid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["parentgpudeviceid"] = v +} + +func (p *CreateGpuDeviceParams) ResetParentgpudeviceid() { + if p.p != nil && p.p["parentgpudeviceid"] != nil { + delete(p.p, "parentgpudeviceid") + } +} + +func (p *CreateGpuDeviceParams) GetParentgpudeviceid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["parentgpudeviceid"].(string) + return value, ok +} + +func (p *CreateGpuDeviceParams) SetType(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["type"] = v +} + +func (p *CreateGpuDeviceParams) ResetType() { + if p.p != nil && p.p["type"] != nil { + delete(p.p, "type") + } +} + +func (p *CreateGpuDeviceParams) GetType() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["type"].(string) + return value, ok +} + +func (p *CreateGpuDeviceParams) SetVgpuprofileid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vgpuprofileid"] = v +} + +func (p *CreateGpuDeviceParams) ResetVgpuprofileid() { + if p.p != nil && p.p["vgpuprofileid"] != nil { + delete(p.p, "vgpuprofileid") + } +} + +func (p *CreateGpuDeviceParams) GetVgpuprofileid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["vgpuprofileid"].(string) + return value, ok +} + +// You should always use this function to get a new CreateGpuDeviceParams instance, +// as then you are sure you have configured all required params +func (s *GPUService) NewCreateGpuDeviceParams(busaddress string, gpucardid string, hostid string, vgpuprofileid string) *CreateGpuDeviceParams { + p := &CreateGpuDeviceParams{} + p.p = make(map[string]interface{}) + p.p["busaddress"] = busaddress + p.p["gpucardid"] = gpucardid + p.p["hostid"] = hostid + p.p["vgpuprofileid"] = vgpuprofileid + return p +} + +// Creates a GPU device manually on a host +func (s *GPUService) CreateGpuDevice(p *CreateGpuDeviceParams) (*CreateGpuDeviceResponse, error) { + resp, err := s.cs.newPostRequest("createGpuDevice", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CreateGpuDeviceResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type CreateGpuDeviceResponse struct { + Busaddress string `json:"busaddress"` + Gpucardid string `json:"gpucardid"` + Gpucardname string `json:"gpucardname"` + Gpudevicetype string `json:"gpudevicetype"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Id string `json:"id"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Managedstate string `json:"managedstate"` + Numanode string `json:"numanode"` + Parentgpudeviceid string `json:"parentgpudeviceid"` + State string `json:"state"` + Vgpuprofileid string `json:"vgpuprofileid"` + Vgpuprofilename string `json:"vgpuprofilename"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualmachinename string `json:"virtualmachinename"` + Vmstate string `json:"vmstate"` +} + +type CreateVgpuProfileParams struct { + p map[string]interface{} +} + +func (p *CreateVgpuProfileParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["description"]; found { + u.Set("description", v.(string)) + } + if v, found := p.p["gpucardid"]; found { + u.Set("gpucardid", v.(string)) + } + if v, found := p.p["maxheads"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("maxheads", vv) + } + if v, found := p.p["maxresolutionx"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("maxresolutionx", vv) + } + if v, found := p.p["maxresolutiony"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("maxresolutiony", vv) + } + if v, found := p.p["maxvgpuperphysicalgpu"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("maxvgpuperphysicalgpu", vv) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["videoram"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("videoram", vv) + } + return u +} + +func (p *CreateVgpuProfileParams) SetDescription(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["description"] = v +} + +func (p *CreateVgpuProfileParams) ResetDescription() { + if p.p != nil && p.p["description"] != nil { + delete(p.p, "description") + } +} + +func (p *CreateVgpuProfileParams) GetDescription() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["description"].(string) + return value, ok +} + +func (p *CreateVgpuProfileParams) SetGpucardid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["gpucardid"] = v +} + +func (p *CreateVgpuProfileParams) ResetGpucardid() { + if p.p != nil && p.p["gpucardid"] != nil { + delete(p.p, "gpucardid") + } +} + +func (p *CreateVgpuProfileParams) GetGpucardid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["gpucardid"].(string) + return value, ok +} + +func (p *CreateVgpuProfileParams) SetMaxheads(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["maxheads"] = v +} + +func (p *CreateVgpuProfileParams) ResetMaxheads() { + if p.p != nil && p.p["maxheads"] != nil { + delete(p.p, "maxheads") + } +} + +func (p *CreateVgpuProfileParams) GetMaxheads() (int64, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["maxheads"].(int64) + return value, ok +} + +func (p *CreateVgpuProfileParams) SetMaxresolutionx(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["maxresolutionx"] = v +} + +func (p *CreateVgpuProfileParams) ResetMaxresolutionx() { + if p.p != nil && p.p["maxresolutionx"] != nil { + delete(p.p, "maxresolutionx") + } +} + +func (p *CreateVgpuProfileParams) GetMaxresolutionx() (int64, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["maxresolutionx"].(int64) + return value, ok +} + +func (p *CreateVgpuProfileParams) SetMaxresolutiony(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["maxresolutiony"] = v +} + +func (p *CreateVgpuProfileParams) ResetMaxresolutiony() { + if p.p != nil && p.p["maxresolutiony"] != nil { + delete(p.p, "maxresolutiony") + } +} + +func (p *CreateVgpuProfileParams) GetMaxresolutiony() (int64, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["maxresolutiony"].(int64) + return value, ok +} + +func (p *CreateVgpuProfileParams) SetMaxvgpuperphysicalgpu(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["maxvgpuperphysicalgpu"] = v +} + +func (p *CreateVgpuProfileParams) ResetMaxvgpuperphysicalgpu() { + if p.p != nil && p.p["maxvgpuperphysicalgpu"] != nil { + delete(p.p, "maxvgpuperphysicalgpu") + } +} + +func (p *CreateVgpuProfileParams) GetMaxvgpuperphysicalgpu() (int64, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["maxvgpuperphysicalgpu"].(int64) + return value, ok +} + +func (p *CreateVgpuProfileParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v +} + +func (p *CreateVgpuProfileParams) ResetName() { + if p.p != nil && p.p["name"] != nil { + delete(p.p, "name") + } +} + +func (p *CreateVgpuProfileParams) GetName() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["name"].(string) + return value, ok +} + +func (p *CreateVgpuProfileParams) SetVideoram(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["videoram"] = v +} + +func (p *CreateVgpuProfileParams) ResetVideoram() { + if p.p != nil && p.p["videoram"] != nil { + delete(p.p, "videoram") + } +} + +func (p *CreateVgpuProfileParams) GetVideoram() (int64, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["videoram"].(int64) + return value, ok +} + +// You should always use this function to get a new CreateVgpuProfileParams instance, +// as then you are sure you have configured all required params +func (s *GPUService) NewCreateVgpuProfileParams(gpucardid string, name string) *CreateVgpuProfileParams { + p := &CreateVgpuProfileParams{} + p.p = make(map[string]interface{}) + p.p["gpucardid"] = gpucardid + p.p["name"] = name + return p +} + +// Creates a vGPU profile in the system +func (s *GPUService) CreateVgpuProfile(p *CreateVgpuProfileParams) (*CreateVgpuProfileResponse, error) { + resp, err := s.cs.newPostRequest("createVgpuProfile", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CreateVgpuProfileResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type CreateVgpuProfileResponse struct { + Description string `json:"description"` + Deviceid string `json:"deviceid"` + Devicename string `json:"devicename"` + Gpucardid string `json:"gpucardid"` + Gpucardname string `json:"gpucardname"` + Id string `json:"id"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Maxheads int64 `json:"maxheads"` + Maxresolutionx int64 `json:"maxresolutionx"` + Maxresolutiony int64 `json:"maxresolutiony"` + Maxvgpuperphysicalgpu int64 `json:"maxvgpuperphysicalgpu"` + Name string `json:"name"` + Vendorid string `json:"vendorid"` + Vendorname string `json:"vendorname"` + Videoram int64 `json:"videoram"` +} + +type DeleteGpuCardParams struct { + p map[string]interface{} +} + +func (p *DeleteGpuCardParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteGpuCardParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v +} + +func (p *DeleteGpuCardParams) ResetId() { + if p.p != nil && p.p["id"] != nil { + delete(p.p, "id") + } +} + +func (p *DeleteGpuCardParams) GetId() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["id"].(string) + return value, ok +} + +// You should always use this function to get a new DeleteGpuCardParams instance, +// as then you are sure you have configured all required params +func (s *GPUService) NewDeleteGpuCardParams(id string) *DeleteGpuCardParams { + p := &DeleteGpuCardParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a GPU card definition from the system +func (s *GPUService) DeleteGpuCard(p *DeleteGpuCardParams) (*DeleteGpuCardResponse, error) { + resp, err := s.cs.newPostRequest("deleteGpuCard", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteGpuCardResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DeleteGpuCardResponse struct { + Displaytext string `json:"displaytext"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Success bool `json:"success"` +} + +func (r *DeleteGpuCardResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + if ostypeid, ok := m["ostypeid"].(float64); ok { + m["ostypeid"] = strconv.Itoa(int(ostypeid)) + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteGpuCardResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type DeleteGpuDeviceParams struct { + p map[string]interface{} +} + +func (p *DeleteGpuDeviceParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["ids"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("ids", vv) + } + return u +} + +func (p *DeleteGpuDeviceParams) SetIds(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ids"] = v +} + +func (p *DeleteGpuDeviceParams) ResetIds() { + if p.p != nil && p.p["ids"] != nil { + delete(p.p, "ids") + } +} + +func (p *DeleteGpuDeviceParams) GetIds() ([]string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["ids"].([]string) + return value, ok +} + +// You should always use this function to get a new DeleteGpuDeviceParams instance, +// as then you are sure you have configured all required params +func (s *GPUService) NewDeleteGpuDeviceParams(ids []string) *DeleteGpuDeviceParams { + p := &DeleteGpuDeviceParams{} + p.p = make(map[string]interface{}) + p.p["ids"] = ids + return p +} + +// Deletes a vGPU profile from the system +func (s *GPUService) DeleteGpuDevice(p *DeleteGpuDeviceParams) (*DeleteGpuDeviceResponse, error) { + resp, err := s.cs.newPostRequest("deleteGpuDevice", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteGpuDeviceResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DeleteGpuDeviceResponse struct { + Displaytext string `json:"displaytext"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Success bool `json:"success"` +} + +func (r *DeleteGpuDeviceResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + if ostypeid, ok := m["ostypeid"].(float64); ok { + m["ostypeid"] = strconv.Itoa(int(ostypeid)) + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteGpuDeviceResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type DeleteVgpuProfileParams struct { + p map[string]interface{} +} + +func (p *DeleteVgpuProfileParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteVgpuProfileParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v +} + +func (p *DeleteVgpuProfileParams) ResetId() { + if p.p != nil && p.p["id"] != nil { + delete(p.p, "id") + } +} + +func (p *DeleteVgpuProfileParams) GetId() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["id"].(string) + return value, ok +} + +// You should always use this function to get a new DeleteVgpuProfileParams instance, +// as then you are sure you have configured all required params +func (s *GPUService) NewDeleteVgpuProfileParams(id string) *DeleteVgpuProfileParams { + p := &DeleteVgpuProfileParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a vGPU profile from the system +func (s *GPUService) DeleteVgpuProfile(p *DeleteVgpuProfileParams) (*DeleteVgpuProfileResponse, error) { + resp, err := s.cs.newPostRequest("deleteVgpuProfile", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteVgpuProfileResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DeleteVgpuProfileResponse struct { + Displaytext string `json:"displaytext"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Success bool `json:"success"` +} + +func (r *DeleteVgpuProfileResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + if ostypeid, ok := m["ostypeid"].(float64); ok { + m["ostypeid"] = strconv.Itoa(int(ostypeid)) + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteVgpuProfileResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type DiscoverGpuDevicesParams struct { + p map[string]interface{} +} + +func (p *DiscoverGpuDevicesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + return u +} + +func (p *DiscoverGpuDevicesParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v +} + +func (p *DiscoverGpuDevicesParams) ResetId() { + if p.p != nil && p.p["id"] != nil { + delete(p.p, "id") + } +} + +func (p *DiscoverGpuDevicesParams) GetId() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["id"].(string) + return value, ok +} + +func (p *DiscoverGpuDevicesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v +} + +func (p *DiscoverGpuDevicesParams) ResetKeyword() { + if p.p != nil && p.p["keyword"] != nil { + delete(p.p, "keyword") + } +} + +func (p *DiscoverGpuDevicesParams) GetKeyword() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["keyword"].(string) + return value, ok +} + +func (p *DiscoverGpuDevicesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v +} + +func (p *DiscoverGpuDevicesParams) ResetPage() { + if p.p != nil && p.p["page"] != nil { + delete(p.p, "page") + } +} + +func (p *DiscoverGpuDevicesParams) GetPage() (int, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["page"].(int) + return value, ok +} + +func (p *DiscoverGpuDevicesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v +} + +func (p *DiscoverGpuDevicesParams) ResetPagesize() { + if p.p != nil && p.p["pagesize"] != nil { + delete(p.p, "pagesize") + } +} + +func (p *DiscoverGpuDevicesParams) GetPagesize() (int, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["pagesize"].(int) + return value, ok +} + +// You should always use this function to get a new DiscoverGpuDevicesParams instance, +// as then you are sure you have configured all required params +func (s *GPUService) NewDiscoverGpuDevicesParams(id string) *DiscoverGpuDevicesParams { + p := &DiscoverGpuDevicesParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Discovers available GPU devices on a host +func (s *GPUService) DiscoverGpuDevices(p *DiscoverGpuDevicesParams) (*DiscoverGpuDevicesResponse, error) { + resp, err := s.cs.newPostRequest("discoverGpuDevices", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DiscoverGpuDevicesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DiscoverGpuDevicesResponse struct { + Busaddress string `json:"busaddress"` + Gpucardid string `json:"gpucardid"` + Gpucardname string `json:"gpucardname"` + Gpudevicetype string `json:"gpudevicetype"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Id string `json:"id"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Managedstate string `json:"managedstate"` + Numanode string `json:"numanode"` + Parentgpudeviceid string `json:"parentgpudeviceid"` + State string `json:"state"` + Vgpuprofileid string `json:"vgpuprofileid"` + Vgpuprofilename string `json:"vgpuprofilename"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualmachinename string `json:"virtualmachinename"` + Vmstate string `json:"vmstate"` +} + +type ListGpuCardsParams struct { + p map[string]interface{} +} + +func (p *ListGpuCardsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["activeonly"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("activeonly", vv) + } + if v, found := p.p["deviceid"]; found { + u.Set("deviceid", v.(string)) + } + if v, found := p.p["devicename"]; found { + u.Set("devicename", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["vendorid"]; found { + u.Set("vendorid", v.(string)) + } + if v, found := p.p["vendorname"]; found { + u.Set("vendorname", v.(string)) + } + return u +} + +func (p *ListGpuCardsParams) SetActiveonly(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["activeonly"] = v +} + +func (p *ListGpuCardsParams) ResetActiveonly() { + if p.p != nil && p.p["activeonly"] != nil { + delete(p.p, "activeonly") + } +} + +func (p *ListGpuCardsParams) GetActiveonly() (bool, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["activeonly"].(bool) + return value, ok +} + +func (p *ListGpuCardsParams) SetDeviceid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["deviceid"] = v +} + +func (p *ListGpuCardsParams) ResetDeviceid() { + if p.p != nil && p.p["deviceid"] != nil { + delete(p.p, "deviceid") + } +} + +func (p *ListGpuCardsParams) GetDeviceid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["deviceid"].(string) + return value, ok +} + +func (p *ListGpuCardsParams) SetDevicename(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["devicename"] = v +} + +func (p *ListGpuCardsParams) ResetDevicename() { + if p.p != nil && p.p["devicename"] != nil { + delete(p.p, "devicename") + } +} + +func (p *ListGpuCardsParams) GetDevicename() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["devicename"].(string) + return value, ok +} + +func (p *ListGpuCardsParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v +} + +func (p *ListGpuCardsParams) ResetId() { + if p.p != nil && p.p["id"] != nil { + delete(p.p, "id") + } +} + +func (p *ListGpuCardsParams) GetId() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["id"].(string) + return value, ok +} + +func (p *ListGpuCardsParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v +} + +func (p *ListGpuCardsParams) ResetKeyword() { + if p.p != nil && p.p["keyword"] != nil { + delete(p.p, "keyword") + } +} + +func (p *ListGpuCardsParams) GetKeyword() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["keyword"].(string) + return value, ok +} + +func (p *ListGpuCardsParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v +} + +func (p *ListGpuCardsParams) ResetPage() { + if p.p != nil && p.p["page"] != nil { + delete(p.p, "page") + } +} + +func (p *ListGpuCardsParams) GetPage() (int, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["page"].(int) + return value, ok +} + +func (p *ListGpuCardsParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v +} + +func (p *ListGpuCardsParams) ResetPagesize() { + if p.p != nil && p.p["pagesize"] != nil { + delete(p.p, "pagesize") + } +} + +func (p *ListGpuCardsParams) GetPagesize() (int, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["pagesize"].(int) + return value, ok +} + +func (p *ListGpuCardsParams) SetVendorid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vendorid"] = v +} + +func (p *ListGpuCardsParams) ResetVendorid() { + if p.p != nil && p.p["vendorid"] != nil { + delete(p.p, "vendorid") + } +} + +func (p *ListGpuCardsParams) GetVendorid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["vendorid"].(string) + return value, ok +} + +func (p *ListGpuCardsParams) SetVendorname(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vendorname"] = v +} + +func (p *ListGpuCardsParams) ResetVendorname() { + if p.p != nil && p.p["vendorname"] != nil { + delete(p.p, "vendorname") + } +} + +func (p *ListGpuCardsParams) GetVendorname() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["vendorname"].(string) + return value, ok +} + +// You should always use this function to get a new ListGpuCardsParams instance, +// as then you are sure you have configured all required params +func (s *GPUService) NewListGpuCardsParams() *ListGpuCardsParams { + p := &ListGpuCardsParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *GPUService) GetGpuCardID(keyword string, opts ...OptionFunc) (string, int, error) { + p := &ListGpuCardsParams{} + p.p = make(map[string]interface{}) + + p.p["keyword"] = keyword + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListGpuCards(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l) + } + + if l.Count == 1 { + return l.GpuCards[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.GpuCards { + if v.Name == keyword { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l) +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *GPUService) GetGpuCardByName(name string, opts ...OptionFunc) (*GpuCard, int, error) { + id, count, err := s.GetGpuCardID(name, opts...) + if err != nil { + return nil, count, err + } + + r, count, err := s.GetGpuCardByID(id, opts...) + if err != nil { + return nil, count, err + } + return r, count, nil +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *GPUService) GetGpuCardByID(id string, opts ...OptionFunc) (*GpuCard, int, error) { + p := &ListGpuCardsParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListGpuCards(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.GpuCards[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for GpuCard UUID: %s!", id) +} + +// Lists all available GPU cards +func (s *GPUService) ListGpuCards(p *ListGpuCardsParams) (*ListGpuCardsResponse, error) { + resp, err := s.cs.newRequest("listGpuCards", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListGpuCardsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListGpuCardsResponse struct { + Count int `json:"count"` + GpuCards []*GpuCard `json:"gpucard"` +} + +type GpuCard struct { + Deviceid string `json:"deviceid"` + Devicename string `json:"devicename"` + Id string `json:"id"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Name string `json:"name"` + Vendorid string `json:"vendorid"` + Vendorname string `json:"vendorname"` +} + +type ListGpuDevicesParams struct { + p map[string]interface{} +} + +func (p *ListGpuDevicesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["gpucardid"]; found { + u.Set("gpucardid", v.(string)) + } + if v, found := p.p["hostid"]; found { + u.Set("hostid", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["vgpuprofileid"]; found { + u.Set("vgpuprofileid", v.(string)) + } + if v, found := p.p["virtualmachineid"]; found { + u.Set("virtualmachineid", v.(string)) + } + return u +} + +func (p *ListGpuDevicesParams) SetGpucardid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["gpucardid"] = v +} + +func (p *ListGpuDevicesParams) ResetGpucardid() { + if p.p != nil && p.p["gpucardid"] != nil { + delete(p.p, "gpucardid") + } +} + +func (p *ListGpuDevicesParams) GetGpucardid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["gpucardid"].(string) + return value, ok +} + +func (p *ListGpuDevicesParams) SetHostid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hostid"] = v +} + +func (p *ListGpuDevicesParams) ResetHostid() { + if p.p != nil && p.p["hostid"] != nil { + delete(p.p, "hostid") + } +} + +func (p *ListGpuDevicesParams) GetHostid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["hostid"].(string) + return value, ok +} + +func (p *ListGpuDevicesParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v +} + +func (p *ListGpuDevicesParams) ResetId() { + if p.p != nil && p.p["id"] != nil { + delete(p.p, "id") + } +} + +func (p *ListGpuDevicesParams) GetId() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["id"].(string) + return value, ok +} + +func (p *ListGpuDevicesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v +} + +func (p *ListGpuDevicesParams) ResetKeyword() { + if p.p != nil && p.p["keyword"] != nil { + delete(p.p, "keyword") + } +} + +func (p *ListGpuDevicesParams) GetKeyword() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["keyword"].(string) + return value, ok +} + +func (p *ListGpuDevicesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v +} + +func (p *ListGpuDevicesParams) ResetPage() { + if p.p != nil && p.p["page"] != nil { + delete(p.p, "page") + } +} + +func (p *ListGpuDevicesParams) GetPage() (int, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["page"].(int) + return value, ok +} + +func (p *ListGpuDevicesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v +} + +func (p *ListGpuDevicesParams) ResetPagesize() { + if p.p != nil && p.p["pagesize"] != nil { + delete(p.p, "pagesize") + } +} + +func (p *ListGpuDevicesParams) GetPagesize() (int, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["pagesize"].(int) + return value, ok +} + +func (p *ListGpuDevicesParams) SetVgpuprofileid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vgpuprofileid"] = v +} + +func (p *ListGpuDevicesParams) ResetVgpuprofileid() { + if p.p != nil && p.p["vgpuprofileid"] != nil { + delete(p.p, "vgpuprofileid") + } +} + +func (p *ListGpuDevicesParams) GetVgpuprofileid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["vgpuprofileid"].(string) + return value, ok +} + +func (p *ListGpuDevicesParams) SetVirtualmachineid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["virtualmachineid"] = v +} + +func (p *ListGpuDevicesParams) ResetVirtualmachineid() { + if p.p != nil && p.p["virtualmachineid"] != nil { + delete(p.p, "virtualmachineid") + } +} + +func (p *ListGpuDevicesParams) GetVirtualmachineid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["virtualmachineid"].(string) + return value, ok +} + +// You should always use this function to get a new ListGpuDevicesParams instance, +// as then you are sure you have configured all required params +func (s *GPUService) NewListGpuDevicesParams() *ListGpuDevicesParams { + p := &ListGpuDevicesParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *GPUService) GetGpuDeviceByID(id string, opts ...OptionFunc) (*GpuDevice, int, error) { + p := &ListGpuDevicesParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListGpuDevices(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.GpuDevices[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for GpuDevice UUID: %s!", id) +} + +// Lists all available GPU devices +func (s *GPUService) ListGpuDevices(p *ListGpuDevicesParams) (*ListGpuDevicesResponse, error) { + resp, err := s.cs.newRequest("listGpuDevices", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListGpuDevicesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListGpuDevicesResponse struct { + Count int `json:"count"` + GpuDevices []*GpuDevice `json:"gpudevice"` +} + +type GpuDevice struct { + Busaddress string `json:"busaddress"` + Gpucardid string `json:"gpucardid"` + Gpucardname string `json:"gpucardname"` + Gpudevicetype string `json:"gpudevicetype"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Id string `json:"id"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Managedstate string `json:"managedstate"` + Numanode string `json:"numanode"` + Parentgpudeviceid string `json:"parentgpudeviceid"` + State string `json:"state"` + Vgpuprofileid string `json:"vgpuprofileid"` + Vgpuprofilename string `json:"vgpuprofilename"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualmachinename string `json:"virtualmachinename"` + Vmstate string `json:"vmstate"` +} + +type ListVgpuProfilesParams struct { + p map[string]interface{} +} + +func (p *ListVgpuProfilesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["activeonly"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("activeonly", vv) + } + if v, found := p.p["gpucardid"]; found { + u.Set("gpucardid", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + return u +} + +func (p *ListVgpuProfilesParams) SetActiveonly(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["activeonly"] = v +} + +func (p *ListVgpuProfilesParams) ResetActiveonly() { + if p.p != nil && p.p["activeonly"] != nil { + delete(p.p, "activeonly") + } +} + +func (p *ListVgpuProfilesParams) GetActiveonly() (bool, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["activeonly"].(bool) + return value, ok +} + +func (p *ListVgpuProfilesParams) SetGpucardid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["gpucardid"] = v +} + +func (p *ListVgpuProfilesParams) ResetGpucardid() { + if p.p != nil && p.p["gpucardid"] != nil { + delete(p.p, "gpucardid") + } +} + +func (p *ListVgpuProfilesParams) GetGpucardid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["gpucardid"].(string) + return value, ok +} + +func (p *ListVgpuProfilesParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v +} + +func (p *ListVgpuProfilesParams) ResetId() { + if p.p != nil && p.p["id"] != nil { + delete(p.p, "id") + } +} + +func (p *ListVgpuProfilesParams) GetId() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["id"].(string) + return value, ok +} + +func (p *ListVgpuProfilesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v +} + +func (p *ListVgpuProfilesParams) ResetKeyword() { + if p.p != nil && p.p["keyword"] != nil { + delete(p.p, "keyword") + } +} + +func (p *ListVgpuProfilesParams) GetKeyword() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["keyword"].(string) + return value, ok +} + +func (p *ListVgpuProfilesParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v +} + +func (p *ListVgpuProfilesParams) ResetName() { + if p.p != nil && p.p["name"] != nil { + delete(p.p, "name") + } +} + +func (p *ListVgpuProfilesParams) GetName() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["name"].(string) + return value, ok +} + +func (p *ListVgpuProfilesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v +} + +func (p *ListVgpuProfilesParams) ResetPage() { + if p.p != nil && p.p["page"] != nil { + delete(p.p, "page") + } +} + +func (p *ListVgpuProfilesParams) GetPage() (int, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["page"].(int) + return value, ok +} + +func (p *ListVgpuProfilesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v +} + +func (p *ListVgpuProfilesParams) ResetPagesize() { + if p.p != nil && p.p["pagesize"] != nil { + delete(p.p, "pagesize") + } +} + +func (p *ListVgpuProfilesParams) GetPagesize() (int, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["pagesize"].(int) + return value, ok +} + +// You should always use this function to get a new ListVgpuProfilesParams instance, +// as then you are sure you have configured all required params +func (s *GPUService) NewListVgpuProfilesParams() *ListVgpuProfilesParams { + p := &ListVgpuProfilesParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *GPUService) GetVgpuProfileID(name string, opts ...OptionFunc) (string, int, error) { + p := &ListVgpuProfilesParams{} + p.p = make(map[string]interface{}) + + p.p["name"] = name + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListVgpuProfiles(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) + } + + if l.Count == 1 { + return l.VgpuProfiles[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.VgpuProfiles { + if v.Name == name { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *GPUService) GetVgpuProfileByName(name string, opts ...OptionFunc) (*VgpuProfile, int, error) { + id, count, err := s.GetVgpuProfileID(name, opts...) + if err != nil { + return nil, count, err + } + + r, count, err := s.GetVgpuProfileByID(id, opts...) + if err != nil { + return nil, count, err + } + return r, count, nil +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *GPUService) GetVgpuProfileByID(id string, opts ...OptionFunc) (*VgpuProfile, int, error) { + p := &ListVgpuProfilesParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListVgpuProfiles(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.VgpuProfiles[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for VgpuProfile UUID: %s!", id) +} + +// Lists all available vGPU profiles +func (s *GPUService) ListVgpuProfiles(p *ListVgpuProfilesParams) (*ListVgpuProfilesResponse, error) { + resp, err := s.cs.newRequest("listVgpuProfiles", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListVgpuProfilesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListVgpuProfilesResponse struct { + Count int `json:"count"` + VgpuProfiles []*VgpuProfile `json:"vgpuprofile"` +} + +type VgpuProfile struct { + Description string `json:"description"` + Deviceid string `json:"deviceid"` + Devicename string `json:"devicename"` + Gpucardid string `json:"gpucardid"` + Gpucardname string `json:"gpucardname"` + Id string `json:"id"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Maxheads int64 `json:"maxheads"` + Maxresolutionx int64 `json:"maxresolutionx"` + Maxresolutiony int64 `json:"maxresolutiony"` + Maxvgpuperphysicalgpu int64 `json:"maxvgpuperphysicalgpu"` + Name string `json:"name"` + Vendorid string `json:"vendorid"` + Vendorname string `json:"vendorname"` + Videoram int64 `json:"videoram"` +} + +type ManageGpuDeviceParams struct { + p map[string]interface{} +} + +func (p *ManageGpuDeviceParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["ids"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("ids", vv) + } + return u +} + +func (p *ManageGpuDeviceParams) SetIds(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ids"] = v +} + +func (p *ManageGpuDeviceParams) ResetIds() { + if p.p != nil && p.p["ids"] != nil { + delete(p.p, "ids") + } +} + +func (p *ManageGpuDeviceParams) GetIds() ([]string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["ids"].([]string) + return value, ok +} + +// You should always use this function to get a new ManageGpuDeviceParams instance, +// as then you are sure you have configured all required params +func (s *GPUService) NewManageGpuDeviceParams(ids []string) *ManageGpuDeviceParams { + p := &ManageGpuDeviceParams{} + p.p = make(map[string]interface{}) + p.p["ids"] = ids + return p +} + +// Manages a GPU device +func (s *GPUService) ManageGpuDevice(p *ManageGpuDeviceParams) (*ManageGpuDeviceResponse, error) { + resp, err := s.cs.newPostRequest("manageGpuDevice", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ManageGpuDeviceResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ManageGpuDeviceResponse struct { + Displaytext string `json:"displaytext"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Success bool `json:"success"` +} + +func (r *ManageGpuDeviceResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + if ostypeid, ok := m["ostypeid"].(float64); ok { + m["ostypeid"] = strconv.Itoa(int(ostypeid)) + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias ManageGpuDeviceResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type UnmanageGpuDeviceParams struct { + p map[string]interface{} +} + +func (p *UnmanageGpuDeviceParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["ids"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("ids", vv) + } + return u +} + +func (p *UnmanageGpuDeviceParams) SetIds(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ids"] = v +} + +func (p *UnmanageGpuDeviceParams) ResetIds() { + if p.p != nil && p.p["ids"] != nil { + delete(p.p, "ids") + } +} + +func (p *UnmanageGpuDeviceParams) GetIds() ([]string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["ids"].([]string) + return value, ok +} + +// You should always use this function to get a new UnmanageGpuDeviceParams instance, +// as then you are sure you have configured all required params +func (s *GPUService) NewUnmanageGpuDeviceParams(ids []string) *UnmanageGpuDeviceParams { + p := &UnmanageGpuDeviceParams{} + p.p = make(map[string]interface{}) + p.p["ids"] = ids + return p +} + +// Unmanage a GPU device +func (s *GPUService) UnmanageGpuDevice(p *UnmanageGpuDeviceParams) (*UnmanageGpuDeviceResponse, error) { + resp, err := s.cs.newPostRequest("unmanageGpuDevice", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UnmanageGpuDeviceResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UnmanageGpuDeviceResponse struct { + Displaytext string `json:"displaytext"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Success bool `json:"success"` +} + +func (r *UnmanageGpuDeviceResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + if ostypeid, ok := m["ostypeid"].(float64); ok { + m["ostypeid"] = strconv.Itoa(int(ostypeid)) + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias UnmanageGpuDeviceResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type UpdateGpuCardParams struct { + p map[string]interface{} +} + +func (p *UpdateGpuCardParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["devicename"]; found { + u.Set("devicename", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["vendorname"]; found { + u.Set("vendorname", v.(string)) + } + return u +} + +func (p *UpdateGpuCardParams) SetDevicename(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["devicename"] = v +} + +func (p *UpdateGpuCardParams) ResetDevicename() { + if p.p != nil && p.p["devicename"] != nil { + delete(p.p, "devicename") + } +} + +func (p *UpdateGpuCardParams) GetDevicename() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["devicename"].(string) + return value, ok +} + +func (p *UpdateGpuCardParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v +} + +func (p *UpdateGpuCardParams) ResetId() { + if p.p != nil && p.p["id"] != nil { + delete(p.p, "id") + } +} + +func (p *UpdateGpuCardParams) GetId() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["id"].(string) + return value, ok +} + +func (p *UpdateGpuCardParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v +} + +func (p *UpdateGpuCardParams) ResetName() { + if p.p != nil && p.p["name"] != nil { + delete(p.p, "name") + } +} + +func (p *UpdateGpuCardParams) GetName() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["name"].(string) + return value, ok +} + +func (p *UpdateGpuCardParams) SetVendorname(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vendorname"] = v +} + +func (p *UpdateGpuCardParams) ResetVendorname() { + if p.p != nil && p.p["vendorname"] != nil { + delete(p.p, "vendorname") + } +} + +func (p *UpdateGpuCardParams) GetVendorname() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["vendorname"].(string) + return value, ok +} + +// You should always use this function to get a new UpdateGpuCardParams instance, +// as then you are sure you have configured all required params +func (s *GPUService) NewUpdateGpuCardParams(id string) *UpdateGpuCardParams { + p := &UpdateGpuCardParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates a GPU card definition in the system +func (s *GPUService) UpdateGpuCard(p *UpdateGpuCardParams) (*UpdateGpuCardResponse, error) { + resp, err := s.cs.newPostRequest("updateGpuCard", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateGpuCardResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UpdateGpuCardResponse struct { + Deviceid string `json:"deviceid"` + Devicename string `json:"devicename"` + Id string `json:"id"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Name string `json:"name"` + Vendorid string `json:"vendorid"` + Vendorname string `json:"vendorname"` +} + +type UpdateGpuDeviceParams struct { + p map[string]interface{} +} + +func (p *UpdateGpuDeviceParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["gpucardid"]; found { + u.Set("gpucardid", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["numanode"]; found { + u.Set("numanode", v.(string)) + } + if v, found := p.p["parentgpudeviceid"]; found { + u.Set("parentgpudeviceid", v.(string)) + } + if v, found := p.p["type"]; found { + u.Set("type", v.(string)) + } + if v, found := p.p["vgpuprofileid"]; found { + u.Set("vgpuprofileid", v.(string)) + } + return u +} + +func (p *UpdateGpuDeviceParams) SetGpucardid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["gpucardid"] = v +} + +func (p *UpdateGpuDeviceParams) ResetGpucardid() { + if p.p != nil && p.p["gpucardid"] != nil { + delete(p.p, "gpucardid") + } +} + +func (p *UpdateGpuDeviceParams) GetGpucardid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["gpucardid"].(string) + return value, ok +} + +func (p *UpdateGpuDeviceParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v +} + +func (p *UpdateGpuDeviceParams) ResetId() { + if p.p != nil && p.p["id"] != nil { + delete(p.p, "id") + } +} + +func (p *UpdateGpuDeviceParams) GetId() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["id"].(string) + return value, ok +} + +func (p *UpdateGpuDeviceParams) SetNumanode(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["numanode"] = v +} + +func (p *UpdateGpuDeviceParams) ResetNumanode() { + if p.p != nil && p.p["numanode"] != nil { + delete(p.p, "numanode") + } +} + +func (p *UpdateGpuDeviceParams) GetNumanode() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["numanode"].(string) + return value, ok +} + +func (p *UpdateGpuDeviceParams) SetParentgpudeviceid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["parentgpudeviceid"] = v +} + +func (p *UpdateGpuDeviceParams) ResetParentgpudeviceid() { + if p.p != nil && p.p["parentgpudeviceid"] != nil { + delete(p.p, "parentgpudeviceid") + } +} + +func (p *UpdateGpuDeviceParams) GetParentgpudeviceid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["parentgpudeviceid"].(string) + return value, ok +} + +func (p *UpdateGpuDeviceParams) SetType(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["type"] = v +} + +func (p *UpdateGpuDeviceParams) ResetType() { + if p.p != nil && p.p["type"] != nil { + delete(p.p, "type") + } +} + +func (p *UpdateGpuDeviceParams) GetType() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["type"].(string) + return value, ok +} + +func (p *UpdateGpuDeviceParams) SetVgpuprofileid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vgpuprofileid"] = v +} + +func (p *UpdateGpuDeviceParams) ResetVgpuprofileid() { + if p.p != nil && p.p["vgpuprofileid"] != nil { + delete(p.p, "vgpuprofileid") + } +} + +func (p *UpdateGpuDeviceParams) GetVgpuprofileid() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["vgpuprofileid"].(string) + return value, ok +} + +// You should always use this function to get a new UpdateGpuDeviceParams instance, +// as then you are sure you have configured all required params +func (s *GPUService) NewUpdateGpuDeviceParams(id string) *UpdateGpuDeviceParams { + p := &UpdateGpuDeviceParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates an existing GPU device +func (s *GPUService) UpdateGpuDevice(p *UpdateGpuDeviceParams) (*UpdateGpuDeviceResponse, error) { + resp, err := s.cs.newPostRequest("updateGpuDevice", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateGpuDeviceResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UpdateGpuDeviceResponse struct { + Busaddress string `json:"busaddress"` + Gpucardid string `json:"gpucardid"` + Gpucardname string `json:"gpucardname"` + Gpudevicetype string `json:"gpudevicetype"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Id string `json:"id"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Managedstate string `json:"managedstate"` + Numanode string `json:"numanode"` + Parentgpudeviceid string `json:"parentgpudeviceid"` + State string `json:"state"` + Vgpuprofileid string `json:"vgpuprofileid"` + Vgpuprofilename string `json:"vgpuprofilename"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualmachinename string `json:"virtualmachinename"` + Vmstate string `json:"vmstate"` +} + +type UpdateVgpuProfileParams struct { + p map[string]interface{} +} + +func (p *UpdateVgpuProfileParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["description"]; found { + u.Set("description", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["maxheads"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("maxheads", vv) + } + if v, found := p.p["maxresolutionx"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("maxresolutionx", vv) + } + if v, found := p.p["maxresolutiony"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("maxresolutiony", vv) + } + if v, found := p.p["maxvgpuperphysicalgpu"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("maxvgpuperphysicalgpu", vv) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["videoram"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("videoram", vv) + } + return u +} + +func (p *UpdateVgpuProfileParams) SetDescription(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["description"] = v +} + +func (p *UpdateVgpuProfileParams) ResetDescription() { + if p.p != nil && p.p["description"] != nil { + delete(p.p, "description") + } +} + +func (p *UpdateVgpuProfileParams) GetDescription() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["description"].(string) + return value, ok +} + +func (p *UpdateVgpuProfileParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v +} + +func (p *UpdateVgpuProfileParams) ResetId() { + if p.p != nil && p.p["id"] != nil { + delete(p.p, "id") + } +} + +func (p *UpdateVgpuProfileParams) GetId() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["id"].(string) + return value, ok +} + +func (p *UpdateVgpuProfileParams) SetMaxheads(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["maxheads"] = v +} + +func (p *UpdateVgpuProfileParams) ResetMaxheads() { + if p.p != nil && p.p["maxheads"] != nil { + delete(p.p, "maxheads") + } +} + +func (p *UpdateVgpuProfileParams) GetMaxheads() (int64, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["maxheads"].(int64) + return value, ok +} + +func (p *UpdateVgpuProfileParams) SetMaxresolutionx(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["maxresolutionx"] = v +} + +func (p *UpdateVgpuProfileParams) ResetMaxresolutionx() { + if p.p != nil && p.p["maxresolutionx"] != nil { + delete(p.p, "maxresolutionx") + } +} + +func (p *UpdateVgpuProfileParams) GetMaxresolutionx() (int64, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["maxresolutionx"].(int64) + return value, ok +} + +func (p *UpdateVgpuProfileParams) SetMaxresolutiony(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["maxresolutiony"] = v +} + +func (p *UpdateVgpuProfileParams) ResetMaxresolutiony() { + if p.p != nil && p.p["maxresolutiony"] != nil { + delete(p.p, "maxresolutiony") + } +} + +func (p *UpdateVgpuProfileParams) GetMaxresolutiony() (int64, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["maxresolutiony"].(int64) + return value, ok +} + +func (p *UpdateVgpuProfileParams) SetMaxvgpuperphysicalgpu(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["maxvgpuperphysicalgpu"] = v +} + +func (p *UpdateVgpuProfileParams) ResetMaxvgpuperphysicalgpu() { + if p.p != nil && p.p["maxvgpuperphysicalgpu"] != nil { + delete(p.p, "maxvgpuperphysicalgpu") + } +} + +func (p *UpdateVgpuProfileParams) GetMaxvgpuperphysicalgpu() (int64, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["maxvgpuperphysicalgpu"].(int64) + return value, ok +} + +func (p *UpdateVgpuProfileParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v +} + +func (p *UpdateVgpuProfileParams) ResetName() { + if p.p != nil && p.p["name"] != nil { + delete(p.p, "name") + } +} + +func (p *UpdateVgpuProfileParams) GetName() (string, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["name"].(string) + return value, ok +} + +func (p *UpdateVgpuProfileParams) SetVideoram(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["videoram"] = v +} + +func (p *UpdateVgpuProfileParams) ResetVideoram() { + if p.p != nil && p.p["videoram"] != nil { + delete(p.p, "videoram") + } +} + +func (p *UpdateVgpuProfileParams) GetVideoram() (int64, bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + value, ok := p.p["videoram"].(int64) + return value, ok +} + +// You should always use this function to get a new UpdateVgpuProfileParams instance, +// as then you are sure you have configured all required params +func (s *GPUService) NewUpdateVgpuProfileParams(id string) *UpdateVgpuProfileParams { + p := &UpdateVgpuProfileParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates a vGPU profile in the system +func (s *GPUService) UpdateVgpuProfile(p *UpdateVgpuProfileParams) (*UpdateVgpuProfileResponse, error) { + resp, err := s.cs.newPostRequest("updateVgpuProfile", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateVgpuProfileResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UpdateVgpuProfileResponse struct { + Description string `json:"description"` + Deviceid string `json:"deviceid"` + Devicename string `json:"devicename"` + Gpucardid string `json:"gpucardid"` + Gpucardname string `json:"gpucardname"` + Id string `json:"id"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Maxheads int64 `json:"maxheads"` + Maxresolutionx int64 `json:"maxresolutionx"` + Maxresolutiony int64 `json:"maxresolutiony"` + Maxvgpuperphysicalgpu int64 `json:"maxvgpuperphysicalgpu"` + Name string `json:"name"` + Vendorid string `json:"vendorid"` + Vendorname string `json:"vendorname"` + Videoram int64 `json:"videoram"` +} diff --git a/cloudstack/GPUService_mock.go b/cloudstack/GPUService_mock.go new file mode 100644 index 0000000..b6e2432 --- /dev/null +++ b/cloudstack/GPUService_mock.go @@ -0,0 +1,641 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +// Code generated by MockGen. DO NOT EDIT. +// Source: ./cloudstack/GPUService.go +// +// Generated by this command: +// +// mockgen -destination=./cloudstack/GPUService_mock.go -package=cloudstack -copyright_file=header.txt -source=./cloudstack/GPUService.go +// + +// Package cloudstack is a generated GoMock package. +package cloudstack + +import ( + reflect "reflect" + + gomock "go.uber.org/mock/gomock" +) + +// MockGPUServiceIface is a mock of GPUServiceIface interface. +type MockGPUServiceIface struct { + ctrl *gomock.Controller + recorder *MockGPUServiceIfaceMockRecorder + isgomock struct{} +} + +// MockGPUServiceIfaceMockRecorder is the mock recorder for MockGPUServiceIface. +type MockGPUServiceIfaceMockRecorder struct { + mock *MockGPUServiceIface +} + +// NewMockGPUServiceIface creates a new mock instance. +func NewMockGPUServiceIface(ctrl *gomock.Controller) *MockGPUServiceIface { + mock := &MockGPUServiceIface{ctrl: ctrl} + mock.recorder = &MockGPUServiceIfaceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockGPUServiceIface) EXPECT() *MockGPUServiceIfaceMockRecorder { + return m.recorder +} + +// CreateGpuCard mocks base method. +func (m *MockGPUServiceIface) CreateGpuCard(p *CreateGpuCardParams) (*CreateGpuCardResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateGpuCard", p) + ret0, _ := ret[0].(*CreateGpuCardResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateGpuCard indicates an expected call of CreateGpuCard. +func (mr *MockGPUServiceIfaceMockRecorder) CreateGpuCard(p any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateGpuCard", reflect.TypeOf((*MockGPUServiceIface)(nil).CreateGpuCard), p) +} + +// CreateGpuDevice mocks base method. +func (m *MockGPUServiceIface) CreateGpuDevice(p *CreateGpuDeviceParams) (*CreateGpuDeviceResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateGpuDevice", p) + ret0, _ := ret[0].(*CreateGpuDeviceResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateGpuDevice indicates an expected call of CreateGpuDevice. +func (mr *MockGPUServiceIfaceMockRecorder) CreateGpuDevice(p any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateGpuDevice", reflect.TypeOf((*MockGPUServiceIface)(nil).CreateGpuDevice), p) +} + +// CreateVgpuProfile mocks base method. +func (m *MockGPUServiceIface) CreateVgpuProfile(p *CreateVgpuProfileParams) (*CreateVgpuProfileResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateVgpuProfile", p) + ret0, _ := ret[0].(*CreateVgpuProfileResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateVgpuProfile indicates an expected call of CreateVgpuProfile. +func (mr *MockGPUServiceIfaceMockRecorder) CreateVgpuProfile(p any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateVgpuProfile", reflect.TypeOf((*MockGPUServiceIface)(nil).CreateVgpuProfile), p) +} + +// DeleteGpuCard mocks base method. +func (m *MockGPUServiceIface) DeleteGpuCard(p *DeleteGpuCardParams) (*DeleteGpuCardResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteGpuCard", p) + ret0, _ := ret[0].(*DeleteGpuCardResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DeleteGpuCard indicates an expected call of DeleteGpuCard. +func (mr *MockGPUServiceIfaceMockRecorder) DeleteGpuCard(p any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteGpuCard", reflect.TypeOf((*MockGPUServiceIface)(nil).DeleteGpuCard), p) +} + +// DeleteGpuDevice mocks base method. +func (m *MockGPUServiceIface) DeleteGpuDevice(p *DeleteGpuDeviceParams) (*DeleteGpuDeviceResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteGpuDevice", p) + ret0, _ := ret[0].(*DeleteGpuDeviceResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DeleteGpuDevice indicates an expected call of DeleteGpuDevice. +func (mr *MockGPUServiceIfaceMockRecorder) DeleteGpuDevice(p any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteGpuDevice", reflect.TypeOf((*MockGPUServiceIface)(nil).DeleteGpuDevice), p) +} + +// DeleteVgpuProfile mocks base method. +func (m *MockGPUServiceIface) DeleteVgpuProfile(p *DeleteVgpuProfileParams) (*DeleteVgpuProfileResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteVgpuProfile", p) + ret0, _ := ret[0].(*DeleteVgpuProfileResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DeleteVgpuProfile indicates an expected call of DeleteVgpuProfile. +func (mr *MockGPUServiceIfaceMockRecorder) DeleteVgpuProfile(p any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteVgpuProfile", reflect.TypeOf((*MockGPUServiceIface)(nil).DeleteVgpuProfile), p) +} + +// DiscoverGpuDevices mocks base method. +func (m *MockGPUServiceIface) DiscoverGpuDevices(p *DiscoverGpuDevicesParams) (*DiscoverGpuDevicesResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DiscoverGpuDevices", p) + ret0, _ := ret[0].(*DiscoverGpuDevicesResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DiscoverGpuDevices indicates an expected call of DiscoverGpuDevices. +func (mr *MockGPUServiceIfaceMockRecorder) DiscoverGpuDevices(p any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DiscoverGpuDevices", reflect.TypeOf((*MockGPUServiceIface)(nil).DiscoverGpuDevices), p) +} + +// GetGpuCardByID mocks base method. +func (m *MockGPUServiceIface) GetGpuCardByID(id string, opts ...OptionFunc) (*GpuCard, int, error) { + m.ctrl.T.Helper() + varargs := []any{id} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "GetGpuCardByID", varargs...) + ret0, _ := ret[0].(*GpuCard) + ret1, _ := ret[1].(int) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetGpuCardByID indicates an expected call of GetGpuCardByID. +func (mr *MockGPUServiceIfaceMockRecorder) GetGpuCardByID(id any, opts ...any) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]any{id}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetGpuCardByID", reflect.TypeOf((*MockGPUServiceIface)(nil).GetGpuCardByID), varargs...) +} + +// GetGpuCardByName mocks base method. +func (m *MockGPUServiceIface) GetGpuCardByName(name string, opts ...OptionFunc) (*GpuCard, int, error) { + m.ctrl.T.Helper() + varargs := []any{name} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "GetGpuCardByName", varargs...) + ret0, _ := ret[0].(*GpuCard) + ret1, _ := ret[1].(int) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetGpuCardByName indicates an expected call of GetGpuCardByName. +func (mr *MockGPUServiceIfaceMockRecorder) GetGpuCardByName(name any, opts ...any) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]any{name}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetGpuCardByName", reflect.TypeOf((*MockGPUServiceIface)(nil).GetGpuCardByName), varargs...) +} + +// GetGpuCardID mocks base method. +func (m *MockGPUServiceIface) GetGpuCardID(keyword string, opts ...OptionFunc) (string, int, error) { + m.ctrl.T.Helper() + varargs := []any{keyword} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "GetGpuCardID", varargs...) + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(int) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetGpuCardID indicates an expected call of GetGpuCardID. +func (mr *MockGPUServiceIfaceMockRecorder) GetGpuCardID(keyword any, opts ...any) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]any{keyword}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetGpuCardID", reflect.TypeOf((*MockGPUServiceIface)(nil).GetGpuCardID), varargs...) +} + +// GetGpuDeviceByID mocks base method. +func (m *MockGPUServiceIface) GetGpuDeviceByID(id string, opts ...OptionFunc) (*GpuDevice, int, error) { + m.ctrl.T.Helper() + varargs := []any{id} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "GetGpuDeviceByID", varargs...) + ret0, _ := ret[0].(*GpuDevice) + ret1, _ := ret[1].(int) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetGpuDeviceByID indicates an expected call of GetGpuDeviceByID. +func (mr *MockGPUServiceIfaceMockRecorder) GetGpuDeviceByID(id any, opts ...any) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]any{id}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetGpuDeviceByID", reflect.TypeOf((*MockGPUServiceIface)(nil).GetGpuDeviceByID), varargs...) +} + +// GetVgpuProfileByID mocks base method. +func (m *MockGPUServiceIface) GetVgpuProfileByID(id string, opts ...OptionFunc) (*VgpuProfile, int, error) { + m.ctrl.T.Helper() + varargs := []any{id} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "GetVgpuProfileByID", varargs...) + ret0, _ := ret[0].(*VgpuProfile) + ret1, _ := ret[1].(int) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetVgpuProfileByID indicates an expected call of GetVgpuProfileByID. +func (mr *MockGPUServiceIfaceMockRecorder) GetVgpuProfileByID(id any, opts ...any) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]any{id}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetVgpuProfileByID", reflect.TypeOf((*MockGPUServiceIface)(nil).GetVgpuProfileByID), varargs...) +} + +// GetVgpuProfileByName mocks base method. +func (m *MockGPUServiceIface) GetVgpuProfileByName(name string, opts ...OptionFunc) (*VgpuProfile, int, error) { + m.ctrl.T.Helper() + varargs := []any{name} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "GetVgpuProfileByName", varargs...) + ret0, _ := ret[0].(*VgpuProfile) + ret1, _ := ret[1].(int) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetVgpuProfileByName indicates an expected call of GetVgpuProfileByName. +func (mr *MockGPUServiceIfaceMockRecorder) GetVgpuProfileByName(name any, opts ...any) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]any{name}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetVgpuProfileByName", reflect.TypeOf((*MockGPUServiceIface)(nil).GetVgpuProfileByName), varargs...) +} + +// GetVgpuProfileID mocks base method. +func (m *MockGPUServiceIface) GetVgpuProfileID(name string, opts ...OptionFunc) (string, int, error) { + m.ctrl.T.Helper() + varargs := []any{name} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "GetVgpuProfileID", varargs...) + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(int) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetVgpuProfileID indicates an expected call of GetVgpuProfileID. +func (mr *MockGPUServiceIfaceMockRecorder) GetVgpuProfileID(name any, opts ...any) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]any{name}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetVgpuProfileID", reflect.TypeOf((*MockGPUServiceIface)(nil).GetVgpuProfileID), varargs...) +} + +// ListGpuCards mocks base method. +func (m *MockGPUServiceIface) ListGpuCards(p *ListGpuCardsParams) (*ListGpuCardsResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListGpuCards", p) + ret0, _ := ret[0].(*ListGpuCardsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListGpuCards indicates an expected call of ListGpuCards. +func (mr *MockGPUServiceIfaceMockRecorder) ListGpuCards(p any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListGpuCards", reflect.TypeOf((*MockGPUServiceIface)(nil).ListGpuCards), p) +} + +// ListGpuDevices mocks base method. +func (m *MockGPUServiceIface) ListGpuDevices(p *ListGpuDevicesParams) (*ListGpuDevicesResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListGpuDevices", p) + ret0, _ := ret[0].(*ListGpuDevicesResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListGpuDevices indicates an expected call of ListGpuDevices. +func (mr *MockGPUServiceIfaceMockRecorder) ListGpuDevices(p any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListGpuDevices", reflect.TypeOf((*MockGPUServiceIface)(nil).ListGpuDevices), p) +} + +// ListVgpuProfiles mocks base method. +func (m *MockGPUServiceIface) ListVgpuProfiles(p *ListVgpuProfilesParams) (*ListVgpuProfilesResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListVgpuProfiles", p) + ret0, _ := ret[0].(*ListVgpuProfilesResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListVgpuProfiles indicates an expected call of ListVgpuProfiles. +func (mr *MockGPUServiceIfaceMockRecorder) ListVgpuProfiles(p any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListVgpuProfiles", reflect.TypeOf((*MockGPUServiceIface)(nil).ListVgpuProfiles), p) +} + +// ManageGpuDevice mocks base method. +func (m *MockGPUServiceIface) ManageGpuDevice(p *ManageGpuDeviceParams) (*ManageGpuDeviceResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ManageGpuDevice", p) + ret0, _ := ret[0].(*ManageGpuDeviceResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ManageGpuDevice indicates an expected call of ManageGpuDevice. +func (mr *MockGPUServiceIfaceMockRecorder) ManageGpuDevice(p any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ManageGpuDevice", reflect.TypeOf((*MockGPUServiceIface)(nil).ManageGpuDevice), p) +} + +// NewCreateGpuCardParams mocks base method. +func (m *MockGPUServiceIface) NewCreateGpuCardParams(deviceid, devicename, name, vendorid, vendorname string) *CreateGpuCardParams { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewCreateGpuCardParams", deviceid, devicename, name, vendorid, vendorname) + ret0, _ := ret[0].(*CreateGpuCardParams) + return ret0 +} + +// NewCreateGpuCardParams indicates an expected call of NewCreateGpuCardParams. +func (mr *MockGPUServiceIfaceMockRecorder) NewCreateGpuCardParams(deviceid, devicename, name, vendorid, vendorname any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewCreateGpuCardParams", reflect.TypeOf((*MockGPUServiceIface)(nil).NewCreateGpuCardParams), deviceid, devicename, name, vendorid, vendorname) +} + +// NewCreateGpuDeviceParams mocks base method. +func (m *MockGPUServiceIface) NewCreateGpuDeviceParams(busaddress, gpucardid, hostid, vgpuprofileid string) *CreateGpuDeviceParams { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewCreateGpuDeviceParams", busaddress, gpucardid, hostid, vgpuprofileid) + ret0, _ := ret[0].(*CreateGpuDeviceParams) + return ret0 +} + +// NewCreateGpuDeviceParams indicates an expected call of NewCreateGpuDeviceParams. +func (mr *MockGPUServiceIfaceMockRecorder) NewCreateGpuDeviceParams(busaddress, gpucardid, hostid, vgpuprofileid any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewCreateGpuDeviceParams", reflect.TypeOf((*MockGPUServiceIface)(nil).NewCreateGpuDeviceParams), busaddress, gpucardid, hostid, vgpuprofileid) +} + +// NewCreateVgpuProfileParams mocks base method. +func (m *MockGPUServiceIface) NewCreateVgpuProfileParams(gpucardid, name string) *CreateVgpuProfileParams { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewCreateVgpuProfileParams", gpucardid, name) + ret0, _ := ret[0].(*CreateVgpuProfileParams) + return ret0 +} + +// NewCreateVgpuProfileParams indicates an expected call of NewCreateVgpuProfileParams. +func (mr *MockGPUServiceIfaceMockRecorder) NewCreateVgpuProfileParams(gpucardid, name any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewCreateVgpuProfileParams", reflect.TypeOf((*MockGPUServiceIface)(nil).NewCreateVgpuProfileParams), gpucardid, name) +} + +// NewDeleteGpuCardParams mocks base method. +func (m *MockGPUServiceIface) NewDeleteGpuCardParams(id string) *DeleteGpuCardParams { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewDeleteGpuCardParams", id) + ret0, _ := ret[0].(*DeleteGpuCardParams) + return ret0 +} + +// NewDeleteGpuCardParams indicates an expected call of NewDeleteGpuCardParams. +func (mr *MockGPUServiceIfaceMockRecorder) NewDeleteGpuCardParams(id any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewDeleteGpuCardParams", reflect.TypeOf((*MockGPUServiceIface)(nil).NewDeleteGpuCardParams), id) +} + +// NewDeleteGpuDeviceParams mocks base method. +func (m *MockGPUServiceIface) NewDeleteGpuDeviceParams(ids []string) *DeleteGpuDeviceParams { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewDeleteGpuDeviceParams", ids) + ret0, _ := ret[0].(*DeleteGpuDeviceParams) + return ret0 +} + +// NewDeleteGpuDeviceParams indicates an expected call of NewDeleteGpuDeviceParams. +func (mr *MockGPUServiceIfaceMockRecorder) NewDeleteGpuDeviceParams(ids any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewDeleteGpuDeviceParams", reflect.TypeOf((*MockGPUServiceIface)(nil).NewDeleteGpuDeviceParams), ids) +} + +// NewDeleteVgpuProfileParams mocks base method. +func (m *MockGPUServiceIface) NewDeleteVgpuProfileParams(id string) *DeleteVgpuProfileParams { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewDeleteVgpuProfileParams", id) + ret0, _ := ret[0].(*DeleteVgpuProfileParams) + return ret0 +} + +// NewDeleteVgpuProfileParams indicates an expected call of NewDeleteVgpuProfileParams. +func (mr *MockGPUServiceIfaceMockRecorder) NewDeleteVgpuProfileParams(id any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewDeleteVgpuProfileParams", reflect.TypeOf((*MockGPUServiceIface)(nil).NewDeleteVgpuProfileParams), id) +} + +// NewDiscoverGpuDevicesParams mocks base method. +func (m *MockGPUServiceIface) NewDiscoverGpuDevicesParams(id string) *DiscoverGpuDevicesParams { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewDiscoverGpuDevicesParams", id) + ret0, _ := ret[0].(*DiscoverGpuDevicesParams) + return ret0 +} + +// NewDiscoverGpuDevicesParams indicates an expected call of NewDiscoverGpuDevicesParams. +func (mr *MockGPUServiceIfaceMockRecorder) NewDiscoverGpuDevicesParams(id any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewDiscoverGpuDevicesParams", reflect.TypeOf((*MockGPUServiceIface)(nil).NewDiscoverGpuDevicesParams), id) +} + +// NewListGpuCardsParams mocks base method. +func (m *MockGPUServiceIface) NewListGpuCardsParams() *ListGpuCardsParams { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewListGpuCardsParams") + ret0, _ := ret[0].(*ListGpuCardsParams) + return ret0 +} + +// NewListGpuCardsParams indicates an expected call of NewListGpuCardsParams. +func (mr *MockGPUServiceIfaceMockRecorder) NewListGpuCardsParams() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewListGpuCardsParams", reflect.TypeOf((*MockGPUServiceIface)(nil).NewListGpuCardsParams)) +} + +// NewListGpuDevicesParams mocks base method. +func (m *MockGPUServiceIface) NewListGpuDevicesParams() *ListGpuDevicesParams { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewListGpuDevicesParams") + ret0, _ := ret[0].(*ListGpuDevicesParams) + return ret0 +} + +// NewListGpuDevicesParams indicates an expected call of NewListGpuDevicesParams. +func (mr *MockGPUServiceIfaceMockRecorder) NewListGpuDevicesParams() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewListGpuDevicesParams", reflect.TypeOf((*MockGPUServiceIface)(nil).NewListGpuDevicesParams)) +} + +// NewListVgpuProfilesParams mocks base method. +func (m *MockGPUServiceIface) NewListVgpuProfilesParams() *ListVgpuProfilesParams { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewListVgpuProfilesParams") + ret0, _ := ret[0].(*ListVgpuProfilesParams) + return ret0 +} + +// NewListVgpuProfilesParams indicates an expected call of NewListVgpuProfilesParams. +func (mr *MockGPUServiceIfaceMockRecorder) NewListVgpuProfilesParams() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewListVgpuProfilesParams", reflect.TypeOf((*MockGPUServiceIface)(nil).NewListVgpuProfilesParams)) +} + +// NewManageGpuDeviceParams mocks base method. +func (m *MockGPUServiceIface) NewManageGpuDeviceParams(ids []string) *ManageGpuDeviceParams { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewManageGpuDeviceParams", ids) + ret0, _ := ret[0].(*ManageGpuDeviceParams) + return ret0 +} + +// NewManageGpuDeviceParams indicates an expected call of NewManageGpuDeviceParams. +func (mr *MockGPUServiceIfaceMockRecorder) NewManageGpuDeviceParams(ids any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewManageGpuDeviceParams", reflect.TypeOf((*MockGPUServiceIface)(nil).NewManageGpuDeviceParams), ids) +} + +// NewUnmanageGpuDeviceParams mocks base method. +func (m *MockGPUServiceIface) NewUnmanageGpuDeviceParams(ids []string) *UnmanageGpuDeviceParams { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewUnmanageGpuDeviceParams", ids) + ret0, _ := ret[0].(*UnmanageGpuDeviceParams) + return ret0 +} + +// NewUnmanageGpuDeviceParams indicates an expected call of NewUnmanageGpuDeviceParams. +func (mr *MockGPUServiceIfaceMockRecorder) NewUnmanageGpuDeviceParams(ids any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewUnmanageGpuDeviceParams", reflect.TypeOf((*MockGPUServiceIface)(nil).NewUnmanageGpuDeviceParams), ids) +} + +// NewUpdateGpuCardParams mocks base method. +func (m *MockGPUServiceIface) NewUpdateGpuCardParams(id string) *UpdateGpuCardParams { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewUpdateGpuCardParams", id) + ret0, _ := ret[0].(*UpdateGpuCardParams) + return ret0 +} + +// NewUpdateGpuCardParams indicates an expected call of NewUpdateGpuCardParams. +func (mr *MockGPUServiceIfaceMockRecorder) NewUpdateGpuCardParams(id any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewUpdateGpuCardParams", reflect.TypeOf((*MockGPUServiceIface)(nil).NewUpdateGpuCardParams), id) +} + +// NewUpdateGpuDeviceParams mocks base method. +func (m *MockGPUServiceIface) NewUpdateGpuDeviceParams(id string) *UpdateGpuDeviceParams { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewUpdateGpuDeviceParams", id) + ret0, _ := ret[0].(*UpdateGpuDeviceParams) + return ret0 +} + +// NewUpdateGpuDeviceParams indicates an expected call of NewUpdateGpuDeviceParams. +func (mr *MockGPUServiceIfaceMockRecorder) NewUpdateGpuDeviceParams(id any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewUpdateGpuDeviceParams", reflect.TypeOf((*MockGPUServiceIface)(nil).NewUpdateGpuDeviceParams), id) +} + +// NewUpdateVgpuProfileParams mocks base method. +func (m *MockGPUServiceIface) NewUpdateVgpuProfileParams(id string) *UpdateVgpuProfileParams { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewUpdateVgpuProfileParams", id) + ret0, _ := ret[0].(*UpdateVgpuProfileParams) + return ret0 +} + +// NewUpdateVgpuProfileParams indicates an expected call of NewUpdateVgpuProfileParams. +func (mr *MockGPUServiceIfaceMockRecorder) NewUpdateVgpuProfileParams(id any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewUpdateVgpuProfileParams", reflect.TypeOf((*MockGPUServiceIface)(nil).NewUpdateVgpuProfileParams), id) +} + +// UnmanageGpuDevice mocks base method. +func (m *MockGPUServiceIface) UnmanageGpuDevice(p *UnmanageGpuDeviceParams) (*UnmanageGpuDeviceResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UnmanageGpuDevice", p) + ret0, _ := ret[0].(*UnmanageGpuDeviceResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UnmanageGpuDevice indicates an expected call of UnmanageGpuDevice. +func (mr *MockGPUServiceIfaceMockRecorder) UnmanageGpuDevice(p any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UnmanageGpuDevice", reflect.TypeOf((*MockGPUServiceIface)(nil).UnmanageGpuDevice), p) +} + +// UpdateGpuCard mocks base method. +func (m *MockGPUServiceIface) UpdateGpuCard(p *UpdateGpuCardParams) (*UpdateGpuCardResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UpdateGpuCard", p) + ret0, _ := ret[0].(*UpdateGpuCardResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UpdateGpuCard indicates an expected call of UpdateGpuCard. +func (mr *MockGPUServiceIfaceMockRecorder) UpdateGpuCard(p any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateGpuCard", reflect.TypeOf((*MockGPUServiceIface)(nil).UpdateGpuCard), p) +} + +// UpdateGpuDevice mocks base method. +func (m *MockGPUServiceIface) UpdateGpuDevice(p *UpdateGpuDeviceParams) (*UpdateGpuDeviceResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UpdateGpuDevice", p) + ret0, _ := ret[0].(*UpdateGpuDeviceResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UpdateGpuDevice indicates an expected call of UpdateGpuDevice. +func (mr *MockGPUServiceIfaceMockRecorder) UpdateGpuDevice(p any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateGpuDevice", reflect.TypeOf((*MockGPUServiceIface)(nil).UpdateGpuDevice), p) +} + +// UpdateVgpuProfile mocks base method. +func (m *MockGPUServiceIface) UpdateVgpuProfile(p *UpdateVgpuProfileParams) (*UpdateVgpuProfileResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UpdateVgpuProfile", p) + ret0, _ := ret[0].(*UpdateVgpuProfileResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UpdateVgpuProfile indicates an expected call of UpdateVgpuProfile. +func (mr *MockGPUServiceIfaceMockRecorder) UpdateVgpuProfile(p any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateVgpuProfile", reflect.TypeOf((*MockGPUServiceIface)(nil).UpdateVgpuProfile), p) +} diff --git a/cloudstack/cloudstack.go b/cloudstack/cloudstack.go index ee8df3c..d7d0d4c 100644 --- a/cloudstack/cloudstack.go +++ b/cloudstack/cloudstack.go @@ -126,6 +126,7 @@ type CloudStackClient struct { Domain DomainServiceIface Event EventServiceIface Firewall FirewallServiceIface + GPU GPUServiceIface GuestOS GuestOSServiceIface Host HostServiceIface Hypervisor HypervisorServiceIface @@ -253,6 +254,7 @@ func newClient(apiurl string, apikey string, secret string, async bool, verifyss cs.Domain = NewDomainService(cs) cs.Event = NewEventService(cs) cs.Firewall = NewFirewallService(cs) + cs.GPU = NewGPUService(cs) cs.GuestOS = NewGuestOSService(cs) cs.Host = NewHostService(cs) cs.Hypervisor = NewHypervisorService(cs) @@ -353,6 +355,7 @@ func newMockClient(ctrl *gomock.Controller) *CloudStackClient { cs.Domain = NewMockDomainServiceIface(ctrl) cs.Event = NewMockEventServiceIface(ctrl) cs.Firewall = NewMockFirewallServiceIface(ctrl) + cs.GPU = NewMockGPUServiceIface(ctrl) cs.GuestOS = NewMockGuestOSServiceIface(ctrl) cs.Host = NewMockHostServiceIface(ctrl) cs.Hypervisor = NewMockHypervisorServiceIface(ctrl) @@ -1020,6 +1023,14 @@ func NewFirewallService(cs *CloudStackClient) FirewallServiceIface { return &FirewallService{cs: cs} } +type GPUService struct { + cs *CloudStackClient +} + +func NewGPUService(cs *CloudStackClient) GPUServiceIface { + return &GPUService{cs: cs} +} + type GuestOSService struct { cs *CloudStackClient } diff --git a/generate/layout.go b/generate/layout.go index a878a67..35da410 100644 --- a/generate/layout.go +++ b/generate/layout.go @@ -398,6 +398,23 @@ var layout = apiInfo{ "validateUserTwoFactorAuthenticationCode", "verifyOAuthCodeAndGetUser", }, + "GPUService": { + "createGpuCard", + "createGpuDevice", + "createVgpuProfile", + "deleteGpuCard", + "deleteGpuDevice", + "deleteVgpuProfile", + "discoverGpuDevices", + "listGpuCards", + "listGpuDevices", + "listVgpuProfiles", + "manageGpuDevice", + "unmanageGpuDevice", + "updateGpuCard", + "updateGpuDevice", + "updateVgpuProfile", + }, "LDAPService": { "addLdapConfiguration", "deleteLdapConfiguration", diff --git a/test/GPUService_test.go b/test/GPUService_test.go new file mode 100644 index 0000000..7ff2d34 --- /dev/null +++ b/test/GPUService_test.go @@ -0,0 +1,239 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +package test + +import ( + "testing" + + "github.com/apache/cloudstack-go/v2/cloudstack" +) + +func TestGPUService(t *testing.T) { + service := "GPUService" + response, err := readData(service) + if err != nil { + t.Skipf("Skipping test as %v", err) + } + server := CreateTestServer(t, response) + client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) + defer server.Close() + + testcreateGpuCard := func(t *testing.T) { + if _, ok := response["createGpuCard"]; !ok { + t.Skipf("Skipping as no json response is provided in testdata") + } + p := client.GPU.NewCreateGpuCardParams("deviceid", "devicename", "name", "vendorid", "vendorname") + r, err := client.GPU.CreateGpuCard(p) + if err != nil { + t.Errorf(err.Error()) + } + if r.Id == "" { + t.Errorf("Failed to parse response. ID not found") + } + } + t.Run("CreateGpuCard", testcreateGpuCard) + + testcreateGpuDevice := func(t *testing.T) { + if _, ok := response["createGpuDevice"]; !ok { + t.Skipf("Skipping as no json response is provided in testdata") + } + p := client.GPU.NewCreateGpuDeviceParams("busaddress", "gpucardid", "hostid", "vgpuprofileid") + r, err := client.GPU.CreateGpuDevice(p) + if err != nil { + t.Errorf(err.Error()) + } + if r.Id == "" { + t.Errorf("Failed to parse response. ID not found") + } + } + t.Run("CreateGpuDevice", testcreateGpuDevice) + + testcreateVgpuProfile := func(t *testing.T) { + if _, ok := response["createVgpuProfile"]; !ok { + t.Skipf("Skipping as no json response is provided in testdata") + } + p := client.GPU.NewCreateVgpuProfileParams("gpucardid", "name") + r, err := client.GPU.CreateVgpuProfile(p) + if err != nil { + t.Errorf(err.Error()) + } + if r.Id == "" { + t.Errorf("Failed to parse response. ID not found") + } + } + t.Run("CreateVgpuProfile", testcreateVgpuProfile) + + testdeleteGpuCard := func(t *testing.T) { + if _, ok := response["deleteGpuCard"]; !ok { + t.Skipf("Skipping as no json response is provided in testdata") + } + p := client.GPU.NewDeleteGpuCardParams("id") + _, err := client.GPU.DeleteGpuCard(p) + if err != nil { + t.Errorf(err.Error()) + } + } + t.Run("DeleteGpuCard", testdeleteGpuCard) + + testdeleteGpuDevice := func(t *testing.T) { + if _, ok := response["deleteGpuDevice"]; !ok { + t.Skipf("Skipping as no json response is provided in testdata") + } + p := client.GPU.NewDeleteGpuDeviceParams([]string{}) + _, err := client.GPU.DeleteGpuDevice(p) + if err != nil { + t.Errorf(err.Error()) + } + } + t.Run("DeleteGpuDevice", testdeleteGpuDevice) + + testdeleteVgpuProfile := func(t *testing.T) { + if _, ok := response["deleteVgpuProfile"]; !ok { + t.Skipf("Skipping as no json response is provided in testdata") + } + p := client.GPU.NewDeleteVgpuProfileParams("id") + _, err := client.GPU.DeleteVgpuProfile(p) + if err != nil { + t.Errorf(err.Error()) + } + } + t.Run("DeleteVgpuProfile", testdeleteVgpuProfile) + + testdiscoverGpuDevices := func(t *testing.T) { + if _, ok := response["discoverGpuDevices"]; !ok { + t.Skipf("Skipping as no json response is provided in testdata") + } + p := client.GPU.NewDiscoverGpuDevicesParams("id") + r, err := client.GPU.DiscoverGpuDevices(p) + if err != nil { + t.Errorf(err.Error()) + } + if r.Id == "" { + t.Errorf("Failed to parse response. ID not found") + } + } + t.Run("DiscoverGpuDevices", testdiscoverGpuDevices) + + testlistGpuCards := func(t *testing.T) { + if _, ok := response["listGpuCards"]; !ok { + t.Skipf("Skipping as no json response is provided in testdata") + } + p := client.GPU.NewListGpuCardsParams() + _, err := client.GPU.ListGpuCards(p) + if err != nil { + t.Errorf(err.Error()) + } + } + t.Run("ListGpuCards", testlistGpuCards) + + testlistGpuDevices := func(t *testing.T) { + if _, ok := response["listGpuDevices"]; !ok { + t.Skipf("Skipping as no json response is provided in testdata") + } + p := client.GPU.NewListGpuDevicesParams() + _, err := client.GPU.ListGpuDevices(p) + if err != nil { + t.Errorf(err.Error()) + } + } + t.Run("ListGpuDevices", testlistGpuDevices) + + testlistVgpuProfiles := func(t *testing.T) { + if _, ok := response["listVgpuProfiles"]; !ok { + t.Skipf("Skipping as no json response is provided in testdata") + } + p := client.GPU.NewListVgpuProfilesParams() + _, err := client.GPU.ListVgpuProfiles(p) + if err != nil { + t.Errorf(err.Error()) + } + } + t.Run("ListVgpuProfiles", testlistVgpuProfiles) + + testmanageGpuDevice := func(t *testing.T) { + if _, ok := response["manageGpuDevice"]; !ok { + t.Skipf("Skipping as no json response is provided in testdata") + } + p := client.GPU.NewManageGpuDeviceParams([]string{}) + _, err := client.GPU.ManageGpuDevice(p) + if err != nil { + t.Errorf(err.Error()) + } + } + t.Run("ManageGpuDevice", testmanageGpuDevice) + + testunmanageGpuDevice := func(t *testing.T) { + if _, ok := response["unmanageGpuDevice"]; !ok { + t.Skipf("Skipping as no json response is provided in testdata") + } + p := client.GPU.NewUnmanageGpuDeviceParams([]string{}) + _, err := client.GPU.UnmanageGpuDevice(p) + if err != nil { + t.Errorf(err.Error()) + } + } + t.Run("UnmanageGpuDevice", testunmanageGpuDevice) + + testupdateGpuCard := func(t *testing.T) { + if _, ok := response["updateGpuCard"]; !ok { + t.Skipf("Skipping as no json response is provided in testdata") + } + p := client.GPU.NewUpdateGpuCardParams("id") + r, err := client.GPU.UpdateGpuCard(p) + if err != nil { + t.Errorf(err.Error()) + } + if r.Id == "" { + t.Errorf("Failed to parse response. ID not found") + } + } + t.Run("UpdateGpuCard", testupdateGpuCard) + + testupdateGpuDevice := func(t *testing.T) { + if _, ok := response["updateGpuDevice"]; !ok { + t.Skipf("Skipping as no json response is provided in testdata") + } + p := client.GPU.NewUpdateGpuDeviceParams("id") + r, err := client.GPU.UpdateGpuDevice(p) + if err != nil { + t.Errorf(err.Error()) + } + if r.Id == "" { + t.Errorf("Failed to parse response. ID not found") + } + } + t.Run("UpdateGpuDevice", testupdateGpuDevice) + + testupdateVgpuProfile := func(t *testing.T) { + if _, ok := response["updateVgpuProfile"]; !ok { + t.Skipf("Skipping as no json response is provided in testdata") + } + p := client.GPU.NewUpdateVgpuProfileParams("id") + r, err := client.GPU.UpdateVgpuProfile(p) + if err != nil { + t.Errorf(err.Error()) + } + if r.Id == "" { + t.Errorf("Failed to parse response. ID not found") + } + } + t.Run("UpdateVgpuProfile", testupdateVgpuProfile) + +}