├── .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 | [](https://github.com/oVirt/ovirt-engine-sdk-go/actions/workflows/build.yaml)
3 | [](https://github.com/oVirt/ovirt-engine-sdk-go/actions/workflows/github-code-scanning/codeql)
4 | [](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 | //
69 | //
70 | // The SDK provides a "FollowLink" method that can be used to retrieve the complete content of these related
71 | // objects.
72 | cluster, _ := conn.FollowLink(vm.MustCluster())
73 | if cluster, ok := cluster.(*ovirtsdk4.Cluster); ok {
74 | fmt.Printf("cluster: %v\n", cluster.MustName())
75 | }
76 | template, _ := conn.FollowLink(vm.MustTemplate())
77 | if template, ok := template.(*ovirtsdk4.Template); ok {
78 | fmt.Printf("template: %v\n", template.MustName())
79 | }
80 | permissionSlice, _ := conn.FollowLink(vm.MustPermissions())
81 | if permissionSlice, ok := permissionSlice.(*ovirtsdk4.PermissionSlice); ok {
82 | for _, per := range permissionSlice.Slice() {
83 | fmt.Printf("role: %v\n", per.MustRole().MustId())
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/sdk/examples/get_vm_ip.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 getVmIp() {
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 service for a particular vm:
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 | // Get the reported-devices service for this vm:
65 | reportedDevicesService := vmsService.VmService(vm.MustId()).ReportedDevicesService()
66 |
67 | // Get the guest reported devices
68 | reportedDeviceResp, err := reportedDevicesService.List().Send()
69 | if err != nil {
70 | fmt.Printf("Failed to get reported devices list, reason: %v\n", err)
71 | return
72 | }
73 | reportedDeviceSlice, _ := reportedDeviceResp.ReportedDevice()
74 | for _, reportedDevice := range reportedDeviceSlice.Slice() {
75 | ips := reportedDevice.MustIps()
76 | if ips != nil {
77 | for _, ip := range ips.Slice() {
78 | fmt.Printf(" - %v", ip.MustAddress())
79 | }
80 | }
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/sdk/examples/import_vm_from_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 importVmFromOVa() {
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 import of external
53 | //virtual machines:
54 | importsService := conn.SystemService().ExternalVmImportsService()
55 |
56 | // Initiate the import of VM 'myvm' from ova:
57 | importsService.Add().
58 | Import(
59 | ovirtsdk4.NewExternalVmImportBuilder().
60 | Name("myvm").
61 | Provider(ovirtsdk4.EXTERNALVMPROVIDERTYPE_KVM).
62 | Url("ova:///myvms/my.ova").
63 | Cluster(
64 | ovirtsdk4.NewClusterBuilder().
65 | Name("mycluster").
66 | MustBuild()).
67 | StorageDomain(
68 | ovirtsdk4.NewStorageDomainBuilder().
69 | Name("mydata").
70 | MustBuild()).
71 | Host(
72 | ovirtsdk4.NewHostBuilder().
73 | Name("myhost").
74 | MustBuild()).
75 | DriversIso(
76 | ovirtsdk4.NewFileBuilder().
77 | Id("virtio-win.iso").
78 | MustBuild()).
79 | Sparse(true).
80 | MustBuild()).
81 | Send()
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/sdk/examples/import_vm_from_vmware.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 importVmFromVmware() {
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 import of external
53 | //virtual machines:
54 | importsService := conn.SystemService().ExternalVmImportsService()
55 |
56 | // Initiate the import of VM 'myvm' from VMware:
57 | importsService.Add().
58 | Import(
59 | ovirtsdk4.NewExternalVmImportBuilder().
60 | Name("myvm").
61 | Provider(ovirtsdk4.EXTERNALVMPROVIDERTYPE_VMWARE).
62 | Username("wmware_user").
63 | Password("wmware123").
64 | Url("vpx://wmware_user@vcenter-host/DataCenter/Cluster/esxi-host?no_verify=1").
65 | Cluster(
66 | ovirtsdk4.NewClusterBuilder().
67 | Name("mycluster").
68 | MustBuild()).
69 | StorageDomain(
70 | ovirtsdk4.NewStorageDomainBuilder().
71 | Name("mydata").
72 | MustBuild()).
73 | Sparse(true).
74 | MustBuild()).
75 | Send()
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/sdk/examples/list_affinity_labels.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 listAffinityLabels() {
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 | affinityLableService := conn.SystemService().AffinityLabelsService()
53 |
54 | resp, err := affinityLableService.List().Send()
55 |
56 | if err != nil {
57 | fmt.Printf("Failed to get affinity label list, reason: %v\n", err)
58 | return
59 | }
60 | labels, _ := resp.Labels()
61 | for _, label := range labels.Slice() {
62 | fmt.Printf("Affinity labels (")
63 | if name, ok := label.Name(); ok {
64 | fmt.Printf(" name: %v", name)
65 | }
66 | if desc, ok := label.Description(); ok {
67 | fmt.Printf(" desc: %v", desc)
68 | }
69 | fmt.Println(")")
70 |
71 | // Print all affinity labels names and virtual machines
72 | // which has assigned that affinity label
73 | if vmSlice, ok := label.Vms(); ok {
74 | vms, err := conn.FollowLink(vmSlice)
75 | if err != nil {
76 | if href, ok := vmSlice.Href(); ok {
77 | fmt.Printf("Failed to follow vms link: %v, reason: %v\n", href, err)
78 | return
79 | }
80 | }
81 | if vms, ok := vms.(*ovirtsdk4.VmSlice); ok {
82 | for _, vmLink := range vms.Slice() {
83 | vm, err := conn.FollowLink(vmLink)
84 | if err != nil {
85 | fmt.Printf("Failed to follow vm link: %v, reason: %v\n", vmLink.MustHref(), err)
86 | return
87 | }
88 | if vm, ok := vm.(*ovirtsdk4.Vm); ok {
89 | fmt.Printf("**** attached VM (%+v)\n", vm.MustName())
90 | }
91 | }
92 | }
93 | }
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/sdk/examples/list_clusters.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 listClusters() {
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 "list" method of the "clusters" service to list all the clusters of the system:
56 | clustersResponse, err := clustersService.List().Send()
57 | if err != nil {
58 | fmt.Printf("Failed to get cluster list, reason: %v\n", err)
59 | return
60 | }
61 |
62 | if clusters, ok := clustersResponse.Clusters(); ok {
63 | // Print the datacenter names and identifiers:
64 | for _, cluster := range clusters.Slice() {
65 | fmt.Printf("Cluster: (")
66 | if clusterName, ok := cluster.Name(); ok {
67 | fmt.Printf(" name: %v", clusterName)
68 | }
69 | if clusterID, ok := cluster.Id(); ok {
70 | fmt.Printf(" id: %v", clusterID)
71 | }
72 | fmt.Println(")")
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/sdk/examples/list_clusters_up_from_datacenter.go:
--------------------------------------------------------------------------------
1 | //
2 | // The oVirt Project - oVirt Engine Go SDK
3 | //
4 | // Copyright (c) oVirt Authors
5 | // Copyright (c) 2020 Douglas Schilling Landgraf
6 | //
7 | // Licensed under the Apache License, Version 2.0 (the "License");
8 | // you may not use this file except in compliance with the License.
9 | // You may obtain a copy of the License at
10 | //
11 | // http://www.apache.org/licenses/LICENSE-2.0
12 | //
13 | // Unless required by applicable law or agreed to in writing, software
14 | // distributed under the License is distributed on an "AS IS" BASIS,
15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | // See the License for the specific language governing permissions and
17 | // limitations under the License.
18 | //
19 |
20 | package examples
21 |
22 | import (
23 | "fmt"
24 | "time"
25 |
26 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4"
27 | )
28 |
29 | func listClusterFromDatacenter() {
30 | inputRawURL := "https://foobar.mydomain.home/ovirt-engine/api"
31 |
32 | conn, err := ovirtsdk4.NewConnectionBuilder().
33 | URL(inputRawURL).
34 | Username("admin@internal").
35 | Password("mysuperpass").
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 | // Find all clusters of the data center:
54 | dataCentersService := conn.SystemService().DataCentersService()
55 | dcsListResp, err := dataCentersService.List().Search("status=up").Send()
56 | if err != nil {
57 | fmt.Printf("Failed to search dataCenter list, reason: %v\n", err)
58 | return
59 | }
60 | dcs := dcsListResp.MustDataCenters()
61 | for _, dc := range dcs.Slice() {
62 | dcService := dataCentersService.DataCenterService(dc.MustId())
63 | fmt.Println("Datacenter:", dc.MustName())
64 | clusters, err := dcService.ClustersService().List().Send()
65 | if err != nil {
66 | fmt.Printf("Failed to search dataCenter list, reason: %v\n", err)
67 | return
68 | }
69 | clusterSlice := clusters.MustClusters()
70 | clusterIds := make(map[string]string, 0)
71 | for _, cluster := range clusterSlice.Slice() {
72 | clusterIds[cluster.MustId()] = cluster.MustId()
73 | fmt.Println("\tCluster:", cluster.MustName())
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/sdk/examples/list_datacenters.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 listDatacenters() {
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 "datacenters" service:
53 | datacentersService := conn.SystemService().DataCentersService()
54 |
55 | // Use the "list" method of the "datacenters" service to list all the datacenters of the system:
56 | datacentersResponse, err := datacentersService.List().Send()
57 | if err != nil {
58 | fmt.Printf("Failed to get datacenter list, reason: %v\n", err)
59 | return
60 | }
61 |
62 | // Print the datacenter names and identifiers:
63 | if datacenters, ok := datacentersResponse.DataCenters(); ok {
64 | for _, dc := range datacenters.Slice() {
65 | fmt.Printf("Datacenter: ")
66 | if dcName, ok := dc.Name(); ok {
67 | fmt.Printf(" name: %v", dcName)
68 | }
69 | if dcID, ok := dc.Id(); ok {
70 | fmt.Printf(" id: %v", dcID)
71 | }
72 | fmt.Printf(" Supported versions are: ")
73 | if svs, ok := dc.SupportedVersions(); ok {
74 | for _, sv := range svs.Slice() {
75 | if major, ok := sv.Major(); ok {
76 | fmt.Printf(" Major: %v", major)
77 | }
78 | if minor, ok := sv.Minor(); ok {
79 | fmt.Printf(" Minor: %v", minor)
80 | }
81 | }
82 | }
83 | fmt.Println("")
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/sdk/examples/list_glance_images.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 listGlanceImages() {
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 Glance storage domain that is available for default in any oVirt installation
53 | sdsService := conn.SystemService().StorageDomainsService()
54 | resp, err := sdsService.List().
55 | Search("name=ovirt-image-repository").
56 | Send()
57 | if err != nil {
58 | fmt.Printf("Failed to get storage domains list, reason: %v\n", err)
59 | return
60 | }
61 | if sds, ok := resp.StorageDomains(); ok {
62 | sd := sds.Slice()[0]
63 | sdService := sdsService.StorageDomainService(sd.MustId())
64 | imagesService := sdService.ImagesService()
65 | // Not recommended, response error should be always be checked
66 | imgResp, _ := imagesService.List().Send()
67 | images, _ := imgResp.Images()
68 | for _, img := range images.Slice() {
69 | fmt.Printf("Image name is %v\n", img.MustName())
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/sdk/examples/list_hosts_statistics.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 listHostsStatistics() {
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 | hostsService := conn.SystemService().HostsService()
53 |
54 | // Error not checked is not recommended
55 | resp, _ := hostsService.List().Search("name=node26").Send()
56 | if hostSlice, ok := resp.Hosts(); ok {
57 | host := hostSlice.Slice()[0]
58 | stats, err := conn.FollowLink(host.MustStatistics())
59 | if err != nil {
60 | if href, ok := host.MustStatistics().Href(); ok {
61 | fmt.Printf("Failed to follow host stats link: %v, reason: %v\n", href, err)
62 | return
63 | }
64 | }
65 | if stats, ok := stats.(*ovirtsdk4.StatisticSlice); ok {
66 | for _, st := range stats.Slice() {
67 | fmt.Printf(
68 | "Stat name (%v) value (%v)\n",
69 | st.MustName(),
70 | st.MustValues().Slice()[0].MustDatum())
71 | }
72 | }
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/sdk/examples/list_networks.go:
--------------------------------------------------------------------------------
1 | // The oVirt Project - oVirt Engine Go SDK
2 | //
3 | // Copyright (c) oVirt Authors
4 | // The oVirt Project - oVirt Engine Go SDK
5 | //
6 | // # Copyright (c) oVirt Authors
7 | //
8 | // Licensed under the Apache License, Version 2.0 (the "License");
9 | // you may not use this file except in compliance with the License.
10 | // You may obtain a copy of the License at
11 | //
12 | // http://www.apache.org/licenses/LICENSE-2.0
13 | //
14 | // Unless required by applicable law or agreed to in writing, software
15 | // distributed under the License is distributed on an "AS IS" BASIS,
16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | // See the License for the specific language governing permissions and
18 | // limitations under the License.
19 | package examples
20 |
21 | import (
22 | "fmt"
23 | "time"
24 |
25 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4"
26 | )
27 |
28 | func listNetworks() {
29 | inputRawURL := "https://foobar.mydomain.home/ovirt-engine/api"
30 |
31 | conn, err := ovirtsdk4.NewConnectionBuilder().
32 | URL(inputRawURL).
33 | Username("admin@internal").
34 | Password("superpass").
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 "list" method of the "clusters" service to list all the clusters of the system:
56 | clustersResponse, err := clustersService.List().Send()
57 | if err != nil {
58 | fmt.Printf("Failed to get cluster list, reason: %v\n", err)
59 | return
60 | }
61 |
62 | if clusters, ok := clustersResponse.Clusters(); ok {
63 | // Print the datacenter names and identifiers:
64 | for _, cluster := range clusters.Slice() {
65 | fmt.Printf("Cluster")
66 | if clusterName, ok := cluster.Name(); ok {
67 | fmt.Printf(": %v", clusterName)
68 | }
69 | clusterID, ok := cluster.Id()
70 | fmt.Printf(" id: %v ", clusterID)
71 | var networkByNames = make(map[string]*ovirtsdk4.Network)
72 | var networkNames []string
73 | systemService := conn.SystemService()
74 | networksResponse, err := systemService.ClustersService().ClusterService(clusterID).NetworksService().List().Send()
75 | if err != nil {
76 | return
77 | }
78 | networks, ok := networksResponse.Networks()
79 | if !ok {
80 | fmt.Printf("there are no available networks for cluster %s", clusterID)
81 | return
82 | }
83 |
84 | for _, network := range networks.Slice() {
85 | networkByNames[network.MustName()] = network
86 | networkNames = append(networkNames, network.MustName())
87 | }
88 | fmt.Println("networks:", networkNames)
89 | }
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/sdk/examples/list_operating_systems.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 listOperationSystem() {
29 | inputRawURL := "https://10.1.111.222/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 | ossService := conn.SystemService().OperatingSystemsService()
53 | listResp := ossService.List().MustSend()
54 | fmt.Printf("os are:\n")
55 | for _, item := range listResp.MustOperatingSystem().Slice() {
56 | fmt.Printf("id:%v, name:%v, href:%v\n", item.MustId(), item.MustName(), item.MustHref())
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/sdk/examples/list_roles.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 listRoles() {
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 | roleService := conn.SystemService().RolesService()
53 | resp, err := roleService.List().Send()
54 | if err != nil {
55 | fmt.Printf("Failed to get role list, reason: %v\n", err)
56 | return
57 | }
58 |
59 | if roleSlice, ok := resp.Roles(); ok {
60 | for _, role := range roleSlice.Slice() {
61 | fmt.Printf("Role: (")
62 | if roleName, ok := role.Name(); ok {
63 | fmt.Printf(" name: %v", roleName)
64 | }
65 | if roleDesc, ok := role.Description(); ok {
66 | fmt.Printf(" desc: %v", roleDesc)
67 | }
68 | fmt.Println(")")
69 | }
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/sdk/examples/list_storage_domains.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 listStorageDomains() {
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 | sdsListResp, err := conn.SystemService().StorageDomainsService().List().Send()
53 | if err != nil {
54 | fmt.Printf("Failed to get storage domains, reason: %v\n", err)
55 | return
56 | }
57 |
58 | for _, sds := range sdsListResp.MustStorageDomains().Slice() {
59 | fmt.Printf("id: %v", sds.MustId())
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/sdk/examples/list_tags.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 listTags() {
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 | tagsService := conn.SystemService().TagsService()
53 | resp, err := tagsService.List().Send()
54 | if err != nil {
55 | fmt.Printf("Failed to get tag list, reason: %v\n", err)
56 | return
57 | }
58 |
59 | if tagSlice, ok := resp.Tags(); ok {
60 | for _, tag := range tagSlice.Slice() {
61 | fmt.Printf("Tag: (")
62 | if tagName, ok := tag.Name(); ok {
63 | fmt.Printf(" name: %v", tagName)
64 | }
65 | if tagDesc, ok := tag.Description(); ok {
66 | fmt.Printf(" desc: %v", tagDesc)
67 | }
68 | fmt.Println(")")
69 | }
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/sdk/examples/list_vm_disks.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 listVMDisks() {
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 | vmsService := conn.SystemService().VmsService()
53 | // Use Must version methods to make a function call chain
54 | vm := vmsService.List().Search("name=test4joey").MustSend().MustVms().Slice()[0]
55 | vmService := vmsService.VmService(vm.MustId())
56 | dasService := vmService.DiskAttachmentsService()
57 |
58 | das := dasService.List().MustSend().MustAttachments()
59 | for _, da := range das.Slice() {
60 | disk, _ := conn.FollowLink(da.MustDisk())
61 | if disk, ok := disk.(*ovirtsdk4.Disk); ok {
62 | fmt.Printf(" name: %v\n", disk.MustName())
63 | fmt.Printf(" id: %v\n", disk.MustId())
64 | fmt.Printf(" status: %v\n", disk.MustStatus())
65 | fmt.Printf(" provisioned_size: %v\n", disk.MustProvisionedSize())
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/sdk/examples/list_vm_tags.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 listVMTags() {
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 | resp, err := tagService.List().Send()
55 | if err != nil {
56 | fmt.Printf("Failed to get tag list, reason: %v\n", err)
57 | return
58 | }
59 | if tagSlice, ok := resp.Tags(); ok {
60 | for _, tag := range tagSlice.Slice() {
61 | fmt.Printf("Tag: (")
62 | if name, ok := tag.Name(); ok {
63 | fmt.Printf(" name: %v", name)
64 | }
65 | if desc, ok := tag.Description(); ok {
66 | fmt.Printf(" desc: %v", desc)
67 | }
68 | fmt.Println(")")
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/sdk/examples/list_vms.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 listVMs() {
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 "list" method of the "vms" service to list all the virtual machines
56 | vmsResponse, err := vmsService.List().Send()
57 |
58 | if err != nil {
59 | fmt.Printf("Failed to get vm list, reason: %v\n", err)
60 | return
61 | }
62 | if vms, ok := vmsResponse.Vms(); ok {
63 | // Print the virtual machine names and identifiers:
64 | for _, vm := range vms.Slice() {
65 | fmt.Print("VM: (")
66 | if vmName, ok := vm.Name(); ok {
67 | fmt.Printf(" name: %v", vmName)
68 | }
69 | if vmID, ok := vm.Id(); ok {
70 | fmt.Printf(" id: %v", vmID)
71 | }
72 | fmt.Println(")")
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/sdk/examples/list_vms_with_tag.go:
--------------------------------------------------------------------------------
1 | //
2 | // The oVirt Project - oVirt Engine Go SDK
3 | //
4 | // Copyright (c) oVirt Authors
5 | // The oVirt Project - oVirt Engine Go SDK
6 | //
7 | // Copyright (c) oVirt Authors
8 | //
9 | // Licensed under the Apache License, Version 2.0 (the "License");
10 | // you may not use this file except in compliance with the License.
11 | // You may obtain a copy of the License at
12 | //
13 | // http://www.apache.org/licenses/LICENSE-2.0
14 | //
15 | // Unless required by applicable law or agreed to in writing, software
16 | // distributed under the License is distributed on an "AS IS" BASIS,
17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | // See the License for the specific language governing permissions and
19 | // limitations under the License.
20 | //
21 |
22 | package examples
23 |
24 | import (
25 | "fmt"
26 | "time"
27 |
28 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4"
29 | )
30 |
31 | func listVMsTag() {
32 | inputRawURL := "https://foobar.mydomain.home/ovirt-engine/api"
33 | tag := "tag=cluster-999wh"
34 |
35 | conn, err := ovirtsdk4.NewConnectionBuilder().
36 | URL(inputRawURL).
37 | Username("admin@internal").
38 | Password("mysuperpass").
39 | Insecure(true).
40 | Compress(true).
41 | Timeout(time.Second * 10).
42 | Build()
43 | if err != nil {
44 | fmt.Printf("Make connection failed, reason: %v\n", err)
45 | return
46 | }
47 | defer conn.Close()
48 |
49 | // To use `Must` methods, you should recover it if panics
50 | defer func() {
51 | if err := recover(); err != nil {
52 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason")
53 | }
54 | }()
55 |
56 | // Get the reference to the "vms" service:
57 | vmsService := conn.SystemService().VmsService()
58 |
59 | // Use the "list" method of the "vms" service to list all the virtual machines
60 | vmsResponse, err := vmsService.List().Search(tag).Send()
61 |
62 | if err != nil {
63 | fmt.Printf("Failed to get vm list, reason: %v\n", err)
64 | return
65 | }
66 | if vms, ok := vmsResponse.Vms(); ok {
67 | // Print the virtual machine names and identifiers:
68 | for _, vm := range vms.Slice() {
69 | fmt.Print("VM: (")
70 | if vmName, ok := vm.Name(); ok {
71 | fmt.Printf(" name: %v", vmName)
72 | }
73 | if vmID, ok := vm.Id(); ok {
74 | fmt.Printf(" id: %v", vmID)
75 | }
76 | fmt.Println(")")
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/sdk/examples/page_vms.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 pageVms() {
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 service:
53 | vmsService := conn.SystemService().VmsService()
54 |
55 | // List the vm page by page:
56 | size := int64(1)
57 | index := int64(1)
58 | for {
59 | pageIndex := fmt.Sprintf("page %v", index)
60 | vmsResp, err := vmsService.List().Search(pageIndex).Max(size).Send()
61 | if err != nil {
62 | fmt.Printf("Failed to get vm list, reason: %v\n", err)
63 | return
64 | }
65 | if len(vmsResp.MustVms().Slice()) == 0 {
66 | break
67 | }
68 |
69 | for _, vm := range vmsResp.MustVms().Slice() {
70 | fmt.Printf("Vm name: %v\n", vm.MustName())
71 | }
72 |
73 | index += int64(1)
74 | fmt.Printf("Index: %v\n", index)
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/sdk/examples/pin_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 pinVM() {
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 service that manages the vms
53 | vmsService := conn.SystemService().VmsService()
54 | vm := vmsService.List().
55 | Search("name=myvm").
56 | MustSend().
57 | MustVms().
58 | Slice()[0]
59 |
60 | // Update the placement policy of the virtual machine so that it's pinned to the host
61 | vmService := vmsService.VmService(vm.MustId())
62 | vmService.Update().
63 | Vm(
64 | ovirtsdk4.NewVmBuilder().
65 | PlacementPolicy(
66 | ovirtsdk4.NewVmPlacementPolicyBuilder().
67 | HostsOfAny(
68 | ovirtsdk4.NewHostBuilder().
69 | Name("myhost").
70 | MustBuild()).
71 | MustBuild()).
72 | MustBuild()).
73 | MustSend()
74 | }
75 |
--------------------------------------------------------------------------------
/sdk/examples/print_vm_mac_duplicates.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 printVmMacDup() {
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 service:
53 | vmsService := conn.SystemService().VmsService()
54 |
55 | vmsResp, err := vmsService.List().Send()
56 | if err != nil {
57 | fmt.Printf("Failed to get vm list, reason: %v\n", err)
58 | return
59 | }
60 |
61 | vmNics := make(map[string]string, 0)
62 | // Iterate via all virtual machines and print if they have duplicated MAC
63 | // address with any other virtual machine in the system:
64 | for _, vm := range vmsResp.MustVms().Slice() {
65 | fmt.Printf("Vm name: %v\n", vm.MustName())
66 | vmService := vmsService.VmService(vm.MustId())
67 | nicsResp, err := vmService.NicsService().List().Send()
68 | if err != nil {
69 | fmt.Printf("Failed to get nic list, reason: %v\n", err)
70 | }
71 | for _, nic := range nicsResp.MustNics().Slice() {
72 | if _, exists := vmNics[nic.MustMac().MustAddress()]; exists {
73 | println("key exists in map")
74 | fmt.Printf("[%v]: MAC address '%v' is used by following virtual machine already: %v",
75 | nic.MustName(), nic.MustMac().MustAddress(), vmNics)
76 | } else {
77 | vmNics[nic.MustMac().MustAddress()] = vm.MustName()
78 | }
79 |
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/sdk/examples/remove_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 removeHost() {
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 service that manages hosts
53 | hostsService := conn.SystemService().HostsService()
54 |
55 | // Find the host
56 | host := hostsService.List().
57 | Search("name=myhost").
58 | MustSend().
59 | MustHosts().
60 | Slice()[0]
61 |
62 | // Find the service that manages the host
63 | hostService := hostsService.HostService(host.MustId())
64 |
65 | // If the host isn't down or in maintenance then move it to maintenance
66 | if host.MustStatus() != ovirtsdk4.HOSTSTATUS_MAINTENANCE {
67 | hostService.Deactivate().MustSend()
68 | }
69 |
70 | // Remove the host
71 | hostService.Remove().MustSend()
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/sdk/examples/remove_numa_nodes_from_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 | "sort"
24 | "time"
25 |
26 | ovirtsdk4 "github.com/ovirt/go-ovirt/v4"
27 | )
28 |
29 | func removeNumaNodesFromVm() {
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 the reference to the vm service:
54 | vmsService := conn.SystemService().VmsService()
55 |
56 | // Retrieve the description of the virtual machine:
57 | vmsResp, err := vmsService.List().Search("name=myvm").Send()
58 | if err != nil {
59 | fmt.Printf("Failed to get vm list, reason: %v\n", err)
60 | return
61 | }
62 | vm := vmsResp.MustVms().Slice()[0]
63 |
64 | //In order to update the virtual machine we need a reference to the service
65 | // the manages it:
66 | vmService := vmsService.VmService(vm.MustId())
67 |
68 | // Get the reference to the numa nodes service of the virtual machine:
69 | vmNodesService := vmService.NumaNodesService()
70 |
71 | // For each numa node of the virtual machine we call the remove method
72 | // to remove the numa node. Note that we must remove the numa nodes from
73 | // highest numa node index to lowest numa node index:
74 | vmNodeResp, err := vmNodesService.List().Send()
75 | vmNodes := vmNodeResp.MustNodes().Slice()
76 | sort.Slice(vmNodes, func(i, j int) bool {
77 | return vmNodes[i].MustIndex() > vmNodes[j].MustIndex() // reverse=True
78 | })
79 |
80 | for _, vmNode := range vmNodes {
81 | fmt.Printf("Removing node with id %v\n", vmNode.MustId())
82 | vmNodeService := vmNodesService.NodeService(vmNode.MustId())
83 | vmNodeService.Remove().Send()
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/sdk/examples/remove_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 removeTag() {
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 | tagsService := conn.SystemService().TagsService()
53 | var tagID string
54 | resp, err := tagsService.List().Send()
55 | if err != nil {
56 | fmt.Printf("Failed to get tag list, reason: %v\n", err)
57 | return
58 | }
59 | tags, _ := resp.Tags()
60 | for _, tag := range tags.Slice() {
61 | if tag.MustName() == "mytag" {
62 | tagID = tag.MustId()
63 | break
64 | }
65 | }
66 | if tagID == "" {
67 | fmt.Printf("Tag (mytag) not found\n")
68 | return
69 | }
70 |
71 | tagService := tagsService.TagService(tagID)
72 | _, err = tagService.Remove().Send()
73 | if err != nil {
74 | fmt.Printf("Failed to remove tag, reason: %v", err)
75 | return
76 | }
77 | fmt.Printf("Remove tag (mytag) successfully\n")
78 | }
79 |
--------------------------------------------------------------------------------
/sdk/examples/remove_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 removeVM() {
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 service that manages VMs
53 | vmsService := conn.SystemService().VmsService()
54 |
55 | // Find the VM
56 | vm := vmsService.List().
57 | Search("name=myvm").
58 | MustSend().
59 | MustVms().
60 | Slice()[0]
61 |
62 | // Note that the "vm" variable that we assigned above contains only the data of the VM, it doesn't have any
63 | // method like "remove". Methods are defined in the services. So now that we have the description of the VM
64 | // we can find the service that manages it, calling the locator method "vmService" defined in the "vms"
65 | // service. This locator method receives as parameter the identifier of the VM and returns a reference to the
66 | // service that manages that VM.
67 | vmService := vmsService.VmService(vm.MustId())
68 |
69 | // Now that we have the reference to the service that manages the VM we can use it to remove the VM. Note that
70 | // this method doesn't need any parameter, as the identifier of the VM is already known by the service that we
71 | // located in the previous step.
72 | vmService.Remove().MustSend()
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/sdk/examples/search_vms.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 searchVM() {
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 "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 | if vms, ok := vmsResponse.Vms(); ok {
63 | // Print the virtual machine names and identifiers:
64 | for _, vm := range vms.Slice() {
65 | fmt.Print("VM: (")
66 | if vmName, ok := vm.Name(); ok {
67 | fmt.Printf(" name: %v", vmName)
68 | }
69 | if vmID, ok := vm.Id(); ok {
70 | fmt.Printf(" id: %v", vmID)
71 | }
72 | fmt.Println(")")
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/sdk/examples/set_vm_comment.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 setVmComment() {
29 | inputRawURL := "https://10.1.111.229/ovirt-engine/api"
30 |
31 | //this is the comment that will be set for the VM
32 | comment := "test comment"
33 |
34 | conn, err := ovirtsdk4.NewConnectionBuilder().
35 | URL(inputRawURL).
36 | Username("admin@internal").
37 | Password("qwer1234").
38 | Insecure(true).
39 | Compress(true).
40 | Timeout(time.Second * 10).
41 | Build()
42 | if err != nil {
43 | fmt.Printf("Make connection failed, reason: %v\n", err)
44 | return
45 | }
46 | defer conn.Close()
47 |
48 | // To use `Must` methods, you should recover it if panics
49 | defer func() {
50 | if err := recover(); err != nil {
51 | fmt.Printf("Panics occurs, try the non-Must methods to find the reason")
52 | }
53 | }()
54 |
55 | // Get the reference to the vm service:
56 | vmsService := conn.SystemService().VmsService()
57 |
58 | // Retrieve the description of the virtual machine:
59 | vmsResp, err := vmsService.List().Search("name=myvm").Send()
60 | if err != nil {
61 | fmt.Printf("Failed to get vm list, reason: %v\n", err)
62 | return
63 | }
64 | vm := vmsResp.MustVms().Slice()[0]
65 |
66 | //In order to update the virtual machine we need a reference to the service
67 | // the manages it:
68 | vmService := vmsService.VmService(vm.MustId())
69 |
70 | // Use the "update" method to set a comment:
71 |
72 | vmService.Update().
73 | Vm(
74 | ovirtsdk4.NewVmBuilder().
75 | Comment(comment).
76 | MustBuild()).
77 | Send()
78 | }
79 |
--------------------------------------------------------------------------------
/sdk/examples/set_vm_lease_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 setVMLeaseStorageDomain() {
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 root of the tree of services
53 | systemService := conn.SystemService()
54 |
55 | // Find the virtual machine
56 | vmsService := systemService.VmsService()
57 | vm := vmsService.List().
58 | Search("name=myvm").
59 | MustSend().
60 | MustVms().
61 | Slice()[0]
62 |
63 | // Find the storage domain
64 | sdsService := systemService.StorageDomainsService()
65 | sd := sdsService.List().
66 | Search("name=mydata").
67 | MustSend().
68 | MustStorageDomains().
69 | Slice()[0]
70 |
71 | // Update the virtual machine so that high availability is enabled and the lease is created in the selected
72 | // storage domain
73 | vmService := vmsService.VmService(vm.MustId())
74 | vmService.Update().
75 | Vm(
76 | ovirtsdk4.NewVmBuilder().
77 | HighAvailability(
78 | ovirtsdk4.NewHighAvailabilityBuilder().
79 | Enabled(true).
80 | MustBuild()).
81 | Lease(
82 | ovirtsdk4.NewStorageDomainLeaseBuilder().
83 | StorageDomain(
84 | ovirtsdk4.NewStorageDomainBuilder().
85 | Id(sd.MustId()).
86 | MustBuild()).
87 | MustBuild()).
88 | MustBuild()).
89 | MustSend()
90 | }
91 |
--------------------------------------------------------------------------------
/sdk/examples/set_vm_serial_number.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 setVmSerialNumber() {
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 service:
53 | vmsService := conn.SystemService().VmsService()
54 |
55 | // Retrieve the description of the virtual machine:
56 | vmsResp, err := vmsService.List().Search("name=myvm").Send()
57 | if err != nil {
58 | fmt.Printf("Failed to get vm list, reason: %v\n", err)
59 | return
60 | }
61 | vm := vmsResp.MustVms().Slice()[0]
62 |
63 | //In order to update the virtual machine we need a reference to the service
64 | // the manages it:
65 | vmService := vmsService.VmService(vm.MustId())
66 |
67 | // Use the "update" method to set a serial number policy and value:
68 | vmService.Update().
69 | Vm(
70 | ovirtsdk4.NewVmBuilder().
71 | SerialNumber(
72 | ovirtsdk4.NewSerialNumberBuilder().
73 | Policy(ovirtsdk4.SERIALNUMBERPOLICY_CUSTOM).
74 | Value("myserial").
75 | MustBuild()).
76 | MustBuild()).
77 | Send()
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/sdk/examples/show_summary.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 showSummary() {
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 API information from the root service:
53 | api := conn.SystemService().Get().MustSend().MustApi()
54 | fmt.Printf("Version: %v\n", api.MustProductInfo().MustVersion().MustFullVersion())
55 | fmt.Printf("Hosts: %v\n", api.MustSummary().MustHosts().MustTotal())
56 | fmt.Printf("StorageDomain: %v\n", api.MustSummary().MustStorageDomains().MustTotal())
57 | fmt.Printf("Users: %v\n", api.MustSummary().MustUsers().MustTotal())
58 | fmt.Printf("Vms: %v\n", api.MustSummary().MustUsers().MustTotal())
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/sdk/examples/sparsify_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 sparsifyDisk() {
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 | // Find the virtual machine:
56 | disksResp, err := disksService.List().Search("name=mydisk").Send()
57 | if err != nil {
58 | fmt.Printf("Failed to get vm list, reason: %v\n", err)
59 | return
60 | }
61 |
62 | //# Find the disk we want to sparsify:
63 | //# Locate the service that manage the disk we want to sparsify:
64 | disk := disksResp.MustDisks().Slice()[0]
65 | diskService := disksService.DiskService(disk.MustId())
66 |
67 | // Sparsify the disk. Note that the virtual machine where the disk is attached
68 | // must not be running so the sparsification is executed. If the virtual
69 | // machine will be running the sparsify operation will fail:
70 | diskService.Sparsify().Send()
71 |
72 | // Wait till the disk is ok:
73 | for {
74 | time.Sleep(5 * time.Second)
75 | diskResp, _ := diskService.Get().Send()
76 | if disk, ok := diskResp.Disk(); ok {
77 | if disk.MustStatus() == ovirtsdk4.DISKSTATUS_OK {
78 | break
79 | }
80 | }
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/sdk/examples/start_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 startVM() {
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 | // Find the virtual machine
56 | vm := vmsService.List().Search("name=myvm").MustSend().MustVms().Slice()[0]
57 |
58 | // Locate the service that manages the virtual machine, as that is where the action methods are defined
59 | vmService := vmsService.VmService(vm.MustId())
60 |
61 | // Call the "start" method of the service to start it
62 | vmService.Start().MustSend()
63 |
64 | // Wait till the virtual machine is up
65 | for {
66 | time.Sleep(5 * time.Second)
67 | vm = vmService.Get().MustSend().MustVm()
68 | if vm.MustStatus() == ovirtsdk4.VMSTATUS_UP {
69 | break
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/sdk/examples/start_vm_with_boot_devices.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 startVmWithBootDevices() {
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 | // Find the virtual machine:
56 | vmsResp, err := vmsService.List().Search("name=myvm").Send()
57 | if err != nil {
58 | fmt.Printf("Failed to get vm list, reason: %v\n", err)
59 | return
60 | }
61 |
62 | // Locate the service that manages the virtual machine, as that is where
63 | // the action methods are defined:
64 | vm := vmsResp.MustVms().Slice()[0]
65 | vmService := vmsService.VmService(vm.MustId())
66 |
67 | // Call the "start" method of the service to start it with
68 | // additional properties in a run once configuration
69 | vmService.Start().
70 | Vm(
71 | ovirtsdk4.NewVmBuilder().
72 | Os(
73 | ovirtsdk4.NewOperatingSystemBuilder().
74 | Boot(
75 | ovirtsdk4.NewBootBuilder().
76 | DevicesOfAny(
77 | ovirtsdk4.BOOTDEVICE_NETWORK,
78 | ovirtsdk4.BOOTDEVICE_CDROM).
79 | MustBuild()).
80 | MustBuild()).
81 | MustBuild()).
82 | Send()
83 |
84 | // Wait till the virtual machine is up:
85 | for {
86 | time.Sleep(5 * time.Second)
87 | vmResp, _ := vmService.Get().Send()
88 | if vm, ok := vmResp.Vm(); ok {
89 | if vm.MustStatus() == ovirtsdk4.VMSTATUS_UP {
90 | break
91 | }
92 | }
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/sdk/examples/stop_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 stopVM() {
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 | // Find the virtual machine
56 | vm := vmsService.List().Search("name=myvm").MustSend().MustVms().Slice()[0]
57 |
58 | // Locate the service that manages the virtual machine, as that is where the action methods are defined
59 | vmService := vmsService.VmService(vm.MustId())
60 |
61 | // Call the "stop" method of the service to stop it
62 | vmService.Stop().MustSend()
63 |
64 | // Wait till the virtual machine is down
65 | for {
66 | time.Sleep(5 * time.Second)
67 | vm = vmService.Get().MustSend().MustVm()
68 | if vm.MustStatus() == ovirtsdk4.VMSTATUS_DOWN {
69 | break
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/sdk/examples/test_connection.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 testConnection() {
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 | // Call the test method to check the connectivity with the server. If
53 | // connectivity works this method will return "nil". If there is any
54 | // connectivy problem it will either return "error":
55 | if conn.Test() == nil {
56 | fmt.Sprintf("Connection works.")
57 | } else {
58 | fmt.Sprintf("Connection doesn't work.")
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/sdk/examples/unassign_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 unassignTagToVM() {
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 | var tagID string
72 | resp, err := assignedTagsService.List().Send()
73 | if err != nil {
74 | fmt.Printf("Failed to get assigned tag list of vm (test4joey), reason: %v\n", err)
75 | return
76 | }
77 | for _, tag := range resp.MustTags().Slice() {
78 | if tag.MustName() == "mytag" {
79 | tagID = tag.MustId()
80 | break
81 | }
82 | }
83 | if tagID == "" {
84 | fmt.Printf("Tag (mytag) not found\n")
85 | return
86 | }
87 | assignedTagService := assignedTagsService.TagService(tagID)
88 | assignedTagService.Remove().Send()
89 | fmt.Println("Unassigned tag (mytag) from vm (test4joey) successfully")
90 | }
91 |
--------------------------------------------------------------------------------
/sdk/examples/update_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 updateDatacenter() {
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 "datacenters" service:
53 | dcsService := conn.SystemService().DataCentersService()
54 |
55 | // Find the datacenter
56 | dc := dcsService.List().
57 | Search("name=mydc").
58 | MustSend().
59 | MustDataCenters().
60 | Slice()[0]
61 |
62 | // In order to update the data center we need a reference to the service that manages it, then we can call the
63 | // "update" method passing the update
64 | dcService := dcsService.DataCenterService(dc.MustId())
65 | dc = dcService.Update().
66 | DataCenter(
67 | ovirtsdk4.NewDataCenterBuilder().
68 | Description("Updated description").
69 | MustBuild()).
70 | MustSend().
71 | MustDataCenter()
72 |
73 | // Print the description of the result of the update
74 | fmt.Printf("%v: %v", dc.MustName(), dc.MustDescription())
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/sdk/examples/wait_vm_status.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 waitVMStatus() {
29 | inputRawURL := "https://10.1.111.222/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 | err = conn.WaitForVM("be0fe882-fa24-4428-92bf-2b01bd08df05", ovirtsdk4.VMSTATUS_UP, 2*time.Minute)
53 |
54 | if err != nil {
55 | fmt.Printf("err is %v", err)
56 | } else {
57 | fmt.Printf("VM is %v now", ovirtsdk4.VMSTATUS_UP)
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/sdk/ovirtsdk/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/ovirt/go-ovirt/v4
2 |
3 | go 1.24
4 |
5 | require github.com/stretchr/testify v1.3.0
6 |
7 | require (
8 | github.com/davecgh/go-spew v1.1.0 // indirect
9 | github.com/pmezard/go-difflib v1.0.0 // indirect
10 | )
11 |
--------------------------------------------------------------------------------
/sdk/ovirtsdk/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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
6 | github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
7 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
8 |
--------------------------------------------------------------------------------
/sdk/ovirtsdk/helper.go:
--------------------------------------------------------------------------------
1 | package ovirtsdk
2 |
3 | import (
4 | "fmt"
5 | "time"
6 | )
7 |
8 | const DefaultInterval = 10 * time.Second
9 |
10 | const DefaultVMTimeout = 120 * time.Second
11 |
12 | // WaitForVM waits for VM to given status
13 | func (c *Connection) WaitForVM(vmID string, status VmStatus, timeout time.Duration) error {
14 | if timeout <= 0 {
15 | timeout = DefaultVMTimeout
16 | }
17 | if vmID == "" {
18 | return fmt.Errorf("the VM ID must not be empty")
19 | }
20 | vmService := c.SystemService().VmsService().VmService(vmID)
21 | for {
22 | resp, err := vmService.Get().Send()
23 | if err != nil {
24 | return err
25 | }
26 | if timeout <= 0 {
27 | return fmt.Errorf("timeout for waiting for VM to %v", status)
28 | }
29 |
30 | vm, ok := resp.Vm()
31 | if !ok {
32 | continue
33 | }
34 | if vm.MustStatus() == status {
35 | break
36 | }
37 |
38 | timeout = timeout - DefaultInterval
39 | time.Sleep(DefaultInterval)
40 | }
41 |
42 | return nil
43 | }
44 |
45 | const DefaultDiskTimeout = 120 * time.Second
46 |
47 | func (c *Connection) WaitForDisk(diskID string, status DiskStatus, timeout time.Duration) error {
48 | if timeout <= 0 {
49 | timeout = DefaultDiskTimeout
50 | }
51 | if diskID == "" {
52 | return fmt.Errorf("the Disk ID must not be empty")
53 | }
54 | diskService := c.SystemService().DisksService().DiskService(diskID)
55 | for {
56 | resp, err := diskService.Get().Send()
57 | if err != nil {
58 | return err
59 | }
60 | if timeout <= 0 {
61 | return fmt.Errorf("timeout for waiting for Disk to %v", status)
62 | }
63 |
64 | disk, ok := resp.Disk()
65 | if !ok {
66 | continue
67 | }
68 | if disk.MustStatus() == status {
69 | break
70 | }
71 |
72 | timeout = timeout - DefaultInterval
73 | time.Sleep(DefaultInterval)
74 | }
75 |
76 | return nil
77 | }
78 |
--------------------------------------------------------------------------------
/sdk/ovirtsdk/http.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 ovirtsdk
20 |
--------------------------------------------------------------------------------
/sdk/ovirtsdk/reader_test.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 ovirtsdk
20 |
21 | import (
22 | "testing"
23 |
24 | "github.com/stretchr/testify/assert"
25 | )
26 |
27 | func TestReadStrings(t *testing.T) {
28 | assert := assert.New(t)
29 | xmlstring := `
30 |
31 | x86_64
32 | Intel SandyBridge Family
33 |
34 | `
35 | reader := NewXMLReader([]byte(xmlstring))
36 |
37 | strs, err := reader.ReadStrings(nil)
38 | assert.Nil(err)
39 |
40 | assert.Equal([]string{"x86_64", "Intel SandyBridge Family"}, strs)
41 | }
42 |
--------------------------------------------------------------------------------
/sdk/ovirtsdk/service.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 ovirtsdk
20 |
21 | // Service is the interface of all type services.
22 | type Service interface {
23 | Connection() *Connection
24 | Path() string
25 | }
26 |
27 | // BaseService represents the base for all the services of the SDK. It contains the
28 | // utility methods used by all of them.
29 | type BaseService struct {
30 | connection *Connection
31 | path string
32 | }
33 |
34 | func (service *BaseService) Connection() *Connection {
35 | return service.connection
36 | }
37 |
38 | func (service *BaseService) Path() string {
39 | return service.path
40 | }
41 |
--------------------------------------------------------------------------------
/sdk/ovirtsdk/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 ovirtsdk
20 |
21 | type Href interface {
22 | Href() (string, bool)
23 | }
24 |
25 | // Link represents struct of href and rel attributes
26 | type Link struct {
27 | href *string
28 | rel *string
29 | }
30 |
31 | // Struct represents the base for all struts defined in types.go
32 | type Struct struct {
33 | href *string
34 | }
35 |
36 | func (p *Struct) Href() (string, bool) {
37 | if p.href != nil {
38 | return *p.href, true
39 | }
40 | return "", false
41 | }
42 |
43 | func (p *Struct) MustHref() string {
44 | if p.href == nil {
45 | panic("href attribute must exist")
46 | }
47 | return *p.href
48 | }
49 |
50 | func (p *Struct) SetHref(attr string) {
51 | p.href = &attr
52 | }
53 |
--------------------------------------------------------------------------------
/sdk/ovirtsdk/utils.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 ovirtsdk
20 |
21 | import (
22 | "reflect"
23 | )
24 |
25 | // Contains returns if target contains the obj parameter
26 | func Contains(obj interface{}, target interface{}) bool {
27 | targetValue := reflect.ValueOf(target)
28 | switch reflect.TypeOf(target).Kind() {
29 | case reflect.Slice, reflect.Array:
30 | for i := 0; i < targetValue.Len(); i++ {
31 | if targetValue.Index(i).Interface() == obj {
32 | return true
33 | }
34 | }
35 | case reflect.Map:
36 | if targetValue.MapIndex(reflect.ValueOf(obj)).IsValid() {
37 | return true
38 | }
39 | }
40 |
41 | return false
42 | }
43 |
--------------------------------------------------------------------------------
/sdk/ovirtsdk/vendor/github.com/davecgh/go-spew/LICENSE:
--------------------------------------------------------------------------------
1 | ISC License
2 |
3 | Copyright (c) 2012-2016 Dave Collins
4 |
5 | Permission to use, copy, modify, and distribute this software for any
6 | purpose with or without fee is hereby granted, provided that the above
7 | copyright notice and this permission notice appear in all copies.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 |
--------------------------------------------------------------------------------
/sdk/ovirtsdk/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2015-2016 Dave Collins
2 | //
3 | // Permission to use, copy, modify, and distribute this software for any
4 | // purpose with or without fee is hereby granted, provided that the above
5 | // copyright notice and this permission notice appear in all copies.
6 | //
7 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 | // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 | // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 | // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 |
15 | // NOTE: Due to the following build constraints, this file will only be compiled
16 | // when the code is running on Google App Engine, compiled by GopherJS, or
17 | // "-tags safe" is added to the go build command line. The "disableunsafe"
18 | // tag is deprecated and thus should not be used.
19 | // +build js appengine safe disableunsafe
20 |
21 | package spew
22 |
23 | import "reflect"
24 |
25 | const (
26 | // UnsafeDisabled is a build-time constant which specifies whether or
27 | // not access to the unsafe package is available.
28 | UnsafeDisabled = true
29 | )
30 |
31 | // unsafeReflectValue typically converts the passed reflect.Value into a one
32 | // that bypasses the typical safety restrictions preventing access to
33 | // unaddressable and unexported data. However, doing this relies on access to
34 | // the unsafe package. This is a stub version which simply returns the passed
35 | // reflect.Value when the unsafe package is not available.
36 | func unsafeReflectValue(v reflect.Value) reflect.Value {
37 | return v
38 | }
39 |
--------------------------------------------------------------------------------
/sdk/ovirtsdk/vendor/github.com/pmezard/go-difflib/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013, Patrick Mezard
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are
6 | met:
7 |
8 | Redistributions of source code must retain the above copyright
9 | notice, this list of conditions and the following disclaimer.
10 | Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in the
12 | documentation and/or other materials provided with the distribution.
13 | The names of its contributors may not be used to endorse or promote
14 | products derived from this software without specific prior written
15 | permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
23 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/sdk/ovirtsdk/vendor/github.com/stretchr/testify/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2012-2018 Mat Ryer and Tyler Bunnell
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/sdk/ovirtsdk/vendor/github.com/stretchr/testify/assert/assertion_format.go.tmpl:
--------------------------------------------------------------------------------
1 | {{.CommentFormat}}
2 | func {{.DocInfo.Name}}f(t TestingT, {{.ParamsFormat}}) bool {
3 | if h, ok := t.(tHelper); ok { h.Helper() }
4 | return {{.DocInfo.Name}}(t, {{.ForwardedParamsFormat}})
5 | }
6 |
--------------------------------------------------------------------------------
/sdk/ovirtsdk/vendor/github.com/stretchr/testify/assert/assertion_forward.go.tmpl:
--------------------------------------------------------------------------------
1 | {{.CommentWithoutT "a"}}
2 | func (a *Assertions) {{.DocInfo.Name}}({{.Params}}) bool {
3 | if h, ok := a.t.(tHelper); ok { h.Helper() }
4 | return {{.DocInfo.Name}}(a.t, {{.ForwardedParams}})
5 | }
6 |
--------------------------------------------------------------------------------
/sdk/ovirtsdk/vendor/github.com/stretchr/testify/assert/doc.go:
--------------------------------------------------------------------------------
1 | // Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.
2 | //
3 | // Example Usage
4 | //
5 | // The following is a complete example using assert in a standard test function:
6 | // import (
7 | // "testing"
8 | // "github.com/stretchr/testify/assert"
9 | // )
10 | //
11 | // func TestSomething(t *testing.T) {
12 | //
13 | // var a string = "Hello"
14 | // var b string = "Hello"
15 | //
16 | // assert.Equal(t, a, b, "The two words should be the same.")
17 | //
18 | // }
19 | //
20 | // if you assert many times, use the format below:
21 | //
22 | // import (
23 | // "testing"
24 | // "github.com/stretchr/testify/assert"
25 | // )
26 | //
27 | // func TestSomething(t *testing.T) {
28 | // assert := assert.New(t)
29 | //
30 | // var a string = "Hello"
31 | // var b string = "Hello"
32 | //
33 | // assert.Equal(a, b, "The two words should be the same.")
34 | // }
35 | //
36 | // Assertions
37 | //
38 | // Assertions allow you to easily write test code, and are global funcs in the `assert` package.
39 | // All assertion functions take, as the first argument, the `*testing.T` object provided by the
40 | // testing framework. This allows the assertion funcs to write the failings and other details to
41 | // the correct place.
42 | //
43 | // Every assertion function also takes an optional string message as the final argument,
44 | // allowing custom error messages to be appended to the message the assertion method outputs.
45 | package assert
46 |
--------------------------------------------------------------------------------
/sdk/ovirtsdk/vendor/github.com/stretchr/testify/assert/errors.go:
--------------------------------------------------------------------------------
1 | package assert
2 |
3 | import (
4 | "errors"
5 | )
6 |
7 | // AnError is an error instance useful for testing. If the code does not care
8 | // about error specifics, and only needs to return the error for example, this
9 | // error should be used to make the test code more readable.
10 | var AnError = errors.New("assert.AnError general error for testing")
11 |
--------------------------------------------------------------------------------
/sdk/ovirtsdk/vendor/github.com/stretchr/testify/assert/forward_assertions.go:
--------------------------------------------------------------------------------
1 | package assert
2 |
3 | // Assertions provides assertion methods around the
4 | // TestingT interface.
5 | type Assertions struct {
6 | t TestingT
7 | }
8 |
9 | // New makes a new Assertions object for the specified TestingT.
10 | func New(t TestingT) *Assertions {
11 | return &Assertions{
12 | t: t,
13 | }
14 | }
15 |
16 | //go:generate go run ../_codegen/main.go -output-package=assert -template=assertion_forward.go.tmpl -include-format-funcs
17 |
--------------------------------------------------------------------------------
/sdk/ovirtsdk/vendor/modules.txt:
--------------------------------------------------------------------------------
1 | # github.com/davecgh/go-spew v1.1.0
2 | ## explicit
3 | github.com/davecgh/go-spew/spew
4 | # github.com/pmezard/go-difflib v1.0.0
5 | ## explicit
6 | github.com/pmezard/go-difflib/difflib
7 | # github.com/stretchr/testify v1.3.0
8 | ## explicit
9 | github.com/stretchr/testify/assert
10 |
--------------------------------------------------------------------------------
/sdk/ovirtsdk/writers_test.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 ovirtsdk
20 |
21 | import (
22 | "bytes"
23 | "testing"
24 |
25 | "github.com/stretchr/testify/assert"
26 | )
27 |
28 | func TestCpuWriteOne(t *testing.T) {
29 | assert := assert.New(t)
30 | var b bytes.Buffer
31 | writer := NewXMLWriter(&b)
32 | cpu, err := NewCpuBuilder().Type("Intel SandyBridge Family").Architecture(ARCHITECTURE_X86_64).Build()
33 | assert.Nil(err)
34 | err = XMLCpuWriteOne(writer, cpu, "")
35 | assert.Nil(err)
36 | writer.Flush()
37 | assert.Equal("x86_64Intel SandyBridge Family",
38 | string(b.Bytes()))
39 |
40 | }
41 |
42 | func TestBootDevice(t *testing.T) {
43 | assert := assert.New(t)
44 | var b bytes.Buffer
45 | writer := NewXMLWriter(&b)
46 | boot, err := NewBootBuilder().DevicesOfAny("network").Build()
47 | assert.Nil(err)
48 | err = XMLBootWriteOne(writer, boot, "")
49 | assert.Nil(err)
50 | writer.Flush()
51 | assert.Equal("network",
52 | string(b.Bytes()))
53 | }
54 |
55 | func TestBootDevices(t *testing.T) {
56 | assert := assert.New(t)
57 | var b bytes.Buffer
58 | writer := NewXMLWriter(&b)
59 | boot, err := NewBootBuilder().DevicesOfAny("network", "hd").Build()
60 | assert.Nil(err)
61 | err = XMLBootWriteOne(writer, boot, "")
62 | assert.Nil(err)
63 | writer.Flush()
64 | assert.Equal("networkhd",
65 | string(b.Bytes()))
66 | }
67 |
--------------------------------------------------------------------------------