├── .rat-excludes ├── test ├── testdata │ ├── LimitService.json │ ├── AsyncJobService.json │ ├── HypervisorService.json │ ├── AuthenticationService.json │ ├── VPNService.json │ ├── NetworkACLService.json │ ├── CertificateService.json │ ├── AffinityGroupService.json │ ├── DiskOfferingService.json │ ├── ISOService.json │ ├── ImageStoreService.json │ ├── ResourcetagsService.json │ ├── ServiceOfferingService.json │ ├── ConfigurationService.json │ ├── PoolService.json │ ├── LoadBalancerService.json │ ├── AddressService.json │ ├── AnnotationService.json │ ├── VLANService.json │ ├── NetworkOfferingService.json │ ├── StoragePoolService.json │ └── FirewallService.json ├── APIDiscoveryService_test.go ├── CloudianService_test.go ├── MetricsService_test.go ├── SystemCapacityService_test.go ├── MiscService_test.go ├── InfrastructureUsageService_test.go ├── ResourceService_test.go ├── CloudIdentifierService_test.go ├── ConsoleEndpointService_test.go ├── RollingMaintenanceService_test.go ├── RegistrationService_test.go ├── ASNumberService_test.go ├── SwiftService_test.go ├── AsyncjobService_test.go ├── DiagnosticsService_test.go ├── StratosphereSSPService_test.go ├── OvsElementService_test.go ├── AuthenticationService_test.go ├── ASNumberRangeService_test.go ├── NsxService_test.go ├── OauthService_test.go ├── NetrisService_test.go ├── ResourceIconService_test.go ├── NetworkDeviceService_test.go ├── NiciraNVPService_test.go ├── BigSwitchBCFService_test.go ├── SolidFireService_test.go ├── HypervisorService_test.go ├── PortableIPService_test.go ├── IPQuarantineService_test.go ├── EventService_test.go ├── RegionService_test.go ├── ResourcetagsService_test.go ├── OutofbandManagementService_test.go ├── NicService_test.go ├── ObjectStoreService_test.go ├── VMGroupService_test.go ├── BrocadeVCSService_test.go ├── DiskOfferingService_test.go ├── AlertService_test.go ├── AnnotationService_test.go ├── LimitService_test.go ├── ServiceOfferingService_test.go ├── NetworkOfferingService_test.go ├── NATService_test.go └── ResourcemetadataService_test.go ├── go.mod ├── header.txt ├── .github ├── workflows │ ├── rat.yaml │ └── build.yml └── actions │ └── setup-go-and-build │ └── action.yml ├── .asf.yaml ├── .gitignore ├── examples ├── mock_test.go ├── ACSOps.go ├── AddHost.go └── CreateDeleteDomain.go ├── generate ├── regex.txt └── requiredParams.go ├── Makefile └── cloudstack ├── CustomService_mock.go ├── CloudianService.go ├── CustomService.go ├── InfrastructureUsageService.go ├── MetricsService.go ├── CloudIdentifierService.go ├── APIDiscoveryService_mock.go ├── MiscService.go ├── MetricsService_mock.go ├── CloudianService_mock.go ├── MiscService_mock.go ├── SystemCapacityService_mock.go └── ResourceService_mock.go /.rat-excludes: -------------------------------------------------------------------------------- 1 | .rat-excludes 2 | go.mod 3 | go.sum 4 | rat-report.txt 5 | apache-rat-0.17 6 | -------------------------------------------------------------------------------- /test/testdata/LimitService.json: -------------------------------------------------------------------------------- 1 | { 2 | "resetApiLimit": { 3 | "resetapilimitresponse": { 4 | "success": true 5 | } 6 | } 7 | } -------------------------------------------------------------------------------- /test/testdata/AsyncJobService.json: -------------------------------------------------------------------------------- 1 | { 2 | "listAsyncJobs": { 3 | "listasyncjobsresponse": { 4 | "asyncjobs": [ 5 | { 6 | "accountid": "bc1b465f-1d18-11ec-9173-50eb7122da94", 7 | "created": "2021-09-29T17:50:11+0530", 8 | "jobid": "6679e6b9-4bf2-4d83-b9f0-235fc1609227", 9 | "jobprocstatus": 0, 10 | "jobresultcode": 0, 11 | "userid": "bc1b60db-1d18-11ec-9173-50eb7122da94" 12 | } 13 | ], 14 | "count": 1 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /test/testdata/HypervisorService.json: -------------------------------------------------------------------------------- 1 | { 2 | "listHypervisorCapabilities": { 3 | "listhypervisorcapabilitiesresponse": { 4 | "count": 1, 5 | "hypervisorCapabilities": [ 6 | { 7 | "id": "1", 8 | "hypervisorversion": "default", 9 | "hypervisor": "XenServer", 10 | "maxguestslimit": 50, 11 | "securitygroupenabled": true, 12 | "maxdatavolumeslimit": 6, 13 | "storagemotionenabled": false 14 | } 15 | ] 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /test/testdata/AuthenticationService.json: -------------------------------------------------------------------------------- 1 | { 2 | "login": { 3 | "loginresponse": { 4 | "username": "admin", 5 | "userid": "27f2484f-5fe0-11ea-9a56-1e006800018c", 6 | "domainid": "e4874e10-5fdf-11ea-9a56-1e006800018c", 7 | "timeout": 3600, 8 | "account": "admin", 9 | "firstname": "admin", 10 | "lastname": "cloud", 11 | "type": "1", 12 | "timezone": "PST", 13 | "timezoneoffset": "-7.0", 14 | "registered": "false", 15 | "sessionkey": "umn5ciBuEdorc784g4pJr-U5POM" 16 | } 17 | }, 18 | "logout": { 19 | "logoutresponse": { 20 | "description": "success" 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /test/testdata/VPNService.json: -------------------------------------------------------------------------------- 1 | { 2 | "deleteRemoteAccessVpn": { 3 | "deleteremoteaccessvpnresponse": { 4 | "accountid": "7a2fad8f-2bde-11ec-b173-1e0086000207", 5 | "cmd": "org.apache.cloudstack.api.command.user.vpn.DeleteRemoteAccessVpnCmd", 6 | "completed": "2021-10-13T07:38:53+0000", 7 | "created": "2021-10-13T07:38:51+0000", 8 | "jobid": "50bdd6c2-6958-48ba-94fe-3e6ec410dcce", 9 | "jobprocstatus": 0, 10 | "jobresult": { 11 | "success": true 12 | }, 13 | "jobresultcode": 0, 14 | "jobresulttype": "object", 15 | "jobstatus": 1, 16 | "userid": "7a309dc2-2bde-11ec-b173-1e0086000207" 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/apache/cloudstack-go/v2 2 | 3 | go 1.23.0 4 | 5 | require ( 6 | github.com/onsi/ginkgo/v2 v2.9.1 7 | github.com/onsi/gomega v1.27.4 8 | go.uber.org/mock v0.5.0 9 | ) 10 | 11 | require ( 12 | github.com/go-logr/logr v1.2.3 // indirect 13 | github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect 14 | github.com/google/go-cmp v0.6.0 // indirect 15 | github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect 16 | golang.org/x/net v0.38.0 // indirect 17 | golang.org/x/sys v0.31.0 // indirect 18 | golang.org/x/text v0.23.0 // indirect 19 | golang.org/x/tools v0.22.0 // indirect 20 | gopkg.in/yaml.v3 v3.0.1 // indirect 21 | ) 22 | -------------------------------------------------------------------------------- /header.txt: -------------------------------------------------------------------------------- 1 | 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an 14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, either express or implied. See the License for the 16 | specific language governing permissions and limitations 17 | under the License. 18 | -------------------------------------------------------------------------------- /test/testdata/NetworkACLService.json: -------------------------------------------------------------------------------- 1 | { 2 | "updateNetworkACLList": { 3 | "updatenetworkacllistresponse": { 4 | "accountid": "27ef5ba2-5fe0-11ea-9a56-1e006800018c", 5 | "userid": "27f2484f-5fe0-11ea-9a56-1e006800018c", 6 | "cmd": "org.apache.cloudstack.api.command.user.network.UpdateNetworkACLListCmd", 7 | "jobstatus": 1, 8 | "jobprocstatus": 0, 9 | "jobresultcode": 0, 10 | "jobresulttype": "object", 11 | "jobresult": { 12 | "networkacllist": { 13 | "id": "a31e11a0-57fe-41df-be7a-34d359673061", 14 | "name": "test", 15 | "description": "testtest", 16 | "vpcid": "40419d33-6d48-4c54-ae2e-5c312b401593", 17 | "fordisplay": true 18 | } 19 | }, 20 | "created": "2021-10-13T04:46:30+0000", 21 | "completed": "2021-10-13T04:46:30+0000", 22 | "jobid": "6dd51379-b8cf-422c-a6ef-f96c07798c97" 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /test/testdata/CertificateService.json: -------------------------------------------------------------------------------- 1 | { 2 | "uploadCustomCertificate": { 3 | "uploadcustomcertificateresponse": { 4 | "accountid": "3bcbd8be-19eb-11ec-83a0-1e00bd000159", 5 | "userid": "3bcd30ee-19eb-11ec-83a0-1e00bd000159", 6 | "cmd": "org.apache.cloudstack.api.command.admin.resource.UploadCustomCertificateCmd", 7 | "jobstatus": 1, 8 | "jobprocstatus": 0, 9 | "jobresultcode": 0, 10 | "jobresulttype": "object", 11 | "jobresult": { 12 | "customcertificate": { 13 | "message": "Certificate has been successfully updated, if its the server certificate we would reboot all running console proxy VMs and secondary storage VMs to propagate the new certificate, please give a few minutes for console access and storage services service to be up and working again" 14 | } 15 | }, 16 | "created": "2021-10-02T07:43:59+0000", 17 | "completed": "2021-10-02T07:43:59+0000", 18 | "jobid": "bb14e24d-af95-4d9d-8ead-e4f42ccd83f7" 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /.github/workflows/rat.yaml: -------------------------------------------------------------------------------- 1 | name: RAT Check 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | branches: 9 | - '**' 10 | 11 | jobs: 12 | rat: 13 | name: Apache RAT Check 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - name: Checkout repository 18 | uses: actions/checkout@v4 19 | 20 | - name: Set up Java 21 | uses: actions/setup-java@v4 22 | with: 23 | distribution: temurin 24 | java-version: 17 25 | 26 | - name: Download Apache RAT 27 | run: | 28 | curl -L -O https://downloads.apache.org/creadur/apache-rat-0.17/apache-rat-0.17-bin.tar.gz 29 | tar -xzf apache-rat-0.17-bin.tar.gz 30 | 31 | - name: Run RAT 32 | run: | 33 | java -jar apache-rat-0.17/apache-rat-0.17.jar -d . -E .rat-excludes > rat-report.txt 34 | cat rat-report.txt 35 | # Fail if unapproved licenses are found 36 | grep -qe '^\s*Unapproved:\s*0\s*A count of unapproved licenses.$' rat-report.txt && exit 0 || exit 1 37 | -------------------------------------------------------------------------------- /test/testdata/AffinityGroupService.json: -------------------------------------------------------------------------------- 1 | { 2 | "createAffinityGroup": { 3 | "createaffinitygroupresponse": { 4 | "accountid": "27ef5ba2-5fe0-11ea-9a56-1e006800018c", 5 | "userid": "27f2484f-5fe0-11ea-9a56-1e006800018c", 6 | "cmd": "org.apache.cloudstack.api.command.user.affinitygroup.CreateAffinityGroupCmd", 7 | "jobstatus": 1, 8 | "jobprocstatus": 0, 9 | "jobresultcode": 0, 10 | "jobresulttype": "object", 11 | "jobresult": { 12 | "affinitygroup": { 13 | "id": "5059d7e3-9213-448d-9314-6ae4e1d95a33", 14 | "name": "testAffinityGroup", 15 | "description": "testAffinityGroup", 16 | "account": "admin", 17 | "domainid": "e4874e10-5fdf-11ea-9a56-1e006800018c", 18 | "domain": "ROOT", 19 | "type": "host affinity" 20 | } 21 | }, 22 | "jobinstancetype": "AffinityGroup", 23 | "created": "2021-10-01T16:59:04+0000", 24 | "completed": "2021-10-01T16:59:04+0000", 25 | "jobid": "58e969e8-768b-44d0-b278-fd1b2f236c00" 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /.asf.yaml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | github: 19 | description: "CloudStack Go SDK" 20 | homepage: https://cloudstack.apache.org 21 | labels: 22 | - go 23 | - golang 24 | - cloudstack 25 | features: 26 | wiki: true 27 | issues: true 28 | projects: true 29 | -------------------------------------------------------------------------------- /test/testdata/DiskOfferingService.json: -------------------------------------------------------------------------------- 1 | { 2 | "createDiskOffering": { 3 | "creatediskofferingresponse": { 4 | "diskoffering": { 5 | "id": "7662b6ae-f00b-4268-973f-f3f87eaf82c5", 6 | "name": "test", 7 | "displaytext": "test", 8 | "disksize": 0, 9 | "created": "2021-10-02T15:19:25+0000", 10 | "iscustomized": true, 11 | "storagetype": "shared", 12 | "provisioningtype": "thin", 13 | "cacheMode": "none", 14 | "displayoffering": true 15 | } 16 | } 17 | }, 18 | "listDiskOfferings": { 19 | "listdiskofferingsresponse": { 20 | "count": 1, 21 | "diskoffering": [ 22 | { 23 | "id": "7662b6ae-f00b-4268-973f-f3f87eaf82c5", 24 | "name": "test", 25 | "displaytext": "test", 26 | "disksize": 0, 27 | "created": "2021-10-02T15:19:25+0000", 28 | "iscustomized": true, 29 | "storagetype": "shared", 30 | "provisioningtype": "thin", 31 | "cacheMode": "none", 32 | "displayoffering": true 33 | } 34 | ] 35 | } 36 | }, 37 | "deleteDiskOffering": { 38 | "deletediskofferingresponse": { 39 | "success": true 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /test/testdata/ISOService.json: -------------------------------------------------------------------------------- 1 | { 2 | "registerIso": { 3 | "registerisoresponse": { 4 | "count": 1, 5 | "iso": [ 6 | { 7 | "id": "e6d86706-aa8c-444c-bf5c-ba677f8e02c2", 8 | "name": "testIso", 9 | "displaytext": "testIso", 10 | "ispublic": false, 11 | "created": "2021-10-03T07:28:41+0000", 12 | "isready": true, 13 | "passwordenabled": false, 14 | "bootable": true, 15 | "isfeatured": false, 16 | "crossZones": false, 17 | "ostypeid": "e510f742-5fdf-11ea-9a56-1e006800018c", 18 | "ostypename": "Other (64-bit)", 19 | "account": "admin", 20 | "zoneid": "1d8d87d4-1425-459c-8d81-c6f57dca2bd2", 21 | "zonename": "shouldwork", 22 | "status": "Successfully Installed", 23 | "size": 5242880, 24 | "domain": "ROOT", 25 | "domainid": "e4874e10-5fdf-11ea-9a56-1e006800018c", 26 | "isextractable": false, 27 | "bits": 64, 28 | "isdynamicallyscalable": false, 29 | "directdownload": false, 30 | "url": "http://dl.openvm.eu/cloudstack/iso/TinyCore-8.0.iso", 31 | "tags": [] 32 | } 33 | ] 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 19 | *.o 20 | *.a 21 | *.so 22 | 23 | # Folders 24 | _obj 25 | _test 26 | 27 | # Architecture specific extensions/prefixes 28 | *.[568vq] 29 | [568vq].out 30 | 31 | *.cgo1.go 32 | *.cgo2.c 33 | _cgo_defun.c 34 | _cgo_gotypes.go 35 | _cgo_export.* 36 | 37 | _testmain.go 38 | 39 | *.exe 40 | *.test 41 | 42 | generate/generate 43 | bin/mockgen 44 | 45 | -------------------------------------------------------------------------------- /test/testdata/ImageStoreService.json: -------------------------------------------------------------------------------- 1 | { 2 | "addImageStore": { 3 | "addimagestoreresponse": { 4 | "imagestore": { 5 | "id": "0ac85364-e31a-4840-97a4-a237b4291dfa", 6 | "zoneid": "04ccc336-d730-42fe-8ff6-5ae36e141e81", 7 | "zonename": "SimZone1", 8 | "name": "nfs://192.168.0.20/export/testing/secondary", 9 | "url": "nfs://192.168.0.20/export/testing/secondary", 10 | "protocol": "nfs", 11 | "providername": "NFS", 12 | "scope": "ZONE", 13 | "readonly": false 14 | } 15 | } 16 | }, 17 | "listImageStores": { 18 | "listimagestoresresponse": { 19 | "count": 1, 20 | "imagestore": [ 21 | { 22 | "id": "06f9e780-fac0-42fa-ac0e-e6eb6a038178", 23 | "zoneid": "3fc049b0-87ae-4d77-90c1-cce70da17db6", 24 | "zonename": "testAdvZone2", 25 | "name": "testAdvSecondaryStorage", 26 | "url": "nfs://10.70.4.150/export/testing/secondary2", 27 | "protocol": "nfs", 28 | "providername": "NFS", 29 | "scope": "ZONE", 30 | "readonly": false 31 | } 32 | ] 33 | } 34 | }, 35 | "deleteImageStore": { 36 | "deleteimagestoreresponse": { 37 | "success": true 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /test/testdata/ResourcetagsService.json: -------------------------------------------------------------------------------- 1 | { 2 | "createTags": { 3 | "createtagsresponse": { 4 | "accountid": "27ef5ba2-5fe0-11ea-9a56-1e006800018c", 5 | "cmd": "org.apache.cloudstack.api.command.user.tag.CreateTagsCmd", 6 | "completed": "2021-10-04T06:58:35+0000", 7 | "created": "2021-10-04T06:58:35+0000", 8 | "jobid": "4901a56e-60aa-4385-8ab6-8f9591ef0469", 9 | "jobprocstatus": 0, 10 | "jobresult": { 11 | "success": true 12 | }, 13 | "jobresultcode": 0, 14 | "jobresulttype": "object", 15 | "jobstatus": 1, 16 | "userid": "27f2484f-5fe0-11ea-9a56-1e006800018c" 17 | } 18 | }, 19 | "deleteTags": { 20 | "deletetagsresponse": { 21 | "accountid": "27ef5ba2-5fe0-11ea-9a56-1e006800018c", 22 | "cmd": "org.apache.cloudstack.api.command.user.tag.DeleteTagsCmd", 23 | "completed": "2021-10-04T07:07:22+0000", 24 | "created": "2021-10-04T07:07:22+0000", 25 | "jobid": "494d0f35-057a-4cc7-bf5d-b52d3b803a36", 26 | "jobprocstatus": 0, 27 | "jobresult": { 28 | "success": true 29 | }, 30 | "jobresultcode": 0, 31 | "jobresulttype": "object", 32 | "jobstatus": 1, 33 | "userid": "27f2484f-5fe0-11ea-9a56-1e006800018c" 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /examples/mock_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package main 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | "go.uber.org/mock/gomock" 27 | ) 28 | 29 | func Test_Mock(t *testing.T) { 30 | mockCtrl := gomock.NewController(t) 31 | cs := cloudstack.NewMockClient(mockCtrl) 32 | ms := cs.Host.(*cloudstack.MockHostServiceIface) 33 | 34 | ms.EXPECT().GetHostByID("host-id").Times(1).Return( 35 | &cloudstack.Host{ 36 | Id: "host-id", 37 | }, 2, nil) 38 | 39 | cs.Host.GetHostByID("host-id") 40 | } 41 | -------------------------------------------------------------------------------- /examples/ACSOps.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package main 21 | 22 | var ( 23 | ApiUrl = "http://qa.cloudstack.cloud:8080/client/api" 24 | SecretKey = "PZAM4nrxKbMnlq8RT0GMqAJyYtJGMN5x-PN7owa9vSmE58zObTcn4Yc8pgLeznln1aEUkHH_d2S-QQTt3E2Azw" 25 | ApiKey = "DN7uIwbqAMASSB1GUGHWvXqUlDDBf7H6A3XI-kNeXahW5LMUoqgfDEDWMv8zWKaj51fDozg8fjqc7tGCSozScA" 26 | ZoneId = "b6afade4-1919-4f0b-a785-12ff05a4d383" 27 | PodId = "83a739b7-bf5f-481e-8016-3a6045045e0b" 28 | ) 29 | 30 | func main() { 31 | AddHost() 32 | CreateDomain() 33 | PerformHostOperations() 34 | } 35 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | name: Build Check 19 | 20 | on: 21 | push: 22 | branches: [ "main" ] 23 | pull_request: 24 | branches: [ "main" ] 25 | 26 | permissions: 27 | contents: read 28 | 29 | jobs: 30 | 31 | build: 32 | runs-on: ubuntu-latest 33 | steps: 34 | - uses: actions/checkout@v4 35 | 36 | - name: Setup Go Environment 37 | uses: ./.github/actions/setup-go-and-build 38 | 39 | - name: Build 40 | run: | 41 | export PATH=$PATH:$(go env GOPATH)/bin 42 | make code 43 | make mocks 44 | 45 | - name: Test 46 | run: go test -v ./test/... ./examples/... 47 | -------------------------------------------------------------------------------- /examples/AddHost.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package main 21 | 22 | import ( 23 | "encoding/json" 24 | "fmt" 25 | "log" 26 | 27 | "github.com/apache/cloudstack-go/v2/cloudstack" 28 | ) 29 | 30 | func AddHost() { 31 | cs := cloudstack.NewAsyncClient(ApiUrl, ApiKey, SecretKey, false) 32 | p := cs.Host.NewAddHostParams("Simulator", PodId, 33 | "http://sim/c0/h0", ZoneId) 34 | p.SetUsername("root") 35 | p.SetPassword("password") 36 | resp, err := cs.Host.AddHost(p) 37 | if err != nil { 38 | fmt.Errorf("Failed to add host due to: %v", err) 39 | } 40 | 41 | b, err := json.MarshalIndent(resp, "", " ") 42 | if err != nil { 43 | fmt.Errorf("%v", err) 44 | return 45 | } 46 | log.Printf("Host response : %v", string(b)) 47 | } 48 | -------------------------------------------------------------------------------- /generate/regex.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | Below are some search/replace regex values (within single quotes) 21 | used within Sublime to format the API docs from the website. 22 | 23 | Maybe I'll add another function for this later on, but for now 24 | this also works fine... 25 | 26 | 27 | Search: '(.*)\n\n' 34 | Replace: ' $1' 35 | 36 | Search: '\n.*\n' 37 | Replace: '' 38 | 39 | Search: '^([\S]+)$' 40 | Replace: '},\n"$1Service": {' 41 | 42 | Search: '^([\S]+)\ ([\S]+)[^{]$' 43 | Replace: '},\n"$1$2Service": {' 44 | 45 | Search: ' \(A\)$' 46 | Replace: '' 47 | 48 | Search: '^ ([\S]+)$' 49 | Replace: ' "$1",' 50 | -------------------------------------------------------------------------------- /test/testdata/ServiceOfferingService.json: -------------------------------------------------------------------------------- 1 | { 2 | "createServiceOffering": { 3 | "createserviceofferingresponse": { 4 | "serviceoffering": { 5 | "id": "efaeeab0-4b09-4729-8b6f-62645db41b37", 6 | "name": "testServiceOffering", 7 | "displaytext": "testServiceOffering", 8 | "cpunumber": 2, 9 | "cpuspeed": 1000, 10 | "memory": 2048, 11 | "created": "2021-10-04T07:16:42+0000", 12 | "storagetype": "shared", 13 | "provisioningtype": "thin", 14 | "offerha": false, 15 | "limitcpuuse": false, 16 | "isvolatile": false, 17 | "issystem": false, 18 | "defaultuse": false, 19 | "iscustomized": false, 20 | "cacheMode": "none", 21 | "rootdisksize": 0 22 | } 23 | } 24 | }, 25 | "updateServiceOffering": { 26 | "updateserviceofferingresponse": { 27 | "serviceoffering": { 28 | "id": "efaeeab0-4b09-4729-8b6f-62645db41b37", 29 | "name": "testServiceOfferingUpdated", 30 | "displaytext": "testServiceOffering", 31 | "cpunumber": 2, 32 | "cpuspeed": 1000, 33 | "memory": 2048, 34 | "created": "2021-10-04T07:16:42+0000", 35 | "storagetype": "shared", 36 | "provisioningtype": "thin", 37 | "offerha": false, 38 | "limitcpuuse": false, 39 | "isvolatile": false, 40 | "issystem": false, 41 | "defaultuse": false, 42 | "iscustomized": false, 43 | "cacheMode": "none", 44 | "rootdisksize": 0 45 | } 46 | } 47 | }, 48 | "deleteServiceOffering": { 49 | "deleteserviceofferingresponse": { 50 | "success": true 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /test/APIDiscoveryService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestAPIDiscoveryService(t *testing.T) { 29 | service := "APIDiscoveryService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testlistApis := func(t *testing.T) { 39 | if _, ok := response["listApis"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.APIDiscovery.NewListApisParams() 43 | _, err := client.APIDiscovery.ListApis(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("ListApis", testlistApis) 49 | 50 | } 51 | -------------------------------------------------------------------------------- /test/CloudianService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestCloudianService(t *testing.T) { 29 | service := "CloudianService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testcloudianIsEnabled := func(t *testing.T) { 39 | if _, ok := response["cloudianIsEnabled"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.Cloudian.NewCloudianIsEnabledParams() 43 | _, err := client.Cloudian.CloudianIsEnabled(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("CloudianIsEnabled", testcloudianIsEnabled) 49 | 50 | } 51 | -------------------------------------------------------------------------------- /test/MetricsService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestMetricsService(t *testing.T) { 29 | service := "MetricsService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testlistInfrastructure := func(t *testing.T) { 39 | if _, ok := response["listInfrastructure"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.Metrics.NewListInfrastructureParams() 43 | _, err := client.Metrics.ListInfrastructure(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("ListInfrastructure", testlistInfrastructure) 49 | 50 | } 51 | -------------------------------------------------------------------------------- /test/SystemCapacityService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestSystemCapacityService(t *testing.T) { 29 | service := "SystemCapacityService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testlistCapacity := func(t *testing.T) { 39 | if _, ok := response["listCapacity"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.SystemCapacity.NewListCapacityParams() 43 | _, err := client.SystemCapacity.ListCapacity(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("ListCapacity", testlistCapacity) 49 | 50 | } 51 | -------------------------------------------------------------------------------- /test/MiscService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestMiscService(t *testing.T) { 29 | service := "MiscService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testlistElastistorInterface := func(t *testing.T) { 39 | if _, ok := response["listElastistorInterface"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.Misc.NewListElastistorInterfaceParams() 43 | _, err := client.Misc.ListElastistorInterface(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("ListElastistorInterface", testlistElastistorInterface) 49 | 50 | } 51 | -------------------------------------------------------------------------------- /test/InfrastructureUsageService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestInfrastructureUsageService(t *testing.T) { 29 | service := "InfrastructureUsageService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testlistDbMetrics := func(t *testing.T) { 39 | if _, ok := response["listDbMetrics"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.InfrastructureUsage.NewListDbMetricsParams() 43 | _, err := client.InfrastructureUsage.ListDbMetrics(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("ListDbMetrics", testlistDbMetrics) 49 | 50 | } 51 | -------------------------------------------------------------------------------- /test/ResourceService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestResourceService(t *testing.T) { 29 | service := "ResourceService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testpurgeExpungedResources := func(t *testing.T) { 39 | if _, ok := response["purgeExpungedResources"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.Resource.NewPurgeExpungedResourcesParams() 43 | _, err := client.Resource.PurgeExpungedResources(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("PurgeExpungedResources", testpurgeExpungedResources) 49 | 50 | } 51 | -------------------------------------------------------------------------------- /test/CloudIdentifierService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestCloudIdentifierService(t *testing.T) { 29 | service := "CloudIdentifierService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testgetCloudIdentifier := func(t *testing.T) { 39 | if _, ok := response["getCloudIdentifier"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.CloudIdentifier.NewGetCloudIdentifierParams("userid") 43 | _, err := client.CloudIdentifier.GetCloudIdentifier(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("GetCloudIdentifier", testgetCloudIdentifier) 49 | 50 | } 51 | -------------------------------------------------------------------------------- /test/ConsoleEndpointService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestConsoleEndpointService(t *testing.T) { 29 | service := "ConsoleEndpointService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testcreateConsoleEndpoint := func(t *testing.T) { 39 | if _, ok := response["createConsoleEndpoint"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.ConsoleEndpoint.NewCreateConsoleEndpointParams("virtualmachineid") 43 | _, err := client.ConsoleEndpoint.CreateConsoleEndpoint(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("CreateConsoleEndpoint", testcreateConsoleEndpoint) 49 | 50 | } 51 | -------------------------------------------------------------------------------- /test/RollingMaintenanceService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestRollingMaintenanceService(t *testing.T) { 29 | service := "RollingMaintenanceService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | teststartRollingMaintenance := func(t *testing.T) { 39 | if _, ok := response["startRollingMaintenance"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.RollingMaintenance.NewStartRollingMaintenanceParams() 43 | _, err := client.RollingMaintenance.StartRollingMaintenance(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("StartRollingMaintenance", teststartRollingMaintenance) 49 | 50 | } 51 | -------------------------------------------------------------------------------- /test/RegistrationService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestRegistrationService(t *testing.T) { 29 | service := "RegistrationService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testregisterOauthProvider := func(t *testing.T) { 39 | if _, ok := response["registerOauthProvider"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.Registration.NewRegisterOauthProviderParams("clientid", "description", "provider", "redirecturi", "secretkey") 43 | _, err := client.Registration.RegisterOauthProvider(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("RegisterOauthProvider", testregisterOauthProvider) 49 | 50 | } 51 | -------------------------------------------------------------------------------- /.github/actions/setup-go-and-build/action.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | name: 'Setup Go Environment' 19 | description: 'Set up Go with caching and install required tools' 20 | 21 | inputs: 22 | go-version: 23 | description: 'Go version to use' 24 | required: false 25 | default: '1.23' 26 | 27 | runs: 28 | using: 'composite' 29 | steps: 30 | - name: Set up Go 31 | uses: actions/setup-go@v5 32 | with: 33 | go-version: ${{ inputs.go-version }} 34 | check-latest: true 35 | 36 | - name: Cache Go modules 37 | uses: actions/cache@v4 38 | with: 39 | path: | 40 | ~/.cache/go-build 41 | ~/go/pkg/mod 42 | key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} 43 | restore-keys: | 44 | ${{ runner.os }}-go- 45 | 46 | - name: Set up tools 47 | shell: bash 48 | run: | 49 | go install golang.org/x/tools/cmd/goimports@latest 50 | go install go.uber.org/mock/mockgen@latest 51 | 52 | 53 | - name: Build 54 | shell: bash 55 | run: | 56 | export PATH=$PATH:$(go env GOPATH)/bin 57 | make code 58 | make mocks 59 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) 19 | ifeq (,$(shell go env GOBIN)) 20 | GOBIN=$(shell go env GOPATH)/bin 21 | else 22 | GOBIN=$(shell go env GOBIN) 23 | endif 24 | 25 | # Setting SHELL to bash allows bash commands to be executed by recipes. 26 | # This is a requirement for 'setup-envtest.sh' in the test target. 27 | # Options are set to exit when a recipe line exits non-zero or a piped command fails. 28 | SHELL = /usr/bin/env bash -o pipefail 29 | .SHELLFLAGS = -ec 30 | 31 | .PHONY: all code mocks test mockgen 32 | 33 | all: code mocks test 34 | 35 | code: 36 | go run generate/generate.go generate/layout.go generate/requiredParams.go --api=generate/listApis.json 37 | 38 | FILES=$(shell for file in `pwd`/cloudstack/*Service.go ;do basename $$file .go ; done) 39 | mocks: 40 | @for f in $(FILES); do \ 41 | $(MOCKGEN) -destination=./cloudstack/$${f}_mock.go -package=cloudstack -copyright_file="header.txt" -source=./cloudstack/$${f}.go ; \ 42 | done 43 | 44 | test: 45 | go test -v github.com/apache/cloudstack-go/v2/test 46 | 47 | MOCKGEN := mockgen 48 | mockgen: ## Install mockgen locally via go install. 49 | go install go.uber.org/mock/mockgen@latest 50 | 51 | -------------------------------------------------------------------------------- /generate/requiredParams.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package main 21 | 22 | // This map contains the API commands and the parameters which needs to be made 23 | // made required to ensure backward compatibility with the older versions of 24 | // the CloudStack API. 25 | 26 | var requiredParams = map[string][]string{ 27 | "createDiskOffering": { 28 | "displaytext", 29 | }, 30 | "createKubernetesCluster": { 31 | "description", 32 | "kubernetesversionid", 33 | "serviceofferingid", 34 | "size", 35 | }, 36 | "createNetworkACLList": { 37 | "vpcid", 38 | }, 39 | "createNetworkOffering": { 40 | "displaytext", 41 | }, 42 | "createProject": { 43 | "displaytext", 44 | }, 45 | "createServiceOffering": { 46 | "displaytext", 47 | }, 48 | "createTemplate": { 49 | "displaytext", 50 | }, 51 | "createVPC": { 52 | "displaytext", 53 | "cidr", 54 | }, 55 | "createVPCOffering": { 56 | "displaytext", 57 | }, 58 | "deployVirtualMachine": { 59 | "templateid", 60 | }, 61 | "disassociateIpAddress": { 62 | "id", 63 | }, 64 | "getUploadParamsForTemplate": { 65 | "displaytext", 66 | }, 67 | "registerIso": { 68 | "displaytext", 69 | }, 70 | "registerTemplate": { 71 | "displaytext", 72 | }, 73 | "updateGuestOs": { 74 | "osdisplayname", 75 | }, 76 | } 77 | -------------------------------------------------------------------------------- /test/testdata/ConfigurationService.json: -------------------------------------------------------------------------------- 1 | { 2 | "listCapabilities": { 3 | "listcapabilitiesresponse": { 4 | "capability": { 5 | "securitygroupsenabled": true, 6 | "dynamicrolesenabled": true, 7 | "cloudstackversion": "4.15.2.0", 8 | "userpublictemplateenabled": false, 9 | "supportELB": "false", 10 | "projectinviterequired": true, 11 | "allowusercreateprojects": true, 12 | "customdiskofferingminsize": 1, 13 | "customdiskofferingmaxsize": 1024, 14 | "regionsecondaryenabled": false, 15 | "kvmsnapshotenabled": true, 16 | "allowuserviewdestroyedvm": true, 17 | "allowuserexpungerecovervm": true, 18 | "allowuserexpungerecovervolume": true, 19 | "allowuserviewalldomainaccounts": false, 20 | "kubernetesserviceenabled": true, 21 | "kubernetesclusterexperimentalfeaturesenabled": true, 22 | "defaultuipagesize": 20 23 | } 24 | } 25 | }, 26 | "listConfigurations": { 27 | "listconfigurationsresponse": { 28 | "configuration": [ 29 | { 30 | "category": "Project Defaults", 31 | "description": "If regular user can create a project; true by default", 32 | "isdynamic": false, 33 | "name": "allow.user.create.projects", 34 | "value": "true" 35 | } 36 | ], 37 | "count": 1 38 | } 39 | }, 40 | "updateConfiguration": { 41 | "updateconfigurationresponse": { 42 | "configuration": { 43 | "category": "Project Defaults", 44 | "name": "allow.user.create.projects", 45 | "value": "false", 46 | "description": "If regular user can create a project; true by default", 47 | "isdynamic": false 48 | } 49 | } 50 | }, 51 | "resetConfiguration": { 52 | "resetconfigurationresponse":{ 53 | "configuration":{ 54 | "category":"Project Defaults", 55 | "name":"allow.user.create.projects", 56 | "value":"true", 57 | "description":"If regular user can create a project; true by default", 58 | "isdynamic":false 59 | } 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /test/ASNumberService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestASNumberService(t *testing.T) { 29 | service := "ASNumberService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testlistASNumbers := func(t *testing.T) { 39 | if _, ok := response["listASNumbers"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.ASNumber.NewListASNumbersParams() 43 | _, err := client.ASNumber.ListASNumbers(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("ListASNumbers", testlistASNumbers) 49 | 50 | testreleaseASNumber := func(t *testing.T) { 51 | if _, ok := response["releaseASNumber"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.ASNumber.NewReleaseASNumberParams(0, "zoneid") 55 | _, err := client.ASNumber.ReleaseASNumber(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | } 60 | t.Run("ReleaseASNumber", testreleaseASNumber) 61 | 62 | } 63 | -------------------------------------------------------------------------------- /test/SwiftService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestSwiftService(t *testing.T) { 29 | service := "SwiftService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testaddSwift := func(t *testing.T) { 39 | if _, ok := response["addSwift"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.Swift.NewAddSwiftParams("url") 43 | r, err := client.Swift.AddSwift(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | if r.Id == "" { 48 | t.Errorf("Failed to parse response. ID not found") 49 | } 50 | } 51 | t.Run("AddSwift", testaddSwift) 52 | 53 | testlistSwifts := func(t *testing.T) { 54 | if _, ok := response["listSwifts"]; !ok { 55 | t.Skipf("Skipping as no json response is provided in testdata") 56 | } 57 | p := client.Swift.NewListSwiftsParams() 58 | _, err := client.Swift.ListSwifts(p) 59 | if err != nil { 60 | t.Errorf(err.Error()) 61 | } 62 | } 63 | t.Run("ListSwifts", testlistSwifts) 64 | 65 | } 66 | -------------------------------------------------------------------------------- /test/testdata/PoolService.json: -------------------------------------------------------------------------------- 1 | { 2 | "createStoragePool": { 3 | "createstoragepoolresponse": { 4 | "storagepool": { 5 | "id": "3fd44942-4881-3fb0-95f1-5d7b7ae64cfb", 6 | "zoneid": "6ebc7a1c-ff98-425c-ac0d-b6c2e3ae6e33", 7 | "zonename": "TestZone", 8 | "podid": "6a1dbf48-8b8e-45ab-8249-cf43a86f012d", 9 | "podname": "TestPod", 10 | "name": "testPrimary1", 11 | "ipaddress": "10.1.1.2", 12 | "path": "/export/primary1", 13 | "created": "2021-10-04T08:17:38+0000", 14 | "type": "NetworkFilesystem", 15 | "clusterid": "a73fb4a4-642b-4ea4-92b8-b74ec8908534", 16 | "clustername": "TestCluster", 17 | "disksizetotal": 1099511627776, 18 | "disksizeallocated": 0, 19 | "state": "Up", 20 | "scope": "CLUSTER", 21 | "overprovisionfactor": "2.0", 22 | "provider": "DefaultPrimary" 23 | } 24 | } 25 | }, 26 | "listStoragePools": { 27 | "liststoragepoolsresponse": { 28 | "count": 1, 29 | "storagepool": [ 30 | { 31 | "clusterid": "a73fb4a4-642b-4ea4-92b8-b74ec8908534", 32 | "clustername": "TestCluster", 33 | "created": "2021-10-04T08:17:38+0000", 34 | "disksizeallocated": 0, 35 | "disksizetotal": 1099511627776, 36 | "disksizeused": 0, 37 | "id": "3fd44942-4881-3fb0-95f1-5d7b7ae64cfb", 38 | "ipaddress": "10.1.1.2", 39 | "name": "testPrimary1", 40 | "overprovisionfactor": "2.0", 41 | "path": "/export/primary1", 42 | "podid": "6a1dbf48-8b8e-45ab-8249-cf43a86f012d", 43 | "podname": "TestPod", 44 | "provider": "DefaultPrimary", 45 | "scope": "CLUSTER", 46 | "state": "Up", 47 | "storagecapabilities": { 48 | "VOLUME_SNAPSHOT_QUIESCEVM": "false" 49 | }, 50 | "type": "NetworkFilesystem", 51 | "zoneid": "6ebc7a1c-ff98-425c-ac0d-b6c2e3ae6e33", 52 | "zonename": "TestZone" 53 | } 54 | ] 55 | } 56 | }, 57 | "deleteStoragePool": { 58 | "deletestoragepoolresponse": { 59 | "success": true 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /test/AsyncjobService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestAsyncjobService(t *testing.T) { 29 | service := "AsyncjobService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testlistAsyncJobs := func(t *testing.T) { 39 | if _, ok := response["listAsyncJobs"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.Asyncjob.NewListAsyncJobsParams() 43 | _, err := client.Asyncjob.ListAsyncJobs(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("ListAsyncJobs", testlistAsyncJobs) 49 | 50 | testqueryAsyncJobResult := func(t *testing.T) { 51 | if _, ok := response["queryAsyncJobResult"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.Asyncjob.NewQueryAsyncJobResultParams("jobid") 55 | _, err := client.Asyncjob.QueryAsyncJobResult(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | } 60 | t.Run("QueryAsyncJobResult", testqueryAsyncJobResult) 61 | 62 | } 63 | -------------------------------------------------------------------------------- /cloudstack/CustomService_mock.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | // Code generated by MockGen. DO NOT EDIT. 21 | // Source: ./cloudstack/CustomService.go 22 | // 23 | // Generated by this command: 24 | // 25 | // mockgen -destination=./cloudstack/CustomService_mock.go -package=cloudstack -copyright_file=header.txt -source=./cloudstack/CustomService.go 26 | // 27 | 28 | // Package cloudstack is a generated GoMock package. 29 | package cloudstack 30 | 31 | import ( 32 | gomock "go.uber.org/mock/gomock" 33 | ) 34 | 35 | // MockCustomServiceIface is a mock of CustomServiceIface interface. 36 | type MockCustomServiceIface struct { 37 | ctrl *gomock.Controller 38 | recorder *MockCustomServiceIfaceMockRecorder 39 | isgomock struct{} 40 | } 41 | 42 | // MockCustomServiceIfaceMockRecorder is the mock recorder for MockCustomServiceIface. 43 | type MockCustomServiceIfaceMockRecorder struct { 44 | mock *MockCustomServiceIface 45 | } 46 | 47 | // NewMockCustomServiceIface creates a new mock instance. 48 | func NewMockCustomServiceIface(ctrl *gomock.Controller) *MockCustomServiceIface { 49 | mock := &MockCustomServiceIface{ctrl: ctrl} 50 | mock.recorder = &MockCustomServiceIfaceMockRecorder{mock} 51 | return mock 52 | } 53 | 54 | // EXPECT returns an object that allows the caller to indicate expected use. 55 | func (m *MockCustomServiceIface) EXPECT() *MockCustomServiceIfaceMockRecorder { 56 | return m.recorder 57 | } 58 | -------------------------------------------------------------------------------- /test/DiagnosticsService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestDiagnosticsService(t *testing.T) { 29 | service := "DiagnosticsService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testgetDiagnosticsData := func(t *testing.T) { 39 | if _, ok := response["getDiagnosticsData"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.Diagnostics.NewGetDiagnosticsDataParams("targetid") 43 | _, err := client.Diagnostics.GetDiagnosticsData(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("GetDiagnosticsData", testgetDiagnosticsData) 49 | 50 | testrunDiagnostics := func(t *testing.T) { 51 | if _, ok := response["runDiagnostics"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.Diagnostics.NewRunDiagnosticsParams("ipaddress", "targetid", "type") 55 | _, err := client.Diagnostics.RunDiagnostics(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | } 60 | t.Run("RunDiagnostics", testrunDiagnostics) 61 | 62 | } 63 | -------------------------------------------------------------------------------- /test/testdata/LoadBalancerService.json: -------------------------------------------------------------------------------- 1 | { 2 | "createLoadBalancerRule": { 3 | "createloadbalancerruleresponse": { 4 | "accountid": "27ef5ba2-5fe0-11ea-9a56-1e006800018c", 5 | "cmd": "org.apache.cloudstack.api.command.user.loadbalancer.CreateLoadBalancerRuleCmd", 6 | "completed": "2021-10-04T04:37:08+0000", 7 | "created": "2021-10-04T04:37:08+0000", 8 | "jobid": "83ab0ded-225b-4a91-9aed-c17b1da07989", 9 | "jobinstanceid": "d9186a3e-b39a-473f-8d5e-70cf1a7aed44", 10 | "jobinstancetype": "FirewallRule", 11 | "jobprocstatus": 0, 12 | "jobresult": { 13 | "loadbalancer": { 14 | "account": "admin", 15 | "algorithm": "roundrobin", 16 | "cidrlist": "", 17 | "domain": "ROOT", 18 | "domainid": "e4874e10-5fdf-11ea-9a56-1e006800018c", 19 | "fordisplay": true, 20 | "id": "d9186a3e-b39a-473f-8d5e-70cf1a7aed44", 21 | "name": "testLBRule", 22 | "networkid": "cc39d938-5ea0-4d9c-b89d-421da3274e54", 23 | "privateport": "9090", 24 | "protocol": "tcp", 25 | "publicip": "192.168.2.107", 26 | "publicipid": "bab02a09-1244-4235-a938-150e75e04ce0", 27 | "publicport": "9090", 28 | "state": "Add", 29 | "tags": [], 30 | "zoneid": "04ccc336-d730-42fe-8ff6-5ae36e141e81", 31 | "zonename": "SimZone1" 32 | } 33 | }, 34 | "jobresultcode": 0, 35 | "jobresulttype": "object", 36 | "jobstatus": 1, 37 | "userid": "27f2484f-5fe0-11ea-9a56-1e006800018c" 38 | } 39 | }, 40 | "assignLoadBalancerRule": { 41 | "assigntoloadbalancerruleresponse": { 42 | "accountid": "27ef5ba2-5fe0-11ea-9a56-1e006800018c", 43 | "userid": "27f2484f-5fe0-11ea-9a56-1e006800018c", 44 | "cmd": "org.apache.cloudstack.api.command.user.loadbalancer.AssignToLoadBalancerRuleCmd", 45 | "jobstatus": 1, 46 | "jobprocstatus": 0, 47 | "jobresultcode": 0, 48 | "jobresulttype": "object", 49 | "jobresult": { 50 | "success": true 51 | }, 52 | "created": "2021-10-03T07:52:26+0000", 53 | "completed": "2021-10-03T07:52:26+0000", 54 | "jobid": "7ab605d2-cddd-4f90-bd6b-884a8f62c16b" 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /test/StratosphereSSPService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestStratosphereSSPService(t *testing.T) { 29 | service := "StratosphereSSPService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testaddStratosphereSsp := func(t *testing.T) { 39 | if _, ok := response["addStratosphereSsp"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.StratosphereSSP.NewAddStratosphereSspParams("name", "url", "zoneid") 43 | _, err := client.StratosphereSSP.AddStratosphereSsp(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("AddStratosphereSsp", testaddStratosphereSsp) 49 | 50 | testdeleteStratosphereSsp := func(t *testing.T) { 51 | if _, ok := response["deleteStratosphereSsp"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.StratosphereSSP.NewDeleteStratosphereSspParams("hostid") 55 | _, err := client.StratosphereSSP.DeleteStratosphereSsp(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | } 60 | t.Run("DeleteStratosphereSsp", testdeleteStratosphereSsp) 61 | 62 | } 63 | -------------------------------------------------------------------------------- /test/OvsElementService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestOvsElementService(t *testing.T) { 29 | service := "OvsElementService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testconfigureOvsElement := func(t *testing.T) { 39 | if _, ok := response["configureOvsElement"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.OvsElement.NewConfigureOvsElementParams(true, "id") 43 | r, err := client.OvsElement.ConfigureOvsElement(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | if r.Id == "" { 48 | t.Errorf("Failed to parse response. ID not found") 49 | } 50 | } 51 | t.Run("ConfigureOvsElement", testconfigureOvsElement) 52 | 53 | testlistOvsElements := func(t *testing.T) { 54 | if _, ok := response["listOvsElements"]; !ok { 55 | t.Skipf("Skipping as no json response is provided in testdata") 56 | } 57 | p := client.OvsElement.NewListOvsElementsParams() 58 | _, err := client.OvsElement.ListOvsElements(p) 59 | if err != nil { 60 | t.Errorf(err.Error()) 61 | } 62 | } 63 | t.Run("ListOvsElements", testlistOvsElements) 64 | 65 | } 66 | -------------------------------------------------------------------------------- /cloudstack/CloudianService.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package cloudstack 21 | 22 | import ( 23 | "encoding/json" 24 | "net/url" 25 | ) 26 | 27 | type CloudianServiceIface interface { 28 | CloudianIsEnabled(p *CloudianIsEnabledParams) (*CloudianIsEnabledResponse, error) 29 | NewCloudianIsEnabledParams() *CloudianIsEnabledParams 30 | } 31 | 32 | type CloudianIsEnabledParams struct { 33 | p map[string]interface{} 34 | } 35 | 36 | func (p *CloudianIsEnabledParams) toURLValues() url.Values { 37 | u := url.Values{} 38 | if p.p == nil { 39 | return u 40 | } 41 | return u 42 | } 43 | 44 | // You should always use this function to get a new CloudianIsEnabledParams instance, 45 | // as then you are sure you have configured all required params 46 | func (s *CloudianService) NewCloudianIsEnabledParams() *CloudianIsEnabledParams { 47 | p := &CloudianIsEnabledParams{} 48 | p.p = make(map[string]interface{}) 49 | return p 50 | } 51 | 52 | // Checks if the Cloudian Connector is enabled 53 | func (s *CloudianService) CloudianIsEnabled(p *CloudianIsEnabledParams) (*CloudianIsEnabledResponse, error) { 54 | resp, err := s.cs.newRequest("cloudianIsEnabled", p.toURLValues()) 55 | if err != nil { 56 | return nil, err 57 | } 58 | 59 | var r CloudianIsEnabledResponse 60 | if err := json.Unmarshal(resp, &r); err != nil { 61 | return nil, err 62 | } 63 | 64 | return &r, nil 65 | } 66 | 67 | type CloudianIsEnabledResponse struct { 68 | Enabled bool `json:"enabled"` 69 | JobID string `json:"jobid"` 70 | Jobstatus int `json:"jobstatus"` 71 | Url string `json:"url"` 72 | } 73 | -------------------------------------------------------------------------------- /examples/CreateDeleteDomain.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package main 21 | 22 | import ( 23 | "encoding/json" 24 | "fmt" 25 | "log" 26 | 27 | "github.com/apache/cloudstack-go/v2/cloudstack" 28 | ) 29 | 30 | func CreateDomain() { 31 | domainName := "DummyDomain" 32 | cs := cloudstack.NewAsyncClient(ApiUrl, ApiKey, SecretKey, false) 33 | domain, _, err := cs.Domain.GetDomainByName(domainName) 34 | if err != nil { 35 | log.Printf("Failed to get domain with name %s due to %v", domainName, err) 36 | } 37 | if domain != nil { 38 | deleteParams := cs.Domain.NewDeleteDomainParams(domain.Id) 39 | delResp, err := cs.Domain.DeleteDomain(deleteParams) 40 | if err != nil { 41 | log.Fatalf("Failed to delete domain %s due to %v", domainName, err) 42 | } 43 | r, err := parseResponse(delResp) 44 | if err != nil { 45 | log.Fatalf("Failed to parse delete domain response due to %v", err) 46 | return 47 | } 48 | fmt.Printf("Delete response: %v\n\n", string(r)) 49 | } 50 | 51 | p := &cloudstack.CreateDomainParams{} 52 | p.SetParentdomainid("e4874e10-5fdf-11ea-9a56-1e006800018c") 53 | p.SetName("DummyDomain") 54 | resp, err := cs.Domain.CreateDomain(p) 55 | if err != nil { 56 | log.Fatalf("Failed to create domain due to: %v", err) 57 | return 58 | } 59 | b, err := json.MarshalIndent(resp, "", " ") 60 | if err != nil { 61 | log.Printf("%v", err) 62 | return 63 | } 64 | fmt.Printf("Create Domain response : %v\n\n", string(b)) 65 | } 66 | 67 | func parseResponse(resp interface{}) ([]byte, error) { 68 | b, err := json.MarshalIndent(resp, "", " ") 69 | if err != nil { 70 | log.Printf("%v", err) 71 | return nil, err 72 | } 73 | return b, nil 74 | } 75 | -------------------------------------------------------------------------------- /test/AuthenticationService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestAuthenticationService(t *testing.T) { 29 | service := "AuthenticationService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testlogin := func(t *testing.T) { 39 | if _, ok := response["login"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.Authentication.NewLoginParams("password", "username") 43 | _, err := client.Authentication.Login(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("Login", testlogin) 49 | 50 | testlogout := func(t *testing.T) { 51 | if _, ok := response["logout"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.Authentication.NewLogoutParams() 55 | _, err := client.Authentication.Logout(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | } 60 | t.Run("Logout", testlogout) 61 | 62 | testoauthlogin := func(t *testing.T) { 63 | if _, ok := response["oauthlogin"]; !ok { 64 | t.Skipf("Skipping as no json response is provided in testdata") 65 | } 66 | p := client.Authentication.NewOauthloginParams("email", "provider") 67 | _, err := client.Authentication.Oauthlogin(p) 68 | if err != nil { 69 | t.Errorf(err.Error()) 70 | } 71 | } 72 | t.Run("Oauthlogin", testoauthlogin) 73 | 74 | } 75 | -------------------------------------------------------------------------------- /test/testdata/AddressService.json: -------------------------------------------------------------------------------- 1 | { 2 | "associateIpAddress": { 3 | "associateipaddressresponse": { 4 | "accountid": "27ef5ba2-5fe0-11ea-9a56-1e006800018c", 5 | "userid": "27f2484f-5fe0-11ea-9a56-1e006800018c", 6 | "cmd": "org.apache.cloudstack.api.command.admin.address.AssociateIPAddrCmdByAdmin", 7 | "jobstatus": 1, 8 | "jobprocstatus": 0, 9 | "jobresultcode": 0, 10 | "jobresulttype": "object", 11 | "jobresult": { 12 | "ipaddress": { 13 | "id": "dc51835f-b0e2-4a2e-91a4-6cccc44bdae3", 14 | "ipaddress": "10.70.3.100", 15 | "allocated": "2021-10-01T16:25:11+0000", 16 | "zoneid": "3fc049b0-87ae-4d77-90c1-cce70da17db6", 17 | "zonename": "testAdvZone2", 18 | "issourcenat": true, 19 | "account": "admin", 20 | "domainid": "e4874e10-5fdf-11ea-9a56-1e006800018c", 21 | "domain": "ROOT", 22 | "forvirtualnetwork": true, 23 | "vlanid": "2e86e486-b472-4f12-a9b2-bb73701241e0", 24 | "vlanname": "vlan://untagged", 25 | "isstaticnat": false, 26 | "issystem": false, 27 | "associatednetworkid": "cf8056db-25e1-49d1-b023-f13a717e5ecc", 28 | "associatednetworkname": "test-adv-network", 29 | "networkid": "f17d38db-4810-437e-be28-d38cd30e3034", 30 | "state": "Allocating", 31 | "physicalnetworkid": "0d6c1e76-2d83-459a-bbce-c133fbd732b7", 32 | "tags": [], 33 | "isportable": false, 34 | "fordisplay": true 35 | } 36 | }, 37 | "jobinstancetype": "IpAddress", 38 | "jobinstanceid": "dc51835f-b0e2-4a2e-91a4-6cccc44bdae3", 39 | "created": "2021-10-01T16:25:12+0000", 40 | "completed": "2021-10-01T16:25:12+0000", 41 | "jobid": "8e805516-1729-46cf-a7d0-7289d523871e" 42 | } 43 | }, 44 | "disassociateIpAddress": { 45 | "disassociateipaddressresponse": { 46 | "accountid": "27ef5ba2-5fe0-11ea-9a56-1e006800018c", 47 | "userid": "27f2484f-5fe0-11ea-9a56-1e006800018c", 48 | "cmd": "org.apache.cloudstack.api.command.user.address.DisassociateIPAddrCmd", 49 | "jobstatus": 1, 50 | "jobprocstatus": 0, 51 | "jobresultcode": 0, 52 | "jobresulttype": "object", 53 | "jobresult": { 54 | "success": true 55 | }, 56 | "jobinstancetype": "IpAddress", 57 | "jobinstanceid": "a767fbe1-ed7a-4d7c-8221-c7d736ca622d", 58 | "created": "2021-10-01T16:42:32+0000", 59 | "completed": "2021-10-01T16:42:33+0000", 60 | "jobid": "44fc961e-9d57-4313-9f11-7556508b319c" 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /test/ASNumberRangeService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestASNumberRangeService(t *testing.T) { 29 | service := "ASNumberRangeService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testcreateASNRange := func(t *testing.T) { 39 | if _, ok := response["createASNRange"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.ASNumberRange.NewCreateASNRangeParams(0, 0, "zoneid") 43 | r, err := client.ASNumberRange.CreateASNRange(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | if r.Id == "" { 48 | t.Errorf("Failed to parse response. ID not found") 49 | } 50 | } 51 | t.Run("CreateASNRange", testcreateASNRange) 52 | 53 | testdeleteASNRange := func(t *testing.T) { 54 | if _, ok := response["deleteASNRange"]; !ok { 55 | t.Skipf("Skipping as no json response is provided in testdata") 56 | } 57 | p := client.ASNumberRange.NewDeleteASNRangeParams("id") 58 | _, err := client.ASNumberRange.DeleteASNRange(p) 59 | if err != nil { 60 | t.Errorf(err.Error()) 61 | } 62 | } 63 | t.Run("DeleteASNRange", testdeleteASNRange) 64 | 65 | testlistASNRanges := func(t *testing.T) { 66 | if _, ok := response["listASNRanges"]; !ok { 67 | t.Skipf("Skipping as no json response is provided in testdata") 68 | } 69 | p := client.ASNumberRange.NewListASNRangesParams() 70 | _, err := client.ASNumberRange.ListASNRanges(p) 71 | if err != nil { 72 | t.Errorf(err.Error()) 73 | } 74 | } 75 | t.Run("ListASNRanges", testlistASNRanges) 76 | 77 | } 78 | -------------------------------------------------------------------------------- /test/NsxService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestNsxService(t *testing.T) { 29 | service := "NsxService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testaddNsxController := func(t *testing.T) { 39 | if _, ok := response["addNsxController"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.Nsx.NewAddNsxControllerParams("edgecluster", "name", "nsxproviderhostname", "password", "tier0gateway", "transportzone", "username", "zoneid") 43 | _, err := client.Nsx.AddNsxController(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("AddNsxController", testaddNsxController) 49 | 50 | testdeleteNsxController := func(t *testing.T) { 51 | if _, ok := response["deleteNsxController"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.Nsx.NewDeleteNsxControllerParams("nsxcontrollerid") 55 | _, err := client.Nsx.DeleteNsxController(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | } 60 | t.Run("DeleteNsxController", testdeleteNsxController) 61 | 62 | testlistNsxControllers := func(t *testing.T) { 63 | if _, ok := response["listNsxControllers"]; !ok { 64 | t.Skipf("Skipping as no json response is provided in testdata") 65 | } 66 | p := client.Nsx.NewListNsxControllersParams() 67 | _, err := client.Nsx.ListNsxControllers(p) 68 | if err != nil { 69 | t.Errorf(err.Error()) 70 | } 71 | } 72 | t.Run("ListNsxControllers", testlistNsxControllers) 73 | 74 | } 75 | -------------------------------------------------------------------------------- /test/OauthService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestOauthService(t *testing.T) { 29 | service := "OauthService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testlistOauthProvider := func(t *testing.T) { 39 | if _, ok := response["listOauthProvider"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.Oauth.NewListOauthProviderParams() 43 | _, err := client.Oauth.ListOauthProvider(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("ListOauthProvider", testlistOauthProvider) 49 | 50 | testupdateOauthProvider := func(t *testing.T) { 51 | if _, ok := response["updateOauthProvider"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.Oauth.NewUpdateOauthProviderParams("id") 55 | r, err := client.Oauth.UpdateOauthProvider(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | if r.Id == "" { 60 | t.Errorf("Failed to parse response. ID not found") 61 | } 62 | } 63 | t.Run("UpdateOauthProvider", testupdateOauthProvider) 64 | 65 | testdeleteOauthProvider := func(t *testing.T) { 66 | if _, ok := response["deleteOauthProvider"]; !ok { 67 | t.Skipf("Skipping as no json response is provided in testdata") 68 | } 69 | p := client.Oauth.NewDeleteOauthProviderParams("id") 70 | _, err := client.Oauth.DeleteOauthProvider(p) 71 | if err != nil { 72 | t.Errorf(err.Error()) 73 | } 74 | } 75 | t.Run("DeleteOauthProvider", testdeleteOauthProvider) 76 | 77 | } 78 | -------------------------------------------------------------------------------- /test/NetrisService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestNetrisService(t *testing.T) { 29 | service := "NetrisService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testaddNetrisProvider := func(t *testing.T) { 39 | if _, ok := response["addNetrisProvider"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.Netris.NewAddNetrisProviderParams("name", "netristag", "netrisurl", "password", "sitename", "tenantname", "username", "zoneid") 43 | _, err := client.Netris.AddNetrisProvider(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("AddNetrisProvider", testaddNetrisProvider) 49 | 50 | testdeleteNetrisProvider := func(t *testing.T) { 51 | if _, ok := response["deleteNetrisProvider"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.Netris.NewDeleteNetrisProviderParams("id") 55 | _, err := client.Netris.DeleteNetrisProvider(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | } 60 | t.Run("DeleteNetrisProvider", testdeleteNetrisProvider) 61 | 62 | testlistNetrisProviders := func(t *testing.T) { 63 | if _, ok := response["listNetrisProviders"]; !ok { 64 | t.Skipf("Skipping as no json response is provided in testdata") 65 | } 66 | p := client.Netris.NewListNetrisProvidersParams() 67 | _, err := client.Netris.ListNetrisProviders(p) 68 | if err != nil { 69 | t.Errorf(err.Error()) 70 | } 71 | } 72 | t.Run("ListNetrisProviders", testlistNetrisProviders) 73 | 74 | } 75 | -------------------------------------------------------------------------------- /test/testdata/AnnotationService.json: -------------------------------------------------------------------------------- 1 | { 2 | "listAnnotations": { 3 | "listannotationsresponse": { 4 | "count": 3, 5 | "annotation": [ 6 | { 7 | "id": "3857fba8-9ec8-4c6d-9c39-a0cf0b25c065", 8 | "entitytype": "SSH_KEYPAIR", 9 | "entityid": "7f524874-babb-42bd-8536-2e27abdaf553", 10 | "entityname": "key", 11 | "annotation": "whatever", 12 | "userid": "10e5a3b9-ba1a-11ec-bdce-1e000700021c", 13 | "username": "admin", 14 | "adminsonly": false, 15 | "created": "2022-04-12T05:55:56+0000" 16 | }, 17 | { 18 | "id": "29119d47-acc6-4f98-a536-88182c810109", 19 | "entitytype": "SSH_KEYPAIR", 20 | "entityid": "7f524874-babb-42bd-8536-2e27abdaf553", 21 | "entityname": "key", 22 | "annotation": "Everyone", 23 | "userid": "10e5a3b9-ba1a-11ec-bdce-1e000700021c", 24 | "username": "admin", 25 | "adminsonly": false, 26 | "created": "2022-04-12T05:32:36+0000" 27 | }, 28 | { 29 | "id": "30779821-30eb-4567-a129-734564c14174", 30 | "entitytype": "SSH_KEYPAIR", 31 | "entityid": "7f524874-babb-42bd-8536-2e27abdaf553", 32 | "entityname": "key", 33 | "annotation": "admin Only", 34 | "userid": "10e5a3b9-ba1a-11ec-bdce-1e000700021c", 35 | "username": "admin", 36 | "adminsonly": true, 37 | "created": "2022-04-12T05:32:31+0000" 38 | } 39 | ] 40 | } 41 | }, 42 | "addAnnotation": { 43 | "addannotationresponse": { 44 | "annotation": { 45 | "id": "c1431a73-070c-4fb5-b3a2-937cd6646ab6", 46 | "entitytype": "SSH_KEYPAIR", 47 | "entityid": "7f524874-babb-42bd-8536-2e27abdaf553", 48 | "entityname": "key", 49 | "annotation": "new", 50 | "userid": "10e5a3b9-ba1a-11ec-bdce-1e000700021c", 51 | "username": "admin", 52 | "adminsonly": false, 53 | "created": "2022-04-18T06:14:54+0000" 54 | } 55 | } 56 | }, 57 | "removeAnnotation": { 58 | "removeannotationresponse": { 59 | "annotation": { 60 | "id": "c1431a73-070c-4fb5-b3a2-937cd6646ab6", 61 | "entitytype": "SSH_KEYPAIR", 62 | "entityid": "7f524874-babb-42bd-8536-2e27abdaf553", 63 | "entityname": "key", 64 | "annotation": "new", 65 | "userid": "10e5a3b9-ba1a-11ec-bdce-1e000700021c", 66 | "username": "admin", 67 | "adminsonly": false, 68 | "created": "2022-04-18T06:14:54+0000" 69 | } 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /test/testdata/VLANService.json: -------------------------------------------------------------------------------- 1 | { 2 | "dedicateGuestVlanRange": { 3 | "dedicateguestvlanrangeresponse": { 4 | "dedicatedguestvlanrange": { 5 | "id": "b1afc5fe-b17c-4db3-8411-c323e4997ead", 6 | "account": "admin", 7 | "domainid": "e4874e10-5fdf-11ea-9a56-1e006800018c", 8 | "domain": "ROOT", 9 | "guestvlanrange": "100-110", 10 | "physicalnetworkid": 200, 11 | "zoneid": 1 12 | } 13 | } 14 | }, 15 | "createVlanIpRange": { 16 | "createvlaniprangeresponse": { 17 | "vlan": { 18 | "id": "9772c190-3ad2-4e9c-8cd0-f1b3ebfe81d7", 19 | "forvirtualnetwork": true, 20 | "zoneid": "5de24f07-6668-4847-bff6-4f84ffc5bd70", 21 | "vlan": "vlan://123", 22 | "gateway": "10.0.0.1", 23 | "netmask": "255.255.255.0", 24 | "cidr": "10.0.0.0/24", 25 | "startip": "10.0.0.2", 26 | "endip": "10.0.0.10", 27 | "networkid": "80cb0f82-f488-4092-91c8-ffb2805c26b2", 28 | "physicalnetworkid": "2b46a0da-5076-481e-9ecf-d7d7055480c1", 29 | "forsystemvms": false 30 | } 31 | } 32 | }, 33 | "updateVlanIpRange": { 34 | "updatevlaniprangeresponse": { 35 | "vlan": { 36 | "id": "9772c190-3ad2-4e9c-8cd0-f1b3ebfe81d7", 37 | "forvirtualnetwork": true, 38 | "zoneid": "5de24f07-6668-4847-bff6-4f84ffc5bd70", 39 | "vlan": "vlan://123", 40 | "gateway": "10.0.0.1", 41 | "netmask": "255.255.255.0", 42 | "cidr": "10.0.0.0/24", 43 | "startip": "10.0.0.2", 44 | "endip": "10.0.0.11", 45 | "networkid": "80cb0f82-f488-4092-91c8-ffb2805c26b2", 46 | "physicalnetworkid": "2b46a0da-5076-481e-9ecf-d7d7055480c1", 47 | "forsystemvms": false 48 | } 49 | } 50 | }, 51 | "listVlanIpRanges": { 52 | "listvlaniprangesresponse": { 53 | "count": 1, 54 | "vlaniprange": [ 55 | { 56 | "id": "9772c190-3ad2-4e9c-8cd0-f1b3ebfe81d7", 57 | "forvirtualnetwork": true, 58 | "zoneid": "5de24f07-6668-4847-bff6-4f84ffc5bd70", 59 | "vlan": "vlan://123", 60 | "gateway": "10.0.0.1", 61 | "netmask": "255.255.255.0", 62 | "cidr": "10.0.0.0/24", 63 | "startip": "10.0.0.2", 64 | "endip": "10.0.0.11", 65 | "networkid": "80cb0f82-f488-4092-91c8-ffb2805c26b2", 66 | "physicalnetworkid": "2b46a0da-5076-481e-9ecf-d7d7055480c1", 67 | "forsystemvms": false 68 | } 69 | ] 70 | } 71 | }, 72 | "deleteVlanIpRange": { 73 | "deletevlaniprangeresponse":{ 74 | "success":true 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /test/ResourceIconService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestResourceIconService(t *testing.T) { 29 | service := "ResourceIconService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testdeleteResourceIcon := func(t *testing.T) { 39 | if _, ok := response["deleteResourceIcon"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.ResourceIcon.NewDeleteResourceIconParams([]string{}, "resourcetype") 43 | _, err := client.ResourceIcon.DeleteResourceIcon(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("DeleteResourceIcon", testdeleteResourceIcon) 49 | 50 | testlistResourceIcon := func(t *testing.T) { 51 | if _, ok := response["listResourceIcon"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.ResourceIcon.NewListResourceIconParams([]string{}, "resourcetype") 55 | _, err := client.ResourceIcon.ListResourceIcon(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | } 60 | t.Run("ListResourceIcon", testlistResourceIcon) 61 | 62 | testuploadResourceIcon := func(t *testing.T) { 63 | if _, ok := response["uploadResourceIcon"]; !ok { 64 | t.Skipf("Skipping as no json response is provided in testdata") 65 | } 66 | p := client.ResourceIcon.NewUploadResourceIconParams("base64image", []string{}, "resourcetype") 67 | _, err := client.ResourceIcon.UploadResourceIcon(p) 68 | if err != nil { 69 | t.Errorf(err.Error()) 70 | } 71 | } 72 | t.Run("UploadResourceIcon", testuploadResourceIcon) 73 | 74 | } 75 | -------------------------------------------------------------------------------- /cloudstack/CustomService.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package cloudstack 21 | 22 | import ( 23 | "encoding/json" 24 | "fmt" 25 | "net/url" 26 | "strconv" 27 | "strings" 28 | ) 29 | 30 | type CustomServiceParams struct { 31 | p map[string]interface{} 32 | } 33 | 34 | func (p *CustomServiceParams) toURLValues() url.Values { 35 | u := url.Values{} 36 | if p.p == nil { 37 | return u 38 | } 39 | 40 | for k, v := range p.p { 41 | switch t := v.(type) { 42 | case bool: 43 | u.Set(k, strconv.FormatBool(t)) 44 | case int: 45 | u.Set(k, strconv.Itoa(t)) 46 | case int64: 47 | vv := strconv.FormatInt(t, 10) 48 | u.Set(k, vv) 49 | case string: 50 | u.Set(k, t) 51 | case []string: 52 | u.Set(k, strings.Join(t, ", ")) 53 | case map[string]string: 54 | i := 0 55 | for kk, vv := range t { 56 | u.Set(fmt.Sprintf("%s[%d].%s", k, i, kk), vv) 57 | i++ 58 | } 59 | } 60 | } 61 | 62 | return u 63 | } 64 | 65 | func (p *CustomServiceParams) SetParam(param string, v interface{}) { 66 | if p.p == nil { 67 | p.p = make(map[string]interface{}) 68 | } 69 | p.p[param] = v 70 | } 71 | func (p *CustomServiceParams) GetParam(param string) (interface{}, bool) { 72 | if p.p == nil { 73 | p.p = make(map[string]interface{}) 74 | } 75 | value, ok := p.p[param].(interface{}) 76 | return value, ok 77 | } 78 | 79 | func (s *CustomService) CustomRequest(api string, p *CustomServiceParams, result interface{}) error { 80 | resp, err := s.cs.newPostRequest(api, p.toURLValues()) 81 | if err != nil { 82 | return err 83 | } 84 | 85 | return json.Unmarshal(resp, result) 86 | } 87 | func (s *CustomService) CustomPostRequest(api string, p *CustomServiceParams, result interface{}) error { 88 | resp, err := s.cs.newPostRequest(api, p.toURLValues()) 89 | if err != nil { 90 | return err 91 | } 92 | 93 | return json.Unmarshal(resp, result) 94 | } 95 | 96 | type CustomServiceIface interface { 97 | } 98 | -------------------------------------------------------------------------------- /test/NetworkDeviceService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestNetworkDeviceService(t *testing.T) { 29 | service := "NetworkDeviceService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testaddNetworkDevice := func(t *testing.T) { 39 | if _, ok := response["addNetworkDevice"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.NetworkDevice.NewAddNetworkDeviceParams() 43 | r, err := client.NetworkDevice.AddNetworkDevice(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | if r.Id == "" { 48 | t.Errorf("Failed to parse response. ID not found") 49 | } 50 | } 51 | t.Run("AddNetworkDevice", testaddNetworkDevice) 52 | 53 | testdeleteNetworkDevice := func(t *testing.T) { 54 | if _, ok := response["deleteNetworkDevice"]; !ok { 55 | t.Skipf("Skipping as no json response is provided in testdata") 56 | } 57 | p := client.NetworkDevice.NewDeleteNetworkDeviceParams("id") 58 | _, err := client.NetworkDevice.DeleteNetworkDevice(p) 59 | if err != nil { 60 | t.Errorf(err.Error()) 61 | } 62 | } 63 | t.Run("DeleteNetworkDevice", testdeleteNetworkDevice) 64 | 65 | testlistNetworkDevice := func(t *testing.T) { 66 | if _, ok := response["listNetworkDevice"]; !ok { 67 | t.Skipf("Skipping as no json response is provided in testdata") 68 | } 69 | p := client.NetworkDevice.NewListNetworkDeviceParams() 70 | _, err := client.NetworkDevice.ListNetworkDevice(p) 71 | if err != nil { 72 | t.Errorf(err.Error()) 73 | } 74 | } 75 | t.Run("ListNetworkDevice", testlistNetworkDevice) 76 | 77 | } 78 | -------------------------------------------------------------------------------- /test/NiciraNVPService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestNiciraNVPService(t *testing.T) { 29 | service := "NiciraNVPService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testaddNiciraNvpDevice := func(t *testing.T) { 39 | if _, ok := response["addNiciraNvpDevice"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.NiciraNVP.NewAddNiciraNvpDeviceParams("hostname", "password", "physicalnetworkid", "transportzoneuuid", "username") 43 | _, err := client.NiciraNVP.AddNiciraNvpDevice(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("AddNiciraNvpDevice", testaddNiciraNvpDevice) 49 | 50 | testdeleteNiciraNvpDevice := func(t *testing.T) { 51 | if _, ok := response["deleteNiciraNvpDevice"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.NiciraNVP.NewDeleteNiciraNvpDeviceParams("nvpdeviceid") 55 | _, err := client.NiciraNVP.DeleteNiciraNvpDevice(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | } 60 | t.Run("DeleteNiciraNvpDevice", testdeleteNiciraNvpDevice) 61 | 62 | testlistNiciraNvpDevices := func(t *testing.T) { 63 | if _, ok := response["listNiciraNvpDevices"]; !ok { 64 | t.Skipf("Skipping as no json response is provided in testdata") 65 | } 66 | p := client.NiciraNVP.NewListNiciraNvpDevicesParams() 67 | _, err := client.NiciraNVP.ListNiciraNvpDevices(p) 68 | if err != nil { 69 | t.Errorf(err.Error()) 70 | } 71 | } 72 | t.Run("ListNiciraNvpDevices", testlistNiciraNvpDevices) 73 | 74 | } 75 | -------------------------------------------------------------------------------- /test/BigSwitchBCFService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestBigSwitchBCFService(t *testing.T) { 29 | service := "BigSwitchBCFService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testaddBigSwitchBcfDevice := func(t *testing.T) { 39 | if _, ok := response["addBigSwitchBcfDevice"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.BigSwitchBCF.NewAddBigSwitchBcfDeviceParams("hostname", true, "password", "physicalnetworkid", "username") 43 | _, err := client.BigSwitchBCF.AddBigSwitchBcfDevice(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("AddBigSwitchBcfDevice", testaddBigSwitchBcfDevice) 49 | 50 | testdeleteBigSwitchBcfDevice := func(t *testing.T) { 51 | if _, ok := response["deleteBigSwitchBcfDevice"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.BigSwitchBCF.NewDeleteBigSwitchBcfDeviceParams("bcfdeviceid") 55 | _, err := client.BigSwitchBCF.DeleteBigSwitchBcfDevice(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | } 60 | t.Run("DeleteBigSwitchBcfDevice", testdeleteBigSwitchBcfDevice) 61 | 62 | testlistBigSwitchBcfDevices := func(t *testing.T) { 63 | if _, ok := response["listBigSwitchBcfDevices"]; !ok { 64 | t.Skipf("Skipping as no json response is provided in testdata") 65 | } 66 | p := client.BigSwitchBCF.NewListBigSwitchBcfDevicesParams() 67 | _, err := client.BigSwitchBCF.ListBigSwitchBcfDevices(p) 68 | if err != nil { 69 | t.Errorf(err.Error()) 70 | } 71 | } 72 | t.Run("ListBigSwitchBcfDevices", testlistBigSwitchBcfDevices) 73 | 74 | } 75 | -------------------------------------------------------------------------------- /test/SolidFireService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestSolidFireService(t *testing.T) { 29 | service := "SolidFireService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testgetSolidFireAccountId := func(t *testing.T) { 39 | if _, ok := response["getSolidFireAccountId"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.SolidFire.NewGetSolidFireAccountIdParams("accountid", "storageid") 43 | _, err := client.SolidFire.GetSolidFireAccountId(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("GetSolidFireAccountId", testgetSolidFireAccountId) 49 | 50 | testgetSolidFireVolumeAccessGroupIds := func(t *testing.T) { 51 | if _, ok := response["getSolidFireVolumeAccessGroupIds"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.SolidFire.NewGetSolidFireVolumeAccessGroupIdsParams("clusterid", "storageid") 55 | _, err := client.SolidFire.GetSolidFireVolumeAccessGroupIds(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | } 60 | t.Run("GetSolidFireVolumeAccessGroupIds", testgetSolidFireVolumeAccessGroupIds) 61 | 62 | testgetSolidFireVolumeSize := func(t *testing.T) { 63 | if _, ok := response["getSolidFireVolumeSize"]; !ok { 64 | t.Skipf("Skipping as no json response is provided in testdata") 65 | } 66 | p := client.SolidFire.NewGetSolidFireVolumeSizeParams("volumeid") 67 | _, err := client.SolidFire.GetSolidFireVolumeSize(p) 68 | if err != nil { 69 | t.Errorf(err.Error()) 70 | } 71 | } 72 | t.Run("GetSolidFireVolumeSize", testgetSolidFireVolumeSize) 73 | 74 | } 75 | -------------------------------------------------------------------------------- /test/HypervisorService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestHypervisorService(t *testing.T) { 29 | service := "HypervisorService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testlistHypervisorCapabilities := func(t *testing.T) { 39 | if _, ok := response["listHypervisorCapabilities"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.Hypervisor.NewListHypervisorCapabilitiesParams() 43 | _, err := client.Hypervisor.ListHypervisorCapabilities(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("ListHypervisorCapabilities", testlistHypervisorCapabilities) 49 | 50 | testlistHypervisors := func(t *testing.T) { 51 | if _, ok := response["listHypervisors"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.Hypervisor.NewListHypervisorsParams() 55 | _, err := client.Hypervisor.ListHypervisors(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | } 60 | t.Run("ListHypervisors", testlistHypervisors) 61 | 62 | testupdateHypervisorCapabilities := func(t *testing.T) { 63 | if _, ok := response["updateHypervisorCapabilities"]; !ok { 64 | t.Skipf("Skipping as no json response is provided in testdata") 65 | } 66 | p := client.Hypervisor.NewUpdateHypervisorCapabilitiesParams() 67 | r, err := client.Hypervisor.UpdateHypervisorCapabilities(p) 68 | if err != nil { 69 | t.Errorf(err.Error()) 70 | } 71 | if r.Id == "" { 72 | t.Errorf("Failed to parse response. ID not found") 73 | } 74 | } 75 | t.Run("UpdateHypervisorCapabilities", testupdateHypervisorCapabilities) 76 | 77 | } 78 | -------------------------------------------------------------------------------- /test/PortableIPService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestPortableIPService(t *testing.T) { 29 | service := "PortableIPService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testcreatePortableIpRange := func(t *testing.T) { 39 | if _, ok := response["createPortableIpRange"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.PortableIP.NewCreatePortableIpRangeParams("endip", "gateway", "netmask", 0, "startip") 43 | r, err := client.PortableIP.CreatePortableIpRange(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | if r.Id == "" { 48 | t.Errorf("Failed to parse response. ID not found") 49 | } 50 | } 51 | t.Run("CreatePortableIpRange", testcreatePortableIpRange) 52 | 53 | testdeletePortableIpRange := func(t *testing.T) { 54 | if _, ok := response["deletePortableIpRange"]; !ok { 55 | t.Skipf("Skipping as no json response is provided in testdata") 56 | } 57 | p := client.PortableIP.NewDeletePortableIpRangeParams("id") 58 | _, err := client.PortableIP.DeletePortableIpRange(p) 59 | if err != nil { 60 | t.Errorf(err.Error()) 61 | } 62 | } 63 | t.Run("DeletePortableIpRange", testdeletePortableIpRange) 64 | 65 | testlistPortableIpRanges := func(t *testing.T) { 66 | if _, ok := response["listPortableIpRanges"]; !ok { 67 | t.Skipf("Skipping as no json response is provided in testdata") 68 | } 69 | p := client.PortableIP.NewListPortableIpRangesParams() 70 | _, err := client.PortableIP.ListPortableIpRanges(p) 71 | if err != nil { 72 | t.Errorf(err.Error()) 73 | } 74 | } 75 | t.Run("ListPortableIpRanges", testlistPortableIpRanges) 76 | 77 | } 78 | -------------------------------------------------------------------------------- /test/IPQuarantineService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestIPQuarantineService(t *testing.T) { 29 | service := "IPQuarantineService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testlistQuarantinedIps := func(t *testing.T) { 39 | if _, ok := response["listQuarantinedIps"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.IPQuarantine.NewListQuarantinedIpsParams() 43 | _, err := client.IPQuarantine.ListQuarantinedIps(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("ListQuarantinedIps", testlistQuarantinedIps) 49 | 50 | testremoveQuarantinedIp := func(t *testing.T) { 51 | if _, ok := response["removeQuarantinedIp"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.IPQuarantine.NewRemoveQuarantinedIpParams("removalreason") 55 | r, err := client.IPQuarantine.RemoveQuarantinedIp(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | if r.Id == "" { 60 | t.Errorf("Failed to parse response. ID not found") 61 | } 62 | } 63 | t.Run("RemoveQuarantinedIp", testremoveQuarantinedIp) 64 | 65 | testupdateQuarantinedIp := func(t *testing.T) { 66 | if _, ok := response["updateQuarantinedIp"]; !ok { 67 | t.Skipf("Skipping as no json response is provided in testdata") 68 | } 69 | p := client.IPQuarantine.NewUpdateQuarantinedIpParams("enddate") 70 | r, err := client.IPQuarantine.UpdateQuarantinedIp(p) 71 | if err != nil { 72 | t.Errorf(err.Error()) 73 | } 74 | if r.Id == "" { 75 | t.Errorf("Failed to parse response. ID not found") 76 | } 77 | } 78 | t.Run("UpdateQuarantinedIp", testupdateQuarantinedIp) 79 | 80 | } 81 | -------------------------------------------------------------------------------- /test/testdata/NetworkOfferingService.json: -------------------------------------------------------------------------------- 1 | { 2 | "createNetworkOffering": { 3 | "createnetworkofferingresponse": { 4 | "networkoffering": { 5 | "id": "c2000683-68fd-437e-a4cf-f3676e1d18c1", 6 | "name": "testNetOffering", 7 | "displaytext": "testNetOffering", 8 | "traffictype": "Guest", 9 | "isdefault": false, 10 | "specifyvlan": true, 11 | "conservemode": true, 12 | "specifyipranges": false, 13 | "availability": "Optional", 14 | "networkrate": 200, 15 | "state": "Disabled", 16 | "guestiptype": "L2", 17 | "serviceofferingid": "c4b50796-22a5-4347-ae81-79911e44ac8d", 18 | "service": [], 19 | "forvpc": false, 20 | "ispersistent": false, 21 | "egressdefaultpolicy": true, 22 | "supportsstrechedl2subnet": false, 23 | "supportspublicaccess": false 24 | } 25 | } 26 | }, 27 | "updateNetworkOffering": { 28 | "updatenetworkofferingresponse": { 29 | "networkoffering": { 30 | "id": "c2000683-68fd-437e-a4cf-f3676e1d18c1", 31 | "name": "testNetOffering", 32 | "displaytext": "testNetOffering", 33 | "traffictype": "Guest", 34 | "isdefault": false, 35 | "specifyvlan": true, 36 | "conservemode": true, 37 | "specifyipranges": false, 38 | "availability": "Optional", 39 | "networkrate": 200, 40 | "state": "Enabled", 41 | "guestiptype": "L2", 42 | "serviceofferingid": "c4b50796-22a5-4347-ae81-79911e44ac8d", 43 | "service": [], 44 | "forvpc": false, 45 | "ispersistent": false, 46 | "egressdefaultpolicy": true, 47 | "supportsstrechedl2subnet": false, 48 | "supportspublicaccess": false 49 | } 50 | } 51 | }, 52 | "listNetworkOfferings": { 53 | "listnetworkofferingsresponse": { 54 | "count": 1, 55 | "networkoffering": [ 56 | { 57 | "id": "c2000683-68fd-437e-a4cf-f3676e1d18c1", 58 | "name": "testNetOffering", 59 | "displaytext": "testNetOffering", 60 | "traffictype": "Guest", 61 | "isdefault": false, 62 | "specifyvlan": true, 63 | "conservemode": true, 64 | "specifyipranges": false, 65 | "availability": "Optional", 66 | "networkrate": 200, 67 | "state": "Enabled", 68 | "guestiptype": "L2", 69 | "serviceofferingid": "c4b50796-22a5-4347-ae81-79911e44ac8d", 70 | "service": [], 71 | "forvpc": false, 72 | "ispersistent": false, 73 | "egressdefaultpolicy": true, 74 | "supportsstrechedl2subnet": false, 75 | "supportspublicaccess": false 76 | } 77 | ] 78 | } 79 | }, 80 | "deleteNetworkOffering": { 81 | "deletenetworkofferingresponse": { 82 | "success": true 83 | } 84 | } 85 | } -------------------------------------------------------------------------------- /test/EventService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestEventService(t *testing.T) { 29 | service := "EventService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testarchiveEvents := func(t *testing.T) { 39 | if _, ok := response["archiveEvents"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.Event.NewArchiveEventsParams() 43 | _, err := client.Event.ArchiveEvents(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("ArchiveEvents", testarchiveEvents) 49 | 50 | testdeleteEvents := func(t *testing.T) { 51 | if _, ok := response["deleteEvents"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.Event.NewDeleteEventsParams() 55 | _, err := client.Event.DeleteEvents(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | } 60 | t.Run("DeleteEvents", testdeleteEvents) 61 | 62 | testlistEventTypes := func(t *testing.T) { 63 | if _, ok := response["listEventTypes"]; !ok { 64 | t.Skipf("Skipping as no json response is provided in testdata") 65 | } 66 | p := client.Event.NewListEventTypesParams() 67 | _, err := client.Event.ListEventTypes(p) 68 | if err != nil { 69 | t.Errorf(err.Error()) 70 | } 71 | } 72 | t.Run("ListEventTypes", testlistEventTypes) 73 | 74 | testlistEvents := func(t *testing.T) { 75 | if _, ok := response["listEvents"]; !ok { 76 | t.Skipf("Skipping as no json response is provided in testdata") 77 | } 78 | p := client.Event.NewListEventsParams() 79 | _, err := client.Event.ListEvents(p) 80 | if err != nil { 81 | t.Errorf(err.Error()) 82 | } 83 | } 84 | t.Run("ListEvents", testlistEvents) 85 | 86 | } 87 | -------------------------------------------------------------------------------- /test/RegionService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestRegionService(t *testing.T) { 29 | service := "RegionService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testaddRegion := func(t *testing.T) { 39 | if _, ok := response["addRegion"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.Region.NewAddRegionParams("endpoint", 0, "name") 43 | _, err := client.Region.AddRegion(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("AddRegion", testaddRegion) 49 | 50 | testlistRegions := func(t *testing.T) { 51 | if _, ok := response["listRegions"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.Region.NewListRegionsParams() 55 | _, err := client.Region.ListRegions(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | } 60 | t.Run("ListRegions", testlistRegions) 61 | 62 | testremoveRegion := func(t *testing.T) { 63 | if _, ok := response["removeRegion"]; !ok { 64 | t.Skipf("Skipping as no json response is provided in testdata") 65 | } 66 | p := client.Region.NewRemoveRegionParams(0) 67 | _, err := client.Region.RemoveRegion(p) 68 | if err != nil { 69 | t.Errorf(err.Error()) 70 | } 71 | } 72 | t.Run("RemoveRegion", testremoveRegion) 73 | 74 | testupdateRegion := func(t *testing.T) { 75 | if _, ok := response["updateRegion"]; !ok { 76 | t.Skipf("Skipping as no json response is provided in testdata") 77 | } 78 | p := client.Region.NewUpdateRegionParams(0) 79 | _, err := client.Region.UpdateRegion(p) 80 | if err != nil { 81 | t.Errorf(err.Error()) 82 | } 83 | } 84 | t.Run("UpdateRegion", testupdateRegion) 85 | 86 | } 87 | -------------------------------------------------------------------------------- /cloudstack/InfrastructureUsageService.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package cloudstack 21 | 22 | import ( 23 | "encoding/json" 24 | "net/url" 25 | ) 26 | 27 | type InfrastructureUsageServiceIface interface { 28 | ListDbMetrics(p *ListDbMetricsParams) (*ListDbMetricsResponse, error) 29 | NewListDbMetricsParams() *ListDbMetricsParams 30 | } 31 | 32 | type ListDbMetricsParams struct { 33 | p map[string]interface{} 34 | } 35 | 36 | func (p *ListDbMetricsParams) toURLValues() url.Values { 37 | u := url.Values{} 38 | if p.p == nil { 39 | return u 40 | } 41 | return u 42 | } 43 | 44 | // You should always use this function to get a new ListDbMetricsParams instance, 45 | // as then you are sure you have configured all required params 46 | func (s *InfrastructureUsageService) NewListDbMetricsParams() *ListDbMetricsParams { 47 | p := &ListDbMetricsParams{} 48 | p.p = make(map[string]interface{}) 49 | return p 50 | } 51 | 52 | // list the db hosts and statistics 53 | func (s *InfrastructureUsageService) ListDbMetrics(p *ListDbMetricsParams) (*ListDbMetricsResponse, error) { 54 | resp, err := s.cs.newRequest("listDbMetrics", p.toURLValues()) 55 | if err != nil { 56 | return nil, err 57 | } 58 | 59 | var r ListDbMetricsResponse 60 | if err := json.Unmarshal(resp, &r); err != nil { 61 | return nil, err 62 | } 63 | 64 | return &r, nil 65 | } 66 | 67 | type ListDbMetricsResponse struct { 68 | DbMetrics DbMetric `json:"dbMetrics"` 69 | } 70 | 71 | type DbMetric struct { 72 | Collectiontime string `json:"collectiontime"` 73 | Connections int `json:"connections"` 74 | Dbloadaverages []float64 `json:"dbloadaverages"` 75 | Hostname string `json:"hostname"` 76 | JobID string `json:"jobid"` 77 | Jobstatus int `json:"jobstatus"` 78 | Queries int64 `json:"queries"` 79 | Replicas []string `json:"replicas"` 80 | Tlsversions string `json:"tlsversions"` 81 | Uptime int64 `json:"uptime"` 82 | Version string `json:"version"` 83 | Versioncomment string `json:"versioncomment"` 84 | } 85 | -------------------------------------------------------------------------------- /test/ResourcetagsService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestResourcetagsService(t *testing.T) { 29 | service := "ResourcetagsService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testcreateTags := func(t *testing.T) { 39 | if _, ok := response["createTags"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.Resourcetags.NewCreateTagsParams([]string{}, "resourcetype", map[string]string{}) 43 | _, err := client.Resourcetags.CreateTags(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("CreateTags", testcreateTags) 49 | 50 | testdeleteTags := func(t *testing.T) { 51 | if _, ok := response["deleteTags"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.Resourcetags.NewDeleteTagsParams([]string{}, "resourcetype") 55 | _, err := client.Resourcetags.DeleteTags(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | } 60 | t.Run("DeleteTags", testdeleteTags) 61 | 62 | testlistStorageTags := func(t *testing.T) { 63 | if _, ok := response["listStorageTags"]; !ok { 64 | t.Skipf("Skipping as no json response is provided in testdata") 65 | } 66 | p := client.Resourcetags.NewListStorageTagsParams() 67 | _, err := client.Resourcetags.ListStorageTags(p) 68 | if err != nil { 69 | t.Errorf(err.Error()) 70 | } 71 | } 72 | t.Run("ListStorageTags", testlistStorageTags) 73 | 74 | testlistTags := func(t *testing.T) { 75 | if _, ok := response["listTags"]; !ok { 76 | t.Skipf("Skipping as no json response is provided in testdata") 77 | } 78 | p := client.Resourcetags.NewListTagsParams() 79 | _, err := client.Resourcetags.ListTags(p) 80 | if err != nil { 81 | t.Errorf(err.Error()) 82 | } 83 | } 84 | t.Run("ListTags", testlistTags) 85 | 86 | } 87 | -------------------------------------------------------------------------------- /test/OutofbandManagementService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestOutofbandManagementService(t *testing.T) { 29 | service := "OutofbandManagementService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testchangeOutOfBandManagementPassword := func(t *testing.T) { 39 | if _, ok := response["changeOutOfBandManagementPassword"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.OutofbandManagement.NewChangeOutOfBandManagementPasswordParams("hostid") 43 | _, err := client.OutofbandManagement.ChangeOutOfBandManagementPassword(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("ChangeOutOfBandManagementPassword", testchangeOutOfBandManagementPassword) 49 | 50 | testconfigureOutOfBandManagement := func(t *testing.T) { 51 | if _, ok := response["configureOutOfBandManagement"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.OutofbandManagement.NewConfigureOutOfBandManagementParams("address", "driver", "hostid", "password", "port", "username") 55 | _, err := client.OutofbandManagement.ConfigureOutOfBandManagement(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | } 60 | t.Run("ConfigureOutOfBandManagement", testconfigureOutOfBandManagement) 61 | 62 | testissueOutOfBandManagementPowerAction := func(t *testing.T) { 63 | if _, ok := response["issueOutOfBandManagementPowerAction"]; !ok { 64 | t.Skipf("Skipping as no json response is provided in testdata") 65 | } 66 | p := client.OutofbandManagement.NewIssueOutOfBandManagementPowerActionParams("action", "hostid") 67 | _, err := client.OutofbandManagement.IssueOutOfBandManagementPowerAction(p) 68 | if err != nil { 69 | t.Errorf(err.Error()) 70 | } 71 | } 72 | t.Run("IssueOutOfBandManagementPowerAction", testissueOutOfBandManagementPowerAction) 73 | 74 | } 75 | -------------------------------------------------------------------------------- /test/NicService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestNicService(t *testing.T) { 29 | service := "NicService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testaddIpToNic := func(t *testing.T) { 39 | if _, ok := response["addIpToNic"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.Nic.NewAddIpToNicParams("nicid") 43 | r, err := client.Nic.AddIpToNic(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | if r.Id == "" { 48 | t.Errorf("Failed to parse response. ID not found") 49 | } 50 | } 51 | t.Run("AddIpToNic", testaddIpToNic) 52 | 53 | testlistNics := func(t *testing.T) { 54 | if _, ok := response["listNics"]; !ok { 55 | t.Skipf("Skipping as no json response is provided in testdata") 56 | } 57 | p := client.Nic.NewListNicsParams("virtualmachineid") 58 | _, err := client.Nic.ListNics(p) 59 | if err != nil { 60 | t.Errorf(err.Error()) 61 | } 62 | } 63 | t.Run("ListNics", testlistNics) 64 | 65 | testremoveIpFromNic := func(t *testing.T) { 66 | if _, ok := response["removeIpFromNic"]; !ok { 67 | t.Skipf("Skipping as no json response is provided in testdata") 68 | } 69 | p := client.Nic.NewRemoveIpFromNicParams("id") 70 | _, err := client.Nic.RemoveIpFromNic(p) 71 | if err != nil { 72 | t.Errorf(err.Error()) 73 | } 74 | } 75 | t.Run("RemoveIpFromNic", testremoveIpFromNic) 76 | 77 | testupdateVmNicIp := func(t *testing.T) { 78 | if _, ok := response["updateVmNicIp"]; !ok { 79 | t.Skipf("Skipping as no json response is provided in testdata") 80 | } 81 | p := client.Nic.NewUpdateVmNicIpParams("nicid") 82 | r, err := client.Nic.UpdateVmNicIp(p) 83 | if err != nil { 84 | t.Errorf(err.Error()) 85 | } 86 | if r.Id == "" { 87 | t.Errorf("Failed to parse response. ID not found") 88 | } 89 | } 90 | t.Run("UpdateVmNicIp", testupdateVmNicIp) 91 | 92 | } 93 | -------------------------------------------------------------------------------- /test/ObjectStoreService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestObjectStoreService(t *testing.T) { 29 | service := "ObjectStoreService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testcreateBucket := func(t *testing.T) { 39 | if _, ok := response["createBucket"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.ObjectStore.NewCreateBucketParams("name", "objectstorageid", 0) 43 | r, err := client.ObjectStore.CreateBucket(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | if r.Id == "" { 48 | t.Errorf("Failed to parse response. ID not found") 49 | } 50 | } 51 | t.Run("CreateBucket", testcreateBucket) 52 | 53 | testdeleteBucket := func(t *testing.T) { 54 | if _, ok := response["deleteBucket"]; !ok { 55 | t.Skipf("Skipping as no json response is provided in testdata") 56 | } 57 | p := client.ObjectStore.NewDeleteBucketParams("id") 58 | _, err := client.ObjectStore.DeleteBucket(p) 59 | if err != nil { 60 | t.Errorf(err.Error()) 61 | } 62 | } 63 | t.Run("DeleteBucket", testdeleteBucket) 64 | 65 | testupdateBucket := func(t *testing.T) { 66 | if _, ok := response["updateBucket"]; !ok { 67 | t.Skipf("Skipping as no json response is provided in testdata") 68 | } 69 | p := client.ObjectStore.NewUpdateBucketParams("id") 70 | _, err := client.ObjectStore.UpdateBucket(p) 71 | if err != nil { 72 | t.Errorf(err.Error()) 73 | } 74 | } 75 | t.Run("UpdateBucket", testupdateBucket) 76 | 77 | testlistBuckets := func(t *testing.T) { 78 | if _, ok := response["listBuckets"]; !ok { 79 | t.Skipf("Skipping as no json response is provided in testdata") 80 | } 81 | p := client.ObjectStore.NewListBucketsParams() 82 | _, err := client.ObjectStore.ListBuckets(p) 83 | if err != nil { 84 | t.Errorf(err.Error()) 85 | } 86 | } 87 | t.Run("ListBuckets", testlistBuckets) 88 | 89 | } 90 | -------------------------------------------------------------------------------- /cloudstack/MetricsService.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package cloudstack 21 | 22 | import ( 23 | "encoding/json" 24 | "net/url" 25 | ) 26 | 27 | type MetricsServiceIface interface { 28 | ListInfrastructure(p *ListInfrastructureParams) (*ListInfrastructureResponse, error) 29 | NewListInfrastructureParams() *ListInfrastructureParams 30 | } 31 | 32 | type ListInfrastructureParams struct { 33 | p map[string]interface{} 34 | } 35 | 36 | func (p *ListInfrastructureParams) toURLValues() url.Values { 37 | u := url.Values{} 38 | if p.p == nil { 39 | return u 40 | } 41 | return u 42 | } 43 | 44 | // You should always use this function to get a new ListInfrastructureParams instance, 45 | // as then you are sure you have configured all required params 46 | func (s *MetricsService) NewListInfrastructureParams() *ListInfrastructureParams { 47 | p := &ListInfrastructureParams{} 48 | p.p = make(map[string]interface{}) 49 | return p 50 | } 51 | 52 | // Lists infrastructure 53 | func (s *MetricsService) ListInfrastructure(p *ListInfrastructureParams) (*ListInfrastructureResponse, error) { 54 | resp, err := s.cs.newRequest("listInfrastructure", p.toURLValues()) 55 | if err != nil { 56 | return nil, err 57 | } 58 | 59 | var r ListInfrastructureResponse 60 | if err := json.Unmarshal(resp, &r); err != nil { 61 | return nil, err 62 | } 63 | 64 | return &r, nil 65 | } 66 | 67 | type ListInfrastructureResponse struct { 68 | Count int `json:"count"` 69 | Infrastructure *Infrastructure `json:"infrastructure"` 70 | } 71 | 72 | type Infrastructure struct { 73 | Alerts int `json:"alerts"` 74 | Backuprepositories int `json:"backuprepositories"` 75 | Clusters int `json:"clusters"` 76 | Cpusockets int `json:"cpusockets"` 77 | Hosts int `json:"hosts"` 78 | Ilbvms int `json:"ilbvms"` 79 | Imagestores int `json:"imagestores"` 80 | JobID string `json:"jobid"` 81 | Jobstatus int `json:"jobstatus"` 82 | Managementservers int `json:"managementservers"` 83 | Objectstores int `json:"objectstores"` 84 | Pods int `json:"pods"` 85 | Routers int `json:"routers"` 86 | Storagepools int `json:"storagepools"` 87 | Systemvms int `json:"systemvms"` 88 | Zones int `json:"zones"` 89 | } 90 | -------------------------------------------------------------------------------- /test/VMGroupService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestVMGroupService(t *testing.T) { 29 | service := "VMGroupService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testcreateInstanceGroup := func(t *testing.T) { 39 | if _, ok := response["createInstanceGroup"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.VMGroup.NewCreateInstanceGroupParams("name") 43 | r, err := client.VMGroup.CreateInstanceGroup(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | if r.Id == "" { 48 | t.Errorf("Failed to parse response. ID not found") 49 | } 50 | } 51 | t.Run("CreateInstanceGroup", testcreateInstanceGroup) 52 | 53 | testdeleteInstanceGroup := func(t *testing.T) { 54 | if _, ok := response["deleteInstanceGroup"]; !ok { 55 | t.Skipf("Skipping as no json response is provided in testdata") 56 | } 57 | p := client.VMGroup.NewDeleteInstanceGroupParams("id") 58 | _, err := client.VMGroup.DeleteInstanceGroup(p) 59 | if err != nil { 60 | t.Errorf(err.Error()) 61 | } 62 | } 63 | t.Run("DeleteInstanceGroup", testdeleteInstanceGroup) 64 | 65 | testlistInstanceGroups := func(t *testing.T) { 66 | if _, ok := response["listInstanceGroups"]; !ok { 67 | t.Skipf("Skipping as no json response is provided in testdata") 68 | } 69 | p := client.VMGroup.NewListInstanceGroupsParams() 70 | _, err := client.VMGroup.ListInstanceGroups(p) 71 | if err != nil { 72 | t.Errorf(err.Error()) 73 | } 74 | } 75 | t.Run("ListInstanceGroups", testlistInstanceGroups) 76 | 77 | testupdateInstanceGroup := func(t *testing.T) { 78 | if _, ok := response["updateInstanceGroup"]; !ok { 79 | t.Skipf("Skipping as no json response is provided in testdata") 80 | } 81 | p := client.VMGroup.NewUpdateInstanceGroupParams("id") 82 | r, err := client.VMGroup.UpdateInstanceGroup(p) 83 | if err != nil { 84 | t.Errorf(err.Error()) 85 | } 86 | if r.Id == "" { 87 | t.Errorf("Failed to parse response. ID not found") 88 | } 89 | } 90 | t.Run("UpdateInstanceGroup", testupdateInstanceGroup) 91 | 92 | } 93 | -------------------------------------------------------------------------------- /test/BrocadeVCSService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestBrocadeVCSService(t *testing.T) { 29 | service := "BrocadeVCSService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testaddBrocadeVcsDevice := func(t *testing.T) { 39 | if _, ok := response["addBrocadeVcsDevice"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.BrocadeVCS.NewAddBrocadeVcsDeviceParams("hostname", "password", "physicalnetworkid", "username") 43 | _, err := client.BrocadeVCS.AddBrocadeVcsDevice(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("AddBrocadeVcsDevice", testaddBrocadeVcsDevice) 49 | 50 | testdeleteBrocadeVcsDevice := func(t *testing.T) { 51 | if _, ok := response["deleteBrocadeVcsDevice"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.BrocadeVCS.NewDeleteBrocadeVcsDeviceParams("vcsdeviceid") 55 | _, err := client.BrocadeVCS.DeleteBrocadeVcsDevice(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | } 60 | t.Run("DeleteBrocadeVcsDevice", testdeleteBrocadeVcsDevice) 61 | 62 | testlistBrocadeVcsDeviceNetworks := func(t *testing.T) { 63 | if _, ok := response["listBrocadeVcsDeviceNetworks"]; !ok { 64 | t.Skipf("Skipping as no json response is provided in testdata") 65 | } 66 | p := client.BrocadeVCS.NewListBrocadeVcsDeviceNetworksParams("vcsdeviceid") 67 | _, err := client.BrocadeVCS.ListBrocadeVcsDeviceNetworks(p) 68 | if err != nil { 69 | t.Errorf(err.Error()) 70 | } 71 | } 72 | t.Run("ListBrocadeVcsDeviceNetworks", testlistBrocadeVcsDeviceNetworks) 73 | 74 | testlistBrocadeVcsDevices := func(t *testing.T) { 75 | if _, ok := response["listBrocadeVcsDevices"]; !ok { 76 | t.Skipf("Skipping as no json response is provided in testdata") 77 | } 78 | p := client.BrocadeVCS.NewListBrocadeVcsDevicesParams() 79 | _, err := client.BrocadeVCS.ListBrocadeVcsDevices(p) 80 | if err != nil { 81 | t.Errorf(err.Error()) 82 | } 83 | } 84 | t.Run("ListBrocadeVcsDevices", testlistBrocadeVcsDevices) 85 | 86 | } 87 | -------------------------------------------------------------------------------- /test/DiskOfferingService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestDiskOfferingService(t *testing.T) { 29 | service := "DiskOfferingService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testcreateDiskOffering := func(t *testing.T) { 39 | if _, ok := response["createDiskOffering"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.DiskOffering.NewCreateDiskOfferingParams("displaytext", "name") 43 | r, err := client.DiskOffering.CreateDiskOffering(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | if r.Id == "" { 48 | t.Errorf("Failed to parse response. ID not found") 49 | } 50 | } 51 | t.Run("CreateDiskOffering", testcreateDiskOffering) 52 | 53 | testdeleteDiskOffering := func(t *testing.T) { 54 | if _, ok := response["deleteDiskOffering"]; !ok { 55 | t.Skipf("Skipping as no json response is provided in testdata") 56 | } 57 | p := client.DiskOffering.NewDeleteDiskOfferingParams("id") 58 | _, err := client.DiskOffering.DeleteDiskOffering(p) 59 | if err != nil { 60 | t.Errorf(err.Error()) 61 | } 62 | } 63 | t.Run("DeleteDiskOffering", testdeleteDiskOffering) 64 | 65 | testlistDiskOfferings := func(t *testing.T) { 66 | if _, ok := response["listDiskOfferings"]; !ok { 67 | t.Skipf("Skipping as no json response is provided in testdata") 68 | } 69 | p := client.DiskOffering.NewListDiskOfferingsParams() 70 | _, err := client.DiskOffering.ListDiskOfferings(p) 71 | if err != nil { 72 | t.Errorf(err.Error()) 73 | } 74 | } 75 | t.Run("ListDiskOfferings", testlistDiskOfferings) 76 | 77 | testupdateDiskOffering := func(t *testing.T) { 78 | if _, ok := response["updateDiskOffering"]; !ok { 79 | t.Skipf("Skipping as no json response is provided in testdata") 80 | } 81 | p := client.DiskOffering.NewUpdateDiskOfferingParams("id") 82 | r, err := client.DiskOffering.UpdateDiskOffering(p) 83 | if err != nil { 84 | t.Errorf(err.Error()) 85 | } 86 | if r.Id == "" { 87 | t.Errorf("Failed to parse response. ID not found") 88 | } 89 | } 90 | t.Run("UpdateDiskOffering", testupdateDiskOffering) 91 | 92 | } 93 | -------------------------------------------------------------------------------- /test/AlertService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestAlertService(t *testing.T) { 29 | service := "AlertService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testarchiveAlerts := func(t *testing.T) { 39 | if _, ok := response["archiveAlerts"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.Alert.NewArchiveAlertsParams() 43 | _, err := client.Alert.ArchiveAlerts(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("ArchiveAlerts", testarchiveAlerts) 49 | 50 | testdeleteAlerts := func(t *testing.T) { 51 | if _, ok := response["deleteAlerts"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.Alert.NewDeleteAlertsParams() 55 | _, err := client.Alert.DeleteAlerts(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | } 60 | t.Run("DeleteAlerts", testdeleteAlerts) 61 | 62 | testgenerateAlert := func(t *testing.T) { 63 | if _, ok := response["generateAlert"]; !ok { 64 | t.Skipf("Skipping as no json response is provided in testdata") 65 | } 66 | p := client.Alert.NewGenerateAlertParams("description", "name", 0) 67 | _, err := client.Alert.GenerateAlert(p) 68 | if err != nil { 69 | t.Errorf(err.Error()) 70 | } 71 | } 72 | t.Run("GenerateAlert", testgenerateAlert) 73 | 74 | testlistAlerts := func(t *testing.T) { 75 | if _, ok := response["listAlerts"]; !ok { 76 | t.Skipf("Skipping as no json response is provided in testdata") 77 | } 78 | p := client.Alert.NewListAlertsParams() 79 | _, err := client.Alert.ListAlerts(p) 80 | if err != nil { 81 | t.Errorf(err.Error()) 82 | } 83 | } 84 | t.Run("ListAlerts", testlistAlerts) 85 | 86 | testlistAlertTypes := func(t *testing.T) { 87 | if _, ok := response["listAlertTypes"]; !ok { 88 | t.Skipf("Skipping as no json response is provided in testdata") 89 | } 90 | p := client.Alert.NewListAlertTypesParams() 91 | _, err := client.Alert.ListAlertTypes(p) 92 | if err != nil { 93 | t.Errorf(err.Error()) 94 | } 95 | } 96 | t.Run("ListAlertTypes", testlistAlertTypes) 97 | 98 | } 99 | -------------------------------------------------------------------------------- /test/AnnotationService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestAnnotationService(t *testing.T) { 29 | service := "AnnotationService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testaddAnnotation := func(t *testing.T) { 39 | if _, ok := response["addAnnotation"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.Annotation.NewAddAnnotationParams() 43 | r, err := client.Annotation.AddAnnotation(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | if r.Id == "" { 48 | t.Errorf("Failed to parse response. ID not found") 49 | } 50 | } 51 | t.Run("AddAnnotation", testaddAnnotation) 52 | 53 | testlistAnnotations := func(t *testing.T) { 54 | if _, ok := response["listAnnotations"]; !ok { 55 | t.Skipf("Skipping as no json response is provided in testdata") 56 | } 57 | p := client.Annotation.NewListAnnotationsParams() 58 | _, err := client.Annotation.ListAnnotations(p) 59 | if err != nil { 60 | t.Errorf(err.Error()) 61 | } 62 | } 63 | t.Run("ListAnnotations", testlistAnnotations) 64 | 65 | testremoveAnnotation := func(t *testing.T) { 66 | if _, ok := response["removeAnnotation"]; !ok { 67 | t.Skipf("Skipping as no json response is provided in testdata") 68 | } 69 | p := client.Annotation.NewRemoveAnnotationParams("id") 70 | r, err := client.Annotation.RemoveAnnotation(p) 71 | if err != nil { 72 | t.Errorf(err.Error()) 73 | } 74 | if r.Id == "" { 75 | t.Errorf("Failed to parse response. ID not found") 76 | } 77 | } 78 | t.Run("RemoveAnnotation", testremoveAnnotation) 79 | 80 | testupdateAnnotationVisibility := func(t *testing.T) { 81 | if _, ok := response["updateAnnotationVisibility"]; !ok { 82 | t.Skipf("Skipping as no json response is provided in testdata") 83 | } 84 | p := client.Annotation.NewUpdateAnnotationVisibilityParams(true, "id") 85 | r, err := client.Annotation.UpdateAnnotationVisibility(p) 86 | if err != nil { 87 | t.Errorf(err.Error()) 88 | } 89 | if r.Id == "" { 90 | t.Errorf("Failed to parse response. ID not found") 91 | } 92 | } 93 | t.Run("UpdateAnnotationVisibility", testupdateAnnotationVisibility) 94 | 95 | } 96 | -------------------------------------------------------------------------------- /cloudstack/CloudIdentifierService.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package cloudstack 21 | 22 | import ( 23 | "encoding/json" 24 | "net/url" 25 | ) 26 | 27 | type CloudIdentifierServiceIface interface { 28 | GetCloudIdentifier(p *GetCloudIdentifierParams) (*GetCloudIdentifierResponse, error) 29 | NewGetCloudIdentifierParams(userid string) *GetCloudIdentifierParams 30 | } 31 | 32 | type GetCloudIdentifierParams struct { 33 | p map[string]interface{} 34 | } 35 | 36 | func (p *GetCloudIdentifierParams) toURLValues() url.Values { 37 | u := url.Values{} 38 | if p.p == nil { 39 | return u 40 | } 41 | if v, found := p.p["userid"]; found { 42 | u.Set("userid", v.(string)) 43 | } 44 | return u 45 | } 46 | 47 | func (p *GetCloudIdentifierParams) SetUserid(v string) { 48 | if p.p == nil { 49 | p.p = make(map[string]interface{}) 50 | } 51 | p.p["userid"] = v 52 | } 53 | 54 | func (p *GetCloudIdentifierParams) ResetUserid() { 55 | if p.p != nil && p.p["userid"] != nil { 56 | delete(p.p, "userid") 57 | } 58 | } 59 | 60 | func (p *GetCloudIdentifierParams) GetUserid() (string, bool) { 61 | if p.p == nil { 62 | p.p = make(map[string]interface{}) 63 | } 64 | value, ok := p.p["userid"].(string) 65 | return value, ok 66 | } 67 | 68 | // You should always use this function to get a new GetCloudIdentifierParams instance, 69 | // as then you are sure you have configured all required params 70 | func (s *CloudIdentifierService) NewGetCloudIdentifierParams(userid string) *GetCloudIdentifierParams { 71 | p := &GetCloudIdentifierParams{} 72 | p.p = make(map[string]interface{}) 73 | p.p["userid"] = userid 74 | return p 75 | } 76 | 77 | // Retrieves a cloud identifier. 78 | func (s *CloudIdentifierService) GetCloudIdentifier(p *GetCloudIdentifierParams) (*GetCloudIdentifierResponse, error) { 79 | resp, err := s.cs.newRequest("getCloudIdentifier", p.toURLValues()) 80 | if err != nil { 81 | return nil, err 82 | } 83 | 84 | var nested struct { 85 | Response GetCloudIdentifierResponse `json:"cloudidentifier"` 86 | } 87 | if err := json.Unmarshal(resp, &nested); err != nil { 88 | return nil, err 89 | } 90 | r := nested.Response 91 | 92 | return &r, nil 93 | } 94 | 95 | type GetCloudIdentifierResponse struct { 96 | Cloudidentifier string `json:"cloudidentifier"` 97 | JobID string `json:"jobid"` 98 | Jobstatus int `json:"jobstatus"` 99 | Signature string `json:"signature"` 100 | Userid string `json:"userid"` 101 | } 102 | -------------------------------------------------------------------------------- /test/LimitService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestLimitService(t *testing.T) { 29 | service := "LimitService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testgetApiLimit := func(t *testing.T) { 39 | if _, ok := response["getApiLimit"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.Limit.NewGetApiLimitParams() 43 | _, err := client.Limit.GetApiLimit(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("GetApiLimit", testgetApiLimit) 49 | 50 | testlistResourceLimits := func(t *testing.T) { 51 | if _, ok := response["listResourceLimits"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.Limit.NewListResourceLimitsParams() 55 | _, err := client.Limit.ListResourceLimits(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | } 60 | t.Run("ListResourceLimits", testlistResourceLimits) 61 | 62 | testresetApiLimit := func(t *testing.T) { 63 | if _, ok := response["resetApiLimit"]; !ok { 64 | t.Skipf("Skipping as no json response is provided in testdata") 65 | } 66 | p := client.Limit.NewResetApiLimitParams() 67 | _, err := client.Limit.ResetApiLimit(p) 68 | if err != nil { 69 | t.Errorf(err.Error()) 70 | } 71 | } 72 | t.Run("ResetApiLimit", testresetApiLimit) 73 | 74 | testupdateResourceCount := func(t *testing.T) { 75 | if _, ok := response["updateResourceCount"]; !ok { 76 | t.Skipf("Skipping as no json response is provided in testdata") 77 | } 78 | p := client.Limit.NewUpdateResourceCountParams("domainid") 79 | _, err := client.Limit.UpdateResourceCount(p) 80 | if err != nil { 81 | t.Errorf(err.Error()) 82 | } 83 | } 84 | t.Run("UpdateResourceCount", testupdateResourceCount) 85 | 86 | testupdateResourceLimit := func(t *testing.T) { 87 | if _, ok := response["updateResourceLimit"]; !ok { 88 | t.Skipf("Skipping as no json response is provided in testdata") 89 | } 90 | p := client.Limit.NewUpdateResourceLimitParams(0) 91 | _, err := client.Limit.UpdateResourceLimit(p) 92 | if err != nil { 93 | t.Errorf(err.Error()) 94 | } 95 | } 96 | t.Run("UpdateResourceLimit", testupdateResourceLimit) 97 | 98 | } 99 | -------------------------------------------------------------------------------- /test/ServiceOfferingService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestServiceOfferingService(t *testing.T) { 29 | service := "ServiceOfferingService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testcreateServiceOffering := func(t *testing.T) { 39 | if _, ok := response["createServiceOffering"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.ServiceOffering.NewCreateServiceOfferingParams("displaytext", "name") 43 | r, err := client.ServiceOffering.CreateServiceOffering(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | if r.Id == "" { 48 | t.Errorf("Failed to parse response. ID not found") 49 | } 50 | } 51 | t.Run("CreateServiceOffering", testcreateServiceOffering) 52 | 53 | testdeleteServiceOffering := func(t *testing.T) { 54 | if _, ok := response["deleteServiceOffering"]; !ok { 55 | t.Skipf("Skipping as no json response is provided in testdata") 56 | } 57 | p := client.ServiceOffering.NewDeleteServiceOfferingParams("id") 58 | _, err := client.ServiceOffering.DeleteServiceOffering(p) 59 | if err != nil { 60 | t.Errorf(err.Error()) 61 | } 62 | } 63 | t.Run("DeleteServiceOffering", testdeleteServiceOffering) 64 | 65 | testlistServiceOfferings := func(t *testing.T) { 66 | if _, ok := response["listServiceOfferings"]; !ok { 67 | t.Skipf("Skipping as no json response is provided in testdata") 68 | } 69 | p := client.ServiceOffering.NewListServiceOfferingsParams() 70 | _, err := client.ServiceOffering.ListServiceOfferings(p) 71 | if err != nil { 72 | t.Errorf(err.Error()) 73 | } 74 | } 75 | t.Run("ListServiceOfferings", testlistServiceOfferings) 76 | 77 | testupdateServiceOffering := func(t *testing.T) { 78 | if _, ok := response["updateServiceOffering"]; !ok { 79 | t.Skipf("Skipping as no json response is provided in testdata") 80 | } 81 | p := client.ServiceOffering.NewUpdateServiceOfferingParams("id") 82 | r, err := client.ServiceOffering.UpdateServiceOffering(p) 83 | if err != nil { 84 | t.Errorf(err.Error()) 85 | } 86 | if r.Id == "" { 87 | t.Errorf("Failed to parse response. ID not found") 88 | } 89 | } 90 | t.Run("UpdateServiceOffering", testupdateServiceOffering) 91 | 92 | } 93 | -------------------------------------------------------------------------------- /test/NetworkOfferingService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestNetworkOfferingService(t *testing.T) { 29 | service := "NetworkOfferingService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testcreateNetworkOffering := func(t *testing.T) { 39 | if _, ok := response["createNetworkOffering"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.NetworkOffering.NewCreateNetworkOfferingParams("displaytext", "guestiptype", "name", "traffictype") 43 | r, err := client.NetworkOffering.CreateNetworkOffering(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | if r.Id == "" { 48 | t.Errorf("Failed to parse response. ID not found") 49 | } 50 | } 51 | t.Run("CreateNetworkOffering", testcreateNetworkOffering) 52 | 53 | testdeleteNetworkOffering := func(t *testing.T) { 54 | if _, ok := response["deleteNetworkOffering"]; !ok { 55 | t.Skipf("Skipping as no json response is provided in testdata") 56 | } 57 | p := client.NetworkOffering.NewDeleteNetworkOfferingParams("id") 58 | _, err := client.NetworkOffering.DeleteNetworkOffering(p) 59 | if err != nil { 60 | t.Errorf(err.Error()) 61 | } 62 | } 63 | t.Run("DeleteNetworkOffering", testdeleteNetworkOffering) 64 | 65 | testlistNetworkOfferings := func(t *testing.T) { 66 | if _, ok := response["listNetworkOfferings"]; !ok { 67 | t.Skipf("Skipping as no json response is provided in testdata") 68 | } 69 | p := client.NetworkOffering.NewListNetworkOfferingsParams() 70 | _, err := client.NetworkOffering.ListNetworkOfferings(p) 71 | if err != nil { 72 | t.Errorf(err.Error()) 73 | } 74 | } 75 | t.Run("ListNetworkOfferings", testlistNetworkOfferings) 76 | 77 | testupdateNetworkOffering := func(t *testing.T) { 78 | if _, ok := response["updateNetworkOffering"]; !ok { 79 | t.Skipf("Skipping as no json response is provided in testdata") 80 | } 81 | p := client.NetworkOffering.NewUpdateNetworkOfferingParams() 82 | r, err := client.NetworkOffering.UpdateNetworkOffering(p) 83 | if err != nil { 84 | t.Errorf(err.Error()) 85 | } 86 | if r.Id == "" { 87 | t.Errorf("Failed to parse response. ID not found") 88 | } 89 | } 90 | t.Run("UpdateNetworkOffering", testupdateNetworkOffering) 91 | 92 | } 93 | -------------------------------------------------------------------------------- /test/testdata/StoragePoolService.json: -------------------------------------------------------------------------------- 1 | { 2 | "cancelStorageMaintenance": { 3 | "cancelprimarystoragemaintenanceresponse": { 4 | "accountid": "27ef5ba2-5fe0-11ea-9a56-1e006800018c", 5 | "userid": "27f2484f-5fe0-11ea-9a56-1e006800018c", 6 | "cmd": "org.apache.cloudstack.api.command.admin.storage.CancelPrimaryStorageMaintenanceCmd", 7 | "jobstatus": 1, 8 | "jobprocstatus": 0, 9 | "jobresultcode": 0, 10 | "jobresulttype": "object", 11 | "jobresult": { 12 | "storagepool": { 13 | "id": "44ad900d-785b-3eff-addc-a5e6bf4927ef", 14 | "zoneid": "753941b6-5239-4ab3-b2b3-7522d2a6d1ba", 15 | "zonename": "DummySG", 16 | "podid": "b52f7877-227e-4e3f-974b-2397a37d6e1c", 17 | "podname": "SGAdvPod", 18 | "name": "SGAdvPS", 19 | "ipaddress": "10.1.1.3", 20 | "path": "/export/testing/primary ", 21 | "created": "2020-07-27T06:01:56+0000", 22 | "type": "NetworkFilesystem", 23 | "clusterid": "a7b4c0e1-8ba4-41ea-a2f4-490798ddd166", 24 | "clustername": "SGAdvCluster", 25 | "disksizetotal": 1099511627776, 26 | "disksizeallocated": 100, 27 | "state": "Up", 28 | "scope": "CLUSTER", 29 | "overprovisionfactor": "2.0", 30 | "provider": "DefaultPrimary", 31 | "jobid": "7cc3faa4-73c5-45cb-a982-683a13023827", 32 | "jobstatus": 0 33 | } 34 | }, 35 | "jobinstancetype": "StoragePool", 36 | "jobinstanceid": "44ad900d-785b-3eff-addc-a5e6bf4927ef", 37 | "created": "2021-10-04T08:06:55+0000", 38 | "completed": "2021-10-04T08:06:55+0000", 39 | "jobid": "7cc3faa4-73c5-45cb-a982-683a13023827" 40 | } 41 | }, 42 | "enableStorageMaintenance": { 43 | "prepareprimarystorageformaintenanceresponse": { 44 | "accountid": "27ef5ba2-5fe0-11ea-9a56-1e006800018c", 45 | "userid": "27f2484f-5fe0-11ea-9a56-1e006800018c", 46 | "cmd": "org.apache.cloudstack.api.command.admin.storage.PreparePrimaryStorageForMaintenanceCmd", 47 | "jobstatus": 1, 48 | "jobprocstatus": 0, 49 | "jobresultcode": 0, 50 | "jobresulttype": "object", 51 | "jobresult": { 52 | "storagepool": { 53 | "id": "44ad900d-785b-3eff-addc-a5e6bf4927ef", 54 | "zoneid": "753941b6-5239-4ab3-b2b3-7522d2a6d1ba", 55 | "zonename": "DummySG", 56 | "podid": "b52f7877-227e-4e3f-974b-2397a37d6e1c", 57 | "podname": "SGAdvPod", 58 | "name": "SGAdvPS", 59 | "ipaddress": "10.1.1.3", 60 | "path": "/export/testing/primary ", 61 | "created": "2020-07-27T06:01:56+0000", 62 | "type": "NetworkFilesystem", 63 | "clusterid": "a7b4c0e1-8ba4-41ea-a2f4-490798ddd166", 64 | "clustername": "SGAdvCluster", 65 | "disksizetotal": 1099511627776, 66 | "disksizeallocated": 100, 67 | "state": "Maintenance", 68 | "scope": "CLUSTER", 69 | "overprovisionfactor": "2.0", 70 | "provider": "DefaultPrimary", 71 | "jobid": "3036df18-12ca-44a0-9c77-19fcf81dad75", 72 | "jobstatus": 0 73 | } 74 | }, 75 | "jobinstancetype": "StoragePool", 76 | "jobinstanceid": "44ad900d-785b-3eff-addc-a5e6bf4927ef", 77 | "created": "2021-10-04T08:13:01+0000", 78 | "completed": "2021-10-04T08:13:02+0000", 79 | "jobid": "3036df18-12ca-44a0-9c77-19fcf81dad75" 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /cloudstack/APIDiscoveryService_mock.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | // Code generated by MockGen. DO NOT EDIT. 21 | // Source: ./cloudstack/APIDiscoveryService.go 22 | // 23 | // Generated by this command: 24 | // 25 | // mockgen -destination=./cloudstack/APIDiscoveryService_mock.go -package=cloudstack -copyright_file=header.txt -source=./cloudstack/APIDiscoveryService.go 26 | // 27 | 28 | // Package cloudstack is a generated GoMock package. 29 | package cloudstack 30 | 31 | import ( 32 | reflect "reflect" 33 | 34 | gomock "go.uber.org/mock/gomock" 35 | ) 36 | 37 | // MockAPIDiscoveryServiceIface is a mock of APIDiscoveryServiceIface interface. 38 | type MockAPIDiscoveryServiceIface struct { 39 | ctrl *gomock.Controller 40 | recorder *MockAPIDiscoveryServiceIfaceMockRecorder 41 | isgomock struct{} 42 | } 43 | 44 | // MockAPIDiscoveryServiceIfaceMockRecorder is the mock recorder for MockAPIDiscoveryServiceIface. 45 | type MockAPIDiscoveryServiceIfaceMockRecorder struct { 46 | mock *MockAPIDiscoveryServiceIface 47 | } 48 | 49 | // NewMockAPIDiscoveryServiceIface creates a new mock instance. 50 | func NewMockAPIDiscoveryServiceIface(ctrl *gomock.Controller) *MockAPIDiscoveryServiceIface { 51 | mock := &MockAPIDiscoveryServiceIface{ctrl: ctrl} 52 | mock.recorder = &MockAPIDiscoveryServiceIfaceMockRecorder{mock} 53 | return mock 54 | } 55 | 56 | // EXPECT returns an object that allows the caller to indicate expected use. 57 | func (m *MockAPIDiscoveryServiceIface) EXPECT() *MockAPIDiscoveryServiceIfaceMockRecorder { 58 | return m.recorder 59 | } 60 | 61 | // ListApis mocks base method. 62 | func (m *MockAPIDiscoveryServiceIface) ListApis(p *ListApisParams) (*ListApisResponse, error) { 63 | m.ctrl.T.Helper() 64 | ret := m.ctrl.Call(m, "ListApis", p) 65 | ret0, _ := ret[0].(*ListApisResponse) 66 | ret1, _ := ret[1].(error) 67 | return ret0, ret1 68 | } 69 | 70 | // ListApis indicates an expected call of ListApis. 71 | func (mr *MockAPIDiscoveryServiceIfaceMockRecorder) ListApis(p any) *gomock.Call { 72 | mr.mock.ctrl.T.Helper() 73 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListApis", reflect.TypeOf((*MockAPIDiscoveryServiceIface)(nil).ListApis), p) 74 | } 75 | 76 | // NewListApisParams mocks base method. 77 | func (m *MockAPIDiscoveryServiceIface) NewListApisParams() *ListApisParams { 78 | m.ctrl.T.Helper() 79 | ret := m.ctrl.Call(m, "NewListApisParams") 80 | ret0, _ := ret[0].(*ListApisParams) 81 | return ret0 82 | } 83 | 84 | // NewListApisParams indicates an expected call of NewListApisParams. 85 | func (mr *MockAPIDiscoveryServiceIfaceMockRecorder) NewListApisParams() *gomock.Call { 86 | mr.mock.ctrl.T.Helper() 87 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewListApisParams", reflect.TypeOf((*MockAPIDiscoveryServiceIface)(nil).NewListApisParams)) 88 | } 89 | -------------------------------------------------------------------------------- /test/testdata/FirewallService.json: -------------------------------------------------------------------------------- 1 | { 2 | "createFirewallRule": { 3 | "createfirewallruleresponse": { 4 | "accountid": "bc1b501c-1d18-11ec-9173-50eb7122da94", 5 | "userid": "bc1b6b47-1d18-11ec-9173-50eb7122da94", 6 | "cmd": "org.apache.cloudstack.api.command.user.firewall.CreateFirewallRuleCmd", 7 | "jobstatus": 1, 8 | "jobprocstatus": 0, 9 | "jobresultcode": 0, 10 | "jobresulttype": "object", 11 | "jobresult": { 12 | "firewallrule": { 13 | "id": "fb4ad2ee-02c8-433e-a769-6f18afddc750", 14 | "protocol": "tcp", 15 | "ipaddressid": "a4aa35ef-34ad-4332-9247-378c83b8f927", 16 | "networkid": "c4a3303c-376d-4d56-b336-1bd91cb130b6", 17 | "ipaddress": "192.168.2.4", 18 | "state": "Active", 19 | "cidrlist": "0.0.0.0/0", 20 | "tags": [], 21 | "fordisplay": true 22 | } 23 | }, 24 | "jobinstancetype": "FirewallRule", 25 | "jobinstanceid": "fb4ad2ee-02c8-433e-a769-6f18afddc750", 26 | "created": "2021-10-02T23:20:07+0530", 27 | "completed": "2021-10-02T23:20:07+0530", 28 | "jobid": "104d5139-91dc-40a1-af2b-a94730e42e89" 29 | } 30 | }, 31 | "deleteFirewallRule": { 32 | "deletefirewallruleresponse": { 33 | "accountid": "bc1b501c-1d18-11ec-9173-50eb7122da94", 34 | "userid": "bc1b6b47-1d18-11ec-9173-50eb7122da94", 35 | "cmd": "org.apache.cloudstack.api.command.user.firewall.DeleteFirewallRuleCmd", 36 | "jobstatus": 1, 37 | "jobprocstatus": 0, 38 | "jobresultcode": 0, 39 | "jobresulttype": "object", 40 | "jobresult": { 41 | "success": true 42 | }, 43 | "created": "2021-10-02T23:25:22+0530", 44 | "completed": "2021-10-02T23:25:22+0530", 45 | "jobid": "6ae96f78-1c28-45f9-a30b-761ac5f3a87b" 46 | } 47 | }, 48 | "createEgressFirewallRule": { 49 | "createegressfirewallruleresponse": { 50 | "accountid": "bc1b501c-1d18-11ec-9173-50eb7122da94", 51 | "userid": "bc1b6b47-1d18-11ec-9173-50eb7122da94", 52 | "cmd": "org.apache.cloudstack.api.command.user.firewall.CreateEgressFirewallRuleCmd", 53 | "jobstatus": 1, 54 | "jobprocstatus": 0, 55 | "jobresultcode": 0, 56 | "jobresulttype": "object", 57 | "jobresult": { 58 | "firewallrule": { 59 | "id": "b7d8b539-8c72-4d25-8539-625f665681ad", 60 | "protocol": "tcp", 61 | "networkid": "c4a3303c-376d-4d56-b336-1bd91cb130b6", 62 | "state": "Active", 63 | "cidrlist": "10.1.1.0/24", 64 | "tags": [], 65 | "fordisplay": true, 66 | "destcidrlist": "" 67 | } 68 | }, 69 | "jobinstancetype": "FirewallRule", 70 | "jobinstanceid": "b7d8b539-8c72-4d25-8539-625f665681ad", 71 | "created": "2021-10-02T23:29:41+0530", 72 | "completed": "2021-10-02T23:29:41+0530", 73 | "jobid": "8841a004-eb50-4d4e-aed5-7bc2494dc856" 74 | } 75 | }, 76 | "deleteEgressFirewallRule": { 77 | "deleteegressfirewallruleresponse": { 78 | "accountid": "bc1b501c-1d18-11ec-9173-50eb7122da94", 79 | "userid": "bc1b6b47-1d18-11ec-9173-50eb7122da94", 80 | "cmd": "org.apache.cloudstack.api.command.user.firewall.DeleteEgressFirewallRuleCmd", 81 | "jobstatus": 1, 82 | "jobprocstatus": 0, 83 | "jobresultcode": 0, 84 | "jobresulttype": "object", 85 | "jobresult": { 86 | "success": true 87 | }, 88 | "created": "2021-10-02T23:32:08+0530", 89 | "completed": "2021-10-02T23:32:08+0530", 90 | "jobid": "91b10008-2e9f-412d-afa6-3c54a0bb19f5" 91 | } 92 | } 93 | } -------------------------------------------------------------------------------- /cloudstack/MiscService.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package cloudstack 21 | 22 | import ( 23 | "encoding/json" 24 | "net/url" 25 | ) 26 | 27 | type MiscServiceIface interface { 28 | ListElastistorInterface(p *ListElastistorInterfaceParams) (*ListElastistorInterfaceResponse, error) 29 | NewListElastistorInterfaceParams() *ListElastistorInterfaceParams 30 | } 31 | 32 | type ListElastistorInterfaceParams struct { 33 | p map[string]interface{} 34 | } 35 | 36 | func (p *ListElastistorInterfaceParams) toURLValues() url.Values { 37 | u := url.Values{} 38 | if p.p == nil { 39 | return u 40 | } 41 | if v, found := p.p["controllerid"]; found { 42 | u.Set("controllerid", v.(string)) 43 | } 44 | return u 45 | } 46 | 47 | func (p *ListElastistorInterfaceParams) SetControllerid(v string) { 48 | if p.p == nil { 49 | p.p = make(map[string]interface{}) 50 | } 51 | p.p["controllerid"] = v 52 | } 53 | 54 | func (p *ListElastistorInterfaceParams) ResetControllerid() { 55 | if p.p != nil && p.p["controllerid"] != nil { 56 | delete(p.p, "controllerid") 57 | } 58 | } 59 | 60 | func (p *ListElastistorInterfaceParams) GetControllerid() (string, bool) { 61 | if p.p == nil { 62 | p.p = make(map[string]interface{}) 63 | } 64 | value, ok := p.p["controllerid"].(string) 65 | return value, ok 66 | } 67 | 68 | // You should always use this function to get a new ListElastistorInterfaceParams instance, 69 | // as then you are sure you have configured all required params 70 | func (s *MiscService) NewListElastistorInterfaceParams() *ListElastistorInterfaceParams { 71 | p := &ListElastistorInterfaceParams{} 72 | p.p = make(map[string]interface{}) 73 | return p 74 | } 75 | 76 | // Lists the network Interfaces of elastistor 77 | func (s *MiscService) ListElastistorInterface(p *ListElastistorInterfaceParams) (*ListElastistorInterfaceResponse, error) { 78 | resp, err := s.cs.newRequest("listElastistorInterface", p.toURLValues()) 79 | if err != nil { 80 | return nil, err 81 | } 82 | 83 | var r ListElastistorInterfaceResponse 84 | if err := json.Unmarshal(resp, &r); err != nil { 85 | return nil, err 86 | } 87 | 88 | return &r, nil 89 | } 90 | 91 | type ListElastistorInterfaceResponse struct { 92 | Count int `json:"count"` 93 | ElastistorInterface []*ElastistorInterface `json:"elastistorinterface"` 94 | } 95 | 96 | type ElastistorInterface struct { 97 | Compression string `json:"compression"` 98 | Deduplication string `json:"deduplication"` 99 | Graceallowed string `json:"graceallowed"` 100 | Id string `json:"id"` 101 | JobID string `json:"jobid"` 102 | Jobstatus int `json:"jobstatus"` 103 | Name string `json:"name"` 104 | Sync string `json:"sync"` 105 | } 106 | -------------------------------------------------------------------------------- /cloudstack/MetricsService_mock.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | // Code generated by MockGen. DO NOT EDIT. 21 | // Source: ./cloudstack/MetricsService.go 22 | // 23 | // Generated by this command: 24 | // 25 | // mockgen -destination=./cloudstack/MetricsService_mock.go -package=cloudstack -copyright_file=header.txt -source=./cloudstack/MetricsService.go 26 | // 27 | 28 | // Package cloudstack is a generated GoMock package. 29 | package cloudstack 30 | 31 | import ( 32 | reflect "reflect" 33 | 34 | gomock "go.uber.org/mock/gomock" 35 | ) 36 | 37 | // MockMetricsServiceIface is a mock of MetricsServiceIface interface. 38 | type MockMetricsServiceIface struct { 39 | ctrl *gomock.Controller 40 | recorder *MockMetricsServiceIfaceMockRecorder 41 | isgomock struct{} 42 | } 43 | 44 | // MockMetricsServiceIfaceMockRecorder is the mock recorder for MockMetricsServiceIface. 45 | type MockMetricsServiceIfaceMockRecorder struct { 46 | mock *MockMetricsServiceIface 47 | } 48 | 49 | // NewMockMetricsServiceIface creates a new mock instance. 50 | func NewMockMetricsServiceIface(ctrl *gomock.Controller) *MockMetricsServiceIface { 51 | mock := &MockMetricsServiceIface{ctrl: ctrl} 52 | mock.recorder = &MockMetricsServiceIfaceMockRecorder{mock} 53 | return mock 54 | } 55 | 56 | // EXPECT returns an object that allows the caller to indicate expected use. 57 | func (m *MockMetricsServiceIface) EXPECT() *MockMetricsServiceIfaceMockRecorder { 58 | return m.recorder 59 | } 60 | 61 | // ListInfrastructure mocks base method. 62 | func (m *MockMetricsServiceIface) ListInfrastructure(p *ListInfrastructureParams) (*ListInfrastructureResponse, error) { 63 | m.ctrl.T.Helper() 64 | ret := m.ctrl.Call(m, "ListInfrastructure", p) 65 | ret0, _ := ret[0].(*ListInfrastructureResponse) 66 | ret1, _ := ret[1].(error) 67 | return ret0, ret1 68 | } 69 | 70 | // ListInfrastructure indicates an expected call of ListInfrastructure. 71 | func (mr *MockMetricsServiceIfaceMockRecorder) ListInfrastructure(p any) *gomock.Call { 72 | mr.mock.ctrl.T.Helper() 73 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListInfrastructure", reflect.TypeOf((*MockMetricsServiceIface)(nil).ListInfrastructure), p) 74 | } 75 | 76 | // NewListInfrastructureParams mocks base method. 77 | func (m *MockMetricsServiceIface) NewListInfrastructureParams() *ListInfrastructureParams { 78 | m.ctrl.T.Helper() 79 | ret := m.ctrl.Call(m, "NewListInfrastructureParams") 80 | ret0, _ := ret[0].(*ListInfrastructureParams) 81 | return ret0 82 | } 83 | 84 | // NewListInfrastructureParams indicates an expected call of NewListInfrastructureParams. 85 | func (mr *MockMetricsServiceIfaceMockRecorder) NewListInfrastructureParams() *gomock.Call { 86 | mr.mock.ctrl.T.Helper() 87 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewListInfrastructureParams", reflect.TypeOf((*MockMetricsServiceIface)(nil).NewListInfrastructureParams)) 88 | } 89 | -------------------------------------------------------------------------------- /cloudstack/CloudianService_mock.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | // Code generated by MockGen. DO NOT EDIT. 21 | // Source: ./cloudstack/CloudianService.go 22 | // 23 | // Generated by this command: 24 | // 25 | // mockgen -destination=./cloudstack/CloudianService_mock.go -package=cloudstack -copyright_file=header.txt -source=./cloudstack/CloudianService.go 26 | // 27 | 28 | // Package cloudstack is a generated GoMock package. 29 | package cloudstack 30 | 31 | import ( 32 | reflect "reflect" 33 | 34 | gomock "go.uber.org/mock/gomock" 35 | ) 36 | 37 | // MockCloudianServiceIface is a mock of CloudianServiceIface interface. 38 | type MockCloudianServiceIface struct { 39 | ctrl *gomock.Controller 40 | recorder *MockCloudianServiceIfaceMockRecorder 41 | isgomock struct{} 42 | } 43 | 44 | // MockCloudianServiceIfaceMockRecorder is the mock recorder for MockCloudianServiceIface. 45 | type MockCloudianServiceIfaceMockRecorder struct { 46 | mock *MockCloudianServiceIface 47 | } 48 | 49 | // NewMockCloudianServiceIface creates a new mock instance. 50 | func NewMockCloudianServiceIface(ctrl *gomock.Controller) *MockCloudianServiceIface { 51 | mock := &MockCloudianServiceIface{ctrl: ctrl} 52 | mock.recorder = &MockCloudianServiceIfaceMockRecorder{mock} 53 | return mock 54 | } 55 | 56 | // EXPECT returns an object that allows the caller to indicate expected use. 57 | func (m *MockCloudianServiceIface) EXPECT() *MockCloudianServiceIfaceMockRecorder { 58 | return m.recorder 59 | } 60 | 61 | // CloudianIsEnabled mocks base method. 62 | func (m *MockCloudianServiceIface) CloudianIsEnabled(p *CloudianIsEnabledParams) (*CloudianIsEnabledResponse, error) { 63 | m.ctrl.T.Helper() 64 | ret := m.ctrl.Call(m, "CloudianIsEnabled", p) 65 | ret0, _ := ret[0].(*CloudianIsEnabledResponse) 66 | ret1, _ := ret[1].(error) 67 | return ret0, ret1 68 | } 69 | 70 | // CloudianIsEnabled indicates an expected call of CloudianIsEnabled. 71 | func (mr *MockCloudianServiceIfaceMockRecorder) CloudianIsEnabled(p any) *gomock.Call { 72 | mr.mock.ctrl.T.Helper() 73 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CloudianIsEnabled", reflect.TypeOf((*MockCloudianServiceIface)(nil).CloudianIsEnabled), p) 74 | } 75 | 76 | // NewCloudianIsEnabledParams mocks base method. 77 | func (m *MockCloudianServiceIface) NewCloudianIsEnabledParams() *CloudianIsEnabledParams { 78 | m.ctrl.T.Helper() 79 | ret := m.ctrl.Call(m, "NewCloudianIsEnabledParams") 80 | ret0, _ := ret[0].(*CloudianIsEnabledParams) 81 | return ret0 82 | } 83 | 84 | // NewCloudianIsEnabledParams indicates an expected call of NewCloudianIsEnabledParams. 85 | func (mr *MockCloudianServiceIfaceMockRecorder) NewCloudianIsEnabledParams() *gomock.Call { 86 | mr.mock.ctrl.T.Helper() 87 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewCloudianIsEnabledParams", reflect.TypeOf((*MockCloudianServiceIface)(nil).NewCloudianIsEnabledParams)) 88 | } 89 | -------------------------------------------------------------------------------- /test/NATService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestNATService(t *testing.T) { 29 | service := "NATService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testcreateIpForwardingRule := func(t *testing.T) { 39 | if _, ok := response["createIpForwardingRule"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.NAT.NewCreateIpForwardingRuleParams("ipaddressid", "protocol", 0) 43 | r, err := client.NAT.CreateIpForwardingRule(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | if r.Id == "" { 48 | t.Errorf("Failed to parse response. ID not found") 49 | } 50 | } 51 | t.Run("CreateIpForwardingRule", testcreateIpForwardingRule) 52 | 53 | testdeleteIpForwardingRule := func(t *testing.T) { 54 | if _, ok := response["deleteIpForwardingRule"]; !ok { 55 | t.Skipf("Skipping as no json response is provided in testdata") 56 | } 57 | p := client.NAT.NewDeleteIpForwardingRuleParams("id") 58 | _, err := client.NAT.DeleteIpForwardingRule(p) 59 | if err != nil { 60 | t.Errorf(err.Error()) 61 | } 62 | } 63 | t.Run("DeleteIpForwardingRule", testdeleteIpForwardingRule) 64 | 65 | testdisableStaticNat := func(t *testing.T) { 66 | if _, ok := response["disableStaticNat"]; !ok { 67 | t.Skipf("Skipping as no json response is provided in testdata") 68 | } 69 | p := client.NAT.NewDisableStaticNatParams("ipaddressid") 70 | _, err := client.NAT.DisableStaticNat(p) 71 | if err != nil { 72 | t.Errorf(err.Error()) 73 | } 74 | } 75 | t.Run("DisableStaticNat", testdisableStaticNat) 76 | 77 | testenableStaticNat := func(t *testing.T) { 78 | if _, ok := response["enableStaticNat"]; !ok { 79 | t.Skipf("Skipping as no json response is provided in testdata") 80 | } 81 | p := client.NAT.NewEnableStaticNatParams("ipaddressid", "virtualmachineid") 82 | _, err := client.NAT.EnableStaticNat(p) 83 | if err != nil { 84 | t.Errorf(err.Error()) 85 | } 86 | } 87 | t.Run("EnableStaticNat", testenableStaticNat) 88 | 89 | testlistIpForwardingRules := func(t *testing.T) { 90 | if _, ok := response["listIpForwardingRules"]; !ok { 91 | t.Skipf("Skipping as no json response is provided in testdata") 92 | } 93 | p := client.NAT.NewListIpForwardingRulesParams() 94 | _, err := client.NAT.ListIpForwardingRules(p) 95 | if err != nil { 96 | t.Errorf(err.Error()) 97 | } 98 | } 99 | t.Run("ListIpForwardingRules", testlistIpForwardingRules) 100 | 101 | } 102 | -------------------------------------------------------------------------------- /cloudstack/MiscService_mock.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | // Code generated by MockGen. DO NOT EDIT. 21 | // Source: ./cloudstack/MiscService.go 22 | // 23 | // Generated by this command: 24 | // 25 | // mockgen -destination=./cloudstack/MiscService_mock.go -package=cloudstack -copyright_file=header.txt -source=./cloudstack/MiscService.go 26 | // 27 | 28 | // Package cloudstack is a generated GoMock package. 29 | package cloudstack 30 | 31 | import ( 32 | reflect "reflect" 33 | 34 | gomock "go.uber.org/mock/gomock" 35 | ) 36 | 37 | // MockMiscServiceIface is a mock of MiscServiceIface interface. 38 | type MockMiscServiceIface struct { 39 | ctrl *gomock.Controller 40 | recorder *MockMiscServiceIfaceMockRecorder 41 | isgomock struct{} 42 | } 43 | 44 | // MockMiscServiceIfaceMockRecorder is the mock recorder for MockMiscServiceIface. 45 | type MockMiscServiceIfaceMockRecorder struct { 46 | mock *MockMiscServiceIface 47 | } 48 | 49 | // NewMockMiscServiceIface creates a new mock instance. 50 | func NewMockMiscServiceIface(ctrl *gomock.Controller) *MockMiscServiceIface { 51 | mock := &MockMiscServiceIface{ctrl: ctrl} 52 | mock.recorder = &MockMiscServiceIfaceMockRecorder{mock} 53 | return mock 54 | } 55 | 56 | // EXPECT returns an object that allows the caller to indicate expected use. 57 | func (m *MockMiscServiceIface) EXPECT() *MockMiscServiceIfaceMockRecorder { 58 | return m.recorder 59 | } 60 | 61 | // ListElastistorInterface mocks base method. 62 | func (m *MockMiscServiceIface) ListElastistorInterface(p *ListElastistorInterfaceParams) (*ListElastistorInterfaceResponse, error) { 63 | m.ctrl.T.Helper() 64 | ret := m.ctrl.Call(m, "ListElastistorInterface", p) 65 | ret0, _ := ret[0].(*ListElastistorInterfaceResponse) 66 | ret1, _ := ret[1].(error) 67 | return ret0, ret1 68 | } 69 | 70 | // ListElastistorInterface indicates an expected call of ListElastistorInterface. 71 | func (mr *MockMiscServiceIfaceMockRecorder) ListElastistorInterface(p any) *gomock.Call { 72 | mr.mock.ctrl.T.Helper() 73 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListElastistorInterface", reflect.TypeOf((*MockMiscServiceIface)(nil).ListElastistorInterface), p) 74 | } 75 | 76 | // NewListElastistorInterfaceParams mocks base method. 77 | func (m *MockMiscServiceIface) NewListElastistorInterfaceParams() *ListElastistorInterfaceParams { 78 | m.ctrl.T.Helper() 79 | ret := m.ctrl.Call(m, "NewListElastistorInterfaceParams") 80 | ret0, _ := ret[0].(*ListElastistorInterfaceParams) 81 | return ret0 82 | } 83 | 84 | // NewListElastistorInterfaceParams indicates an expected call of NewListElastistorInterfaceParams. 85 | func (mr *MockMiscServiceIfaceMockRecorder) NewListElastistorInterfaceParams() *gomock.Call { 86 | mr.mock.ctrl.T.Helper() 87 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewListElastistorInterfaceParams", reflect.TypeOf((*MockMiscServiceIface)(nil).NewListElastistorInterfaceParams)) 88 | } 89 | -------------------------------------------------------------------------------- /test/ResourcemetadataService_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | package test 21 | 22 | import ( 23 | "testing" 24 | 25 | "github.com/apache/cloudstack-go/v2/cloudstack" 26 | ) 27 | 28 | func TestResourcemetadataService(t *testing.T) { 29 | service := "ResourcemetadataService" 30 | response, err := readData(service) 31 | if err != nil { 32 | t.Skipf("Skipping test as %v", err) 33 | } 34 | server := CreateTestServer(t, response) 35 | client := cloudstack.NewClient(server.URL, "APIKEY", "SECRETKEY", true) 36 | defer server.Close() 37 | 38 | testaddResourceDetail := func(t *testing.T) { 39 | if _, ok := response["addResourceDetail"]; !ok { 40 | t.Skipf("Skipping as no json response is provided in testdata") 41 | } 42 | p := client.Resourcemetadata.NewAddResourceDetailParams(map[string]string{}, "resourceid", "resourcetype") 43 | _, err := client.Resourcemetadata.AddResourceDetail(p) 44 | if err != nil { 45 | t.Errorf(err.Error()) 46 | } 47 | } 48 | t.Run("AddResourceDetail", testaddResourceDetail) 49 | 50 | testlistDetailOptions := func(t *testing.T) { 51 | if _, ok := response["listDetailOptions"]; !ok { 52 | t.Skipf("Skipping as no json response is provided in testdata") 53 | } 54 | p := client.Resourcemetadata.NewListDetailOptionsParams("resourcetype") 55 | _, err := client.Resourcemetadata.ListDetailOptions(p) 56 | if err != nil { 57 | t.Errorf(err.Error()) 58 | } 59 | } 60 | t.Run("ListDetailOptions", testlistDetailOptions) 61 | 62 | testgetVolumeSnapshotDetails := func(t *testing.T) { 63 | if _, ok := response["getVolumeSnapshotDetails"]; !ok { 64 | t.Skipf("Skipping as no json response is provided in testdata") 65 | } 66 | p := client.Resourcemetadata.NewGetVolumeSnapshotDetailsParams("snapshotid") 67 | _, err := client.Resourcemetadata.GetVolumeSnapshotDetails(p) 68 | if err != nil { 69 | t.Errorf(err.Error()) 70 | } 71 | } 72 | t.Run("GetVolumeSnapshotDetails", testgetVolumeSnapshotDetails) 73 | 74 | testlistResourceDetails := func(t *testing.T) { 75 | if _, ok := response["listResourceDetails"]; !ok { 76 | t.Skipf("Skipping as no json response is provided in testdata") 77 | } 78 | p := client.Resourcemetadata.NewListResourceDetailsParams("resourcetype") 79 | _, err := client.Resourcemetadata.ListResourceDetails(p) 80 | if err != nil { 81 | t.Errorf(err.Error()) 82 | } 83 | } 84 | t.Run("ListResourceDetails", testlistResourceDetails) 85 | 86 | testremoveResourceDetail := func(t *testing.T) { 87 | if _, ok := response["removeResourceDetail"]; !ok { 88 | t.Skipf("Skipping as no json response is provided in testdata") 89 | } 90 | p := client.Resourcemetadata.NewRemoveResourceDetailParams("resourceid", "resourcetype") 91 | _, err := client.Resourcemetadata.RemoveResourceDetail(p) 92 | if err != nil { 93 | t.Errorf(err.Error()) 94 | } 95 | } 96 | t.Run("RemoveResourceDetail", testremoveResourceDetail) 97 | 98 | } 99 | -------------------------------------------------------------------------------- /cloudstack/SystemCapacityService_mock.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | // Code generated by MockGen. DO NOT EDIT. 21 | // Source: ./cloudstack/SystemCapacityService.go 22 | // 23 | // Generated by this command: 24 | // 25 | // mockgen -destination=./cloudstack/SystemCapacityService_mock.go -package=cloudstack -copyright_file=header.txt -source=./cloudstack/SystemCapacityService.go 26 | // 27 | 28 | // Package cloudstack is a generated GoMock package. 29 | package cloudstack 30 | 31 | import ( 32 | reflect "reflect" 33 | 34 | gomock "go.uber.org/mock/gomock" 35 | ) 36 | 37 | // MockSystemCapacityServiceIface is a mock of SystemCapacityServiceIface interface. 38 | type MockSystemCapacityServiceIface struct { 39 | ctrl *gomock.Controller 40 | recorder *MockSystemCapacityServiceIfaceMockRecorder 41 | isgomock struct{} 42 | } 43 | 44 | // MockSystemCapacityServiceIfaceMockRecorder is the mock recorder for MockSystemCapacityServiceIface. 45 | type MockSystemCapacityServiceIfaceMockRecorder struct { 46 | mock *MockSystemCapacityServiceIface 47 | } 48 | 49 | // NewMockSystemCapacityServiceIface creates a new mock instance. 50 | func NewMockSystemCapacityServiceIface(ctrl *gomock.Controller) *MockSystemCapacityServiceIface { 51 | mock := &MockSystemCapacityServiceIface{ctrl: ctrl} 52 | mock.recorder = &MockSystemCapacityServiceIfaceMockRecorder{mock} 53 | return mock 54 | } 55 | 56 | // EXPECT returns an object that allows the caller to indicate expected use. 57 | func (m *MockSystemCapacityServiceIface) EXPECT() *MockSystemCapacityServiceIfaceMockRecorder { 58 | return m.recorder 59 | } 60 | 61 | // ListCapacity mocks base method. 62 | func (m *MockSystemCapacityServiceIface) ListCapacity(p *ListCapacityParams) (*ListCapacityResponse, error) { 63 | m.ctrl.T.Helper() 64 | ret := m.ctrl.Call(m, "ListCapacity", p) 65 | ret0, _ := ret[0].(*ListCapacityResponse) 66 | ret1, _ := ret[1].(error) 67 | return ret0, ret1 68 | } 69 | 70 | // ListCapacity indicates an expected call of ListCapacity. 71 | func (mr *MockSystemCapacityServiceIfaceMockRecorder) ListCapacity(p any) *gomock.Call { 72 | mr.mock.ctrl.T.Helper() 73 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListCapacity", reflect.TypeOf((*MockSystemCapacityServiceIface)(nil).ListCapacity), p) 74 | } 75 | 76 | // NewListCapacityParams mocks base method. 77 | func (m *MockSystemCapacityServiceIface) NewListCapacityParams() *ListCapacityParams { 78 | m.ctrl.T.Helper() 79 | ret := m.ctrl.Call(m, "NewListCapacityParams") 80 | ret0, _ := ret[0].(*ListCapacityParams) 81 | return ret0 82 | } 83 | 84 | // NewListCapacityParams indicates an expected call of NewListCapacityParams. 85 | func (mr *MockSystemCapacityServiceIfaceMockRecorder) NewListCapacityParams() *gomock.Call { 86 | mr.mock.ctrl.T.Helper() 87 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewListCapacityParams", reflect.TypeOf((*MockSystemCapacityServiceIface)(nil).NewListCapacityParams)) 88 | } 89 | -------------------------------------------------------------------------------- /cloudstack/ResourceService_mock.go: -------------------------------------------------------------------------------- 1 | // 2 | // Licensed to the Apache Software Foundation (ASF) under one 3 | // or more contributor license agreements. See the NOTICE file 4 | // distributed with this work for additional information 5 | // regarding copyright ownership. The ASF licenses this file 6 | // to you under the Apache License, Version 2.0 (the 7 | // "License"); you may not use this file except in compliance 8 | // with the License. You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, 13 | // software distributed under the License is distributed on an 14 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | // KIND, either express or implied. See the License for the 16 | // specific language governing permissions and limitations 17 | // under the License. 18 | // 19 | 20 | // Code generated by MockGen. DO NOT EDIT. 21 | // Source: ./cloudstack/ResourceService.go 22 | // 23 | // Generated by this command: 24 | // 25 | // mockgen -destination=./cloudstack/ResourceService_mock.go -package=cloudstack -copyright_file=header.txt -source=./cloudstack/ResourceService.go 26 | // 27 | 28 | // Package cloudstack is a generated GoMock package. 29 | package cloudstack 30 | 31 | import ( 32 | reflect "reflect" 33 | 34 | gomock "go.uber.org/mock/gomock" 35 | ) 36 | 37 | // MockResourceServiceIface is a mock of ResourceServiceIface interface. 38 | type MockResourceServiceIface struct { 39 | ctrl *gomock.Controller 40 | recorder *MockResourceServiceIfaceMockRecorder 41 | isgomock struct{} 42 | } 43 | 44 | // MockResourceServiceIfaceMockRecorder is the mock recorder for MockResourceServiceIface. 45 | type MockResourceServiceIfaceMockRecorder struct { 46 | mock *MockResourceServiceIface 47 | } 48 | 49 | // NewMockResourceServiceIface creates a new mock instance. 50 | func NewMockResourceServiceIface(ctrl *gomock.Controller) *MockResourceServiceIface { 51 | mock := &MockResourceServiceIface{ctrl: ctrl} 52 | mock.recorder = &MockResourceServiceIfaceMockRecorder{mock} 53 | return mock 54 | } 55 | 56 | // EXPECT returns an object that allows the caller to indicate expected use. 57 | func (m *MockResourceServiceIface) EXPECT() *MockResourceServiceIfaceMockRecorder { 58 | return m.recorder 59 | } 60 | 61 | // NewPurgeExpungedResourcesParams mocks base method. 62 | func (m *MockResourceServiceIface) NewPurgeExpungedResourcesParams() *PurgeExpungedResourcesParams { 63 | m.ctrl.T.Helper() 64 | ret := m.ctrl.Call(m, "NewPurgeExpungedResourcesParams") 65 | ret0, _ := ret[0].(*PurgeExpungedResourcesParams) 66 | return ret0 67 | } 68 | 69 | // NewPurgeExpungedResourcesParams indicates an expected call of NewPurgeExpungedResourcesParams. 70 | func (mr *MockResourceServiceIfaceMockRecorder) NewPurgeExpungedResourcesParams() *gomock.Call { 71 | mr.mock.ctrl.T.Helper() 72 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewPurgeExpungedResourcesParams", reflect.TypeOf((*MockResourceServiceIface)(nil).NewPurgeExpungedResourcesParams)) 73 | } 74 | 75 | // PurgeExpungedResources mocks base method. 76 | func (m *MockResourceServiceIface) PurgeExpungedResources(p *PurgeExpungedResourcesParams) (*PurgeExpungedResourcesResponse, error) { 77 | m.ctrl.T.Helper() 78 | ret := m.ctrl.Call(m, "PurgeExpungedResources", p) 79 | ret0, _ := ret[0].(*PurgeExpungedResourcesResponse) 80 | ret1, _ := ret[1].(error) 81 | return ret0, ret1 82 | } 83 | 84 | // PurgeExpungedResources indicates an expected call of PurgeExpungedResources. 85 | func (mr *MockResourceServiceIfaceMockRecorder) PurgeExpungedResources(p any) *gomock.Call { 86 | mr.mock.ctrl.T.Helper() 87 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PurgeExpungedResources", reflect.TypeOf((*MockResourceServiceIface)(nil).PurgeExpungedResources), p) 88 | } 89 | --------------------------------------------------------------------------------