├── .copr └── Makefile ├── .github └── workflows │ └── build.yml ├── .gitignore ├── README.adoc ├── automation.yaml ├── automation ├── README.adoc ├── build-artifacts.packages ├── build-artifacts.sh ├── build.packages ├── build.py ├── check-merged.packages ├── check-merged.sh ├── check-patch.packages └── check-patch.sh ├── generator ├── README.adoc ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── ovirt │ │ └── sdk │ │ └── java │ │ ├── ServicesGenerator.java │ │ ├── ServicesImplGenerator.java │ │ └── Tool.java │ └── resources │ ├── META-INF │ └── beans.xml │ └── log4j.xml ├── packaging ├── README.adoc ├── build.xml ├── spec.el8.in ├── spec.fc34.in ├── spec.fc35.in ├── spec.in └── transform-pom.xsl ├── pom.xml └── sdk ├── CHANGES.adoc ├── LICENSE.txt ├── README.adoc ├── pom.xml └── src ├── main └── java │ └── org │ └── ovirt │ └── engine │ └── sdk4 │ ├── BaseRequest.java │ ├── Connection.java │ ├── ConnectionBuilder.java │ ├── Error.java │ ├── HttpClient.java │ ├── Request.java │ ├── Response.java │ ├── Service.java │ └── internal │ ├── ConnectionBuilder42.java │ ├── ConnectionBuilder45.java │ ├── HttpClient42.java │ ├── HttpClient45.java │ ├── HttpConnection.java │ ├── NoCaTrustManager.java │ ├── SsoUtils.java │ └── services │ └── ServiceImpl.java └── test ├── java └── org │ └── ovirt │ └── engine │ └── sdk4 │ ├── ActionReaderTest.java │ ├── ClusterReaderTest.java │ ├── ClusterServiceTest.java │ ├── ConnectionCreateTest.java │ ├── ConnectionUseTest.java │ ├── DataCentersServiceTest.java │ ├── DiscoverIscsiTest.java │ ├── FollowLinkTest.java │ ├── GlobalHeadersTest.java │ ├── ResponseCodeTest.java │ ├── SecondaryParametersTest.java │ ├── ServerTest.java │ ├── SetupNetworksTest.java │ ├── SimpleTest.java │ ├── StorageDomainsServiceTest.java │ ├── VmTest.java │ ├── VmsServiceTest.java │ └── examples │ ├── AddAffinityLabel.java │ ├── AddBond.java │ ├── AddCluster.java │ ├── AddDataCenter.java │ ├── AddFloatingDisk.java │ ├── AddGroup.java │ ├── AddHost.java │ ├── AddIndependentVm.java │ ├── AddInstanceType.java │ ├── AddLogicalNetwork.java │ ├── AddLunDiskToVm.java │ ├── AddMacPool.java │ ├── AddNfsDataStorageDomain.java │ ├── AddNfsIsoStorageDomain.java │ ├── AddSystemPermission.java │ ├── AddTag.java │ ├── AddTemplate.java │ ├── AddUserPublicSshKey.java │ ├── AddVm.java │ ├── AddVmDisk.java │ ├── AddVmFromTemplateVersion.java │ ├── AddVmNic.java │ ├── AddVmSnapshot.java │ ├── AddVmWithSysprep.java │ ├── AddVncConsole.java │ ├── AssignAffinityLabelToVm.java │ ├── AssignNetworkToCluster.java │ ├── AssignTagToVm.java │ ├── AttachNfsDataStorageDomain.java │ ├── AttachNfsIsoStorageDomain.java │ ├── ChangeVmCd.java │ ├── CloneVmFromSnapshot.java │ ├── DiscoverIscsi.java │ ├── EnableSerialConsole.java │ ├── ExportVm.java │ ├── FollowVmLinks.java │ ├── GetDisplayTicket.java │ ├── ImportGlanceImage.java │ ├── ImportVm.java │ ├── ListAffinityLabels.java │ ├── ListGlanceImages.java │ ├── ListHostStatistics.java │ ├── ListRoles.java │ ├── ListTags.java │ ├── ListVmDisks.java │ ├── ListVmSnapshots.java │ ├── ListVmTags.java │ ├── ListVms.java │ ├── PinVm.java │ ├── RegisterVm.java │ ├── RemoveHost.java │ ├── RemoveTag.java │ ├── RemoveVm.java │ ├── SearchVms.java │ ├── SetVmLeaseStorageDomain.java │ ├── StartVm.java │ ├── StartVmWithCloudInit.java │ ├── StopVm.java │ ├── UnassignTagToVm.java │ ├── UpdateDataCenter.java │ ├── UpdateFencingOptions.java │ ├── UpdateQuotaLimits.java │ └── VmBackup.java └── resources ├── log4j.xml └── pki ├── README.adoc ├── ca.crt ├── ca.jks ├── localhost.crt ├── localhost.jks ├── localhost.key ├── localhost.p12 ├── server.crt ├── server.key ├── ugly.crt ├── ugly.jks ├── ugly.key └── ugly.p12 /.copr/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: installdeps git_cfg_safe srpm 2 | 3 | installdeps: 4 | dnf -y install ant git httpcomponents-client jackson-annotations jackson-core jackson-databind java-11-openjdk-devel javapackages-local \ 5 | libxslt maven maven-local python3 python3-lxml rpm-build rpmdevtools slf4j 6 | 7 | git_cfg_safe: 8 | # From git 2.35.2 we need to mark temporary directory, where the project is cloned to, as safe, otherwise 9 | # git commands won't work because of the fix for CVE-2022-24765 10 | git config --global --add safe.directory "$(shell pwd)" 11 | 12 | srpm: installdeps git_cfg_safe 13 | ./automation/build.py 14 | cp exported-artifacts/*.src.rpm $(outdir) 15 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | on: 3 | push: 4 | branches: [master] 5 | pull_request: 6 | branches: [master] 7 | workflow_dispatch: 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | strategy: 13 | fail-fast: false 14 | matrix: 15 | include: 16 | - name: centos-stream-8 17 | shortcut: cs8 18 | container-name: el8stream 19 | 20 | name: ${{ matrix.name }} 21 | 22 | env: 23 | ARTIFACTS_DIR: exported-artifacts 24 | 25 | container: 26 | image: quay.io/ovirt/buildcontainer:${{ matrix.container-name }} 27 | 28 | steps: 29 | 30 | - name: Checkout sources 31 | uses: actions/checkout@v2 32 | 33 | - name: Use cache for maven 34 | uses: actions/cache@v2 35 | with: 36 | path: ~/.m2/repository 37 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} 38 | restore-keys: | 39 | ${{ runner.os }}-maven- 40 | 41 | - name: Perform build 42 | run: | 43 | python3 automation/build.py $ARTIFACTS_DIR 44 | 45 | - name: Upload RPM artifacts 46 | uses: ovirt/upload-rpms-action@v2 47 | with: 48 | directory: ${{ env.ARTIFACTS_DIR}} 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.gz 3 | *.iml 4 | .idea/ 5 | exported-artifacts/ 6 | packaging/*.spec 7 | settings.xml 8 | target/ 9 | **/methods.properties 10 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = oVirt Java SDK 2 | 3 | image:https://copr.fedorainfracloud.org/coprs/ovirt/ovirt-master-snapshot/package/java-ovirt-engine-sdk4/status_image/last_build.png[link="https://copr.fedorainfracloud.org/coprs/ovirt/ovirt-master-snapshot/package/java-ovirt-engine-sdk4/"] 4 | 5 | == TODO 6 | Update the project so it can be built in a standard way using xmvn 7 | 8 | == Introduction 9 | 10 | The oVirt Java SDK is a Java package that simplifies access to the 11 | oVirt Engine API. 12 | 13 | == Building 14 | 15 | Most of the source code of the Java SDK is automatically generated 16 | from the API model. 17 | 18 | The code generator is a Java program that resides in the `generator` 19 | directory. This Java program will get the API model and the metamodel 20 | artifacts from the available Maven repositories. To build and run it use 21 | the following commands: 22 | 23 | $ git clone git://gerrit.ovirt.org/ovirt-engine-sdk-java 24 | $ mvn package 25 | 26 | This will build the code generator and run it to generate the SDK for 27 | the version of the API that corresponds to the branch of the SDK that 28 | you are using. 29 | 30 | If you need to generate it for a different version of the API then you 31 | can use the `model.version` property. For example, if you need to 32 | generate the SDK for version `4.1.0` of the SDK you can use this 33 | command: 34 | 35 | $ mvn package -Dmodel.version=4.1.0 36 | 37 | Once the source code is generated, it needs to be built: 38 | 39 | $ cd sdk 40 | $ mvn clean install 41 | 42 | The generated `.jar` files will be located in the `sdk/target` 43 | directory: 44 | 45 | $ find target -name '*.jar' 46 | target/ovirt-engine-sdk-4.0.0-SNAPSHOT.jar 47 | -------------------------------------------------------------------------------- /automation.yaml: -------------------------------------------------------------------------------- 1 | distros: 2 | - el8 3 | release_branches: 4 | master: ovirt-master 5 | -------------------------------------------------------------------------------- /automation/README.adoc: -------------------------------------------------------------------------------- 1 | = Continuous integration scripts 2 | 3 | This directory contains scripts for continuous integration provided by 4 | http://jenkins.ovirt.org[oVirt Jenkins] system and follows the standard 5 | defined in http://www.ovirt.org/CI/Build_and_test_standards[Build and 6 | test standards] wiki page. 7 | -------------------------------------------------------------------------------- /automation/build-artifacts.packages: -------------------------------------------------------------------------------- 1 | build.packages -------------------------------------------------------------------------------- /automation/build-artifacts.sh: -------------------------------------------------------------------------------- 1 | build.py -------------------------------------------------------------------------------- /automation/build.packages: -------------------------------------------------------------------------------- 1 | ant 2 | git 3 | httpcomponents-client 4 | jackson-annotations 5 | jackson-core 6 | jackson-databind 7 | java-11-openjdk-devel 8 | javapackages-local 9 | libxslt 10 | maven 11 | maven-local 12 | python3 13 | python3-lxml 14 | rpm-build 15 | rpmdevtools 16 | slf4j 17 | -------------------------------------------------------------------------------- /automation/check-merged.packages: -------------------------------------------------------------------------------- 1 | build.packages -------------------------------------------------------------------------------- /automation/check-merged.sh: -------------------------------------------------------------------------------- 1 | build.py -------------------------------------------------------------------------------- /automation/check-patch.packages: -------------------------------------------------------------------------------- 1 | build.packages -------------------------------------------------------------------------------- /automation/check-patch.sh: -------------------------------------------------------------------------------- 1 | build.py -------------------------------------------------------------------------------- /generator/README.adoc: -------------------------------------------------------------------------------- 1 | = oVirt Engine Java SDK Generator 2 | 3 | == Introduction 4 | 5 | This project contains the code generator for the oVirt Java SDK. 6 | -------------------------------------------------------------------------------- /generator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.ovirt.engine.api 25 | java-sdk-parent 26 | 4.6.0-SNAPSHOT 27 | 28 | 29 | java-sdk-generator 30 | jar 31 | 32 | oVirt Java SDK Generator 33 | 34 | 35 | 36 | 37 | org.ovirt.engine.api 38 | metamodel-concepts 39 | 40 | 41 | 42 | org.ovirt.engine.api 43 | metamodel-analyzer 44 | 45 | 46 | 47 | org.ovirt.engine.api 48 | metamodel-tool 49 | 50 | 51 | 52 | commons-cli 53 | commons-cli 54 | 55 | 56 | 57 | commons-io 58 | commons-io 59 | 60 | 61 | 62 | org.apache.httpcomponents 63 | httpclient 64 | 65 | 66 | 67 | org.apache.httpcomponents 68 | httpcore 69 | 70 | 71 | 72 | 73 | org.jboss.weld.se 74 | weld-se 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | org.apache.maven.plugins 84 | maven-compiler-plugin 85 | 2.3.2 86 | 87 | 1.8 88 | 1.8 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /generator/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oVirt/ovirt-engine-sdk-java/0bdd5c9fd7ccc9b83a59b9d353b12c92b79079e8/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 | -------------------------------------------------------------------------------- /packaging/README.adoc: -------------------------------------------------------------------------------- 1 | = oVirt Java SDK Packaging 2 | 3 | == Introduction 4 | 5 | This directory contains the files required to package the SDK for 6 | packaging systems other than the Java standard packaging system. 7 | 8 | == RPM 9 | 10 | To build the RPM put the `.tar.gz` file containing the source of the 11 | SDK in this directory and run the `build.sh` script. 12 | -------------------------------------------------------------------------------- /packaging/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /packaging/spec.el8.in: -------------------------------------------------------------------------------- 1 | spec.in -------------------------------------------------------------------------------- /packaging/spec.fc34.in: -------------------------------------------------------------------------------- 1 | spec.in -------------------------------------------------------------------------------- /packaging/spec.fc35.in: -------------------------------------------------------------------------------- 1 | spec.in -------------------------------------------------------------------------------- /packaging/spec.in: -------------------------------------------------------------------------------- 1 | %global tar_version 4.4.0 2 | 3 | Name: java-ovirt-engine-sdk4 4 | Version: 4.4.0 5 | Release: 1%{?dist} 6 | Summary: Java SDK for version 4 of the oVirt Engine API 7 | Group: Development/Languages 8 | License: ASL 2.0 9 | URL: http://ovirt.org/wiki/SDK 10 | 11 | # This should be a tar file containing the generated source code of the 12 | # SDK, as we can't build and run the generator with the packages 13 | # available in the distribution: 14 | Source0: ovirt-engine-sdk-java-%{tar_version}.tar.gz 15 | 16 | # This file is used to perform the build using Ant, because the upstream 17 | # project has build dependencies that make it impossible to build it 18 | # with the packages available in the distribution: 19 | Source1: build.xml 20 | 21 | # This file is used to transform the upstream 'pom.xml' file into a 22 | # 'pom-nodeps.xml' file that doesn't have the dependencies of the 23 | # code generator, as those aren't available in the distribution: 24 | Source2: transform-pom.xsl 25 | 26 | BuildArch: noarch 27 | 28 | BuildRequires: ant 29 | BuildRequires: javapackages-local 30 | BuildRequires: mvn(org.apache.httpcomponents:httpclient) 31 | BuildRequires: mvn(org.apache.httpcomponents:httpcore) 32 | BuildRequires: mvn(com.fasterxml.jackson.core:jackson-databind) 33 | BuildRequires: mvn(com.fasterxml.jackson.core:jackson-core) 34 | BuildRequires: mvn(com.fasterxml.jackson.core:jackson-annotations) 35 | BuildRequires: mvn(org.slf4j:slf4j-api) 36 | 37 | %description 38 | This package contains the Java SDK for version 4 of the oVirt Engine 39 | API. 40 | 41 | %prep 42 | 43 | # Extract the source: 44 | %setup -q -n ovirt-engine-sdk-java-%{tar_version} 45 | 46 | %build 47 | 48 | # Copy the files required for the Ant build to the extracted SDK 49 | # directory: 50 | cp %{SOURCE1} %{SOURCE2} . 51 | 52 | # Populate the lib directory with symlinks to the required dependencies that 53 | # will be used to create the compiler classpath: 54 | mkdir lib 55 | while read jar 56 | do 57 | ln -s %{_javadir}/${jar}.jar lib 58 | done << __EOF__ 59 | httpcomponents/httpclient 60 | httpcomponents/httpcore 61 | jackson/jackson-databind 62 | jackson/jackson-core 63 | jackson/jackson-annotations 64 | 65 | slf4j/api 66 | __EOF__ 67 | 68 | # Perform build using Ant: 69 | java -jar %{_javadir}/ant-launcher.jar -f build.xml 70 | 71 | %install 72 | 73 | # Install the POM without dependencies created during the build process 74 | # and the .jar file: 75 | %mvn_artifact pom-nodeps.xml target/%{name}.jar 76 | %mvn_install 77 | 78 | %files -f .mfiles 79 | %dir %{_javadir}/%{name} 80 | %doc README.adoc 81 | %license LICENSE.txt 82 | 83 | %changelog 84 | * Wed May 22 2019 Sandro Bonazzola - 4.3.0 85 | - Rebase on 4.3.0 for fc29 support 86 | 87 | * Thu Apr 7 2016 Juan Hernandez - 4.0.0 88 | - Initial packaging. 89 | -------------------------------------------------------------------------------- /packaging/transform-pom.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /sdk/src/main/java/org/ovirt/engine/sdk4/BaseRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4; 18 | 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | public abstract class BaseRequest 23 | implements Request { 24 | 25 | protected Map headers; 26 | protected Map query; 27 | 28 | @Override 29 | public REQUEST header(String name, String value) { 30 | if (headers == null) { 31 | headers = new HashMap<>(); 32 | } 33 | 34 | headers.put(name, value); 35 | return (REQUEST) this; 36 | } 37 | 38 | @Override 39 | public REQUEST query(String name, String value) { 40 | if (query == null) { 41 | query = new HashMap<>(); 42 | } 43 | 44 | query.put(name, value); 45 | return (REQUEST) this; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /sdk/src/main/java/org/ovirt/engine/sdk4/Connection.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4; 18 | 19 | import org.ovirt.engine.sdk4.services.SystemService; 20 | 21 | /** 22 | * This interface represents a connection to the API server. 23 | */ 24 | public interface Connection extends AutoCloseable { 25 | /** 26 | * Returns a reference to the root of the services tree. 27 | */ 28 | SystemService systemService(); 29 | 30 | /** 31 | * Indicates if the given object is a link. An object is a link if it has an `href` attribute. 32 | * 33 | * @param object the object to check 34 | * @return {@code true} iff the object is a link 35 | */ 36 | boolean isLink(Object object); 37 | 38 | /** 39 | * Follows the `href` attribute of the given object, retrieves the target object and returns it. 40 | * 41 | * @param object the object containing the `href` attribute 42 | * @param the type of the target of the link 43 | * @return the object retrieved from the `href` 44 | */ 45 | TYPE followLink(TYPE object); 46 | 47 | /** 48 | * Return token which can be used for authentication instead of credentials. 49 | * It will be created, if it not exists, yet. By default the token will be 50 | * revoked when the connection is closed, unless the `logout` parameter of 51 | * the `close` method is `false`. 52 | */ 53 | String authenticate(); 54 | 55 | /** 56 | * Releases the resources used by this connection. 57 | * 58 | * @param logout A boolean, which specify if token should be revoked, 59 | * and so user should be logged out. 60 | */ 61 | void close(boolean logout) throws Exception; 62 | 63 | /** 64 | * Validate the connection by making a trivial request and checking that 65 | * the result is not null 66 | * 67 | * @return true if the connection is valid, false otherwise 68 | */ 69 | boolean validate(); 70 | } 71 | -------------------------------------------------------------------------------- /sdk/src/main/java/org/ovirt/engine/sdk4/Error.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4; 18 | 19 | /** 20 | * General exception which is thrown by SDK, indicates that some exception happened in SDK. 21 | */ 22 | public class Error extends RuntimeException { 23 | 24 | public Error(Throwable cause) { 25 | super(cause); 26 | } 27 | 28 | public Error(String message) { 29 | super(message); 30 | } 31 | 32 | public Error(String message, Throwable cause) { 33 | super(message, cause); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /sdk/src/main/java/org/ovirt/engine/sdk4/HttpClient.java: -------------------------------------------------------------------------------- 1 | package org.ovirt.engine.sdk4; 2 | 3 | import org.apache.http.HttpResponse; 4 | import org.apache.http.client.methods.HttpUriRequest; 5 | 6 | /** 7 | * This interface defines methods which should implement HttpClient class of specific http client version. 8 | */ 9 | public interface HttpClient { 10 | 11 | /** 12 | * This method will send http request 13 | * 14 | * @param request request which should be send to host 15 | * @return response returned by host 16 | */ 17 | HttpResponse execute(HttpUriRequest request) throws Exception; 18 | 19 | /** 20 | * Close http connection 21 | * 22 | * @throws Exception 23 | */ 24 | void close() throws Exception; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /sdk/src/main/java/org/ovirt/engine/sdk4/Request.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4; 18 | 19 | /** 20 | * This class represents a request that can be sent to the API server. This interface isn't intended to be used 21 | * directly, applications should instead use the extensions for specific operations. 22 | * 23 | * @param the specific request type 24 | * @param the specific response type 25 | */ 26 | public interface Request { 27 | /** 28 | * Sends the request to the server, and waits for the response. 29 | * 30 | * @return the response received from the server 31 | */ 32 | RESPONSE send(); 33 | 34 | /** 35 | * Add additional HTTP header. 36 | * 37 | * @return the request 38 | */ 39 | REQUEST header(String name, String value); 40 | 41 | /** 42 | * Add additional URL query parameter. 43 | * 44 | * @return the request 45 | */ 46 | REQUEST query(String name, String value); 47 | } 48 | -------------------------------------------------------------------------------- /sdk/src/main/java/org/ovirt/engine/sdk4/Response.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4; 18 | 19 | /** 20 | * This class represents a response received from the API server. This interface isn't intended to be used 21 | * directly, applications should instead use the extensions for specific operations. 22 | */ 23 | public interface Response { 24 | } 25 | -------------------------------------------------------------------------------- /sdk/src/main/java/org/ovirt/engine/sdk4/Service.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4; 18 | 19 | /** 20 | * This interface represents a service available in the API. 21 | */ 22 | public interface Service { 23 | } 24 | -------------------------------------------------------------------------------- /sdk/src/main/java/org/ovirt/engine/sdk4/internal/HttpClient42.java: -------------------------------------------------------------------------------- 1 | package org.ovirt.engine.sdk4.internal; 2 | 3 | import org.apache.http.HttpResponse; 4 | import org.apache.http.client.HttpClient; 5 | import org.apache.http.client.methods.HttpUriRequest; 6 | import org.apache.http.impl.client.DecompressingHttpClient; 7 | import org.apache.http.impl.client.DefaultHttpClient; 8 | 9 | /** 10 | * * This class implements methods to work with httpclient version 4.2 11 | */ 12 | public class HttpClient42 implements org.ovirt.engine.sdk4.HttpClient { 13 | 14 | private HttpClient client; 15 | 16 | public HttpClient42(DefaultHttpClient client) { 17 | this.client = client; 18 | } 19 | 20 | public HttpClient42(DecompressingHttpClient client) { 21 | this.client = client; 22 | } 23 | 24 | @Override 25 | public HttpResponse execute(HttpUriRequest request) throws Exception { 26 | return client.execute(request); 27 | } 28 | 29 | @Override 30 | public void close() throws Exception { 31 | client.getConnectionManager().shutdown(); 32 | } 33 | } -------------------------------------------------------------------------------- /sdk/src/main/java/org/ovirt/engine/sdk4/internal/HttpClient45.java: -------------------------------------------------------------------------------- 1 | package org.ovirt.engine.sdk4.internal; 2 | 3 | import org.apache.http.HttpResponse; 4 | import org.apache.http.client.methods.HttpUriRequest; 5 | import org.apache.http.impl.client.CloseableHttpClient; 6 | import org.ovirt.engine.sdk4.HttpClient; 7 | 8 | /** 9 | * This class implements methods to work with httpclient version 4.5 10 | */ 11 | public class HttpClient45 implements HttpClient { 12 | 13 | private CloseableHttpClient client; 14 | 15 | public HttpClient45(CloseableHttpClient client) { 16 | this.client = client; 17 | } 18 | 19 | @Override 20 | public HttpResponse execute(HttpUriRequest request) throws Exception { 21 | return client.execute(request); 22 | } 23 | 24 | @Override 25 | public void close() throws Exception { 26 | client.close(); 27 | } 28 | } -------------------------------------------------------------------------------- /sdk/src/main/java/org/ovirt/engine/sdk4/internal/NoCaTrustManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.internal; 18 | 19 | import javax.net.ssl.X509TrustManager; 20 | 21 | /** 22 | * This TrustManager used to ignore CA cert validation 23 | * and should not be used unless user explicitly asks to ignore 24 | * host identity validation. 25 | */ 26 | public class NoCaTrustManager implements X509TrustManager { 27 | 28 | @Override 29 | public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) 30 | throws java.security.cert.CertificateException { 31 | // do nothing 32 | } 33 | 34 | @Override 35 | public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) 36 | throws java.security.cert.CertificateException { 37 | // do nothing 38 | 39 | } 40 | 41 | @Override 42 | public java.security.cert.X509Certificate[] getAcceptedIssuers() { 43 | return null; 44 | } 45 | } -------------------------------------------------------------------------------- /sdk/src/main/java/org/ovirt/engine/sdk4/internal/SsoUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.internal; 18 | 19 | import java.net.URI; 20 | import java.net.URISyntaxException; 21 | 22 | import org.apache.http.client.utils.URIBuilder; 23 | import org.ovirt.engine.sdk4.Error; 24 | 25 | /** 26 | * Helper class, which provides methods to work with SSO. 27 | */ 28 | public class SsoUtils { 29 | 30 | private static final String ENTRY_POINT_HTTP = "token-http-auth"; 31 | private static final String ENTRY_POINT_TOKEN = "token"; 32 | 33 | /** 34 | * Construct SSO URL to obtain token from username and password. 35 | * 36 | * @param url oVirt engine URL 37 | * @return URI to be used to obtain token 38 | */ 39 | public static URI buildSsoUrlBasic(String url) { 40 | try { 41 | URI uri = new URI(url); 42 | URIBuilder uriBuilder = new URIBuilder( 43 | String.format( 44 | "%1$s://%2$s/ovirt-engine/sso/oauth/%3$s", 45 | uri.getScheme(), 46 | uri.getAuthority(), 47 | ENTRY_POINT_TOKEN 48 | ) 49 | ); 50 | return uriBuilder.build(); 51 | } 52 | catch (URISyntaxException ex) { 53 | throw new Error("Failed to build SSO authentication URL", ex); 54 | } 55 | } 56 | 57 | /** 58 | * Construct SSO URL to obtain token from kerberos authentication. 59 | * 60 | * @param url oVirt engine URL 61 | * @return URI to be used to obtain token 62 | */ 63 | public static URI buildSsoUrlKerberos(String url) { 64 | try { 65 | URI uri = new URI(url); 66 | URIBuilder uriBuilder = new URIBuilder( 67 | String.format( 68 | "%1$s://%2$s/ovirt-engine/sso/oauth/%3$s", 69 | uri.getScheme(), 70 | uri.getAuthority(), 71 | ENTRY_POINT_HTTP 72 | ) 73 | ); 74 | return uriBuilder.build(); 75 | } 76 | catch (URISyntaxException ex) { 77 | throw new Error("Failed to build SSO authentication URL", ex); 78 | } 79 | } 80 | 81 | /** 82 | * Construct SSO URL to revoke SSO token 83 | * 84 | * @param url oVirt engine URL 85 | * @return URI to be used to revoke token 86 | */ 87 | public static URI buildSsoRevokeUrl(String url) { 88 | try { 89 | URI uri = new URI(url); 90 | URIBuilder uriBuilder = new URIBuilder( 91 | String.format( 92 | "%1$s://%2$s/ovirt-engine/services/sso-logout", 93 | uri.getScheme(), 94 | uri.getAuthority() 95 | ) 96 | ); 97 | return uriBuilder.build(); 98 | } 99 | catch (URISyntaxException ex) { 100 | throw new Error("Failed to build SSO revoke URL", ex); 101 | } 102 | } 103 | 104 | /** 105 | * Construct simple URL 106 | * 107 | * @param url url to build 108 | * @return URI 109 | */ 110 | public static URI buildUrl(String url) { 111 | try { 112 | return new URI(url); 113 | } 114 | catch (URISyntaxException ex) { 115 | throw new Error("Failed to build URL", ex); 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/ClusterReaderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertTrue; 21 | 22 | import java.io.ByteArrayInputStream; 23 | import java.io.InputStream; 24 | import java.nio.charset.StandardCharsets; 25 | import java.util.Arrays; 26 | 27 | import org.junit.Test; 28 | import org.ovirt.api.metamodel.runtime.xml.XmlReader; 29 | import org.ovirt.engine.sdk4.internal.xml.XmlClusterReader; 30 | import org.ovirt.engine.sdk4.types.Cluster; 31 | import org.ovirt.engine.sdk4.types.SwitchType; 32 | 33 | public class ClusterReaderTest { 34 | 35 | /** 36 | * Test given switch type after empty RNG source both are read correctly. 37 | */ 38 | @Test 39 | public void testReadValueAfterEmptyList() throws Exception { 40 | String response = 41 | "" + 42 | "" + 43 | "legacy" + 44 | ""; 45 | try ( 46 | InputStream stream = new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8)); 47 | XmlReader reader = new XmlReader(stream) 48 | ) { 49 | Cluster cluster = XmlClusterReader.readOne(reader); 50 | assertEquals(Arrays.asList(), cluster.requiredRngSources()); 51 | assertEquals(SwitchType.LEGACY, cluster.switchType()); 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/ClusterServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertNotNull; 21 | import static org.junit.Assert.assertNull; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | import org.junit.After; 27 | import org.junit.Before; 28 | import org.junit.Test; 29 | import org.ovirt.engine.sdk4.services.ClusterService; 30 | import org.ovirt.engine.sdk4.services.ClustersService; 31 | import org.ovirt.engine.sdk4.types.Cluster; 32 | 33 | public class ClusterServiceTest extends ServerTest { 34 | 35 | private Connection connection; 36 | private ClustersService clustersService; 37 | 38 | @Before 39 | public void setUp() { 40 | setXmlResponse("clusters", 200, ""); 41 | setXmlResponse("clusters/123", 200, "testcluster"); 42 | startServer(); 43 | connection = testConnection(); 44 | clustersService = connection.systemService().clustersService(); 45 | } 46 | 47 | @After 48 | public void tearDown() throws Exception { 49 | connection.close(); 50 | stopServer(); 51 | } 52 | 53 | /** 54 | * Test we don't get null clusters service 55 | */ 56 | @Test 57 | public void testGetService() { 58 | assertNotNull(clustersService); 59 | } 60 | 61 | /** 62 | * Test returning empty clusters list 63 | */ 64 | @Test 65 | public void testEmptyListResponse() { 66 | List clusters = clustersService.list().send().clusters(); 67 | assertNotNull(clusters); 68 | assertEquals(new ArrayList(), clusters); 69 | } 70 | 71 | /** 72 | * Test list clusters with query 73 | */ 74 | @Test 75 | public void testEmptyListResponseWithQuery() { 76 | List clusters = clustersService.list().search("name=ugly").send().clusters(); 77 | assertNotNull(clusters); 78 | assertEquals(new ArrayList(), clusters); 79 | } 80 | 81 | /** 82 | * Test we don't get null cluster service for existing cluster id and correct object 83 | */ 84 | @Test 85 | public void testGetObjectFromClusterService() { 86 | ClusterService clusterService = clustersService.clusterService("123"); 87 | Cluster cluster = clusterService.get().send().cluster(); 88 | assertEquals("123", cluster.id()); 89 | assertEquals("testcluster", cluster.name()); 90 | assertNull(cluster.description()); 91 | } 92 | } -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/ConnectionCreateTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | 21 | import org.junit.Test; 22 | 23 | public class ConnectionCreateTest extends ServerTest { 24 | 25 | /** 26 | * Test exception is not thrown when no CA is provided to connection 27 | */ 28 | public void testSecureModeWithoutCA() { 29 | connection() 30 | .url(testUrl()) 31 | .user(testUser()) 32 | .password(testPassword()) 33 | .build(); 34 | } 35 | 36 | /** 37 | * Test exception isn't thrown when CA is provided to connection 38 | */ 39 | @Test 40 | public void testSecureModeWithCA() throws Exception { 41 | Connection connection = testConnection(); 42 | connection.close(); 43 | } 44 | 45 | /** 46 | * Test that CA isn't required in insecure mode 47 | */ 48 | @Test 49 | public void testInsecureModeWithoutCA() throws Exception { 50 | Connection connection = connection() 51 | .url(testUrl()) 52 | .user(testUser()) 53 | .password(testPassword()) 54 | .insecure(true) 55 | .build(); 56 | connection.close(); 57 | } 58 | 59 | /** 60 | * Test creation of kerberos connection 61 | */ 62 | @Test 63 | public void testKerberosAuth() throws Exception { 64 | Connection connection = connection() 65 | .url(testUrl()) 66 | .kerberos(true) 67 | .trustStoreFile(testTrustStoreFile()) 68 | .trustStorePassword(testTrustStorePassword()) 69 | .build(); 70 | connection.close(); 71 | } 72 | } -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/ConnectionUseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertNotNull; 21 | import static org.junit.Assert.assertTrue; 22 | 23 | import org.junit.After; 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | import org.ovirt.engine.sdk4.internal.HttpConnection; 27 | import org.ovirt.engine.sdk4.services.ClustersService; 28 | import org.ovirt.engine.sdk4.services.DiskAttachmentsService; 29 | import org.ovirt.engine.sdk4.services.VmService; 30 | import org.ovirt.engine.sdk4.services.VmsService; 31 | 32 | public class ConnectionUseTest extends ServerTest { 33 | 34 | private HttpConnection connection; 35 | private ClustersService clustersService; 36 | 37 | @Before 38 | public void setUp() { 39 | setXmlResponse("", 200, ""); 40 | startServer(); 41 | connection = (HttpConnection) testConnection(); 42 | clustersService = connection.systemService().clustersService(); 43 | } 44 | 45 | @After 46 | public void tearDown() throws Exception { 47 | connection.close(); 48 | stopServer(); 49 | } 50 | 51 | /** 52 | * Test when connection is created URL can be obtained 53 | */ 54 | @Test 55 | public void testBuildUrlBase() { 56 | assertEquals(testUrl(), connection.getUrl()); 57 | } 58 | 59 | /** 60 | * Test get root 61 | */ 62 | @Test 63 | public void testGetRoot() throws Exception { 64 | assertNotNull(connection.systemService().get().send()); 65 | } 66 | 67 | /** 68 | * Test given 'vms' returns a reference to the virtual machines service 69 | */ 70 | @Test 71 | public void testReturnVmsService() { 72 | assertTrue(connection.systemService().service("vms") instanceof VmsService); 73 | } 74 | 75 | /** 76 | * Test given 'vms/123' returns a reference to the virtual machine service 77 | */ 78 | @Test 79 | public void testReturnVmService() { 80 | assertTrue(connection.systemService().service("vms/123") instanceof VmService); 81 | } 82 | 83 | /** 84 | * Test given 'vms/123/diskattachments' returns a reference to the virtual machine disk attachments service 85 | */ 86 | @Test 87 | public void testReturnVmDisksService() { 88 | assertTrue(connection.systemService().service("vms/123/diskattachments") instanceof DiskAttachmentsService); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/DataCentersServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertNotNull; 21 | import static org.junit.Assert.assertNull; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | import org.junit.After; 27 | import org.junit.Before; 28 | import org.junit.Test; 29 | import org.ovirt.engine.sdk4.services.DataCenterService; 30 | import org.ovirt.engine.sdk4.services.DataCentersService; 31 | import org.ovirt.engine.sdk4.types.DataCenter; 32 | 33 | public class DataCentersServiceTest extends ServerTest { 34 | 35 | private Connection connection; 36 | private DataCentersService dataCentersService; 37 | 38 | @Before 39 | public void setUp() { 40 | setXmlResponse("datacenters", 200, ""); 41 | setXmlResponse("datacenters/123", 200, "testdc"); 42 | startServer(); 43 | connection = testConnection(); 44 | dataCentersService = connection.systemService().dataCentersService(); 45 | } 46 | 47 | @After 48 | public void tearDown() throws Exception { 49 | connection.close(); 50 | stopServer(); 51 | } 52 | 53 | /** 54 | * Test we don't get null data centers service 55 | */ 56 | @Test 57 | public void testGetDataCentersService() { 58 | assertNotNull(dataCentersService); 59 | } 60 | 61 | /** 62 | * Test returning empty data centers list 63 | */ 64 | @Test 65 | public void testEmptyListResponse() { 66 | List dataCenters = dataCentersService.list().send().dataCenters(); 67 | assertNotNull(dataCenters); 68 | assertEquals(new ArrayList(), dataCenters); 69 | } 70 | 71 | /** 72 | * Test list data centers with query 73 | */ 74 | @Test 75 | public void testEmptyListResponseWithQuery() { 76 | List dataCenters = dataCentersService.list().search("name=ugly").send().dataCenters(); 77 | assertNotNull(dataCenters); 78 | assertEquals(new ArrayList(), dataCenters); 79 | } 80 | 81 | /** 82 | * Test we don't get null data center service for existing data center id and correct object 83 | */ 84 | @Test 85 | public void testGetObjectFromDataCenterService() { 86 | DataCenterService dcService = dataCentersService.dataCenterService("123"); 87 | DataCenter dc = dcService.get().send().dataCenter(); 88 | assertEquals("123", dc.id()); 89 | assertEquals("testdc", dc.name()); 90 | assertNull(dc.description()); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/DiscoverIscsiTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.ovirt.engine.sdk4.builders.Builders.iscsiDetails; 21 | 22 | import java.math.BigInteger; 23 | 24 | import org.junit.After; 25 | import org.junit.Before; 26 | import org.junit.Test; 27 | import org.ovirt.engine.sdk4.services.HostService; 28 | import org.ovirt.engine.sdk4.services.HostsService; 29 | 30 | public class DiscoverIscsiTest extends ServerTest { 31 | 32 | private Connection connection; 33 | 34 | @Before 35 | public void setUp() { 36 | setXmlResponse( 37 | "hosts/123/discoveriscsi", 38 | 200, 39 | "" + 40 | "" + 41 | "
iscsi.example.com
" + 42 | "3260" + 43 | "
" + 44 | "" + 45 | "" + 46 | "
192.168.121.102
" + 47 | "3260" + 48 | "myiqn" + 49 | "
" + 50 | "
" + 51 | "
" 52 | ); 53 | startServer(); 54 | connection = testConnection(); 55 | } 56 | 57 | @After 58 | public void tearDown() throws Exception { 59 | connection.close(); 60 | stopServer(); 61 | } 62 | 63 | /** 64 | * Test we don't get null vm service for existing vm id and correct object 65 | */ 66 | @Test 67 | public void testActionParameters() { 68 | HostsService hostsService = connection.systemService().hostsService(); 69 | HostService hostService = hostsService.hostService("123"); 70 | HostService.DiscoverIscsiResponse response = hostService.discoverIscsi() 71 | .iscsi( 72 | iscsiDetails() 73 | .address("iscsi.example.com") 74 | .port(3260) 75 | ) 76 | .send(); 77 | assertEquals( 78 | "" + 79 | "" + 80 | "
iscsi.example.com
" + 81 | "3260" + 82 | "
" + 83 | "
", 84 | getLastRequestContent() 85 | ); 86 | 87 | assertEquals("192.168.121.102", response.discoveredTargets().get(0).address()); 88 | assertEquals(BigInteger.valueOf(3260), response.discoveredTargets().get(0).port()); 89 | assertEquals("myiqn", response.discoveredTargets().get(0).target()); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/FollowLinkTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import org.junit.After; 22 | import org.junit.Before; 23 | import org.junit.Test; 24 | import org.ovirt.engine.sdk4.services.ClusterService; 25 | import org.ovirt.engine.sdk4.services.ClustersService; 26 | import org.ovirt.engine.sdk4.types.Cluster; 27 | import org.ovirt.engine.sdk4.types.DataCenter; 28 | 29 | public class FollowLinkTest extends ServerTest { 30 | 31 | private Connection connection; 32 | private ClustersService clustersService; 33 | 34 | @Before 35 | public void setUp() { 36 | setXmlResponse("clusters/123", 200, ""); 37 | setXmlResponse("datacenters/123", 200, "testdc"); 38 | startServer(); 39 | connection = testConnection(); 40 | clustersService = connection.systemService().clustersService(); 41 | } 42 | 43 | @After 44 | public void tearDown() throws Exception { 45 | connection.close(); 46 | stopServer(); 47 | } 48 | 49 | /** 50 | * Test follow link to data center from cluster 51 | */ 52 | @Test 53 | public void testFollowLinkToDatacenter() { 54 | ClusterService clusterService = clustersService.clusterService("123"); 55 | Cluster cluster = clusterService.get().send().cluster(); 56 | DataCenter dc = connection.followLink(cluster.dataCenter()); 57 | assertEquals("testdc", dc.name()); 58 | } 59 | } -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/ResponseCodeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4; 18 | 19 | import static org.ovirt.engine.sdk4.builders.Builders.vm; 20 | 21 | import org.junit.Test; 22 | import org.ovirt.engine.sdk4.services.VmsService; 23 | 24 | public class ResponseCodeTest extends ServerTest { 25 | 26 | /** 27 | * Test when server return response with 200 code, 28 | * the SDK don't raise exception. 29 | */ 30 | @Test 31 | public void test200codeDontThrowException() throws Exception { 32 | setXmlResponse("vms", 200, ""); 33 | startServer(); 34 | Connection connection = testConnection(); 35 | VmsService vmsService = connection.systemService().vmsService(); 36 | vmsService.add().vm(vm()).send(); 37 | connection.close(); 38 | stopServer(); 39 | } 40 | 41 | /** 42 | * Test when server return response with 201 code, 43 | * the SDK don't raise exception. 44 | */ 45 | @Test 46 | public void test201codeDontThrowException() throws Exception { 47 | setXmlResponse("vms", 201, ""); 48 | startServer(); 49 | Connection connection = testConnection(); 50 | VmsService vmsService = connection.systemService().vmsService(); 51 | vmsService.add().vm(vm()).send(); 52 | connection.close(); 53 | stopServer(); 54 | } 55 | 56 | /** 57 | * Test when server return response with 202 code, 58 | * the SDK don't raise exception. 59 | */ 60 | @Test 61 | public void test202codeDontThrowException() throws Exception { 62 | setXmlResponse("vms", 202, ""); 63 | startServer(); 64 | Connection connection = testConnection(); 65 | VmsService vmsService = connection.systemService().vmsService(); 66 | vmsService.add().vm(vm()).send(); 67 | connection.close(); 68 | stopServer(); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/SecondaryParametersTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertNotNull; 21 | import static org.ovirt.engine.sdk4.builders.Builders.vm; 22 | 23 | import org.junit.After; 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | import org.ovirt.engine.sdk4.services.VmsService; 27 | 28 | public class SecondaryParametersTest extends ServerTest { 29 | 30 | private Connection connection; 31 | private VmsService vmsService; 32 | 33 | @Before 34 | public void setUp() { 35 | setXmlResponse("vms", 201, ""); 36 | startServer(); 37 | connection = testConnection(); 38 | vmsService = connection.systemService().vmsService(); 39 | } 40 | 41 | @After 42 | public void tearDown() throws Exception { 43 | connection.close(); 44 | stopServer(); 45 | } 46 | 47 | /** 48 | * Test we don't get null vms service 49 | */ 50 | @Test 51 | public void testGetService() { 52 | assertNotNull(vmsService); 53 | } 54 | 55 | /** 56 | * Test when adding clone vm the query with this parameter is sent. 57 | */ 58 | @Test 59 | public void testSecondaryParamenters() { 60 | vmsService.add().vm(vm()).clone_(true).send(); 61 | assertEquals("clone=true", getLastRequestQuery()); 62 | } 63 | 64 | /** 65 | * Test when adding vm clone and clone_permissions the query with 66 | * those parameters is sent. 67 | */ 68 | @Test 69 | public void testMultipleSecondaryParameters() { 70 | vmsService.add().vm(vm()).clone_(true).clonePermissions(true).send(); 71 | assertEquals("clone=true&clone_permissions=true", getLastRequestQuery()); 72 | } 73 | } -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/SetupNetworksTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.ovirt.engine.sdk4.builders.Builders.bonding; 21 | import static org.ovirt.engine.sdk4.builders.Builders.hostNic; 22 | import static org.ovirt.engine.sdk4.builders.Builders.option; 23 | 24 | import org.junit.After; 25 | import org.junit.Before; 26 | import org.junit.Test; 27 | import org.ovirt.engine.sdk4.services.HostService; 28 | 29 | 30 | public class SetupNetworksTest extends ServerTest { 31 | 32 | private Connection connection; 33 | private HostService hostService; 34 | 35 | @Before 36 | public void setUp() { 37 | setXmlResponse("hosts/123/setupnetworks", 200, ""); 38 | startServer(); 39 | connection = testConnection(); 40 | hostService = connection.systemService().hostsService().hostService("123"); 41 | } 42 | 43 | @After 44 | public void tearDown() throws Exception { 45 | connection.close(); 46 | stopServer(); 47 | } 48 | /** 49 | * Test if action parameters are constructed in correct way. 50 | */ 51 | @Test 52 | public void testActionParameters() { 53 | hostService.setupNetworks() 54 | .modifiedBonds( 55 | hostNic() 56 | .name("bond0") 57 | .bonding( 58 | bonding() 59 | .options( 60 | option() 61 | .name("mode") 62 | .type("4") 63 | ) 64 | .slaves( 65 | hostNic() 66 | .name("eth1"), 67 | hostNic() 68 | .name("eth2") 69 | ) 70 | ) 71 | ).send(); 72 | assertEquals( 73 | "" + 74 | "" + 75 | "" + 76 | "" + 77 | "" + 78 | "" + 82 | "" + 83 | "" + 84 | "" + 85 | "eth1" + 86 | "" + 87 | "" + 88 | "eth2" + 89 | "" + 90 | "" + 91 | "" + 92 | "bond0" + 93 | "" + 94 | "" + 95 | "", 96 | getLastRequestContent() 97 | ); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/SimpleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4; 18 | 19 | import org.junit.After; 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | 23 | public class SimpleTest extends ServerTest { 24 | @Before 25 | public void setUp() { 26 | startServer(); 27 | } 28 | 29 | @After 30 | public void tearDown() { 31 | stopServer(); 32 | } 33 | 34 | /** 35 | * Checks that creating and closing a connection works correctly. 36 | */ 37 | @Test 38 | public void testCreateConnection() throws Exception { 39 | Connection connection = testConnection(); 40 | connection.close(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/StorageDomainsServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertNotNull; 21 | import static org.junit.Assert.assertNull; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | import org.junit.After; 27 | import org.junit.Before; 28 | import org.junit.Test; 29 | import org.ovirt.engine.sdk4.services.StorageDomainService; 30 | import org.ovirt.engine.sdk4.services.StorageDomainsService; 31 | import org.ovirt.engine.sdk4.types.StorageDomain; 32 | 33 | public class StorageDomainsServiceTest extends ServerTest { 34 | 35 | private Connection connection; 36 | private StorageDomainsService storageDomainsService; 37 | 38 | @Before 39 | public void setUp() { 40 | setXmlResponse("storagedomains", 200, ""); 41 | setXmlResponse("storagedomains/123", 200, "testsd"); 42 | startServer(); 43 | connection = testConnection(); 44 | storageDomainsService = connection.systemService().storageDomainsService(); 45 | } 46 | 47 | @After 48 | public void tearDown() throws Exception { 49 | connection.close(); 50 | stopServer(); 51 | } 52 | 53 | /** 54 | * Test we don't get null storage domains service 55 | */ 56 | @Test 57 | public void testGetService() { 58 | assertNotNull(storageDomainsService); 59 | } 60 | 61 | /** 62 | * Test returning empty storage domains list 63 | */ 64 | @Test 65 | public void testEmptyListResponse() { 66 | List storageDomains = storageDomainsService.list().send().storageDomains(); 67 | assertNotNull(storageDomains); 68 | assertEquals(new ArrayList(), storageDomains); 69 | } 70 | 71 | /** 72 | * Test list storage domains with query 73 | */ 74 | @Test 75 | public void testEmptyListResponseWithQuery() { 76 | List storageDomains = storageDomainsService.list().search("name=ugly").send().storageDomains(); 77 | assertNotNull(storageDomains); 78 | assertEquals(new ArrayList(), storageDomains); 79 | } 80 | 81 | /** 82 | * Test we don't get null storage service for existing storage id and correct object 83 | */ 84 | @Test 85 | public void testGetObjectFromStorageDomainService() { 86 | StorageDomainService sdService = storageDomainsService.storageDomainService("123"); 87 | StorageDomain sd = sdService.get().send().storageDomain(); 88 | assertEquals("123", sd.id()); 89 | assertEquals("testsd", sd.name()); 90 | assertNull(sd.description()); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/VmTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertNotNull; 21 | 22 | import java.util.Arrays; 23 | 24 | import org.junit.Test; 25 | import org.ovirt.engine.sdk4.internal.containers.DiskAttachmentContainer; 26 | import org.ovirt.engine.sdk4.internal.containers.VmContainer; 27 | import org.ovirt.engine.sdk4.types.DiskAttachment; 28 | 29 | public class VmTest { 30 | 31 | /** 32 | * Check when creating null vm disks it creates empty list 33 | */ 34 | @Test 35 | public void testVmDiskIsEmpty() { 36 | VmContainer vm = new VmContainer(); 37 | vm.diskAttachments(null); 38 | assertNotNull(vm.diskAttachments()); 39 | assertEquals(0, vm.diskAttachments().size()); 40 | } 41 | 42 | /** 43 | * Check when creating list of vm disks it creates that list 44 | */ 45 | @Test 46 | public void testVmDiskWithValues() { 47 | VmContainer vm = new VmContainer(); 48 | vm.diskAttachments(Arrays.asList((DiskAttachment) new DiskAttachmentContainer())); 49 | assertNotNull(vm.diskAttachments()); 50 | assertEquals(1, vm.diskAttachments().size()); 51 | assertNotNull(vm.diskAttachments().get(0)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AddAffinityLabel.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.affinityLabel; 21 | 22 | import org.ovirt.engine.sdk4.Connection; 23 | import org.ovirt.engine.sdk4.services.AffinityLabelsService; 24 | 25 | // This example will connect to the server and create a new affinity label 26 | public class AddAffinityLabel { 27 | public static void main(String[] args) throws Exception { 28 | // Create the connection to the server: 29 | Connection connection = connection() 30 | .url("https://engine40.example.com/ovirt-engine/api") 31 | .user("admin@internal") 32 | .password("redhat123") 33 | .trustStoreFile("truststore.jks") 34 | .build(); 35 | 36 | // Get the reference to the affinity labels service: 37 | AffinityLabelsService affinityLabelsService = connection.systemService().affinityLabelsService(); 38 | 39 | // Use the "add" method to create a affinity label: 40 | affinityLabelsService.add() 41 | .label( 42 | affinityLabel() 43 | .name("myaffinitylabel") 44 | ) 45 | .send(); 46 | 47 | // Close the connection to the server: 48 | connection.close(); 49 | } 50 | } -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AddCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.cluster; 21 | import static org.ovirt.engine.sdk4.builders.Builders.cpu; 22 | import static org.ovirt.engine.sdk4.builders.Builders.dataCenter; 23 | 24 | import org.ovirt.engine.sdk4.Connection; 25 | import org.ovirt.engine.sdk4.services.ClustersService; 26 | import org.ovirt.engine.sdk4.types.Architecture; 27 | 28 | // This example will connect to the server and create a new cluster: 29 | public class AddCluster { 30 | public static void main(String[] args) throws Exception { 31 | // Create the connection to the server: 32 | Connection connection = connection() 33 | .url("https://engine40.example.com/ovirt-engine/api") 34 | .user("admin@internal") 35 | .password("redhat123") 36 | .trustStoreFile("truststore.jks") 37 | .build(); 38 | 39 | // Get the reference to the clusters service: 40 | ClustersService clustersService = connection.systemService().clustersService(); 41 | 42 | // Use the "add" method to create a new data center: 43 | clustersService.add() 44 | .cluster( 45 | cluster() 46 | .name("mycluster") 47 | .description("My cluster") 48 | .cpu( 49 | cpu() 50 | .architecture(Architecture.X86_64) 51 | .type("Intel Conroe Family") 52 | ) 53 | .dataCenter( 54 | dataCenter() 55 | .name("mydc") 56 | ) 57 | ) 58 | .send(); 59 | 60 | // Close the connection to the server: 61 | connection.close(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AddDataCenter.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.dataCenter; 21 | 22 | import org.ovirt.engine.sdk4.Connection; 23 | import org.ovirt.engine.sdk4.services.DataCentersService; 24 | 25 | // This example will connect to the server and create a new data center: 26 | public class AddDataCenter { 27 | public static void main(String[] args) throws Exception { 28 | // Create the connection to the server: 29 | Connection connection = connection() 30 | .url("https://engine40.example.com/ovirt-engine/api") 31 | .user("admin@internal") 32 | .password("redhat123") 33 | .trustStoreFile("truststore.jks") 34 | .build(); 35 | 36 | // Get the reference to the data centers service: 37 | DataCentersService dcsService = connection.systemService().dataCentersService(); 38 | 39 | // Use the "add" method to create a new data center: 40 | dcsService.add() 41 | .dataCenter( 42 | dataCenter() 43 | .name("mydc") 44 | .description("My data center") 45 | .local(false) 46 | ) 47 | .send(); 48 | 49 | // Close the connection to the server: 50 | connection.close(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AddFloatingDisk.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.disk; 21 | import static org.ovirt.engine.sdk4.builders.Builders.storageDomain; 22 | 23 | import java.math.BigInteger; 24 | 25 | import org.ovirt.engine.sdk4.Connection; 26 | import org.ovirt.engine.sdk4.services.DiskService; 27 | import org.ovirt.engine.sdk4.services.DisksService; 28 | import org.ovirt.engine.sdk4.types.Disk; 29 | import org.ovirt.engine.sdk4.types.DiskFormat; 30 | import org.ovirt.engine.sdk4.types.DiskStatus; 31 | 32 | // This example will connect to the server and create a new `floating` disk, one that isn't attached to any virtual 33 | // machine. 34 | public class AddFloatingDisk { 35 | public static void main(String[] args) throws Exception { 36 | // Create the connection to the server: 37 | Connection connection = connection() 38 | .url("https://engine40.example.com/ovirt-engine/api") 39 | .user("admin@internal") 40 | .password("redhat123") 41 | .trustStoreFile("truststore.jks") 42 | .build(); 43 | 44 | // Get the reference to the disks service: 45 | DisksService disksService = connection.systemService().disksService(); 46 | 47 | // Add the disk. Note that the size of the disk, the `provisionedSize` attribute, is specified in bytes, 48 | // so to create a disk of 10 GiB the value should be 10 * 2^30. 49 | Disk disk = disksService.add() 50 | .disk( 51 | disk() 52 | .name("mydisk") 53 | .description("My disk") 54 | .format(DiskFormat.COW) 55 | .provisionedSize(BigInteger.valueOf(10).multiply(BigInteger.valueOf(2).pow(30))) 56 | .storageDomains( 57 | storageDomain() 58 | .name("mydata") 59 | ) 60 | ) 61 | .send() 62 | .disk(); 63 | 64 | // Wait till the disk is completely created: 65 | DiskService diskService = disksService.diskService(disk.id()); 66 | for (;;) { 67 | Thread.sleep(5 * 1000); 68 | disk = diskService.get().send().disk(); 69 | if (disk.status() == DiskStatus.OK) { 70 | break; 71 | } 72 | } 73 | 74 | // Close the connection to the server: 75 | connection.close(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AddGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.cluster; 21 | import static org.ovirt.engine.sdk4.builders.Builders.cpu; 22 | import static org.ovirt.engine.sdk4.builders.Builders.dataCenter; 23 | import static org.ovirt.engine.sdk4.builders.Builders.domain; 24 | import static org.ovirt.engine.sdk4.builders.Builders.group; 25 | 26 | import org.ovirt.engine.sdk4.Connection; 27 | import org.ovirt.engine.sdk4.services.ClustersService; 28 | import org.ovirt.engine.sdk4.services.GroupsService; 29 | import org.ovirt.engine.sdk4.types.Architecture; 30 | 31 | // This example will connect to the server and create a group from a directory service: 32 | public class AddGroup { 33 | public static void main(String[] args) throws Exception { 34 | // Create the connection to the server: 35 | Connection connection = connection() 36 | .url("https://engine40.example.com/ovirt-engine/api") 37 | .user("admin@internal") 38 | .password("redhat123") 39 | .trustStoreFile("truststore.jks") 40 | .build(); 41 | 42 | // Get the reference to the groups service: 43 | GroupsService groupsService = connection.systemService().groupsService(); 44 | 45 | // Use the "add" method to add group from a directory service. Please note that domain name is name of the 46 | // authorization provider: 47 | groupsService.add() 48 | .group( 49 | group() 50 | .name("Developers") 51 | .domain( 52 | domain() 53 | .name("internal-authz") 54 | ) 55 | ) 56 | .send(); 57 | 58 | // Close the connection to the server: 59 | connection.close(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AddHost.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.cluster; 21 | import static org.ovirt.engine.sdk4.builders.Builders.host; 22 | 23 | import org.ovirt.engine.sdk4.Connection; 24 | import org.ovirt.engine.sdk4.services.HostService; 25 | import org.ovirt.engine.sdk4.services.HostsService; 26 | import org.ovirt.engine.sdk4.types.Host; 27 | import org.ovirt.engine.sdk4.types.HostStatus; 28 | 29 | // This example will connect to the server and add a new host: 30 | public class AddHost { 31 | public static void main(String[] args) throws Exception { 32 | // Create the connection to the server: 33 | Connection connection = connection() 34 | .url("https://engine40.example.com/ovirt-engine/api") 35 | .user("admin@internal") 36 | .password("redhat123") 37 | .trustStoreFile("truststore.jks") 38 | .build(); 39 | 40 | // Get the reference to the hosts service: 41 | HostsService hostsService = connection.systemService().hostsService(); 42 | 43 | // Add the host: 44 | Host host = hostsService.add() 45 | .host( 46 | host() 47 | .name("myhost") 48 | .description("My host") 49 | .address("node40.example.com") 50 | .rootPassword("redhat123") 51 | .cluster( 52 | cluster() 53 | .name("mycluster") 54 | ) 55 | ) 56 | .send() 57 | .host(); 58 | 59 | // Wait till the host is up: 60 | HostService hostService = hostsService.hostService(host.id()); 61 | for (;;) { 62 | Thread.sleep(5 * 1000); 63 | host = hostService.get().send().host(); 64 | if (host.status() == HostStatus.UP) { 65 | break; 66 | } 67 | } 68 | 69 | // Close the connection to the server: 70 | connection.close(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AddIndependentVm.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.cluster; 21 | import static org.ovirt.engine.sdk4.builders.Builders.template; 22 | import static org.ovirt.engine.sdk4.builders.Builders.vm; 23 | 24 | import org.ovirt.engine.sdk4.Connection; 25 | import org.ovirt.engine.sdk4.services.VmsService; 26 | 27 | // This example will connect to the server and create a new virtual 28 | // machine from a template. The disks of the new virtual machine will 29 | // be cloned, so that it will be independent of the template. 30 | public class AddIndependentVm { 31 | public static void main(String[] args) throws Exception { 32 | // Create the connection to the server: 33 | Connection connection = connection() 34 | .url("https://engine40.example.com/ovirt-engine/api") 35 | .user("admin@internal") 36 | .password("redhat123") 37 | .trustStoreFile("truststore.jks") 38 | .build(); 39 | 40 | // Get the reference to the "vms" service: 41 | VmsService vmsService = connection.systemService().vmsService(); 42 | 43 | // Use the "clone" parameter of the "add" method to request that the 44 | // disks of the new virtual machine are independent of the template. 45 | vmsService.add() 46 | .vm( 47 | vm() 48 | .name("myvm") 49 | .cluster( 50 | cluster() 51 | .name("mycluster") 52 | ) 53 | .template( 54 | template() 55 | .name("mytemplate") 56 | ) 57 | ) 58 | .clone_(true) 59 | .send(); 60 | 61 | // Close the connection to the server: 62 | connection.close(); 63 | } 64 | } -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AddInstanceType.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.cpu; 21 | import static org.ovirt.engine.sdk4.builders.Builders.cpuTopology; 22 | import static org.ovirt.engine.sdk4.builders.Builders.highAvailability; 23 | import static org.ovirt.engine.sdk4.builders.Builders.instanceType; 24 | 25 | import java.math.BigInteger; 26 | 27 | import org.ovirt.engine.sdk4.Connection; 28 | import org.ovirt.engine.sdk4.services.InstanceTypesService; 29 | 30 | // This example will connect to the server and create a new instance type 31 | public class AddInstanceType { 32 | public static void main(String[] args) throws Exception { 33 | // Create the connection to the server: 34 | Connection connection = connection() 35 | .url("https://engine40.example.com/ovirt-engine/api") 36 | .user("admin@internal") 37 | .password("redhat123") 38 | .trustStoreFile("truststore.jks") 39 | .build(); 40 | 41 | // Get the reference to the instance types service: 42 | InstanceTypesService instanceTypesService = connection.systemService().instanceTypesService(); 43 | 44 | // Add the instance type. Note that the size of the memory, the `memory` 45 | // attribute, is specified in bytes, so to create a instance type with 46 | // 2 GiB of memory the value should be 2 * 2^30. 47 | instanceTypesService.add() 48 | .instanceType( 49 | instanceType() 50 | .name("myinstancetype") 51 | .description("My instance type") 52 | .memory(BigInteger.valueOf(2).multiply(BigInteger.valueOf(2).pow(30))) 53 | .highAvailability( 54 | highAvailability() 55 | .enabled(true) 56 | ) 57 | .cpu( 58 | cpu() 59 | .topology( 60 | cpuTopology() 61 | .cores(2) 62 | .sockets(2) 63 | ) 64 | ) 65 | ) 66 | .send(); 67 | 68 | // Close the connection to the server: 69 | connection.close(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AddLogicalNetwork.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.dataCenter; 21 | import static org.ovirt.engine.sdk4.builders.Builders.network; 22 | import static org.ovirt.engine.sdk4.builders.Builders.vlan; 23 | 24 | import java.util.Arrays; 25 | 26 | import org.ovirt.engine.sdk4.Connection; 27 | import org.ovirt.engine.sdk4.services.NetworksService; 28 | import org.ovirt.engine.sdk4.types.NetworkUsage; 29 | 30 | // This example will connect to the server and create new logical network. 31 | public class AddLogicalNetwork { 32 | public static void main(String[] args) throws Exception { 33 | // Create the connection to the server: 34 | Connection connection = connection() 35 | .url("https://engine40.example.com/ovirt-engine/api") 36 | .user("admin@internal") 37 | .password("redhat123") 38 | .trustStoreFile("truststore.jks") 39 | .build(); 40 | 41 | // Get the reference to the "networks" service: 42 | NetworksService networksService = connection.systemService().networksService(); 43 | 44 | // Use the "add" method to create new VM logical network in data center called "mydatacenter", with VLAN tag 45 | // 100 and MTU 1500. 46 | networksService.add() 47 | .network( 48 | network() 49 | .name("mynetwork") 50 | .description("My logical network") 51 | .dataCenter( 52 | dataCenter() 53 | .name("mydatacenter") 54 | ) 55 | .vlan( 56 | vlan() 57 | .id(100) 58 | ) 59 | .usages(Arrays.asList(NetworkUsage.DISPLAY)) 60 | .mtu(1500) 61 | ) 62 | .send(); 63 | 64 | // Close the connection to the server: 65 | connection.close(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AddLunDiskToVm.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.disk; 21 | import static org.ovirt.engine.sdk4.builders.Builders.diskAttachment; 22 | import static org.ovirt.engine.sdk4.builders.Builders.hostStorage; 23 | import static org.ovirt.engine.sdk4.builders.Builders.logicalUnit; 24 | 25 | import org.ovirt.engine.sdk4.Connection; 26 | import org.ovirt.engine.sdk4.services.DiskAttachmentsService; 27 | import org.ovirt.engine.sdk4.services.VmsService; 28 | import org.ovirt.engine.sdk4.types.DiskInterface; 29 | import org.ovirt.engine.sdk4.types.StorageType; 30 | import org.ovirt.engine.sdk4.types.Vm; 31 | 32 | // This example will connect to the server and add LUN disk to virtual machine: 33 | public class AddLunDiskToVm { 34 | public static void main(String[] args) throws Exception { 35 | // Create the connection to the server: 36 | Connection connection = connection() 37 | .url("https://engine/ovirt-engine/api") 38 | .user("admin@internal") 39 | .password("123456") 40 | .trustStoreFile("truststore.jks") 41 | .build(); 42 | 43 | // Locate the virtual machines service and use it to find the virtual machine: 44 | VmsService vmsService = connection.systemService().vmsService(); 45 | Vm vm = vmsService.list().search("name=myvm").send().vms().get(0); 46 | 47 | // Locate the service that manages the disk attachments of the virtual machine: 48 | DiskAttachmentsService diskAttachmentsService = vmsService.vmService(vm.id()).diskAttachmentsService(); 49 | 50 | // Use the "add" method of the disk attachments service to add the LUN disk. 51 | diskAttachmentsService.add() 52 | .attachment( 53 | diskAttachment() 54 | .disk( 55 | disk() 56 | .name("myiscsidisk") 57 | .lunStorage( 58 | hostStorage() 59 | .type(StorageType.ISCSI) 60 | .logicalUnits( 61 | logicalUnit() 62 | .address("192.168.200.3") 63 | .port(3260) 64 | .target("iqn.2014-07.org.ovirt:storage") 65 | .id("36001405e793bf9c57a840f58c9a8a220") 66 | .username("username") 67 | .password("password") 68 | ) 69 | ) 70 | ) 71 | .interface_(DiskInterface.VIRTIO) 72 | .bootable(false) 73 | .active(true) 74 | ) 75 | .send() 76 | .attachment(); 77 | 78 | // Close the connection to the server: 79 | connection.close(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AddMacPool.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.cluster; 21 | import static org.ovirt.engine.sdk4.builders.Builders.macPool; 22 | import static org.ovirt.engine.sdk4.builders.Builders.range; 23 | 24 | import org.ovirt.engine.sdk4.Connection; 25 | import org.ovirt.engine.sdk4.services.ClusterService; 26 | import org.ovirt.engine.sdk4.services.ClustersService; 27 | import org.ovirt.engine.sdk4.services.MacPoolsService; 28 | import org.ovirt.engine.sdk4.types.Cluster; 29 | import org.ovirt.engine.sdk4.types.MacPool; 30 | 31 | // This example will connect to the server, create a new MAC address pool and assign it to a cluster: 32 | public class AddMacPool { 33 | public static void main(String[] args) throws Exception { 34 | // Create the connection to the server: 35 | Connection connection = connection() 36 | .url("https://engine40.example.com/ovirt-engine/api") 37 | .user("admin@internal") 38 | .password("redhat123") 39 | .trustStoreFile("truststore.jks") 40 | .build(); 41 | 42 | // Get the reference to the service that manages the MAC address pools: 43 | MacPoolsService poolsService = connection.systemService().macPoolsService(); 44 | 45 | // Add a new MAC address pool: 46 | MacPool pool = poolsService.add() 47 | .pool( 48 | macPool() 49 | .name("mymacpool") 50 | .ranges( 51 | range() 52 | .from("02:00:00:00:00:00") 53 | .to("02:00:00:01:00:00") 54 | ) 55 | ) 56 | .send() 57 | .pool(); 58 | 59 | // Find the service that manages clusters, as we need it in order to find the cluster where we wnt to set the 60 | // MAC address pool: 61 | ClustersService clustersService = connection.systemService().clustersService(); 62 | 63 | // Find the cluster: 64 | Cluster cluster = clustersService.list() 65 | .search("name=mycluster") 66 | .send() 67 | .clusters() 68 | .get(0); 69 | 70 | // Find the service that manages the cluster, as we need it in order to do the update: 71 | ClusterService clusterService = clustersService.clusterService(cluster.id()); 72 | 73 | // Update the service so that it uses the new MAC pool: 74 | clusterService.update() 75 | .cluster( 76 | cluster() 77 | .macPool( 78 | macPool() 79 | .id(pool.id()) 80 | ) 81 | ) 82 | .send(); 83 | 84 | // Close the connection to the server: 85 | connection.close(); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AddNfsDataStorageDomain.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.host; 21 | import static org.ovirt.engine.sdk4.builders.Builders.hostStorage; 22 | import static org.ovirt.engine.sdk4.builders.Builders.storageDomain; 23 | 24 | import org.ovirt.engine.sdk4.Connection; 25 | import org.ovirt.engine.sdk4.services.StorageDomainService; 26 | import org.ovirt.engine.sdk4.services.StorageDomainsService; 27 | import org.ovirt.engine.sdk4.types.StorageDomain; 28 | import org.ovirt.engine.sdk4.types.StorageDomainStatus; 29 | import org.ovirt.engine.sdk4.types.StorageDomainType; 30 | import org.ovirt.engine.sdk4.types.StorageType; 31 | 32 | // This example will connect to the server and create a new NFS data storage domain: 33 | public class AddNfsDataStorageDomain { 34 | public static void main(String[] args) throws Exception { 35 | // Create the connection to the server: 36 | Connection connection = connection() 37 | .url("https://engine40.example.com/ovirt-engine/api") 38 | .user("admin@internal") 39 | .password("redhat123") 40 | .trustStoreFile("truststore.jks") 41 | .build(); 42 | 43 | // Get the reference to the storage domains service: 44 | StorageDomainsService sdsService = connection.systemService().storageDomainsService(); 45 | 46 | // Create a new NFS storage domain: 47 | StorageDomain sd = sdsService.add() 48 | .storageDomain( 49 | storageDomain() 50 | .name("mydata") 51 | .description("My data") 52 | .type(StorageDomainType.DATA) 53 | .host( 54 | host() 55 | .name("myhost") 56 | ) 57 | .storage( 58 | hostStorage() 59 | .type(StorageType.NFS) 60 | .address("server0.example.com") 61 | .path("/nfs/ovirt/40/mydata") 62 | ) 63 | ) 64 | .send() 65 | .storageDomain(); 66 | 67 | // Wait till the storage domain is unattached: 68 | StorageDomainService sdService = sdsService.storageDomainService(sd.id()); 69 | for (;;) { 70 | Thread.sleep(5 * 1000); 71 | sd = sdService.get().send().storageDomain(); 72 | if (sd.status() == StorageDomainStatus.UNATTACHED) { 73 | break; 74 | } 75 | } 76 | 77 | // Close the connection to the server: 78 | connection.close(); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AddNfsIsoStorageDomain.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.host; 21 | import static org.ovirt.engine.sdk4.builders.Builders.hostStorage; 22 | import static org.ovirt.engine.sdk4.builders.Builders.storageDomain; 23 | 24 | import org.ovirt.engine.sdk4.Connection; 25 | import org.ovirt.engine.sdk4.services.StorageDomainService; 26 | import org.ovirt.engine.sdk4.services.StorageDomainsService; 27 | import org.ovirt.engine.sdk4.types.StorageDomain; 28 | import org.ovirt.engine.sdk4.types.StorageDomainStatus; 29 | import org.ovirt.engine.sdk4.types.StorageDomainType; 30 | import org.ovirt.engine.sdk4.types.StorageType; 31 | 32 | // This example will connect to the server and create a new NFS ISO storage domain: 33 | public class AddNfsIsoStorageDomain { 34 | public static void main(String[] args) throws Exception { 35 | // Create the connection to the server: 36 | Connection connection = connection() 37 | .url("https://engine40.example.com/ovirt-engine/api") 38 | .user("admin@internal") 39 | .password("redhat123") 40 | .trustStoreFile("truststore.jks") 41 | .build(); 42 | 43 | // Get the reference to the storage domains service: 44 | StorageDomainsService sdsService = connection.systemService().storageDomainsService(); 45 | 46 | // Create a new NFS storage domain: 47 | StorageDomain sd = sdsService.add() 48 | .storageDomain( 49 | storageDomain() 50 | .name("myiso") 51 | .description("My ISO") 52 | .type(StorageDomainType.ISO) 53 | .host( 54 | host() 55 | .name("myhost") 56 | ) 57 | .storage( 58 | hostStorage() 59 | .type(StorageType.NFS) 60 | .address("server0.example.com") 61 | .path("/nfs/ovirt/40/myiso") 62 | ) 63 | ) 64 | .send() 65 | .storageDomain(); 66 | 67 | // Wait till the storage domain is unattached: 68 | StorageDomainService sdService = sdsService.storageDomainService(sd.id()); 69 | for (;;) { 70 | Thread.sleep(5 * 1000); 71 | sd = sdService.get().send().storageDomain(); 72 | if (sd.status() == StorageDomainStatus.UNATTACHED) { 73 | break; 74 | } 75 | } 76 | 77 | // Close the connection to the server: 78 | connection.close(); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AddSystemPermission.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.permission; 21 | import static org.ovirt.engine.sdk4.builders.Builders.role; 22 | import static org.ovirt.engine.sdk4.builders.Builders.user; 23 | 24 | import org.ovirt.engine.sdk4.Connection; 25 | import org.ovirt.engine.sdk4.services.SystemPermissionsService; 26 | import org.ovirt.engine.sdk4.services.SystemService; 27 | 28 | // This example shows how to add a system permission: 29 | public class AddSystemPermission { 30 | public static void main(String[] args) throws Exception { 31 | // Create the connection to the server: 32 | Connection connection = connection() 33 | .url("https://engine40.example.com/ovirt-engine/api") 34 | .user("admin@internal") 35 | .password("redhat123") 36 | .trustStoreFile("truststore.jks") 37 | .build(); 38 | 39 | // Get the reference to the root of the tree of services: 40 | SystemService systemService = connection.systemService(); 41 | 42 | // Get the reference to the service that manages system permissions: 43 | SystemPermissionsService permissionsService = systemService.permissionsService(); 44 | 45 | // Add the "SupeUser" permission to the user with id "123": 46 | permissionsService.add() 47 | .permission( 48 | permission() 49 | .role( 50 | role() 51 | .name("SuperUser") 52 | ) 53 | .user( 54 | user() 55 | .id("123") 56 | ) 57 | ) 58 | .send(); 59 | 60 | // Close the connection to the server: 61 | connection.close(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AddTag.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.tag; 21 | 22 | import org.ovirt.engine.sdk4.Connection; 23 | import org.ovirt.engine.sdk4.services.TagsService; 24 | 25 | // This example will connect to the server and create a new tag 26 | public class AddTag { 27 | public static void main(String[] args) throws Exception { 28 | // Create the connection to the server: 29 | Connection connection = connection() 30 | .url("https://engine40.example.com/ovirt-engine/api") 31 | .user("admin@internal") 32 | .password("redhat123") 33 | .trustStoreFile("truststore.jks") 34 | .build(); 35 | 36 | // Get the reference to the tags service: 37 | TagsService tagsService = connection.systemService().tagsService(); 38 | 39 | // Use the "add" method to create new tag: 40 | tagsService.add() 41 | .tag( 42 | tag() 43 | .name("mytag") 44 | ) 45 | .send(); 46 | 47 | // Close the connection to the server: 48 | connection.close(); 49 | } 50 | } -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AddUserPublicSshKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.sshPublicKey; 21 | 22 | import org.ovirt.engine.sdk4.Connection; 23 | import org.ovirt.engine.sdk4.services.SshPublicKeysService; 24 | import org.ovirt.engine.sdk4.services.SystemService; 25 | import org.ovirt.engine.sdk4.services.UserService; 26 | import org.ovirt.engine.sdk4.services.UsersService; 27 | import org.ovirt.engine.sdk4.types.User; 28 | 29 | // This example will connect to the server, find a user by name and add a public SSH key. 30 | public class AddUserPublicSshKey { 31 | public static void main(String[] args) throws Exception { 32 | // Create the connection to the server: 33 | Connection connection = connection() 34 | .url("https://engine40.example.com/ovirt-engine/api") 35 | .user("admin@internal") 36 | .password("redhat123") 37 | .trustStoreFile("truststore.jks") 38 | .build(); 39 | 40 | // Get the reference to the root of the tree of services: 41 | SystemService systemService = connection.systemService(); 42 | 43 | // Get the reference to the service that manages the users: 44 | UsersService usersService = systemService.usersService(); 45 | 46 | // Find the user: 47 | User user = usersService.list() 48 | .search("name=myuser") 49 | .send() 50 | .users() 51 | .get(0); 52 | 53 | // Get the reference to the service that manages the user that we found in the previous step: 54 | UserService userService = usersService.userService(user.id()); 55 | 56 | // Get a reference to the service that manages the public SSH keys of the user: 57 | SshPublicKeysService keysService = userService.sshPublicKeysService(); 58 | 59 | // Add a new SSH public key: 60 | keysService.add() 61 | .key( 62 | sshPublicKey() 63 | .content("ssh-rsa AAA...mu9 myuser@example.com") 64 | ) 65 | .send(); 66 | 67 | // Note that the above operation will fail because the example SSH public key is not valid, make sure to use a 68 | // valid key. 69 | 70 | // Close the connection to the server: 71 | connection.close(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AddVm.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.cluster; 21 | import static org.ovirt.engine.sdk4.builders.Builders.template; 22 | import static org.ovirt.engine.sdk4.builders.Builders.vm; 23 | 24 | import org.ovirt.engine.sdk4.Connection; 25 | import org.ovirt.engine.sdk4.services.VmsService; 26 | 27 | // This example will connect to the server and create a new virtual machine: 28 | public class AddVm { 29 | public static void main(String[] args) throws Exception { 30 | // Create the connection to the server: 31 | Connection connection = connection() 32 | .url("https://engine40.example.com/ovirt-engine/api") 33 | .user("admin@internal") 34 | .password("redhat123") 35 | .trustStoreFile("truststore.jks") 36 | .build(); 37 | 38 | // Get the reference to the "vms" service: 39 | VmsService vmsService = connection.systemService().vmsService(); 40 | 41 | // Use the "add" method to create a new virtual machine: 42 | vmsService.add() 43 | .vm( 44 | vm() 45 | .name("myvm") 46 | .cluster( 47 | cluster() 48 | .name("mycluster") 49 | ) 50 | .template( 51 | template() 52 | .name("Blank") 53 | ) 54 | ) 55 | .send(); 56 | 57 | // Close the connection to the server: 58 | connection.close(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AddVmNic.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.nic; 21 | import static org.ovirt.engine.sdk4.builders.Builders.vnicProfile; 22 | 23 | import java.util.List; 24 | import java.util.Objects; 25 | 26 | import org.ovirt.engine.sdk4.Connection; 27 | import org.ovirt.engine.sdk4.services.VmNicsService; 28 | import org.ovirt.engine.sdk4.services.VmsService; 29 | import org.ovirt.engine.sdk4.services.VnicProfilesService; 30 | import org.ovirt.engine.sdk4.types.Vm; 31 | import org.ovirt.engine.sdk4.types.VnicProfile; 32 | 33 | // This example will connect to the server and add a network interface card to an existing virtual machine: 34 | public class AddVmNic { 35 | public static void main(String[] args) throws Exception { 36 | // Create the connection to the server: 37 | Connection connection = connection() 38 | .url("https://engine40.example.com/ovirt-engine/api") 39 | .user("admin@internal") 40 | .password("redhat123") 41 | .trustStoreFile("truststore.jks") 42 | .build(); 43 | 44 | // Locate the virtual machines service and use it to find the virtual machine: 45 | VmsService vmsService = connection.systemService().vmsService(); 46 | Vm vm = vmsService.list().search("name=myvm").send().vms().get(0); 47 | 48 | // In order to specify the network that the new interface will be connected to, we need to specify the 49 | // identifier of the virtual network interface profile, so we need to find it: 50 | VnicProfilesService profilesService = connection.systemService().vnicProfilesService(); 51 | String profileId = null; 52 | List profiles = profilesService.list().send().profiles(); 53 | for (VnicProfile profile : profiles) { 54 | if (Objects.equals(profile.name(), "mynetwork")) { 55 | profileId = profile.id(); 56 | break; 57 | } 58 | } 59 | 60 | // Locate the service that manages the NICs of the virtual machine: 61 | VmNicsService nicsService = vmsService.vmService(vm.id()).nicsService(); 62 | 63 | // Use the "add" method of the disks service to add the disk: 64 | nicsService.add() 65 | .nic( 66 | nic() 67 | .name("mynic") 68 | .description("My network interface card") 69 | .vnicProfile( 70 | vnicProfile() 71 | .id(profileId) 72 | ) 73 | ) 74 | .send(); 75 | 76 | // Close the connection to the server: 77 | connection.close(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AddVmSnapshot.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.snapshot; 21 | 22 | import org.ovirt.engine.sdk4.Connection; 23 | import org.ovirt.engine.sdk4.services.SnapshotsService; 24 | import org.ovirt.engine.sdk4.services.VmsService; 25 | import org.ovirt.engine.sdk4.types.Vm; 26 | 27 | // This example will connect to the server and add a snapshot to an existing virtual machine: 28 | public class AddVmSnapshot { 29 | public static void main(String[] args) throws Exception { 30 | // Create the connection to the server: 31 | Connection connection = connection() 32 | .url("https://engine40.example.com/ovirt-engine/api") 33 | .user("admin@internal") 34 | .password("redhat123") 35 | .trustStoreFile("truststore.jks") 36 | .build(); 37 | 38 | // Locate the virtual machines service and use it to find the virtual machine: 39 | VmsService vmsService = connection.systemService().vmsService(); 40 | Vm vm = vmsService.list().search("name=myvm").send().vms().get(0); 41 | 42 | // Locate the service that manages the snapshots of the virtual machine: 43 | SnapshotsService snapshotsService = vmsService.vmService(vm.id()).snapshotsService(); 44 | 45 | // Add the snapshot: 46 | snapshotsService.add() 47 | .snapshot( 48 | snapshot() 49 | .description("My snapshot") 50 | ) 51 | .send(); 52 | 53 | // Close the connection to the server: 54 | connection.close(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AddVmWithSysprep.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.cluster; 21 | import static org.ovirt.engine.sdk4.builders.Builders.operatingSystem; 22 | import static org.ovirt.engine.sdk4.builders.Builders.template; 23 | import static org.ovirt.engine.sdk4.builders.Builders.vm; 24 | 25 | import org.ovirt.engine.sdk4.Connection; 26 | import org.ovirt.engine.sdk4.services.VmService; 27 | import org.ovirt.engine.sdk4.services.VmsService; 28 | import org.ovirt.engine.sdk4.types.Vm; 29 | import org.ovirt.engine.sdk4.types.VmStatus; 30 | 31 | // This example will create a new virtual machine and start it using Sysprep: 32 | public class AddVmWithSysprep { 33 | public static void main(String[] args) throws Exception { 34 | // Create the connection to the server: 35 | Connection connection = connection() 36 | .url("https://engine40.example.com/ovirt-engine/api") 37 | .user("admin@internal") 38 | .password("redhat123") 39 | .trustStoreFile("truststore.jks") 40 | .build(); 41 | 42 | // Find the service that manages the collection of virtual machines: 43 | VmsService vmsService = connection.systemService().vmsService(); 44 | 45 | // Create the virtual machine. Note that no Sysprep stuff is needed here, when creating it, it will be used 46 | // later, when starting it: 47 | Vm vm = vmsService.add() 48 | .vm( 49 | vm() 50 | .name("myvm") 51 | .cluster( 52 | cluster() 53 | .name("mycluster") 54 | ) 55 | .template( 56 | template() 57 | .name("mytemplate") 58 | ) 59 | ) 60 | .send() 61 | .vm(); 62 | 63 | // Find the service that manages the virtual machine: 64 | VmService vmService = vmsService.vmService(vm.id()); 65 | 66 | // Wait till the virtual machine is down, which indicates that all the disks have been created: 67 | while (vm.status() != VmStatus.DOWN) { 68 | Thread.sleep(5 * 1000); 69 | vm = vmService.get().send().vm(); 70 | } 71 | 72 | // The content of the Unattend.xml file. Note that this is an incomplete file, make sure to use a complete one, 73 | // maybe reading it from an external file: 74 | String unattendXml = 75 | "\n" + 76 | "\n" + 77 | " ...\n" + 78 | "\n"; 79 | 80 | // Start the virtual machine enabling Sysprep. Make sure to use a Windows operating system, either in the 81 | // template, or overriding it explicitly here. Without that the Sysprep logic won't be triggered. 82 | vmService.start() 83 | .useSysprep(true) 84 | .vm( 85 | vm() 86 | .os( 87 | operatingSystem() 88 | .type("windows_7x64") 89 | ) 90 | ) 91 | .send(); 92 | 93 | // Close the connection to the server: 94 | connection.close(); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AddVncConsole.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.graphicsConsole; 21 | 22 | import java.util.List; 23 | 24 | import org.ovirt.engine.sdk4.Connection; 25 | import org.ovirt.engine.sdk4.services.VmGraphicsConsolesService; 26 | import org.ovirt.engine.sdk4.services.VmService; 27 | import org.ovirt.engine.sdk4.services.VmsService; 28 | import org.ovirt.engine.sdk4.types.GraphicsConsole; 29 | import org.ovirt.engine.sdk4.types.GraphicsType; 30 | import org.ovirt.engine.sdk4.types.Vm; 31 | 32 | // This example checks if a virtual machine has a VNC console, and adds it if it doesn't. 33 | public class AddVncConsole { 34 | public static void main(String[] args) throws Exception { 35 | // Create the connection to the server: 36 | Connection connection = connection() 37 | .url("https://engine40.example.com/ovirt-engine/api") 38 | .user("admin@internal") 39 | .password("redhat123") 40 | .trustStoreFile("truststore.jks") 41 | .build(); 42 | 43 | // Find the virtual machine: 44 | VmsService vmsService = connection.systemService().vmsService(); 45 | Vm vm = vmsService.list() 46 | .search("name=myvm") 47 | .send() 48 | .vms() 49 | .get(0); 50 | VmService vmService = vmsService.vmService(vm.id()); 51 | 52 | // Find the graphics consoles of the virtual machine: 53 | VmGraphicsConsolesService consolesService = vmService.graphicsConsolesService(); 54 | List consoles = consolesService.list() 55 | .send() 56 | .consoles(); 57 | 58 | // Add a VNC console if it doesn't exist: 59 | GraphicsConsole console = null; 60 | for (GraphicsConsole c : consoles) { 61 | if (c.protocol() == GraphicsType.VNC) { 62 | console = c; 63 | break; 64 | } 65 | } 66 | if (console == null) { 67 | consolesService.add() 68 | .console( 69 | graphicsConsole() 70 | .protocol(GraphicsType.VNC) 71 | ) 72 | .send(); 73 | } 74 | 75 | // Close the connection to the server: 76 | connection.close(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AssignAffinityLabelToVm.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.vm; 21 | 22 | import org.ovirt.engine.sdk4.Connection; 23 | import org.ovirt.engine.sdk4.services.AffinityLabelService; 24 | import org.ovirt.engine.sdk4.services.AffinityLabelVmsService; 25 | import org.ovirt.engine.sdk4.services.AffinityLabelsService; 26 | import org.ovirt.engine.sdk4.services.VmsService; 27 | import org.ovirt.engine.sdk4.types.AffinityLabel; 28 | import org.ovirt.engine.sdk4.types.Vm; 29 | 30 | // This example will connect to the server and assign affinity label to virtual machine: 31 | public class AssignAffinityLabelToVm { 32 | public static void main(String[] args) throws Exception { 33 | // Create the connection to the server: 34 | Connection connection = connection() 35 | .url("https://engine40.example.com/ovirt-engine/api") 36 | .user("admin@internal") 37 | .password("redhat123") 38 | .trustStoreFile("truststore.jks") 39 | .build(); 40 | 41 | // Get the reference to the "vms" service: 42 | VmsService vmsService = connection.systemService().vmsService(); 43 | 44 | // Find the virtual machine: 45 | Vm vm = vmsService.list().search("name=myvm").send().vms().get(0); 46 | 47 | // Get the reference to the affinity labels service: 48 | AffinityLabelsService affinityLabelsService = connection.systemService().affinityLabelsService(); 49 | 50 | // Find the id of the affinity label: 51 | String affinityLabelId = null; 52 | for (AffinityLabel affinityLabel : affinityLabelsService.list().send().labels()) { 53 | if (affinityLabel.name().equals("my_affinity_label")) { 54 | affinityLabelId = affinityLabel.id(); 55 | break; 56 | } 57 | } 58 | 59 | // Locate the service that manages the affinity label named `my_affinity_label`: 60 | AffinityLabelService affinityLabelService = affinityLabelsService.labelService(affinityLabelId); 61 | 62 | // Get the reference to the service that manages the set of virtual machines that have the affinity label 63 | // named `my_affinity_label` assigned: 64 | AffinityLabelVmsService affinityLabelVmsService = affinityLabelService.vmsService(); 65 | 66 | // Assign affinity label to virtual machine: 67 | affinityLabelVmsService.add() 68 | .vm( 69 | vm() 70 | .id(vm.id()) 71 | ) 72 | .send(); 73 | 74 | // Close the connection to the server: 75 | connection.close(); 76 | } 77 | } -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AssignNetworkToCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.network; 21 | 22 | import org.ovirt.engine.sdk4.Connection; 23 | import org.ovirt.engine.sdk4.services.ClusterNetworksService; 24 | import org.ovirt.engine.sdk4.services.ClusterService; 25 | import org.ovirt.engine.sdk4.services.ClustersService; 26 | import org.ovirt.engine.sdk4.services.NetworksService; 27 | import org.ovirt.engine.sdk4.types.Cluster; 28 | import org.ovirt.engine.sdk4.types.Network; 29 | 30 | // This example will connect to the server and assign 'mynetwork' network to cluster 'mycluster': 31 | public class AssignNetworkToCluster { 32 | public static void main(String[] args) throws Exception { 33 | // Create the connection to the server: 34 | Connection connection = connection() 35 | .url("https://engine40.example.com/ovirt-engine/api") 36 | .user("admin@internal") 37 | .password("redhat123") 38 | .trustStoreFile("truststore.jks") 39 | .build(); 40 | 41 | // Locate the networks service and use it to find the network: 42 | NetworksService networksService = connection.systemService().networksService(); 43 | Network network = networksService.list().search( 44 | "name=mynetwork and datacenter=mydatacenter" 45 | ).send().networks().get(0); 46 | 47 | // Locate the clusters service and use it to find the cluster: 48 | ClustersService clustersService = connection.systemService().clustersService(); 49 | Cluster cluster = clustersService.list().search("name=mycluster").send().clusters().get(0); 50 | 51 | // Locate the service that manages the networks of the cluster: 52 | ClusterService clusterService = clustersService.clusterService(cluster.id()); 53 | ClusterNetworksService assignedNetworksService = clusterService.networksService(); 54 | 55 | // Use the "add" method to assign network to cluster: 56 | assignedNetworksService.add() 57 | .network( 58 | network() 59 | .id(network.id()) 60 | .required(true) 61 | ) 62 | .send(); 63 | 64 | // Close the connection to the server: 65 | connection.close(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AssignTagToVm.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.tag; 21 | 22 | import org.ovirt.engine.sdk4.Connection; 23 | import org.ovirt.engine.sdk4.services.AssignedTagsService; 24 | import org.ovirt.engine.sdk4.services.VmService; 25 | import org.ovirt.engine.sdk4.services.VmsService; 26 | import org.ovirt.engine.sdk4.types.Vm; 27 | 28 | // This example will connect to the server and assign tag to virtual machine: 29 | public class AssignTagToVm { 30 | public static void main(String[] args) throws Exception { 31 | // Create the connection to the server: 32 | Connection connection = connection() 33 | .url("https://engine40.example.com/ovirt-engine/api") 34 | .user("admin@internal") 35 | .password("redhat123") 36 | .trustStoreFile("truststore.jks") 37 | .build(); 38 | 39 | // Get the reference to the "vms" service: 40 | VmsService vmsService = connection.systemService().vmsService(); 41 | 42 | // Find the virtual machine: 43 | Vm vm = vmsService.list().search("name=myvm0").send().vms().get(0); 44 | 45 | // Find the service that manages the vm: 46 | VmService vmService = vmsService.vmService(vm.id()); 47 | 48 | // Locate the service that manages the tags of the vm: 49 | AssignedTagsService assignedTagsService = vmService.tagsService(); 50 | 51 | // Assign tag to virtual machine: 52 | assignedTagsService.add() 53 | .tag( 54 | tag() 55 | .name("mytag") 56 | ) 57 | .send(); 58 | 59 | // Close the connection to the server: 60 | connection.close(); 61 | } 62 | } -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AttachNfsDataStorageDomain.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.storageDomain; 21 | 22 | import org.ovirt.engine.sdk4.Connection; 23 | import org.ovirt.engine.sdk4.services.AttachedStorageDomainService; 24 | import org.ovirt.engine.sdk4.services.AttachedStorageDomainsService; 25 | import org.ovirt.engine.sdk4.services.DataCenterService; 26 | import org.ovirt.engine.sdk4.services.DataCentersService; 27 | import org.ovirt.engine.sdk4.services.StorageDomainsService; 28 | import org.ovirt.engine.sdk4.types.DataCenter; 29 | import org.ovirt.engine.sdk4.types.StorageDomain; 30 | import org.ovirt.engine.sdk4.types.StorageDomainStatus; 31 | 32 | // This example will connect to the server and attach an existing NFS data storage domain to a data center: 33 | public class AttachNfsDataStorageDomain { 34 | public static void main(String[] args) throws Exception { 35 | // Create the connection to the server: 36 | Connection connection = connection() 37 | .url("https://engine40.example.com/ovirt-engine/api") 38 | .user("admin@internal") 39 | .password("redhat123") 40 | .trustStoreFile("truststore.jks") 41 | .build(); 42 | 43 | // Locate the service that manages the storage domains, and use it to search for the storage domain: 44 | StorageDomainsService sdsService = connection.systemService().storageDomainsService(); 45 | StorageDomain sd = sdsService.list().search("name=mydata").send().storageDomains().get(0); 46 | 47 | // Locate the service that manages the data centers and use it to search for the data center: 48 | DataCentersService dcsService = connection.systemService().dataCentersService(); 49 | DataCenter dc = dcsService.list().search("name=mydc").send().dataCenters().get(0); 50 | 51 | // Locate the service that manages the data center where we want to attach the storage domain: 52 | DataCenterService dcService = dcsService.dataCenterService(dc.id()); 53 | 54 | // Locate the service that manages the storage domains that are attached to the data center: 55 | AttachedStorageDomainsService attachedSdsService = dcService.storageDomainsService(); 56 | 57 | // Use the "add" method of the service that manages the attached storage domains to attach it: 58 | attachedSdsService.add() 59 | .storageDomain( 60 | storageDomain() 61 | .id(sd.id()) 62 | ) 63 | .send(); 64 | 65 | // Wait till the storage domain is active: 66 | AttachedStorageDomainService attachedSdService = attachedSdsService.storageDomainService(sd.id()); 67 | for (;;) { 68 | Thread.sleep(5 * 1000); 69 | sd = attachedSdService.get().send().storageDomain(); 70 | if (sd.status() == StorageDomainStatus.ACTIVE) { 71 | break; 72 | } 73 | } 74 | 75 | // Close the connection to the server: 76 | connection.close(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/AttachNfsIsoStorageDomain.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.storageDomain; 21 | 22 | import org.ovirt.engine.sdk4.Connection; 23 | import org.ovirt.engine.sdk4.services.AttachedStorageDomainService; 24 | import org.ovirt.engine.sdk4.services.AttachedStorageDomainsService; 25 | import org.ovirt.engine.sdk4.services.DataCenterService; 26 | import org.ovirt.engine.sdk4.services.DataCentersService; 27 | import org.ovirt.engine.sdk4.services.StorageDomainsService; 28 | import org.ovirt.engine.sdk4.types.DataCenter; 29 | import org.ovirt.engine.sdk4.types.StorageDomain; 30 | import org.ovirt.engine.sdk4.types.StorageDomainStatus; 31 | 32 | // This example will connect to the server and attach an existing NFS ISO storage domain to a data center: 33 | public class AttachNfsIsoStorageDomain { 34 | public static void main(String[] args) throws Exception { 35 | // Create the connection to the server: 36 | Connection connection = connection() 37 | .url("https://engine40.example.com/ovirt-engine/api") 38 | .user("admin@internal") 39 | .password("redhat123") 40 | .trustStoreFile("truststore.jks") 41 | .build(); 42 | 43 | // Locate the service that manages the storage domains, and use it to search for the storage domain: 44 | StorageDomainsService sdsService = connection.systemService().storageDomainsService(); 45 | StorageDomain sd = sdsService.list().search("name=myiso").send().storageDomains().get(0); 46 | 47 | // Locate the service that manages the data centers and use it to search for the data center: 48 | DataCentersService dcsService = connection.systemService().dataCentersService(); 49 | DataCenter dc = dcsService.list().search("name=mydc").send().dataCenters().get(0); 50 | 51 | // Locate the service that manages the data center where we want to attach the storage domain: 52 | DataCenterService dcService = dcsService.dataCenterService(dc.id()); 53 | 54 | // Locate the service that manages the storage domains that are attached to the data center: 55 | AttachedStorageDomainsService attachedSdsService = dcService.storageDomainsService(); 56 | 57 | // Use the "add" method of the service that manages the attached storage domains to attach it: 58 | attachedSdsService.add() 59 | .storageDomain( 60 | storageDomain() 61 | .id(sd.id()) 62 | ) 63 | .send(); 64 | 65 | // Wait till the storage domain is active: 66 | AttachedStorageDomainService attachedSdService = attachedSdsService.storageDomainService(sd.id()); 67 | for (;;) { 68 | Thread.sleep(5 * 1000); 69 | sd = attachedSdService.get().send().storageDomain(); 70 | if (sd.status() == StorageDomainStatus.ACTIVE) { 71 | break; 72 | } 73 | } 74 | 75 | // Close the connection to the server: 76 | connection.close(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/ChangeVmCd.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.cdrom; 21 | import static org.ovirt.engine.sdk4.builders.Builders.file; 22 | 23 | import org.ovirt.engine.sdk4.Connection; 24 | import org.ovirt.engine.sdk4.services.VmCdromService; 25 | import org.ovirt.engine.sdk4.services.VmCdromsService; 26 | import org.ovirt.engine.sdk4.services.VmService; 27 | import org.ovirt.engine.sdk4.services.VmsService; 28 | import org.ovirt.engine.sdk4.types.Cdrom; 29 | import org.ovirt.engine.sdk4.types.Vm; 30 | 31 | // This example will connect to the server and change the CDROM attached to a virtual machine: 32 | public class ChangeVmCd { 33 | public static void main(String[] args) throws Exception { 34 | // Create the connection to the server: 35 | Connection connection = connection() 36 | .url("https://engine40.example.com/ovirt-engine/api") 37 | .user("admin@internal") 38 | .password("redhat123") 39 | .trustStoreFile("truststore.jks") 40 | .build(); 41 | 42 | // Locate the service that manages the virtual machines: 43 | VmsService vmsService = connection.systemService().vmsService(); 44 | 45 | // Find the virtual machine: 46 | Vm vm = vmsService.list() 47 | .search("name=myvm") 48 | .send() 49 | .vms() 50 | .get(0); 51 | 52 | // Locate the service that manages the virtual machine: 53 | VmService vmService = vmsService.vmService(vm.id()); 54 | 55 | // Locate the service that manages the CDROM devices of the virtual machine: 56 | VmCdromsService cdromsService = vmService.cdromsService(); 57 | 58 | // Get the first CDROM: 59 | Cdrom cdrom = cdromsService.list() 60 | .send() 61 | .cdroms() 62 | .get(0); 63 | 64 | // Locate the service that manages the CDROM device found in the previous step: 65 | VmCdromService cdromService = cdromsService.cdromService(cdrom.id()); 66 | 67 | // Change the CDROM disk of the virtual machine to 'my_iso_file.iso'. By default the below operation changes 68 | // permanently the disk that will be visible to the virtual machine after the next boot, but it doesn't have 69 | // any effect on the currently running virtual machine. If you want to change the disk that is visible to the 70 | // current running virtual machine, change the value of the 'current' parameter to 'true'. 71 | cdromService.update() 72 | .cdrom( 73 | cdrom() 74 | .file( 75 | file() 76 | .id("my_iso_file.iso") 77 | ) 78 | ) 79 | .current(false) 80 | .send(); 81 | 82 | // Close the connection to the server: 83 | connection.close(); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/DiscoverIscsi.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.iscsiDetails; 21 | 22 | import org.ovirt.engine.sdk4.Connection; 23 | import org.ovirt.engine.sdk4.services.HostService; 24 | import org.ovirt.engine.sdk4.services.HostsService; 25 | import org.ovirt.engine.sdk4.types.Host; 26 | import org.ovirt.engine.sdk4.types.IscsiDetails; 27 | 28 | // This example will connect to the server and call iscsiDiscover method of host, 29 | // to discover iSCSI targets of the host. 30 | public class DiscoverIscsi { 31 | public static void main(String[] args) throws Exception { 32 | // Create the connection to the server: 33 | Connection connection = connection() 34 | .url("https://engine40.example.com/ovirt-engine/api") 35 | .user("admin@internal") 36 | .password("redhat123") 37 | .trustStoreFile("truststore.jks") 38 | .build(); 39 | 40 | // Get the reference to the hosts service: 41 | HostsService hostsService = connection.systemService().hostsService(); 42 | 43 | // Find the host: 44 | Host host = hostsService.list().search("name=myhost").send().hosts().get(0); 45 | 46 | // Locate the service that manages the host, as that is where the action methods are defined: 47 | HostService hostService = hostsService.hostService(host.id()); 48 | 49 | // Call the "iscsiDiscover" method of the service to start it: 50 | HostService.DiscoverIscsiResponse response = hostService.discoverIscsi() 51 | .iscsi( 52 | iscsiDetails() 53 | .address("myaddress") 54 | ) 55 | .send(); 56 | 57 | 58 | // Print only address corresponding to target: 59 | for (IscsiDetails detail : response.discoveredTargets()) { 60 | System.out.println(detail.address() + ":" + detail.target()); 61 | } 62 | 63 | // Close the connection to the server: 64 | connection.close(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/EnableSerialConsole.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.console; 21 | import static org.ovirt.engine.sdk4.builders.Builders.vm; 22 | 23 | import org.ovirt.engine.sdk4.Connection; 24 | import org.ovirt.engine.sdk4.services.VmService; 25 | import org.ovirt.engine.sdk4.services.VmsService; 26 | import org.ovirt.engine.sdk4.types.Vm; 27 | 28 | // This example will connect to the server, find a virtual machine and enable the serial console if it isn't 29 | // enabled yet: 30 | public class EnableSerialConsole { 31 | public static void main(String[] args) throws Exception { 32 | // Create the connection to the server: 33 | Connection connection = connection() 34 | .url("https://engine40.example.com/ovirt-engine/api") 35 | .user("admin@internal") 36 | .password("redhat123") 37 | .trustStoreFile("truststore.jks") 38 | .build(); 39 | 40 | // Find the virtual machine. Note the use of the `all_content` parameter, it is required in order to obtain 41 | // additional information that isn't retrieved by default, like the configuration of the serial console. 42 | VmsService vmsService = connection.systemService().vmsService(); 43 | Vm vm = vmsService.list() 44 | .search("name=myvm") 45 | .allContent(true) 46 | .send() 47 | .vms() 48 | .get(0); 49 | 50 | // Check if the serial console is enabled, and if it isn't then update the virtual machine to enable it: 51 | if (!vm.console().enabled()) { 52 | VmService vmService = vmsService.vmService(vm.id()); 53 | vmService.update() 54 | .vm( 55 | vm() 56 | .console( 57 | console() 58 | .enabled(true) 59 | ) 60 | ) 61 | .send(); 62 | } 63 | 64 | // Close the connection to the server: 65 | connection.close(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/ExportVm.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | import static org.ovirt.engine.sdk4.builders.Builders.storageDomain; 21 | 22 | import org.ovirt.engine.sdk4.Connection; 23 | import org.ovirt.engine.sdk4.services.SystemService; 24 | import org.ovirt.engine.sdk4.services.VmService; 25 | import org.ovirt.engine.sdk4.services.VmsService; 26 | import org.ovirt.engine.sdk4.types.Vm; 27 | 28 | // This example shows how to export a virtual machine to an export storage domain. 29 | public class ExportVm { 30 | public static void main(String[] args) throws Exception { 31 | // Create the connection to the server: 32 | Connection connection = connection() 33 | .url("https://engine40.example.com/ovirt-engine/api") 34 | .user("admin@internal") 35 | .password("redhat123") 36 | .trustStoreFile("truststore.jks") 37 | .build(); 38 | 39 | // Get the reference to the root of the services tree: 40 | SystemService systemService = connection.systemService(); 41 | 42 | // Find the virtual machine: 43 | VmsService vmsService = systemService.vmsService(); 44 | Vm vm = vmsService.list() 45 | .search("name=myvm") 46 | .send() 47 | .vms() 48 | .get(0); 49 | 50 | // Export the virtual machine. Note that the 'exclusive' parameter is optional, and only required if you want 51 | // to overwrite a virtual machine that has already been exported before. 52 | VmService vmService = vmsService.vmService(vm.id()); 53 | vmService.export() 54 | .exclusive(true) 55 | .discardSnapshots(true) 56 | .storageDomain( 57 | storageDomain() 58 | .name("myexport") 59 | ) 60 | .send(); 61 | 62 | // Close the connection to the server: 63 | connection.close(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /sdk/src/test/java/org/ovirt/engine/sdk4/examples/FollowVmLinks.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Red Hat, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package org.ovirt.engine.sdk4.examples; 18 | 19 | import static org.ovirt.engine.sdk4.ConnectionBuilder.connection; 20 | 21 | import java.util.List; 22 | 23 | import org.ovirt.engine.sdk4.Connection; 24 | import org.ovirt.engine.sdk4.services.VmsService; 25 | import org.ovirt.engine.sdk4.types.Cluster; 26 | import org.ovirt.engine.sdk4.types.Permission; 27 | import org.ovirt.engine.sdk4.types.Template; 28 | import org.ovirt.engine.sdk4.types.Vm; 29 | 30 | // This example will connect to the server, retrieve the detail of a virtual machine and then it will follow the links 31 | // to the permissions of the virtual machine: 32 | public class FollowVmLinks { 33 | public static void main(String[] args) throws Exception { 34 | // Create the connection to the server: 35 | Connection connection = connection() 36 | .url("https://engine40.example.com/ovirt-engine/api") 37 | .user("admin@internal") 38 | .password("redhat123") 39 | .trustStoreFile("truststore.jks") 40 | .build(); 41 | 42 | // Get the reference to the service that manages virtual machines: 43 | VmsService vmsService = connection.systemService().vmsService(); 44 | 45 | // Find the virtual machine: 46 | Vm vm = vmsService.list() 47 | .search("name=myvm") 48 | .send() 49 | .vms() 50 | .get(0); 51 | 52 | // When the server returns a virtual machine it will return links to related objects, like the cluster, 53 | // template and permissions something like this: 54 | // 55 | // 56 | // ... 57 | // 58 | //