├── .github └── workflows │ └── build.yaml ├── .gitignore ├── LICENSE ├── README.md ├── docs ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── generator ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── ovirt │ │ └── sdk │ │ └── go │ │ ├── GoBuffer.java │ │ ├── GoClassName.java │ │ ├── GoFuncName.java │ │ ├── GoGenerator.java │ │ ├── GoNames.java │ │ ├── GoPackages.java │ │ ├── GoReservedWords.java │ │ ├── GoTypeReference.java │ │ ├── GoTypes.java │ │ ├── Main.java │ │ ├── ReadersGenerator.java │ │ ├── ServicesGenerator.java │ │ ├── Tool.java │ │ ├── TypesGenerator.java │ │ ├── VersionGenerator.java │ │ └── WritersGenerator.java │ └── resources │ ├── META-INF │ └── beans.xml │ └── log4j.xml ├── go.mod ├── go.sum ├── packaging ├── README.adoc └── spec.c9s.in ├── pom.xml └── sdk ├── CHANGES.adoc ├── LICENSE.txt ├── MANIFEST.in ├── examples ├── add_affinity_label.go ├── add_bond.go ├── add_cluster.go ├── add_datacenter.go ├── add_disk.go ├── add_fence_agent.go ├── add_floating_disk.go ├── add_group.go ├── add_host.go ├── add_independent_vm.go ├── add_instance_type.go ├── add_iscsi_data_storage_domain.go ├── add_logical_network.go ├── add_lun_disk_to_vm.go ├── add_mac_pool.go ├── add_nfs_data_storage_domain.go ├── add_nfs_iso_storage_domain.go ├── add_openstack_image_provider.go ├── add_role.go ├── add_tag.go ├── add_template.go ├── add_user_public_sshkey.go ├── add_vm.go ├── add_vm_disk.go ├── add_vm_from_template.go ├── add_vm_nic.go ├── add_vm_pool.go ├── add_vm_snapshot.go ├── add_vm_with_sysprep.go ├── add_vnc_console.go ├── assign_affinity_label_to_vm.go ├── assign_network_to_cluster.go ├── assign_permission.go ├── assign_permission_to_vms.go ├── assign_tag_to_vm.go ├── asynchronous_inventory.go ├── attach_nfs_data_storage_domain.go ├── attach_nfs_iso_storage_domain.go ├── change_host_cluster.go ├── change_vm_cd.go ├── check_OCP_support.go ├── clone_vm_from_snapshot.go ├── data_center_maintenance.go ├── deactivate_disk_attachment.go ├── disable_compression.go ├── download_disk.go ├── download_vm_ovf.go ├── enable_serial_console.go ├── export_template.go ├── export_template_as_ova.go ├── export_vm.go ├── export_vm_as_ova.go ├── extend_disk.go ├── follow_vm_links.go ├── get_display_ticket.go ├── get_vm_ip.go ├── import_glance_image.go ├── import_vm.go ├── import_vm_from_ova.go ├── import_vm_from_vmware.go ├── list_affinity_labels.go ├── list_clusters.go ├── list_clusters_up_from_datacenter.go ├── list_datacenters.go ├── list_glance_images.go ├── list_hosts_statistics.go ├── list_networks.go ├── list_operating_systems.go ├── list_roles.go ├── list_storage_domains.go ├── list_tags.go ├── list_vm_disks.go ├── list_vm_snapshots.go ├── list_vm_tags.go ├── list_vms.go ├── list_vms_with_tag.go ├── page_vms.go ├── pin_vm.go ├── poll_events.go ├── print_vm_mac_duplicates.go ├── process_errors.go ├── register_vm.go ├── remove_host.go ├── remove_numa_nodes_from_vm.go ├── remove_tag.go ├── remove_vm.go ├── search_vms.go ├── set_vm_comment.go ├── set_vm_lease_storage_domain.go ├── set_vm_serial_number.go ├── show_summary.go ├── sparsify_disk.go ├── start_vm.go ├── start_vm_with_boot_devices.go ├── start_vm_with_cloudinit.go ├── stop_vm.go ├── test_connection.go ├── unassign_tag_to_vm.go ├── update_datacenter.go ├── update_fencing_options.go ├── update_quota_limits.go ├── upgrade_host.go ├── vm_backup.go └── wait_vm_status.go ├── ovirtsdk ├── README.md ├── connection.go ├── error.go ├── go.mod ├── go.sum ├── helper.go ├── http.go ├── reader.go ├── reader_test.go ├── readers_test.go ├── service.go ├── type.go ├── utils.go ├── vendor │ ├── github.com │ │ ├── davecgh │ │ │ └── go-spew │ │ │ │ ├── LICENSE │ │ │ │ └── spew │ │ │ │ ├── bypass.go │ │ │ │ ├── bypasssafe.go │ │ │ │ ├── common.go │ │ │ │ ├── config.go │ │ │ │ ├── doc.go │ │ │ │ ├── dump.go │ │ │ │ ├── format.go │ │ │ │ └── spew.go │ │ ├── pmezard │ │ │ └── go-difflib │ │ │ │ ├── LICENSE │ │ │ │ └── difflib │ │ │ │ └── difflib.go │ │ └── stretchr │ │ │ └── testify │ │ │ ├── LICENSE │ │ │ └── assert │ │ │ ├── assertion_format.go │ │ │ ├── assertion_format.go.tmpl │ │ │ ├── assertion_forward.go │ │ │ ├── assertion_forward.go.tmpl │ │ │ ├── assertions.go │ │ │ ├── doc.go │ │ │ ├── errors.go │ │ │ ├── forward_assertions.go │ │ │ └── http_assertions.go │ └── modules.txt ├── writer.go └── writers_test.go └── pom.xml /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | name: Build, Test, Release 2 | on: 3 | push: 4 | branches: 5 | - '*' 6 | tags: 7 | - '*' 8 | pull_request: 9 | branches: 10 | - '*' 11 | jobs: 12 | package: 13 | name: Package 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: Checkout 17 | uses: actions/checkout@v4 18 | - name: Set up JDK 19 | uses: actions/setup-java@v4 20 | with: 21 | java-version: '11' 22 | distribution: 'adopt' 23 | - name: Set up go 24 | uses: actions/setup-go@v5 25 | with: 26 | go-version: '^1.24.2' 27 | - name: Build 28 | run: | 29 | mvn package 30 | mkdir -p go-ovirt 31 | cp -r sdk/ovirtsdk/* go-ovirt/ 32 | cp -r sdk/examples go-ovirt/ 33 | cp -r sdk/CHANGES.adoc sdk/LICENSE.txt go-ovirt/ 34 | - name: Upload artifacts 35 | uses: actions/upload-artifact@v4 36 | with: 37 | name: sdk 38 | if-no-files-found: error 39 | path: | 40 | go-ovirt/* 41 | publish: 42 | name: Publish 43 | needs: package 44 | if: 45 | github.event_name == 'push' && contains(' 46 | refs/heads/master 47 | refs/tags/ 48 | ', github.ref) 49 | runs-on: ubuntu-latest 50 | steps: 51 | - name: Check secrets 52 | run: | 53 | if [ -z "${{ secrets.TARGET_REPO }}" -o -z "${{ secrets.DEPLOY_KEY }}" ]; then 54 | echo "The TARGET_REPO and DEPLOY_KEY secrets must be set." 55 | exit 1 56 | fi 57 | - name: Download artifacts 58 | uses: actions/download-artifact@v4 59 | with: 60 | name: sdk 61 | path: go-ovirt-new/ 62 | - name: Check out target repository 63 | uses: actions/checkout@v4 64 | with: 65 | repository: '${{ secrets.TARGET_REPO }}' 66 | ssh-key: '${{ secrets.DEPLOY_KEY }}' 67 | path: go-ovirt 68 | - name: Sync files 69 | run: | 70 | rm -fr go-ovirt/* 71 | rsync -avz go-ovirt-new/ go-ovirt/ 72 | git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com 73 | git config --global user.name "github-actions[bot]" 74 | pushd go-ovirt 75 | if git status --porcelain 2>/dev/null | grep -E "^??|^M"; then 76 | git add -A 77 | SHA=${{ github.sha }} 78 | git commit --message "Generator commit ID: ${SHA:0:7} with message: ${{ github.event.head_commit.message }}. GitHub build: ${{ github.run_number }}." 79 | BRANCH=$(echo "${{ github.ref }}" | sed -e 's/refs\/heads\///') 80 | git push origin HEAD:${BRANCH} 81 | fi 82 | if [ "${{ github.ref }}" == refs/tags/* ]; then 83 | VER=$(echo "${{ github.ref }}" | sed -e 's/refs\/tags\///' -e 's/v//') 84 | git tag v${VER} 85 | git push origin v${VER} 86 | fi 87 | popd 88 | 89 | 90 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IntelliJ 2 | *.iml 3 | .idea 4 | 5 | # Compiled class file 6 | *.class 7 | 8 | # Log file 9 | *.log 10 | 11 | # BlueJ files 12 | *.ctxt 13 | 14 | # Mobile Tools for Java (J2ME) 15 | .mtj.tmp/ 16 | 17 | # Package Files # 18 | *.jar 19 | *.war 20 | *.ear 21 | *.zip 22 | *.tar.gz 23 | *.rar 24 | 25 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 26 | hs_err_pid* 27 | 28 | sdk/build/ 29 | sdk/dist/ 30 | target/ 31 | 32 | .settings/ 33 | .vscode/ 34 | .project 35 | .idea/ 36 | 37 | # generator related files 38 | generator/.classpath 39 | generator/bin 40 | 41 | 42 | # Auto-generated files 43 | sdk/ovirtsdk/services.go 44 | sdk/ovirtsdk/types.go 45 | sdk/ovirtsdk/readers.go 46 | sdk/ovirtsdk/writers.go 47 | sdk/ovirtsdk/version.go 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # oVirt Go SDK 2 | [![Build, Test, Release](https://github.com/oVirt/ovirt-engine-sdk-go/actions/workflows/build.yaml/badge.svg)](https://github.com/oVirt/ovirt-engine-sdk-go/actions/workflows/build.yaml) 3 | [![CodeQL](https://github.com/oVirt/ovirt-engine-sdk-go/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/oVirt/ovirt-engine-sdk-go/actions/workflows/github-code-scanning/codeql) 4 | [![Go Report Card](https://goreportcard.com/badge/github.com/oVirt/ovirt-engine-sdk-go)](https://goreportcard.com/report/github.com/oVirt/ovirt-engine-sdk-go) 5 | 6 | 7 | ## Introduction 8 | 9 | The oVirt Go SDK is a Go package that simplifies access to the 10 | oVirt Engine API. 11 | 12 | > IMPORTANT: This document describes how to generate, build and test the 13 | SDK. If you are interested in how to use it read the `README.md` file 14 | in the [oVirt/go-ovirt](https://github.com/oVirt/go-ovirt) repository instead. 15 | 16 | ## Building 17 | 18 | You must install the Go binary and setup the Go environments, including 19 | `GOROOT` and `GOPATH`. 20 | 21 | Most of the source code of the Go SDK is automatically generated 22 | from the API model (Java). 23 | 24 | The code generator is a Java program that resides in the `generator` 25 | directory. This Java program will get the API model and the metamodel 26 | artifacts (offered by oVirt team) from the available Maven repositories. 27 | To build and run it use the following commands: 28 | 29 | ```bash 30 | $ git clone git@github.com:oVirt/ovirt-engine-sdk-go.git 31 | $ cd ovirt-engine-sdk-go 32 | $ mvn package 33 | ``` 34 | 35 | This will build the code generator, run it to generate the SDK for the 36 | version of the API that corresponds to the branch of the SDK that you 37 | are using. 38 | 39 | If you need to generate it for a different version of the API then you 40 | can use the `model.version` property. For example, if you need to 41 | generate the SDK for version `4.1.0` of the SDK you can use this 42 | command: 43 | ```bash 44 | $ mvn package -Dmodel.version=4.1.0 45 | ``` 46 | 47 | By default the build and the tests are executed using the `go` command. 48 | If you wish to use a different version of Go you can use the 49 | `go.command` property: 50 | ```bash 51 | $ mvn package -Dgo.command=go1.7 52 | ``` 53 | -------------------------------------------------------------------------------- /docs/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## The problem 2 | 3 | Briefly describe the issue you are experiencing (or the feature you want to see added). Tell us what you were trying to do and what happened instead. 4 | 5 | ## Environment 6 | 7 | * Desktop OS/version 8 | * Java version to run maven 9 | * Go version under test 10 | * The metamodel version speicifed in the root pom.xml 11 | * The model version sepecified in the root pom.xml 12 | 13 | ## Description 14 | 15 | [Description of the issue] 16 | 17 | ## Steps to Reproduce 18 | 19 | 1. [First Step] 20 | 2. [Second Step] 21 | 3. [and so on...] 22 | 23 | **Expected behavior:** [What you expect to happen] 24 | 25 | **Actual behavior:** [What actually happens] 26 | 27 | **Reproduces how often:** [What percentage of the time does it reproduce?] 28 | 29 | ## Link to logs [ Good To Have ] 30 | 31 | Create a [GIST](https://gist.github.com) which is a paste of your _full_ logs, and link them here. 32 | -------------------------------------------------------------------------------- /docs/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Requirements 2 | 3 | * Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion. 4 | * All new code requires tests to ensure against regressions 5 | 6 | ### Description of the Change 7 | 8 | 13 | 14 | ### Alternate Designs 15 | 16 | 17 | 18 | ### Benefits 19 | 20 | 21 | 22 | ### Possible Drawbacks 23 | 24 | 25 | 26 | ### Verification Process 27 | 28 | 38 | 39 | ### Applicable Issues 40 | 41 | 42 | -------------------------------------------------------------------------------- /generator/README.md: -------------------------------------------------------------------------------- 1 | # oVirt Engine Go SDK Generator 2 | 3 | ## Introduction 4 | 5 | This project contains the code generator for the oVirt Go SDK. 6 | 7 | The Java code use the `org.ovirt.api.metamodel` package, which 8 | offered by oVirt team and describes details about all the model, 9 | functions, class infomation. 10 | 11 | But the `metamodel` package is poorly documented, so I read 12 | the Python SDK generator source code to learn everything. 13 | 14 | 15 | > Maybe I should write some guides about how to generate SDK for 16 | other develop languanges. ^_^ 17 | 18 | -------------------------------------------------------------------------------- /generator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 20 | 21 | 25 | 26 | 4.0.0 27 | 28 | 29 | org.ovirt.engine.api 30 | go-sdk-parent 31 | 4.4.3 32 | 33 | 34 | go-sdk-generator 35 | jar 36 | 37 | oVirt Go SDK Generator 38 | 39 | 40 | 41 | 42 | org.ovirt.engine.api 43 | metamodel-concepts 44 | ${metamodel.version} 45 | 46 | 47 | 48 | org.ovirt.engine.api 49 | metamodel-analyzer 50 | ${metamodel.version} 51 | 52 | 53 | 54 | org.ovirt.engine.api 55 | metamodel-tool 56 | ${metamodel.version} 57 | 58 | 59 | 60 | commons-cli 61 | commons-cli 62 | 1.3.1 63 | 64 | 65 | 66 | commons-io 67 | commons-io 68 | 2.14.0 69 | 70 | 71 | 72 | 73 | org.jboss.weld.se 74 | weld-se-shaded 75 | 3.1.9.Final 76 | 77 | 78 | org.slf4j 79 | * 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /generator/src/main/java/org/ovirt/sdk/go/GoClassName.java: -------------------------------------------------------------------------------- 1 | /* 2 | The oVirt Project - oVirt Engine Go SDK 3 | 4 | Copyright (c) oVirt Authors 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | 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, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package org.ovirt.sdk.go; 20 | 21 | /** 22 | * This class represents the fully qualified name of a Go class, composed by the package name and the struct. 23 | */ 24 | public class GoClassName { 25 | private String packageName; 26 | private String simpleName; 27 | 28 | public String getPackageName() { 29 | return packageName; 30 | } 31 | 32 | public void setPackageName(String newPackageName) { 33 | packageName = newPackageName; 34 | } 35 | 36 | public String getSimpleName() { 37 | return simpleName; 38 | } 39 | 40 | public void setSimpleName(String newClassName) { 41 | simpleName = newClassName; 42 | } 43 | 44 | public void setClass(Class newClass) { 45 | packageName = newClass.getPackage().getName(); 46 | simpleName = newClass.getSimpleName(); 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | StringBuilder buffer = new StringBuilder(); 52 | if (packageName != null && packageName.length() > 0) { 53 | buffer.append(packageName); 54 | buffer.append("/"); 55 | } 56 | buffer.append(simpleName); 57 | return buffer.toString(); 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /generator/src/main/java/org/ovirt/sdk/go/GoFuncName.java: -------------------------------------------------------------------------------- 1 | /* 2 | The oVirt Project - oVirt Engine Go SDK 3 | 4 | Copyright (c) oVirt Authors 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | 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, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package org.ovirt.sdk.go; 20 | 21 | /** 22 | * This class represents the fully qualified name of a Go function and its package 23 | */ 24 | public class GoFuncName { 25 | private String packageName; 26 | private String simpleName; 27 | 28 | public String getPackageName() { 29 | return packageName; 30 | } 31 | 32 | public void setPackageName(String newPackageName) { 33 | packageName = newPackageName; 34 | } 35 | 36 | public String getSimpleName() { 37 | return simpleName; 38 | } 39 | 40 | public void setSimpleName(String newClassName) { 41 | simpleName = newClassName; 42 | } 43 | 44 | public void setClass(Class newClass) { 45 | packageName = newClass.getPackage().getName(); 46 | simpleName = newClass.getSimpleName(); 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | StringBuilder buffer = new StringBuilder(); 52 | if (packageName != null && packageName.length() > 0) { 53 | buffer.append(packageName); 54 | buffer.append("/"); 55 | } 56 | buffer.append(simpleName); 57 | return buffer.toString(); 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /generator/src/main/java/org/ovirt/sdk/go/GoGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | The oVirt Project - oVirt Engine Go SDK 3 | 4 | Copyright (c) oVirt Authors 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | 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, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package org.ovirt.sdk.go; 20 | 21 | import java.io.File; 22 | import java.io.IOException; 23 | 24 | import org.ovirt.api.metamodel.concepts.Model; 25 | 26 | /** 27 | * The interface to be implemented by code generators. The tool will locate all the code generators, and for each 28 | * of them it will set the output file and invoke the {@link #generate(Model)} method. No specific order will be 29 | * used when there are multiple generators. 30 | */ 31 | public interface GoGenerator { 32 | /** 33 | * Set the directory were the output should be generated. 34 | */ 35 | void setOut(File out); 36 | 37 | /** 38 | * Generates the code for the given model. 39 | */ 40 | void generate(Model model) throws IOException; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /generator/src/main/java/org/ovirt/sdk/go/GoTypeReference.java: -------------------------------------------------------------------------------- 1 | /* 2 | The oVirt Project - oVirt Engine Go SDK 3 | 4 | Copyright (c) oVirt Authors 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | 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, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package org.ovirt.sdk.go; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | /** 25 | * This class represents a reference to a Go type, including all the imports that are necessary to use it. 26 | */ 27 | public class GoTypeReference { 28 | private String text; 29 | private List imports = new ArrayList<>(1); 30 | 31 | public String getText() { 32 | return text; 33 | } 34 | 35 | public void setText(String newText) { 36 | text = newText; 37 | } 38 | 39 | public void setText(Class clazz) { 40 | text = clazz.getSimpleName(); 41 | } 42 | 43 | public List getImports() { 44 | return new ArrayList<>(imports); 45 | } 46 | 47 | public void setImports(List newImports) { 48 | imports.clear(); 49 | imports.addAll(newImports); 50 | } 51 | 52 | public void addImport(String newImport) { 53 | if (newImport != null && newImport.length() >0 ) { 54 | imports.add(newImport); 55 | } 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return text; 61 | } 62 | } 63 | 64 | -------------------------------------------------------------------------------- /generator/src/main/java/org/ovirt/sdk/go/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | The oVirt Project - oVirt Engine Go SDK 3 | 4 | Copyright (c) oVirt Authors 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | 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, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package org.ovirt.sdk.go; 20 | 21 | import org.jboss.weld.environment.se.Weld; 22 | import org.jboss.weld.environment.se.WeldContainer; 23 | 24 | /** 25 | * This class is responsible for bootstrapping the CDI container, creating the application entry point and running it 26 | * with the command line arguments. 27 | */ 28 | public class Main { 29 | public static void main(String[] args) throws Exception { 30 | Weld weld = new Weld(); 31 | WeldContainer container = weld.initialize(); 32 | Tool tool = container.instance().select(Tool.class).get(); 33 | tool.run(args); 34 | weld.shutdown(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /generator/src/main/java/org/ovirt/sdk/go/VersionGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | The oVirt Project - oVirt Engine Go SDK 3 | 4 | Copyright (c) oVirt Authors 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | 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, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | package org.ovirt.sdk.go; 20 | 21 | import java.io.File; 22 | import java.io.IOException; 23 | import javax.inject.Inject; 24 | 25 | import org.ovirt.api.metamodel.concepts.Model; 26 | 27 | /** 28 | * This class is responsible for generating the file that contains the version number information. 29 | */ 30 | public class VersionGenerator implements GoGenerator { 31 | // The directory were the output will be generated: 32 | private File out; 33 | 34 | // Reference to the objects used to generate the code: 35 | @Inject private GoPackages goPackages; 36 | 37 | // The buffer used to generate the Ruby code: 38 | private GoBuffer buffer; 39 | 40 | public void setOut(File newOut) { 41 | out = newOut; 42 | } 43 | 44 | public void generate(Model model) throws IOException { 45 | // Prepare the buffer: 46 | buffer = new GoBuffer(); 47 | buffer.setPackageName(goPackages.getVersionPackageName()); 48 | 49 | // Generate the source: 50 | generateVersion(); 51 | 52 | // Write the file: 53 | try { 54 | buffer.write(out); 55 | } 56 | catch (IOException exception) { 57 | throw new IllegalStateException("Error writing version file", exception); 58 | } 59 | } 60 | 61 | public void generateVersion() { 62 | // Generate the version constant: 63 | String version = goPackages.getVersion(); 64 | buffer.addLine("// The version of the SDK:"); 65 | buffer.addLine("var SDK_VERSION = \"%1$s\"", version.toLowerCase()); 66 | buffer.addLine(); 67 | } 68 | } 69 | 70 | -------------------------------------------------------------------------------- /generator/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oVirt/ovirt-engine-sdk-go/5c80d83ca8ff02f46c5a756c169711f2a5bf197a/generator/src/main/resources/META-INF/beans.xml -------------------------------------------------------------------------------- /generator/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module ovirt-engine-sdk-go 2 | 3 | go 1.24 4 | 5 | toolchain go1.24.2 6 | 7 | require ( 8 | github.com/ovirt/go-ovirt/v4 v4.4.3 9 | github.com/pkg/errors v0.9.1 10 | github.com/satori/go.uuid v1.2.0 11 | ) 12 | 13 | require gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect 14 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 2 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= 4 | github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= 5 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 6 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= 7 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 8 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 9 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 10 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 11 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 12 | github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= 13 | github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= 14 | github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= 15 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 16 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= 17 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= 18 | -------------------------------------------------------------------------------- /packaging/README.adoc: -------------------------------------------------------------------------------- 1 | = oVirt Go SDK Packaging 2 | 3 | == Introduction 4 | 5 | This directory contains the files required to package the SDK for 6 | packaging systems other than the Go standard packaging system. 7 | 8 | == RPM 9 | The RPM .spec files in this directory are examples of how to package the 10 | SDK, and are also used by the automation scripts to build the packages 11 | with each commit. 12 | 13 | If you want to use these RPM .spec files directly you will have to copy 14 | the file corresponding to your distribution, rename it to 15 | `go-ovirt-engine-sdk.spec` and adjust the `Version`, `Release` and 16 | `Source` tags. 17 | -------------------------------------------------------------------------------- /packaging/spec.c9s.in: -------------------------------------------------------------------------------- 1 | %global tar_version 4.3.0 2 | %global import_path github.com/ovirt/go-ovirt/v4 3 | %global gopath %{_datadir}/gocode 4 | %global build_gopath %{buildroot}/%{gopath} 5 | 6 | Name: go-ovirt-engine-sdk4 7 | Summary: Go SDK for version 4 of the oVirt Engine API 8 | Version: %{tar_version} 9 | Release: 1%{?dist} 10 | Group: Development/Languages 11 | License: ASL 2.0 12 | URL: http://godoc.org/%{import_path} 13 | Source: ovirt-engine-sdk-go-%{tar_version}.tar.gz 14 | 15 | BuildRequires: golang 16 | 17 | %description 18 | This package contains the Go SDK for version 4 of the oVirt Engine API. 19 | 20 | 21 | %package devel 22 | BuildRequires: golang 23 | Requires: golang 24 | Summary: Go SDK for version 4 of the oVirt Engine API 25 | Provides: golang(%{import_path}) = %{version}-%{release} 26 | 27 | %description devel 28 | This package contains the Go SDK for version 4 of the oVirt Engine API. 29 | 30 | %define debug_package %{nil} 31 | 32 | %prep 33 | %setup -q -n ovirt-engine-sdk-go-%{tar_version} 34 | 35 | 36 | %build 37 | 38 | 39 | %install 40 | install -d %{build_gopath}/src/%{import_path} 41 | cp -av ./* %{build_gopath}/src/%{import_path} 42 | 43 | 44 | %check 45 | export GOPATH=%{build_gopath} 46 | go test -v -mod=vendor ./ 47 | rm -fr %{build_gopath}/pkg/* 48 | 49 | 50 | %clean 51 | rm -rf %{buildroot} 52 | 53 | 54 | %files devel 55 | %defattr(-,root,root,-) 56 | %doc README.md examples 57 | %license LICENSE.txt 58 | %dir %{gopath}/src/%{import_path} 59 | %{gopath}/src/%{import_path}/* 60 | 61 | 62 | %changelog 63 | -------------------------------------------------------------------------------- /sdk/MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE.txt 2 | include README.md 3 | recursive-include ext *.c *.h 4 | recursive-include examples *.go 5 | -------------------------------------------------------------------------------- /sdk/examples/add_affinity_label.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func addAffinityLabel() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %s\n", err.Error()) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | affinityLableService := conn.SystemService().AffinityLabelsService() 53 | 54 | resp, err := affinityLableService.Add(). 55 | Label( 56 | ovirtsdk4.NewAffinityLabelBuilder(). 57 | Name("myaffinitylabel"). 58 | MustBuild()). 59 | Send() 60 | if err != nil { 61 | fmt.Printf("Failed to create a affinity label, reason: %v\n", err) 62 | return 63 | } 64 | addedLabel, _ := resp.Label() 65 | fmt.Printf("Affinity label with name (%v) added successfully\n", addedLabel.MustName()) 66 | } 67 | -------------------------------------------------------------------------------- /sdk/examples/add_cluster.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func addCluster() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Get the reference to the clusters service: 53 | clustersService := conn.SystemService().ClustersService() 54 | 55 | // Use the "add" method to create a cluster: 56 | _, err = clustersService.Add(). 57 | Cluster( 58 | ovirtsdk4.NewClusterBuilder(). 59 | Name("mycluster"). 60 | Description("My cluster"). 61 | Cpu( 62 | ovirtsdk4.NewCpuBuilder(). 63 | Architecture(ovirtsdk4.ARCHITECTURE_X86_64). 64 | Type("Intel Conroe Family"). 65 | MustBuild()). 66 | DataCenter( 67 | ovirtsdk4.NewDataCenterBuilder(). 68 | Name("mydc"). 69 | MustBuild()). 70 | MustBuild()). 71 | Send() 72 | if err != nil { 73 | fmt.Printf("Failed to add cluster, reason: %v\n", err) 74 | return 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /sdk/examples/add_datacenter.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func addDatacenter() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | dcsService := conn.SystemService().DataCentersService() 53 | resp, err := dcsService.Add(). 54 | DataCenter( 55 | ovirtsdk4.NewDataCenterBuilder(). 56 | Name("mydc"). 57 | Description("My data center"). 58 | Local(false). 59 | MustBuild()). 60 | Send() 61 | if err != nil { 62 | fmt.Printf("Failed to add datacenter, reason: %v\n", err) 63 | return 64 | } 65 | if dc, ok := resp.DataCenter(); ok { 66 | fmt.Printf("Add datacenter (%v) successfully\n", dc.MustName()) 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /sdk/examples/add_disk.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "bytes" 23 | "fmt" 24 | "time" 25 | 26 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 27 | ) 28 | 29 | func addDisk() { 30 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 31 | 32 | conn, err := ovirtsdk4.NewConnectionBuilder(). 33 | URL(inputRawURL). 34 | Username("admin@internal"). 35 | Password("qwer1234"). 36 | Insecure(true). 37 | Compress(true). 38 | Timeout(time.Second * 10). 39 | Build() 40 | if err != nil { 41 | fmt.Printf("Make connection failed, reason: %v\n", err) 42 | return 43 | } 44 | defer conn.Close() 45 | 46 | // To use `Must` methods, you should recover it if panics 47 | defer func() { 48 | if err := recover(); err != nil { 49 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 50 | } 51 | }() 52 | 53 | diskBuilder := ovirtsdk4.NewDiskBuilder(). 54 | Name("joey_disk"). 55 | Format(ovirtsdk4.DISKFORMAT_COW). 56 | ProvisionedSize(53687091200). 57 | StorageDomainsOfAny( 58 | ovirtsdk4.NewStorageDomainBuilder(). 59 | Id("cadbe661-0e35-4fcb-a70d-2b17e2559d9c"). 60 | MustBuild()) 61 | disk, err := diskBuilder.Build() 62 | if err != nil { 63 | fmt.Printf("error: %v", err) 64 | return 65 | } 66 | 67 | var body bytes.Buffer 68 | writer := ovirtsdk4.NewXMLWriter(&body) 69 | err = ovirtsdk4.XMLDiskWriteOne(writer, disk, "") 70 | writer.Flush() 71 | 72 | fmt.Println("*********************" + body.String()) 73 | 74 | _, err = conn.SystemService().DisksService().Add().Disk(disk).Send() 75 | 76 | if err != nil { 77 | fmt.Printf("error is %v\n", err) 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /sdk/examples/add_floating_disk.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func addFloatingDisk() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Get the reference to the disks service 53 | disksService := conn.SystemService().DisksService() 54 | 55 | // Add the disk. Note that the size of the disk, the `provisionedSize` attribute, is specified in bytes, 56 | // so to create a disk of 10 GiB the value should be 10 * 2^30. 57 | addDiskResp, err := disksService.Add(). 58 | Disk( 59 | ovirtsdk4.NewDiskBuilder(). 60 | Name("mydisk"). 61 | Description("My disk"). 62 | Format(ovirtsdk4.DISKFORMAT_COW). 63 | ProvisionedSize(int64(10) * int64(1<<30)). 64 | StorageDomainsOfAny( 65 | ovirtsdk4.NewStorageDomainBuilder(). 66 | Name("mydata"). 67 | MustBuild()). 68 | MustBuild()). 69 | Send() 70 | if err != nil { 71 | fmt.Printf("Faild to add disk, reason: %v\n", err) 72 | return 73 | } 74 | 75 | // Get disk from response 76 | if disk, ok := addDiskResp.Disk(); ok { 77 | // Wait till the disk is completely created 78 | diskService := disksService.DiskService(disk.MustId()) 79 | for { 80 | time.Sleep(5 * time.Second) 81 | getResp, err := diskService.Get().Send() 82 | if err != nil { 83 | fmt.Printf("Faild to get disk status, reason: %v\n", err) 84 | continue 85 | } 86 | // Check if the disk status is OK 87 | if d, ok := getResp.Disk(); ok { 88 | if d.MustStatus() == ovirtsdk4.DISKSTATUS_OK { 89 | break 90 | } 91 | } 92 | } 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /sdk/examples/add_group.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func addGroup() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Get the reference to the groups service 53 | groupsService := conn.SystemService().GroupsService() 54 | 55 | // Use the "add" method to add group from a directory service. Please note that domain name is name of the 56 | // authorization provider 57 | _, err = groupsService.Add(). 58 | Group( 59 | ovirtsdk4.NewGroupBuilder(). 60 | Name("Developers"). 61 | Domain( 62 | ovirtsdk4.NewDomainBuilder(). 63 | Name("internal-authz"). 64 | MustBuild()). 65 | MustBuild()). 66 | Send() 67 | if err != nil { 68 | fmt.Printf("Failed to add group, reason: %v\n", err) 69 | return 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /sdk/examples/add_host.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func addHost() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Get the reference to the hosts service 53 | hostsService := conn.SystemService().HostsService() 54 | 55 | // Add the host 56 | addHostResp, err := hostsService.Add(). 57 | Host( 58 | ovirtsdk4.NewHostBuilder(). 59 | Name("myhost"). 60 | Description("My host"). 61 | Address("node40.example.com"). 62 | RootPassword("123456"). 63 | Cluster( 64 | ovirtsdk4.NewClusterBuilder(). 65 | Name("mycluster"). 66 | MustBuild()). 67 | MustBuild()). 68 | Send() 69 | if err != nil { 70 | fmt.Printf("Failed to add host, reason: %v\n", err) 71 | return 72 | } 73 | if host, ok := addHostResp.Host(); ok { 74 | hostService := hostsService.HostService(host.MustId()) 75 | // Wait till the host is up 76 | for { 77 | time.Sleep(5 * time.Second) 78 | getHostResp, err := hostService.Get().Send() 79 | if err != nil { 80 | continue 81 | } 82 | if getHost, ok := getHostResp.Host(); ok { 83 | if getHost.MustStatus() == ovirtsdk4.HOSTSTATUS_UP { 84 | break 85 | } 86 | } 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /sdk/examples/add_independent_vm.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func addIndependentVM() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Get the reference to the "vms" service 53 | vmsService := conn.SystemService().VmsService() 54 | 55 | // Use the "clone" parameter of the "add" method to request that the 56 | // disks of the new virtual machine are independent of the template. 57 | vmsService.Add(). 58 | Vm( 59 | ovirtsdk4.NewVmBuilder(). 60 | Name("myvm"). 61 | Cluster( 62 | ovirtsdk4.NewClusterBuilder(). 63 | Name("mycluster"). 64 | MustBuild()). 65 | Template( 66 | ovirtsdk4.NewTemplateBuilder(). 67 | Name("mytemplate"). 68 | MustBuild()). 69 | MustBuild()). 70 | Clone(true). 71 | Send() 72 | 73 | } 74 | -------------------------------------------------------------------------------- /sdk/examples/add_instance_type.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func addInstanceType() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Get the reference to the instance types service 53 | instypesService := conn.SystemService().InstanceTypesService() 54 | 55 | // Add the instance type. Note that the size of the memory, the `memory` 56 | // attribute, is specified in bytes, so to create a instance type with 57 | // 2 GiB of memory the value should be 2 * 2^30. 58 | instypesService.Add(). 59 | InstanceType( 60 | ovirtsdk4.NewInstanceTypeBuilder(). 61 | Name("myinstancetype"). 62 | Description("My instance type"). 63 | Memory(int64(2) * int64(1<<30)). 64 | HighAvailability( 65 | ovirtsdk4.NewHighAvailabilityBuilder(). 66 | Enabled(true). 67 | MustBuild()). 68 | Cpu( 69 | ovirtsdk4.NewCpuBuilder(). 70 | Topology( 71 | ovirtsdk4.NewCpuTopologyBuilder(). 72 | Cores(2). 73 | Sockets(2). 74 | MustBuild()). 75 | MustBuild()). 76 | MustBuild()). 77 | Send() 78 | 79 | } 80 | -------------------------------------------------------------------------------- /sdk/examples/add_logical_network.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func addLogicalNetwork() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Get the reference to the "networks" service 53 | networksService := conn.SystemService().NetworksService() 54 | 55 | // Use the "add" method to create new VM logical network in data center called "mydatacenter", with VLAN tag 56 | // 100 and MTU 1500. 57 | networksService.Add(). 58 | Network( 59 | ovirtsdk4.NewNetworkBuilder(). 60 | Name("mynetwork"). 61 | Description("My logical network"). 62 | DataCenter( 63 | ovirtsdk4.NewDataCenterBuilder(). 64 | Name("mydatacenter"). 65 | MustBuild()). 66 | Vlan( 67 | ovirtsdk4.NewVlanBuilder(). 68 | Id(100). 69 | MustBuild()). 70 | UsagesOfAny(ovirtsdk4.NETWORKUSAGE_DISPLAY). 71 | Mtu(1500). 72 | MustBuild()). 73 | Send() 74 | } 75 | -------------------------------------------------------------------------------- /sdk/examples/add_lun_disk_to_vm.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func addLunDiskToVM() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Locate the virtual machines service and use it to find the virtual machine 53 | vmsService := conn.SystemService().VmsService() 54 | vmResp, _ := vmsService.List().Search("name=myvm").Send() 55 | vmSlice, _ := vmResp.Vms() 56 | vm := vmSlice.Slice()[0] 57 | 58 | // Locate the service that manages the disk attachments of the virtual machine 59 | diskAttachmentsService := vmsService.VmService(vm.MustId()).DiskAttachmentsService() 60 | 61 | // Use the "add" method of the disk attachments service to add the LUN disk. 62 | diskAttachmentsService.Add(). 63 | Attachment( 64 | ovirtsdk4.NewDiskAttachmentBuilder(). 65 | Disk( 66 | ovirtsdk4.NewDiskBuilder(). 67 | Name("myiscsidisk"). 68 | LunStorage( 69 | ovirtsdk4.NewHostStorageBuilder(). 70 | Type(ovirtsdk4.STORAGETYPE_ISCSI). 71 | LogicalUnitsOfAny( 72 | ovirtsdk4.NewLogicalUnitBuilder(). 73 | Address("192.168.200.3"). 74 | Port(3260). 75 | Target("iqn.2014-07.org.ovirt:storage"). 76 | Id("36001405e793bf9c57a840f58c9a8a220"). 77 | Username("username"). 78 | Password("password"). 79 | MustBuild()). 80 | MustBuild()). 81 | MustBuild()). 82 | Interface(ovirtsdk4.DISKINTERFACE_VIRTIO). 83 | Bootable(false). 84 | Active(true). 85 | MustBuild()). 86 | Send() 87 | 88 | } 89 | -------------------------------------------------------------------------------- /sdk/examples/add_mac_pool.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func addMacPool() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Get the reference to the service that manages the MAC address pools 53 | poolsService := conn.SystemService().MacPoolsService() 54 | 55 | // Add a new MAC address pool 56 | addPoolResp, err := poolsService.Add(). 57 | Pool( 58 | ovirtsdk4.NewMacPoolBuilder(). 59 | Name("mymacpool"). 60 | RangesOfAny( 61 | ovirtsdk4.NewRangeBuilder(). 62 | From("02:00:00:00:00:00"). 63 | To("02:00:00:01:00:00"). 64 | MustBuild()). 65 | MustBuild()). 66 | Send() 67 | if err != nil { 68 | fmt.Printf("Faild to add mac pool, reason: %v\n", err) 69 | return 70 | } 71 | if pool, ok := addPoolResp.Pool(); ok { 72 | // Find the service that manages clusters, as we need it in order to find the cluster where we wnt to set the 73 | // MAC address pool 74 | clustersService := conn.SystemService().ClustersService() 75 | 76 | // Find the cluster 77 | searchClusterResp, _ := clustersService.List().Search("name=mycluster").Send() 78 | clustersSlice, _ := searchClusterResp.Clusters() 79 | cluster := clustersSlice.Slice()[0] 80 | 81 | // Find the service that manages the cluster, as we need it in order to do the update 82 | clusterService := clustersService.ClusterService(cluster.MustId()) 83 | 84 | // Update the service so that it uses the new MAC pool 85 | clusterService.Update(). 86 | Cluster( 87 | ovirtsdk4.NewClusterBuilder(). 88 | MacPool( 89 | ovirtsdk4.NewMacPoolBuilder(). 90 | Id(pool.MustId()). 91 | MustBuild()). 92 | MustBuild()). 93 | Send() 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /sdk/examples/add_nfs_data_storage_domain.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func addNFSDataStorageDomain() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Get the reference to the storage domains service 53 | sdsService := conn.SystemService().StorageDomainsService() 54 | 55 | // Create a new NFS storage domain 56 | addSdResp, err := sdsService.Add(). 57 | StorageDomain( 58 | ovirtsdk4.NewStorageDomainBuilder(). 59 | Name("mydata"). 60 | Description("My data"). 61 | Type(ovirtsdk4.STORAGEDOMAINTYPE_DATA). 62 | Host( 63 | ovirtsdk4.NewHostBuilder(). 64 | Name("myhost"). 65 | MustBuild()). 66 | Storage( 67 | ovirtsdk4.NewHostStorageBuilder(). 68 | Type(ovirtsdk4.STORAGETYPE_NFS). 69 | Address("server0.example.com"). 70 | Path("/nfs/ovirt/40/mydata"). 71 | MustBuild()). 72 | MustBuild()). 73 | Send() 74 | if err != nil { 75 | fmt.Printf("Faild to add sd, reason: %v\n", err) 76 | return 77 | } 78 | 79 | // Wait till the storage domain is unattached 80 | if sd, ok := addSdResp.StorageDomain(); ok { 81 | sdService := sdsService.StorageDomainService(sd.MustId()) 82 | for { 83 | time.Sleep(5 * time.Second) 84 | getSdResp, _ := sdService.Get().Send() 85 | getSd, _ := getSdResp.StorageDomain() 86 | if getSd.MustStatus() == ovirtsdk4.STORAGEDOMAINSTATUS_UNATTACHED { 87 | break 88 | } 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /sdk/examples/add_nfs_iso_storage_domain.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func addISODataStorageDomain() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Get the reference to the storage domains service 53 | sdsService := conn.SystemService().StorageDomainsService() 54 | 55 | // Create a new ISO storage domain 56 | addSdResp, err := sdsService.Add(). 57 | StorageDomain( 58 | ovirtsdk4.NewStorageDomainBuilder(). 59 | Name("myiso"). 60 | Description("My ISO"). 61 | Type(ovirtsdk4.STORAGEDOMAINTYPE_ISO). 62 | Host( 63 | ovirtsdk4.NewHostBuilder(). 64 | Name("myhost"). 65 | MustBuild()). 66 | Storage( 67 | ovirtsdk4.NewHostStorageBuilder(). 68 | Type(ovirtsdk4.STORAGETYPE_NFS). 69 | Address("server0.example.com"). 70 | Path("/nfs/ovirt/40/myiso"). 71 | MustBuild()). 72 | MustBuild()). 73 | Send() 74 | if err != nil { 75 | fmt.Printf("Faild to add sd, reason: %v\n", err) 76 | return 77 | } 78 | 79 | // Wait till the storage domain is unattached 80 | if sd, ok := addSdResp.StorageDomain(); ok { 81 | sdService := sdsService.StorageDomainService(sd.MustId()) 82 | for { 83 | time.Sleep(5 * time.Second) 84 | getSdResp, _ := sdService.Get().Send() 85 | getSd, _ := getSdResp.StorageDomain() 86 | if getSd.MustStatus() == ovirtsdk4.STORAGEDOMAINSTATUS_UNATTACHED { 87 | break 88 | } 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /sdk/examples/add_role.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func addRole() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Get the reference to the roles service: 53 | rolesService := conn.SystemService().RolesService() 54 | 55 | // Use the "add" method to create a role: 56 | permitSlice := &ovirtsdk4.PermitSlice{} 57 | permitSlice.SetSlice(genPermits([]string{"1", "1300"})) 58 | _, err = rolesService.Add(). 59 | Role( 60 | ovirtsdk4.NewRoleBuilder(). 61 | Name("myrole"). 62 | Description("My role"). 63 | Administrative(false). 64 | Permits(permitSlice). 65 | MustBuild()). 66 | Send() 67 | if err != nil { 68 | fmt.Printf("Failed to add role, reason: %v\n", err) 69 | return 70 | } 71 | } 72 | 73 | func genPermits(ids []string) []*ovirtsdk4.Permit { 74 | permits := make([]*ovirtsdk4.Permit, 0) 75 | for _, id := range ids { 76 | if id == "" { 77 | continue 78 | } 79 | permit := &ovirtsdk4.Permit{} 80 | permit.SetId(id) 81 | permits = append(permits, permit) 82 | } 83 | return permits 84 | } 85 | -------------------------------------------------------------------------------- /sdk/examples/add_tag.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func addTag() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | tagService := conn.SystemService().TagsService() 53 | 54 | newTag, err := ovirtsdk4.NewTagBuilder(). 55 | Name("mytag"). 56 | Description("mytag desc"). 57 | Build() 58 | if err != nil { 59 | fmt.Printf("Construct a new tag failed, reason: %v\n", err) 60 | } 61 | 62 | resp, err := tagService.Add().Tag(newTag).Send() 63 | if err != nil { 64 | fmt.Printf("Failed to create a tag, reason: %v\n", err) 65 | return 66 | } 67 | tagAdded, _ := resp.Tag() 68 | fmt.Printf("Tag with name-(%v) and desc-(%v) added successfully\n", 69 | tagAdded.MustName(), tagAdded.MustDescription()) 70 | 71 | // If tag added successfully, print out: 72 | // `Tag with name-(mytag) and desc-(mytag desc) added successfully` 73 | // If failed due to duplicate name, print out: 74 | // `Failed to create a tag, reason: Fault reason is "Operation Failed". 75 | // Fault detail is "[The specified Tag name already exists.]". 76 | // HTTP response code is "409". HTTP response message is "409 Conflict".` 77 | 78 | } 79 | -------------------------------------------------------------------------------- /sdk/examples/add_user_public_sshkey.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func addUserPublicSSHKey() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Get the reference to the service that manages the users 53 | usersService := conn.SystemService().UsersService() 54 | 55 | // Find the user 56 | getUserResp, _ := usersService.List().Search("name=myuser").Send() 57 | userSlice, _ := getUserResp.Users() 58 | user := userSlice.Slice()[0] 59 | 60 | // Get the reference to the service that manages the user that we found in the previous step 61 | userService := usersService.UserService(user.MustId()) 62 | 63 | // Get a reference to the service that manages the public SSH keys 64 | keysService := userService.SshPublicKeysService() 65 | 66 | // Add a new SSH public key 67 | keysService.Add(). 68 | Key( 69 | ovirtsdk4.NewSshPublicKeyBuilder(). 70 | Content("ssh-rsa AAA...mu9 myuser@example.com"). 71 | MustBuild()). 72 | Send() 73 | 74 | // Note that the above operation will fail because the example SSH public key is not valid, make sure to use a 75 | // valid key. 76 | } 77 | -------------------------------------------------------------------------------- /sdk/examples/add_vm.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func addVM() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Get the reference to the "vms" service 53 | vmsService := conn.SystemService().VmsService() 54 | 55 | // Use the "Add" method to create a new virtual machine: 56 | resp, err := vmsService.Add(). 57 | Vm( 58 | ovirtsdk4.NewVmBuilder(). 59 | Name("myvm"). 60 | Cluster( 61 | ovirtsdk4.NewClusterBuilder(). 62 | Name("mycluster"). 63 | MustBuild()). 64 | Template( 65 | ovirtsdk4.NewTemplateBuilder(). 66 | Name("Blank"). 67 | MustBuild()). 68 | MustBuild()). 69 | Send() 70 | 71 | if err != nil { 72 | fmt.Printf("Failed to add vm, reason: %v\n", err) 73 | return 74 | } 75 | if vm, ok := resp.Vm(); ok { 76 | fmt.Printf("Add vm (%v) successfully\n", vm.MustName()) 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /sdk/examples/add_vm_nic.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func addVMNic() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Locate the virtual machines service and use it to find the virtual machine 53 | vmsService := conn.SystemService().VmsService() 54 | vmsResp, _ := vmsService.List().Search("name=myvm").Send() 55 | vmsSlice, _ := vmsResp.Vms() 56 | vm := vmsSlice.Slice()[0] 57 | 58 | // In order to specify the network that the new interface will be connected to, we need to specify the 59 | // identifier of the virtual network interface profile, so we need to find it 60 | profilesService := conn.SystemService().VnicProfilesService() 61 | var profileID string 62 | pfsResp, _ := profilesService.List().Send() 63 | pfSlice, _ := pfsResp.Profiles() 64 | for _, pf := range pfSlice.Slice() { 65 | if pf.MustName() == "mynetwork" { 66 | profileID = pf.MustId() 67 | break 68 | } 69 | } 70 | 71 | // Locate the service that manages the NICs of the virtual machine 72 | nicsService := vmsService.VmService(vm.MustId()).NicsService() 73 | nicsService.Add(). 74 | Nic( 75 | ovirtsdk4.NewNicBuilder(). 76 | Name("mynic"). 77 | Description("My network interface card"). 78 | VnicProfile( 79 | ovirtsdk4.NewVnicProfileBuilder(). 80 | Id(profileID). 81 | MustBuild()). 82 | MustBuild()). 83 | Send() 84 | } 85 | -------------------------------------------------------------------------------- /sdk/examples/add_vm_pool.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func addVmPool() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Get the reference to the vm pools service: 53 | vmPoolsService := conn.SystemService().VmPoolsService() 54 | 55 | // Use the "add" method to create a vmPool: 56 | _, err = vmPoolsService.Add(). 57 | Pool( 58 | ovirtsdk4.NewVmPoolBuilder(). 59 | Name("myVmPool"). 60 | Description("My vmPool"). 61 | Cluster( 62 | ovirtsdk4.NewClusterBuilder(). 63 | Name("mycluster"). 64 | MustBuild()). 65 | Template( 66 | ovirtsdk4.NewTemplateBuilder(). 67 | Name("mytemplate"). 68 | MustBuild()). 69 | Size(3). 70 | PrestartedVms(1). 71 | MaxUserVms(1). 72 | Type(ovirtsdk4.VMPOOLTYPE_AUTOMATIC). 73 | MustBuild()). 74 | Send() 75 | if err != nil { 76 | fmt.Printf("Failed to add vmPool, reason: %v\n", err) 77 | return 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /sdk/examples/add_vm_snapshot.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func addVMSnapshot() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Locate the virtual machines service and use it to find the virtual machine 53 | vmsService := conn.SystemService().VmsService() 54 | vmsResp, _ := vmsService.List().Search("name=myvm").Send() 55 | vmsSlice, _ := vmsResp.Vms() 56 | vm := vmsSlice.Slice()[0] 57 | 58 | // Locate the service that manages the snapshots of the virtual machine 59 | snapshotsService := vmsService.VmService(vm.MustId()).SnapshotsService() 60 | 61 | // Add the snapshot 62 | snapshotsService.Add(). 63 | Snapshot( 64 | ovirtsdk4.NewSnapshotBuilder(). 65 | Description("My snapshot"). 66 | MustBuild()). 67 | Send() 68 | } 69 | -------------------------------------------------------------------------------- /sdk/examples/add_vnc_console.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func addVNCConsole() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Find the virtual machine 53 | vmsService := conn.SystemService().VmsService() 54 | vmsResp, _ := vmsService.List().Search("name=myvm").Send() 55 | vmsSlice, _ := vmsResp.Vms() 56 | vm := vmsSlice.Slice()[0] 57 | 58 | // Locate the service that manages the virtual machine 59 | vmService := vmsService.VmService(vm.MustId()) 60 | 61 | // Find the graphics consoles of the virtual machine 62 | consolesService := vmService.GraphicsConsolesService() 63 | consoleListResp, _ := consolesService.List().Send() 64 | consoleSlice, _ := consoleListResp.Consoles() 65 | 66 | // Add a VNC console if it doesn't exist 67 | var console *ovirtsdk4.GraphicsConsole 68 | for _, c := range consoleSlice.Slice() { 69 | if c.MustProtocol() == ovirtsdk4.GRAPHICSTYPE_VNC { 70 | console = c 71 | } 72 | } 73 | 74 | if console == nil { 75 | consolesService.Add(). 76 | Console( 77 | ovirtsdk4.NewGraphicsConsoleBuilder(). 78 | Protocol(ovirtsdk4.GRAPHICSTYPE_VNC). 79 | MustBuild()). 80 | Send() 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /sdk/examples/assign_network_to_cluster.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func assignNetworkToCluster() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | // Create the connection to the server 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Locate the networks service and use it to find the network 53 | networksService := conn.SystemService().NetworksService() 54 | getNSResp, _ := networksService.List(). 55 | Search("name=mynetwork and datacenter=mydatacenter"). 56 | Send() 57 | nsSlice, _ := getNSResp.Networks() 58 | network := nsSlice.Slice()[0] 59 | 60 | // Locate the clusters service and use it to find the cluster 61 | clustersService := conn.SystemService().ClustersService() 62 | getClustersResp, _ := clustersService.List().Search("name=mycluster").Send() 63 | clustersSlice, _ := getClustersResp.Clusters() 64 | cluster := clustersSlice.Slice()[0] 65 | 66 | // Locate the service that manages the networks of the cluster 67 | cluService := clustersService.ClusterService(cluster.MustId()) 68 | assignedNSService := cluService.NetworksService() 69 | 70 | // Use the "add" method to assign network to cluster 71 | assignedNSService.Add(). 72 | Network( 73 | ovirtsdk4.NewNetworkBuilder(). 74 | Id(network.MustId()). 75 | Required(true). 76 | MustBuild()). 77 | Send() 78 | } 79 | -------------------------------------------------------------------------------- /sdk/examples/assign_tag_to_vm.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func assignTagToVM() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | // Create the connection to the server: 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Get the reference to the "vms" service: 53 | vmsService := conn.SystemService().VmsService() 54 | 55 | // Use the "List" method of the "vms" service to search the virtual machines: 56 | vmsResponse, err := vmsService.List().Search("name=test4joey").CaseSensitive(false).Send() 57 | 58 | if err != nil { 59 | fmt.Printf("Failed to get vm list, reason: %v\n", err) 60 | return 61 | } 62 | // Find the vm: 63 | vm := vmsResponse.MustVms().Slice()[0] 64 | 65 | // Find the service that manages the vm: 66 | vmService := vmsService.VmService(vm.MustId()) 67 | 68 | // Locate the service that manages the tags of the vm: 69 | assignedTagsService := vmService.TagsService() 70 | 71 | tag, _ := ovirtsdk4.NewTagBuilder().Name("mytag").Build() 72 | _, err = assignedTagsService.Add().Tag(tag).Send() 73 | if err != nil { 74 | // If the assigned tag not exists, print out: 75 | // `Failed to assigne tag to vm, reason: Fault reason is "Operation Failed". 76 | // Fault detail is "Entity not found: tagnotexits". HTTP response code is "404". 77 | // HTTP response message is "404 Not Found".` 78 | fmt.Printf("Failed to assigne tag to vm, reason: %v\n", err) 79 | return 80 | } 81 | 82 | listResp, err := assignedTagsService.List().Send() 83 | tags, _ := listResp.Tags() 84 | for _, tag := range tags.Slice() { 85 | fmt.Printf("Assigned tag name is %v\n", tag.MustName()) 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /sdk/examples/change_vm_cd.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func changeVMCd() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | // Create the connection to the server: 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Locate the service that manages the virtual machines 53 | vmsService := conn.SystemService().VmsService() 54 | 55 | // Find the virtual machine 56 | vmsResp, _ := vmsService.List().Search("name=myvm").Send() 57 | vmsSlice, _ := vmsResp.Vms() 58 | vm := vmsSlice.Slice()[0] 59 | 60 | // Locate the service that manages the virtual machine 61 | vmService := vmsService.VmService(vm.MustId()) 62 | 63 | // Locate the service that manages the CDROM devices of the virtual machine 64 | cdromsService := vmService.CdromsService() 65 | 66 | // Get the first CDROM 67 | getcdsResp, _ := cdromsService.List().Send() 68 | cdSlice, _ := getcdsResp.Cdroms() 69 | cdrom := cdSlice.Slice()[0] 70 | 71 | // Locate the service that manages the CDROM device found in the previous step 72 | cdromService := cdromsService.CdromService(cdrom.MustId()) 73 | 74 | // Change the CDROM disk of the virtual machine to 'my_iso_file.iso'. By default the below operation changes 75 | // permanently the disk that will be visible to the virtual machine after the next boot, but it doesn't have 76 | // any effect on the currently running virtual machine. If you want to change the disk that is visible to the 77 | // current running virtual machine, change the value of the 'current' parameter to 'true'. 78 | cdromService.Update(). 79 | Cdrom( 80 | ovirtsdk4.NewCdromBuilder(). 81 | File( 82 | ovirtsdk4.NewFileBuilder(). 83 | Id("my_iso_file.iso"). 84 | MustBuild()). 85 | MustBuild()). 86 | Current(false). 87 | Send() 88 | } 89 | -------------------------------------------------------------------------------- /sdk/examples/disable_compression.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func disableCompression() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // By disabling compression you can debug the communication, 53 | // as communication will be visible in plain text and won't 54 | // be raw compressed. Note that compression is automatically 55 | // disabled in case user pass debug parameter set to `true`. 56 | 57 | // Get some data: 58 | api := conn.SystemService().Get().MustSend().MustApi() 59 | version := api.MustProductInfo().MustVersion().MustFullVersion() 60 | fmt.Printf("Use FullVersion() function to get the fullVersion %v", version) 61 | } 62 | -------------------------------------------------------------------------------- /sdk/examples/download_vm_ovf.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "os" 24 | "time" 25 | 26 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 27 | ) 28 | 29 | func downloadVmOvf() { 30 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 31 | 32 | conn, err := ovirtsdk4.NewConnectionBuilder(). 33 | URL(inputRawURL). 34 | Username("admin@internal"). 35 | Password("qwer1234"). 36 | Insecure(true). 37 | Compress(true). 38 | Timeout(time.Second * 10). 39 | Build() 40 | if err != nil { 41 | fmt.Printf("Make connection failed, reason: %v\n", err) 42 | return 43 | } 44 | defer conn.Close() 45 | 46 | // To use `Must` methods, you should recover it if panics 47 | defer func() { 48 | if err := recover(); err != nil { 49 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 50 | } 51 | }() 52 | 53 | // Get a reference to the vm service: 54 | vmsService := conn.SystemService().VmsService() 55 | 56 | //# Look up fot the vm by name: 57 | vmResp, err := vmsService.List(). 58 | Search("name=myvm"). 59 | AllContent(true). 60 | Send() 61 | if err != nil { 62 | fmt.Printf("Failed to search vm list, reason: %v\n", err) 63 | return 64 | } 65 | vmSlice, _ := vmResp.Vms() 66 | vm := vmSlice.Slice()[0] 67 | 68 | ovfFileName := fmt.Sprintf("%v.ovf", vm.MustId()) 69 | 70 | file, err := os.Open(ovfFileName) 71 | if err != nil { 72 | fmt.Printf("Failed to open the file, reason: %v\n", err) 73 | return 74 | } 75 | defer file.Close() 76 | 77 | file.WriteString(vm.MustInitialization().MustConfiguration().MustData()) 78 | 79 | } 80 | -------------------------------------------------------------------------------- /sdk/examples/enable_serial_console.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func enableSerialConsole() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | // Create the connection to the server: 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Locate the service that manages the virtual machines 53 | vmsService := conn.SystemService().VmsService() 54 | 55 | // Find the virtual machine. Note the use of the `all_content` parameter, it is required in order to obtain 56 | // additional information that isn't retrieved by default, like the configuration of the serial console. 57 | vmsResp, _ := vmsService.List(). 58 | Search("name=myvm"). 59 | AllContent(true). 60 | Send() 61 | vmsSlice, _ := vmsResp.Vms() 62 | vm := vmsSlice.Slice()[0] 63 | 64 | // Check if the serial console is enabled, and if it isn't then update the virtual machine to enable it 65 | if !vm.MustConsole().MustEnabled() { 66 | vmService := vmsService.VmService(vm.MustId()) 67 | vmService.Update(). 68 | Vm( 69 | ovirtsdk4.NewVmBuilder(). 70 | Console( 71 | ovirtsdk4.NewConsoleBuilder(). 72 | Enabled(true). 73 | MustBuild()). 74 | MustBuild()). 75 | Send() 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /sdk/examples/export_template.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func exportTemplate() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Get a reference to the template service: 53 | templatesService := conn.SystemService().TemplatesService() 54 | 55 | //# Look up fot the template by name: 56 | templateResp, err := templatesService.List().Search("name=mytemplate").Send() 57 | if err != nil { 58 | fmt.Printf("Failed to search template list, reason: %v\n", err) 59 | return 60 | } 61 | templateSlice, _ := templateResp.Templates() 62 | template := templateSlice.Slice()[0] 63 | 64 | templateService := templatesService.TemplateService(template.MustId()) 65 | 66 | storageDomain := &ovirtsdk4.StorageDomain{} 67 | storageDomain.SetName("myexport") 68 | templateService.Export(). 69 | Exclusive(true). 70 | StorageDomain(storageDomain). 71 | Send() 72 | 73 | } 74 | -------------------------------------------------------------------------------- /sdk/examples/export_template_as_ova.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func exportTemplateAsOva() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Get a reference to the template service: 53 | templatesService := conn.SystemService().TemplatesService() 54 | 55 | //# Look up fot the template by name: 56 | templateResp, err := templatesService.List().Search("name=mytemplate").Send() 57 | if err != nil { 58 | fmt.Printf("Failed to search template list, reason: %v\n", err) 59 | return 60 | } 61 | templateSlice, _ := templateResp.Templates() 62 | template := templateSlice.Slice()[0] 63 | 64 | templateService := templatesService.TemplateService(template.MustId()) 65 | 66 | // Find the host 67 | hostsService := conn.SystemService().HostsService() 68 | hostResp, err := hostsService.List().Search("name=myhost").Send() 69 | if err != nil { 70 | fmt.Printf("Failed to search host list, reason: %v\n", err) 71 | return 72 | } 73 | hostSlice, _ := hostResp.Hosts() 74 | host := hostSlice.Slice()[0] 75 | 76 | // Export the virtual machine template. Note that the 'filename' 77 | // parameter is optional, and only required if you want to specify 78 | // a name for the generated OVA file that is different from 79 | // .ova. 80 | // Note that this operation is only available since version 4.2.3 81 | // of the engine and since version 4.2.5 of the SDK. 82 | templateService.ExportToPathOnHost(). 83 | Host(host). 84 | Directory("/tmp"). 85 | Filename("mytemplate2.ova"). 86 | Send() 87 | 88 | } 89 | -------------------------------------------------------------------------------- /sdk/examples/export_vm.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func exportVM() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | // Create the connection to the server: 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Locate the service that manages the virtual machines 53 | vmsService := conn.SystemService().VmsService() 54 | 55 | // Find the virtual machine. Note the use of the `all_content` parameter, it is required in order to obtain 56 | // additional information that isn't retrieved by default, like the configuration of the serial console. 57 | vmsResp, _ := vmsService.List(). 58 | Search("name=myvm"). 59 | AllContent(true). 60 | Send() 61 | vmsSlice, _ := vmsResp.Vms() 62 | vm := vmsSlice.Slice()[0] 63 | 64 | // Export the virtual machine. Note that the 'exclusive' parameter is optional, and only required if you want 65 | // to overwrite a virtual machine that has already been exported before. 66 | vmService := vmsService.VmService(vm.MustId()) 67 | vmService.Export(). 68 | Exclusive(true). 69 | DiscardSnapshots(true). 70 | StorageDomain( 71 | ovirtsdk4.NewStorageDomainBuilder(). 72 | Name("myexport"). 73 | MustBuild()). 74 | Send() 75 | 76 | } 77 | -------------------------------------------------------------------------------- /sdk/examples/export_vm_as_ova.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func exportVmAsOva() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Get a reference to the vm service: 53 | vmsService := conn.SystemService().VmsService() 54 | 55 | //# Look up fot the vm by name: 56 | vmResp, err := vmsService.List().Search("name=myvm").Send() 57 | if err != nil { 58 | fmt.Printf("Failed to search vm list, reason: %v\n", err) 59 | return 60 | } 61 | vmSlice, _ := vmResp.Vms() 62 | vm := vmSlice.Slice()[0] 63 | 64 | vmService := vmsService.VmService(vm.MustId()) 65 | 66 | // Find the host 67 | hostsService := conn.SystemService().HostsService() 68 | hostResp, err := hostsService.List().Search("name=myhost").Send() 69 | if err != nil { 70 | fmt.Printf("Failed to search host list, reason: %v\n", err) 71 | return 72 | } 73 | hostSlice, _ := hostResp.Hosts() 74 | host := hostSlice.Slice()[0] 75 | 76 | vmService.ExportToPathOnHost(). 77 | Host(host). 78 | Directory("/tmp"). 79 | Filename("myvm2.ova"). 80 | Send() 81 | 82 | } 83 | -------------------------------------------------------------------------------- /sdk/examples/follow_vm_links.go: -------------------------------------------------------------------------------- 1 | // 2 | // The oVirt Project - oVirt Engine Go SDK 3 | // 4 | // Copyright (c) oVirt Authors 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | package examples 20 | 21 | import ( 22 | "fmt" 23 | "time" 24 | 25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4" 26 | ) 27 | 28 | func followVMLinks() { 29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api" 30 | // Create the connection to the server: 31 | conn, err := ovirtsdk4.NewConnectionBuilder(). 32 | URL(inputRawURL). 33 | Username("admin@internal"). 34 | Password("qwer1234"). 35 | Insecure(true). 36 | Compress(true). 37 | Timeout(time.Second * 10). 38 | Build() 39 | if err != nil { 40 | fmt.Printf("Make connection failed, reason: %v\n", err) 41 | return 42 | } 43 | defer conn.Close() 44 | 45 | // To use `Must` methods, you should recover it if panics 46 | defer func() { 47 | if err := recover(); err != nil { 48 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason") 49 | } 50 | }() 51 | 52 | // Locate the service that manages the virtual machines 53 | vmsService := conn.SystemService().VmsService() 54 | 55 | // Find the virtual machine 56 | vm := vmsService.List(). 57 | Search("name=test4joey"). 58 | MustSend(). 59 | MustVms(). 60 | Slice()[0] 61 | 62 | // When the server returns a virtual machine it will return links to related objects, like the cluster, 63 | // template and permissions something like this: 64 | // 65 | // 66 | // ... 67 | // 68 | //