├── .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 | //
59 | //
60 | // The SDK provides a "followLink" method that can be used to retrieve the complete content of these related
61 | // objects.
62 | Cluster cluster = connection.followLink(vm.cluster());
63 | Template template = connection.followLink(vm.template());
64 | List permissions = connection.followLink(vm.permissions());
65 |
66 | // Now we can use the details of the cluster, template and permissions:
67 | System.out.printf("cluster: %s\n", cluster.name());
68 | System.out.printf("template: %s\n", template.name());
69 | for (Permission permission : permissions) {
70 | System.out.printf("role: %s\n", permission.role().id());
71 | }
72 |
73 | // Close the connection to the server:
74 | connection.close();
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/sdk/src/test/java/org/ovirt/engine/sdk4/examples/ImportVm.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.storageDomain;
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.ClustersService;
26 | import org.ovirt.engine.sdk4.services.StorageDomainVmsService;
27 | import org.ovirt.engine.sdk4.services.StorageDomainsService;
28 | import org.ovirt.engine.sdk4.types.Cluster;
29 | import org.ovirt.engine.sdk4.types.StorageDomain;
30 | import org.ovirt.engine.sdk4.types.Vm;
31 |
32 | // This example will import an exported VM
33 | public class ImportVm {
34 | public static void main(String[] args) throws Exception {
35 |
36 | // Create connection to the oVirt engine 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 storage domains service
45 | StorageDomainsService storageDomainsService = connection.systemService().storageDomainsService();
46 |
47 | // Get export storage domain
48 | StorageDomain exportDomain = storageDomainsService.list()
49 | .search("name=myexport")
50 | .send()
51 | .storageDomains()
52 | .get(0);
53 |
54 | // Get target storage domain
55 | StorageDomain targetStorageDomain = storageDomainsService.list()
56 | .search("name=mydata")
57 | .send()
58 | .storageDomains()
59 | .get(0);
60 |
61 | // Get cluster service
62 | ClustersService clustersService = connection.systemService().clustersService();
63 |
64 | // Get the cluster we import the VM to
65 | Cluster cluster = clustersService.list()
66 | .search("name=mycluster")
67 | .send()
68 | .clusters()
69 | .get(0);
70 |
71 | // Get VM service for export storage domain
72 | StorageDomainVmsService vmsService = storageDomainsService
73 | .storageDomainService(exportDomain.id())
74 | .vmsService();
75 |
76 | // Get the first exported VM, assuming we have one
77 | Vm exportedVm = vmsService.list()
78 | .send()
79 | .vm()
80 | .get(0);
81 |
82 | // Import the exported VM into target storage domain, 'mydata'
83 | vmsService.vmService(exportedVm.id())
84 | .import_()
85 | .storageDomain(
86 | storageDomain()
87 | .id(targetStorageDomain.id())
88 | )
89 | .cluster(
90 | cluster()
91 | .id(cluster.id())
92 | )
93 | .vm(
94 | vm()
95 | .id(exportedVm.id())
96 | )
97 | .send();
98 |
99 | // Close the connection
100 | connection.close();
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/sdk/src/test/java/org/ovirt/engine/sdk4/examples/ListAffinityLabels.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.AffinityLabelsService;
25 | import org.ovirt.engine.sdk4.types.AffinityLabel;
26 | import org.ovirt.engine.sdk4.types.Vm;
27 |
28 | // This example will connect to the server and print the names
29 | // and virtual machines of all affinity labels in system:
30 | public class ListAffinityLabels {
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 affinity labels service:
41 | AffinityLabelsService affinityLabelsService = connection.systemService().affinityLabelsService();
42 |
43 | // Use the "list" method of the affinity labels service
44 | // to list all the affinity labels of the system:
45 | List affinityLabels = affinityLabelsService.list().send().labels();
46 |
47 | // Print all affinity labels names and virtual machines
48 | // which has assigned that affinity label:
49 | for (AffinityLabel affinityLabel : affinityLabels) {
50 | System.out.printf("%s:\n", affinityLabel.name());
51 | for (Vm vm_link : connection.followLink(affinityLabel.vms())) {
52 | System.out.printf(" - %s\n", connection.followLink(vm_link).name());
53 | }
54 | }
55 |
56 | // Close the connection to the server:
57 | connection.close();
58 | }
59 | }
--------------------------------------------------------------------------------
/sdk/src/test/java/org/ovirt/engine/sdk4/examples/ListGlanceImages.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 |
21 | import java.util.List;
22 |
23 | import org.ovirt.engine.sdk4.Connection;
24 | import org.ovirt.engine.sdk4.services.ImagesService;
25 | import org.ovirt.engine.sdk4.services.StorageDomainService;
26 | import org.ovirt.engine.sdk4.services.StorageDomainsService;
27 | import org.ovirt.engine.sdk4.services.SystemService;
28 | import org.ovirt.engine.sdk4.types.Image;
29 | import org.ovirt.engine.sdk4.types.StorageDomain;
30 |
31 | // This example will connect to the server list the images available in the 'ovirt-image-repository' Glance storge
32 | // domain that is available by default in every oVirt installation.
33 | public class ListGlanceImages {
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 root of the services tree:
44 | SystemService systemService = connection.systemService();
45 |
46 | // Find the Glance storage domain that is available for default in any oVirt installation:
47 | StorageDomainsService sdsService = systemService.storageDomainsService();
48 | StorageDomain sd = sdsService.list()
49 | .search("name=ovirt-image-repository")
50 | .send()
51 | .storageDomains()
52 | .get(0);
53 |
54 | // Find the service that manages the Glance storage domain:
55 | StorageDomainService sdService = sdsService.storageDomainService(sd.id());
56 |
57 | // Find the service that manages the images available in that storage domain:
58 | ImagesService imagesService = sdService.imagesService();
59 |
60 | // List the images available in the storage domain:
61 | List images = imagesService.list()
62 | .send()
63 | .images();
64 | for (Image image : images) {
65 | System.out.println(image.name());
66 | }
67 |
68 | // Close the connection to the server:
69 | connection.close();
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/sdk/src/test/java/org/ovirt/engine/sdk4/examples/ListHostStatistics.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 |
21 | import java.util.List;
22 |
23 | import org.ovirt.engine.sdk4.Connection;
24 | import org.ovirt.engine.sdk4.services.HostsService;
25 | import org.ovirt.engine.sdk4.types.Host;
26 | import org.ovirt.engine.sdk4.types.Statistic;
27 |
28 | // This example shows to to get host statistics.
29 | public class ListHostStatistics {
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 | // Find the host:
40 | HostsService hostsService = connection.systemService().hostsService();
41 | Host host = hostsService.list()
42 | .search("name=myhost")
43 | .send()
44 | .hosts()
45 | .get(0);
46 |
47 | // Follow the link to the statistics and print their names and values:
48 | List stats = connection.followLink(host.statistics());
49 | for (Statistic stat : stats) {
50 | System.out.printf("%s: %s\n", stat.name(), stat.values().get(0).datum());
51 | }
52 |
53 | // Close the connection to the server:
54 | connection.close();
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/sdk/src/test/java/org/ovirt/engine/sdk4/examples/ListRoles.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.RolesService;
25 | import org.ovirt.engine.sdk4.types.Role;
26 |
27 | // This example will connect to the server and then list the names and descriptions of all the available roles.
28 | public class ListRoles {
29 | public static void main(String[] args) throws Exception {
30 | // Create the connection to the server:
31 | Connection connection = connection()
32 | .url("https://engine41.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 service that manages the roles:
39 | RolesService rolesService = connection.systemService().rolesService();
40 |
41 | // Retrieve the roles:
42 | List roles = rolesService.list().send().roles();
43 |
44 | // For each role print its name and description:
45 | for (Role role : roles) {
46 | System.out.printf("%s: %s\n", role.name(), role.description());
47 | }
48 |
49 | // Close the connection to the server:
50 | connection.close();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/sdk/src/test/java/org/ovirt/engine/sdk4/examples/ListTags.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.TagsService;
25 | import org.ovirt.engine.sdk4.types.Tag;
26 |
27 | // This example will connect to the server and then list the names and descriptions of all the available tags.
28 | public class ListTags {
29 | public static void main(String[] args) throws Exception {
30 | Connection connection = connection()
31 | .url("https://engine40.example.com/ovirt-engine/api")
32 | .user("admin@internal")
33 | .password("redhat123")
34 | .trustStoreFile("truststore.jks")
35 | .build();
36 |
37 | // Find the service that manages tags:
38 | TagsService tagsService = connection.systemService().tagsService();
39 |
40 | // Retrieve the tags:
41 | List tags = tagsService.list().send().tags();
42 |
43 | // For each tag print its name and description:
44 | for (Tag tag : tags) {
45 | System.out.printf("%s: %s\n", tag.name(), tag.description());
46 | }
47 |
48 | // Close the connection to the server:
49 | connection.close();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/sdk/src/test/java/org/ovirt/engine/sdk4/examples/ListVmDisks.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.DiskAttachmentsService;
25 | import org.ovirt.engine.sdk4.services.VmService;
26 | import org.ovirt.engine.sdk4.services.VmsService;
27 | import org.ovirt.engine.sdk4.types.Disk;
28 | import org.ovirt.engine.sdk4.types.DiskAttachment;
29 | import org.ovirt.engine.sdk4.types.Vm;
30 |
31 | // This example will connect to the server and list the disks attached to a virtual machine:
32 | public class ListVmDisks {
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 "vms" service:
43 | VmsService vmsService = connection.systemService().vmsService();
44 |
45 | // Find the virtual machine:
46 | Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
47 |
48 | // Locate the service that manages the virtual machine:
49 | VmService vmService = vmsService.vmService(vm.id());
50 |
51 | // Locate the service that manages the disk attachments of the virtual machine:
52 | DiskAttachmentsService diskAttachmentsService = vmService.diskAttachmentsService();
53 |
54 | // Retrieve the list of disks attachments, and print the disk details. Note that each attachment contains a link
55 | // to the corresponding disk, but not the actual disk data. In order to retrieve the actual disk data we use the
56 | // `follow_link` method.
57 | List diskAttachments = diskAttachmentsService.list().send().attachments();
58 | for (DiskAttachment diskAttachment : diskAttachments) {
59 | Disk disk = connection.followLink(diskAttachment.disk());
60 | System.out.printf("name: %s\n", disk.name());
61 | System.out.printf("id: %s\n", disk.id());
62 | System.out.printf("status: %s\n", disk.status());
63 | System.out.printf("provisioned_size: %s\n", disk.provisionedSize());
64 | }
65 |
66 | // Close the connection to the server:
67 | connection.close();
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/sdk/src/test/java/org/ovirt/engine/sdk4/examples/ListVmTags.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 org.ovirt.engine.sdk4.Connection;
22 | import org.ovirt.engine.sdk4.services.AssignedTagsService;
23 | import org.ovirt.engine.sdk4.services.VmService;
24 | import org.ovirt.engine.sdk4.services.VmsService;
25 | import org.ovirt.engine.sdk4.types.Tag;
26 | import org.ovirt.engine.sdk4.types.Vm;
27 |
28 | // This example will connect to the server and list all tags of the virtual machine:
29 | public class ListVmTags {
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 tagsService = vmService.tagsService();
50 |
51 | // For each tag print its name and description:
52 | for (Tag tag : tagsService.list().send().tags()) {
53 | System.out.printf("%s: %s\n", tag.name(), tag.description());
54 | }
55 |
56 | // Close the connection to the server:
57 | connection.close();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/sdk/src/test/java/org/ovirt/engine/sdk4/examples/ListVms.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.Vm;
26 |
27 | // This example will connect to the server and print the names and identifiers of all the virtual machines:
28 | public class ListVms {
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 "list" method of the "vms" service to list all the virtual machines of the system:
42 | List vms = vmsService.list().send().vms();
43 |
44 | // Print the virtual machine names and identifiers:
45 | for (Vm vm : vms) {
46 | System.out.printf("%s: %s\n", vm.name(), vm.id());
47 | }
48 |
49 | // Close the connection to the server:
50 | connection.close();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/sdk/src/test/java/org/ovirt/engine/sdk4/examples/PinVm.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.host;
21 | import static org.ovirt.engine.sdk4.builders.Builders.vm;
22 | import static org.ovirt.engine.sdk4.builders.Builders.vmPlacementPolicy;
23 |
24 | import org.ovirt.engine.sdk4.Connection;
25 | import org.ovirt.engine.sdk4.services.SystemService;
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 |
30 | // This example shows how to pin a virtual machine to a host, so that it will always run in that host.
31 | public class PinVm {
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 root of the tree of services:
42 | SystemService systemService = connection.systemService();
43 |
44 | // Find the virtual machine:
45 | VmsService vmsService = systemService.vmsService();
46 | Vm vm = vmsService.list()
47 | .search("name=myvm")
48 | .send()
49 | .vms()
50 | .get(0);
51 |
52 | // Update the placement policy of the virtual machine so that it is pinned to the host:
53 | VmService vmService = vmsService.vmService(vm.id());
54 | vmService.update()
55 | .vm(
56 | vm()
57 | .placementPolicy(
58 | vmPlacementPolicy()
59 | .hosts(
60 | host()
61 | .name("myhost")
62 | )
63 | )
64 | )
65 | .send();
66 |
67 | // Close the connection to the server:
68 | connection.close();
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/sdk/src/test/java/org/ovirt/engine/sdk4/examples/RemoveHost.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 org.ovirt.engine.sdk4.Connection;
22 | import org.ovirt.engine.sdk4.services.HostService;
23 | import org.ovirt.engine.sdk4.services.HostsService;
24 | import org.ovirt.engine.sdk4.types.Host;
25 | import org.ovirt.engine.sdk4.types.HostStatus;
26 |
27 | // This example will connect to the server, search for a host by name and remove it:
28 | public class RemoveHost {
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 | // Find the service that manages hosts:
39 | HostsService hostsService = connection.systemService().hostsService();
40 |
41 | // Find the host:
42 | Host host = hostsService.list()
43 | .search("name=myhost")
44 | .send()
45 | .hosts()
46 | .get(0);
47 |
48 | // Find the service that manages the host:
49 | HostService hostService = hostsService.hostService(host.id());
50 |
51 | // If the host isn't down or in maintenance then move it to maintenance:
52 | if (host.status() != HostStatus.MAINTENANCE) {
53 | hostService.deactivate().send();
54 | }
55 |
56 | // Remove the host:
57 | hostService.remove().send();
58 |
59 | // Close the connection to the server:
60 | connection.close();
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/sdk/src/test/java/org/ovirt/engine/sdk4/examples/RemoveTag.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 org.ovirt.engine.sdk4.Connection;
22 | import org.ovirt.engine.sdk4.services.TagService;
23 | import org.ovirt.engine.sdk4.services.TagsService;
24 | import org.ovirt.engine.sdk4.types.Tag;
25 |
26 | // This example will connect to the server, search for a tag by name and remove it:
27 | public class RemoveTag {
28 | public static void main(String[] args) throws Exception {
29 | // Create the connection to the server:
30 | Connection connection = connection()
31 | .url("https://engine40.example.com/ovirt-engine/api")
32 | .user("admin@internal")
33 | .password("redhat123")
34 | .trustStoreFile("truststore.jks")
35 | .build();
36 |
37 | // Find the service that manages tags:
38 | TagsService tagsService = connection.systemService().tagsService();
39 |
40 | // Find the tag id:
41 | String tagId = null;
42 | for (Tag tag : tagsService.list().send().tags()) {
43 | if (tag.name().equals("mytag")) {
44 | tagId = tag.id();
45 | break;
46 | }
47 | }
48 |
49 | // Find the service that manages the tag:
50 | TagService tagService = tagsService.tagService(tagId);
51 |
52 | // Remove the tag:
53 | tagService.remove().send();
54 |
55 | // Close the connection to the server:
56 | connection.close();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/sdk/src/test/java/org/ovirt/engine/sdk4/examples/RemoveVm.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 org.ovirt.engine.sdk4.Connection;
22 | import org.ovirt.engine.sdk4.services.VmService;
23 | import org.ovirt.engine.sdk4.services.VmsService;
24 | import org.ovirt.engine.sdk4.types.Vm;
25 |
26 | // This example will connect to the server, search for a VM by name and remove it:
27 | public class RemoveVm {
28 | public static void main(String[] args) throws Exception {
29 | // Create the connection to the server:
30 | Connection connection = connection()
31 | .url("https://engine40.example.com/ovirt-engine/api")
32 | .user("admin@internal")
33 | .password("redhat123")
34 | .trustStoreFile("truststore.jks")
35 | .build();
36 |
37 | // Find the service that manages VMs:
38 | VmsService vmsService = connection.systemService().vmsService();
39 |
40 | // Find the VM:
41 | Vm vm = vmsService.list()
42 | .search("name=myvm")
43 | .send()
44 | .vms()
45 | .get(0);
46 |
47 | // Note that the "vm" variable that we assigned above contains only the data of the VM, it doesn't have any
48 | // method like "remove". Methods are defined in the services. So now that we have the description of the VM
49 | // we can find the service that manages it, calling the locator method "vmService" defined in the "vms"
50 | // service. This locator method receives as parameter the identifier of the VM and returns a reference to the
51 | // service that manages that VM.
52 | VmService vmService = vmsService.vmService(vm.id());
53 |
54 | // Now that we have the reference to the service that manages the VM we can use it to remove the VM. Note that
55 | // this method doesn't need any parameter, as the identifier of the VM is already known by the service that we
56 | // located in the previous step.
57 | vmService.remove().send();
58 |
59 | // Close the connection to the server:
60 | connection.close();
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/sdk/src/test/java/org/ovirt/engine/sdk4/examples/SearchVms.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.Vm;
26 |
27 | // This example will connect to the server and print the names and identifiers of the virtual machines that match a
28 | // given search criteria:
29 | public class SearchVms {
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 | // Use the "list" method of the "vms" service to search the virtual machines that match a search query:
43 | List vms = vmsService.list()
44 | .search("name=MYVM")
45 | .caseSensitive(false)
46 | .send()
47 | .vms();
48 |
49 | // Note that the format of the search query is the same that is supported by the GUI search bar.
50 |
51 | // Print the virtual machine names and identifiers:
52 | for (Vm vm : vms) {
53 | System.out.printf("%s: %s", vm.name(), vm.id());
54 | }
55 |
56 | // Close the connection to the server:
57 | connection.close();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/sdk/src/test/java/org/ovirt/engine/sdk4/examples/SetVmLeaseStorageDomain.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.highAvailability;
21 | import static org.ovirt.engine.sdk4.builders.Builders.storageDomain;
22 | import static org.ovirt.engine.sdk4.builders.Builders.storageDomainLease;
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.StorageDomainsService;
27 | import org.ovirt.engine.sdk4.services.SystemService;
28 | import org.ovirt.engine.sdk4.services.VmService;
29 | import org.ovirt.engine.sdk4.services.VmsService;
30 | import org.ovirt.engine.sdk4.types.StorageDomain;
31 | import org.ovirt.engine.sdk4.types.Vm;
32 |
33 | // This example shows how to set the storage domain where the lease of a virtual machine should be created:
34 | public class SetVmLeaseStorageDomain {
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 root of the tree of services:
45 | SystemService systemService = connection.systemService();
46 |
47 | // Find the virtual machine:
48 | VmsService vmsService = systemService.vmsService();
49 | Vm vm = vmsService.list()
50 | .search("name=myvm")
51 | .send()
52 | .vms()
53 | .get(0);
54 |
55 | // Find the storage domain:
56 | StorageDomainsService sdsService = systemService.storageDomainsService();
57 | StorageDomain sd = sdsService.list()
58 | .search("name=mydata")
59 | .send()
60 | .storageDomains()
61 | .get(0);
62 |
63 | // Update the virtual machine so that high availability is enabled and the lease is created in the selected
64 | // storage domain:
65 | VmService vmService = vmsService.vmService(vm.id());
66 | vmService.update()
67 | .vm(
68 | vm()
69 | .highAvailability(
70 | highAvailability()
71 | .enabled(true)
72 | )
73 | .lease(
74 | storageDomainLease()
75 | .storageDomain(
76 | storageDomain()
77 | .id(sd.id())
78 | )
79 | )
80 | )
81 | .send();
82 |
83 | // Close the connection to the server:
84 | connection.close();
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/sdk/src/test/java/org/ovirt/engine/sdk4/examples/StartVm.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 org.ovirt.engine.sdk4.Connection;
22 | import org.ovirt.engine.sdk4.services.VmService;
23 | import org.ovirt.engine.sdk4.services.VmsService;
24 | import org.ovirt.engine.sdk4.types.Vm;
25 | import org.ovirt.engine.sdk4.types.VmStatus;
26 |
27 | // This example will connect to the server and start a virtual machine:
28 | public class StartVm {
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 | // Find the virtual machine:
42 | Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
43 |
44 | // Locate the service that manages the virtual machine, as that is where the action methods are defined:
45 | VmService vmService = vmsService.vmService(vm.id());
46 |
47 | // Call the "start" method of the service to start it:
48 | vmService.start().send();
49 |
50 | // What till the virtual machine is up:
51 | for (;;) {
52 | Thread.sleep(5 * 1000);
53 | vm = vmService.get().send().vm();
54 | if (vm.status() == VmStatus.UP) {
55 | break;
56 | }
57 | }
58 |
59 | // Close the connection to the server:
60 | connection.close();
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/sdk/src/test/java/org/ovirt/engine/sdk4/examples/StopVm.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 org.ovirt.engine.sdk4.Connection;
22 | import org.ovirt.engine.sdk4.services.VmService;
23 | import org.ovirt.engine.sdk4.services.VmsService;
24 | import org.ovirt.engine.sdk4.types.Vm;
25 | import org.ovirt.engine.sdk4.types.VmStatus;
26 |
27 | // This example will connect to the server and stop a virtual machine:
28 | public class StopVm {
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 | // Find the virtual machine:
42 | Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
43 |
44 | // Locate the service that manages the virtual machine, as that is where the action methods are defined:
45 | VmService vmService = vmsService.vmService(vm.id());
46 |
47 | // Call the "stop" method of the service to stop it:
48 | vmService.stop().send();
49 |
50 | // What till the virtual machine is down:
51 | for (;;) {
52 | Thread.sleep(5 * 1000);
53 | vm = vmService.get().send().vm();
54 | if (vm.status() == VmStatus.DOWN) {
55 | break;
56 | }
57 | }
58 |
59 | // Close the connection to the server:
60 | connection.close();
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/sdk/src/test/java/org/ovirt/engine/sdk4/examples/UnassignTagToVm.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 org.ovirt.engine.sdk4.Connection;
22 | import org.ovirt.engine.sdk4.services.AssignedTagService;
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.Tag;
27 | import org.ovirt.engine.sdk4.types.Vm;
28 |
29 | // This example will connect to the server and unassign tag from virtual machine:
30 | public class UnassignTagToVm {
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 | // Find the virtual machine:
44 | Vm vm = vmsService.list().search("name=myvm0").send().vms().get(0);
45 |
46 | // Find the service that manages the vm:
47 | VmService vmService = vmsService.vmService(vm.id());
48 |
49 | // Locate the service that manages the tags of the vm:
50 | AssignedTagsService tagsService = vmService.tagsService();
51 |
52 | // Find the tag id:
53 | String tagId = null;
54 | for (Tag tag : tagsService.list().send().tags()) {
55 | if (tag.name().equals("mytag")) {
56 | tagId = tag.id();
57 | break;
58 | }
59 | }
60 |
61 | // Locate the service that manages the tag:
62 | AssignedTagService tagService = tagsService.tagService(tagId);
63 |
64 | // Unassign tag from virtual machine:
65 | tagService.remove().send();
66 |
67 | // Close the connection to the server:
68 | connection.close();
69 | }
70 | }
--------------------------------------------------------------------------------
/sdk/src/test/java/org/ovirt/engine/sdk4/examples/UpdateDataCenter.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.DataCenterService;
24 | import org.ovirt.engine.sdk4.services.DataCentersService;
25 | import org.ovirt.engine.sdk4.types.DataCenter;
26 |
27 | // This example will connect to the server and update the description of a data center:
28 | public class UpdateDataCenter {
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 data centers service:
39 | DataCentersService dcsService = connection.systemService().dataCentersService();
40 |
41 | // Retrieve the description of the data center:
42 | DataCenter dc = dcsService.list()
43 | .search("name=mydc")
44 | .send()
45 | .dataCenters()
46 | .get(0);
47 |
48 | // In order to update the data center we need a reference to the service that manages it, then we can call the
49 | // "update" method passing the update:
50 | DataCenterService dcService = dcsService.dataCenterService(dc.id());
51 | dc = dcService.update()
52 | .dataCenter(
53 | dataCenter()
54 | .description("Updated description")
55 | )
56 | .send()
57 | .dataCenter();
58 |
59 | // Print the description of the result of the update:
60 | System.out.printf("%s: %s", dc.name(), dc.description());
61 |
62 | // Close the connection to the server:
63 | connection.close();
64 | }
65 | }
66 |
67 |
--------------------------------------------------------------------------------
/sdk/src/test/resources/log4j.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/sdk/src/test/resources/pki/README.adoc:
--------------------------------------------------------------------------------
1 | = PKI Resources
2 |
3 | This directory contains private key files and certificates used by the
4 | tests:
5 |
6 | ca.crt:: The certificate of the CA that is used to sign all the other
7 | certificates.
8 |
9 | ca.jks:: A JKS keystore file containing the CA certificate.
10 |
11 | localhost.key:: The private key of the `localhost` certificate.
12 |
13 | localhost.crt:: The certificate for `localhost`.
14 |
15 | localhost.jks:: A key store in JKS format containing the private key and
16 | the certificate for `localhost`.
17 |
18 | localhost.p12:: A key store in PKCS12 format containing the private key and
19 | the certificate for `localhost`.
20 |
21 | ugly.key:: The private key of the `ugly` certificate.
22 |
23 | ugly.crt:: The certificate for `ugly`.
24 |
25 | ugly.jks:: A key store in JKS format containing the private key and
26 | the certificate for `ugly`.
27 |
28 | ugly.p12:: A key store in PKCS12 format containing the private key and
29 | the certificate for `ugly`.
30 |
31 | The `ugly` private key and certificate are intended for tests that
32 | check that connections to servers whose host name doesn't match the
33 | certifcate common name fail.
34 |
35 | All these certificates expire in 100 years, hopefully they will live
36 | longer than the SDK.
37 |
38 | The passwords of the JKS and PKCS12 key stores are `mypass`.
39 |
--------------------------------------------------------------------------------
/sdk/src/test/resources/pki/ca.crt:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIC+TCCAeGgAwIBAgIJAIF42K0qiqRiMA0GCSqGSIb3DQEBCwUAMBIxEDAOBgNV
3 | BAMMB2xvY2FsY2EwIBcNMTYwMzA3MTc0MTA2WhgPMjExNjAyMTIxNzQxMDZaMBIx
4 | EDAOBgNVBAMMB2xvY2FsY2EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB
5 | AQC56TRp5pdbdSL9Qjo4XiwwyI2ZF/QTy1Q9rxBA5vcdAXVInr/kwforOGAvlaUQ
6 | j7jWRg+9tKYOOJrAj57kSqlaeRdIRyE3zpeFKBjFZMbRZDqXLTGF83LFVBfchA0A
7 | rEui+/5ZSpsVU5k+/7dm6hMUejjRv72ze3OpxCUp1+sWj93mjFBCHpV37XlWSv3D
8 | 64DWq1V8y6NVLRU01yWXd7Wyl4x1mx6Qr/hLuEaoQ5HHCM6XHuSFD3kQpyhxpNxx
9 | SAXUvAtNt2l8SgeD9TuldUg1HpwKQD9j7Y1YQTrwLuvyIaG7QiTx4KGPSAiQy8Y8
10 | MkzasS64oH9jTeQv3DezCfldAgMBAAGjUDBOMB0GA1UdDgQWBBQ47O7MqlaUMmbj
11 | /hwheqIDBvkcqDAfBgNVHSMEGDAWgBQ47O7MqlaUMmbj/hwheqIDBvkcqDAMBgNV
12 | HRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQBvoStZltaAie6EliNHaUJuwHUy
13 | iYH96D6vu2hbT0ALStdkI/cpmcxqxcUWw83V9ecKp+JPUKvuhXQI9WSwrrT5ADW+
14 | yOIZkmlMzX5SWkn5gjLYWGZNAWx8wbgLI6STCXHI+F6EHZcD8Bn6cJiayBOsVwZV
15 | e++6sR1iP5bq0OBiiDoUqPeoQpwuIUatpxmI6Km9KKjgIhGoxFl64nGPz6rdrDA/
16 | 59iW1jy0b0pS3HyzkF06G8SiNTSy/9EW088AmIs3NhTFD6mG/RjrAxO1YshZNI9S
17 | g491iuwOffheGbgZhHcAwA6ByzzK2/8D4AbOefkAvhKkcrVjGpD4HhcxsamN
18 | -----END CERTIFICATE-----
19 |
--------------------------------------------------------------------------------
/sdk/src/test/resources/pki/ca.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oVirt/ovirt-engine-sdk-java/0bdd5c9fd7ccc9b83a59b9d353b12c92b79079e8/sdk/src/test/resources/pki/ca.jks
--------------------------------------------------------------------------------
/sdk/src/test/resources/pki/localhost.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oVirt/ovirt-engine-sdk-java/0bdd5c9fd7ccc9b83a59b9d353b12c92b79079e8/sdk/src/test/resources/pki/localhost.jks
--------------------------------------------------------------------------------
/sdk/src/test/resources/pki/localhost.key:
--------------------------------------------------------------------------------
1 | -----BEGIN PRIVATE KEY-----
2 | MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC9uT+7UljrtCLB
3 | AhvgRSpZHdoirK4+bILS8KMNSsjjjfv7vnVA2AkMPCfg3zmy0HwVpy3FRpYaQz9y
4 | gKuOmh5B04/QKcZ17HnT375NAzAeC70i9763zhXuV4BEVyTMBgnRV+lWku/CorqW
5 | 3CR03Hicm5sgL3HyjrnET7DhWmiN0u7sUU8XFGII0PAtlfhu0j+aPxt96HmqzgY0
6 | 6yMJFIXBJdGTSrauKSHh1nAhq6RltgP1ldNPxqZ6TvgZgGuy4BEtGCYFGd2x2l9D
7 | 5MviNeX/hSwNZM1vh21Z3jmcsUzR3XzIm3YzNKwzFiiwDXpUdn6bETpwKWCiBO0O
8 | M1VvwDu3AgMBAAECggEBAJduw5Xq9pq8H3lbC5EI4/JZx4Ehv7qHtixUcnDrnkkz
9 | TUv1C3YEecRQR6xPwKgfjMtjsz7hRnIT9xKX7VdXYIs+KG4IyiXZ6KvazPR/dOqm
10 | iALfKFVho1Ood/MUc4R91VxJBTBa/BCo/rHnaRn12Dd4ZGteM19d2Jz+1ropBYcc
11 | 0mlLHYvTdP9IO1J+2h3UmZZFpcvZmSdSlWl14thnzIrDRqVnUDPNk8sHPfjaCzEa
12 | Zb7UAH438C6qFHzVVzvJ26cqS7KYfohE+1f/vAApA+K4Y7VX2l5YSyKN2ljcMERQ
13 | agdykkLhWlh4ztHqqq6Cy5yQhyJBxILJAF1yxKb/xfECgYEA9Je6kjW6YyN44pf4
14 | /OaRJcXKdhAi8DGG9nd4T/hldpgit+2RU3ThGGbZ+hAKgejpWDXTs77VeWXd1fNC
15 | sdnrCWecmasXg0aeAuaELhG+Q9poRdSDcEhKWsGngvtBffrBYQrV4qVTenZ7UnKd
16 | JLSOyqAB/bzLhhUyleIur+G9YysCgYEAxpJrsl0TArCe7vHuUPJyzmQa7k0r4haH
17 | m8OeR+QWYmmaS5dYmRIfGLyUN1khFyhLKhB/xm11jd5VayHvcVp+TpnKRG+truTI
18 | eaAf/NM2dMeg07b6jyD7HXv4mHiM69HKrBKrEos6o5beARZjUtRPwa/PaY3nfu78
19 | ZKDC81Hpc6UCgYB2b3oCDk4gby672gbQvvyNo8azgIDKedD2S0dQweCvml9FXJ3A
20 | IZpVbIgkE9xip1tGQVovcTqBPBg83zvuTq0GsssbhcMu5+TfVquuexz8UienmI3E
21 | stx+McNhIzTFQcSdrtd+lbtkUzbH54O8IEn8R5pvORn75QvHk+wzckV4XQKBgA9p
22 | yCBFJzebPAryDnyMBStOC+UZamGXPBl0GrIb2zzyU36wlbjz9iP2Z07QhUgF4ae3
23 | NiPR1UEY0+qH7M0QqCMzvsaHIKUlrwX5zuHSBzUTVcF5P4OinLtSJx62pMGdPC0V
24 | GeBLnFacXEkbUsRYJIS1P9VCpYhtxnuNGvTGE+fdAoGADdazRIIz9ts+1lq5RWZP
25 | JI2cRcWh1ftx5jwrcv7IaPBGU9VB+qVrb1yJDNa/ITnAFYQusy/jNVAlLPVQ59Sq
26 | gIjgIVeQg07ElidcrrkTj+E1BXuPles29ePvCVz89+XPQnAWahklyuugEUIAfyH9
27 | V3BnGenWkHns5rI31w4PkDQ=
28 | -----END PRIVATE KEY-----
29 |
--------------------------------------------------------------------------------
/sdk/src/test/resources/pki/localhost.p12:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oVirt/ovirt-engine-sdk-java/0bdd5c9fd7ccc9b83a59b9d353b12c92b79079e8/sdk/src/test/resources/pki/localhost.p12
--------------------------------------------------------------------------------
/sdk/src/test/resources/pki/server.crt:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIICpjCCAY4CCQDhOu9ZcMpGjTANBgkqhkiG9w0BAQsFADAUMRIwEAYDVQQDDAls
3 | b2NhbGhvc3QwIBcNMTYwMzA3MTcyMjMxWhgPMjExMzA4MjYxNzIyMzFaMBQxEjAQ
4 | BgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
5 | AL/bgdVnw5XROOblW4n26Vkm87Pe8HNwRBXnjQOIsQM6iJcLQQRLYi4GDrCKNhGk
6 | KtzsTjf6Uk9WGC7lpJgQNwmkDbzPxdQMtzg+Y7HIlH8mECuYLzbBVyK+FNvch2Rq
7 | hfkN1EscOYWQXPK4eVLvwqZx9u0VkfVp3+6VRSWGrljhEc3HckcSNm8gMT5rYpYu
8 | LATuBh9iNx8+5EC/09ed2owLFean2yOUSKY1YbvLu0cFtsDq5eRhFJTrGzuG8iAd
9 | UnopXHMf78WAtWIsBUDyWgNvXh2cIwmRJJq24GHIpViCm9oOaF7xrlHwZ9+1T/hK
10 | GVXEjCNl4XHVeORv7wFj1p0CAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAAqYHKRP5
11 | 3gJLSWmczZmc299N/1ECHrxpzmiBEHcq+r+8/vYSPlVReS8c+9hUeQhGJqveqmLu
12 | XvjnN1JOXwKDu2riS88S0X31dsdTX7yFKqIR7AsCT50KfLh6BifTlc4NB4EYQgXA
13 | Y2VpN+elIxhGupaOgx7qeN+hBt1mq3wGnw5VAmygpgX8caHjn+HFlBLSDBfrKxmq
14 | rF8g10PcXq+v7Zlo/FPxbxLLTRoeDjwuOTrMCahXblJOPrDs29Vtiq7Dfs/NxWt/
15 | UF3S37rh7oSepB/yzJkLwH8zJPz5u1npoBLG9wNBx5SK8a9bqeNAc0MLzUDhGfVM
16 | nK+ILXDLBvkQHg==
17 | -----END CERTIFICATE-----
18 |
--------------------------------------------------------------------------------
/sdk/src/test/resources/pki/server.key:
--------------------------------------------------------------------------------
1 | -----BEGIN RSA PRIVATE KEY-----
2 | MIIEpAIBAAKCAQEAv9uB1WfDldE45uVbifbpWSbzs97wc3BEFeeNA4ixAzqIlwtB
3 | BEtiLgYOsIo2EaQq3OxON/pST1YYLuWkmBA3CaQNvM/F1Ay3OD5jsciUfyYQK5gv
4 | NsFXIr4U29yHZGqF+Q3USxw5hZBc8rh5Uu/CpnH27RWR9Wnf7pVFJYauWOERzcdy
5 | RxI2byAxPmtili4sBO4GH2I3Hz7kQL/T153ajAsV5qfbI5RIpjVhu8u7RwW2wOrl
6 | 5GEUlOsbO4byIB1Seilccx/vxYC1YiwFQPJaA29eHZwjCZEkmrbgYcilWIKb2g5o
7 | XvGuUfBn37VP+EoZVcSMI2XhcdV45G/vAWPWnQIDAQABAoIBAEuwjq0hbaDqVLeK
8 | 3q00MuUQH+7jUhtIvCOkIRa205bBfeeQ8gp+rvIXQ65UKHaXPK3BsC4XXGeeQJYn
9 | 1OKE6yGrjhviIFrC1Xmj63LU/fiXjKOWO3Ivnm+/a709aFCuUcJquUkUjoDp7jF3
10 | o62bl0BRD6iC7P1T0ptuWkQuuROosDXodNjroJ6kAtUIuuOzi669wTpFC14dLRf3
11 | pkI1iyKXIcWYXRWF0kJTb/HySk0UU4qdvoV2J5l99HdQhZw6a/8QZO9P5wSRyEzB
12 | OHgsIfu15hc0jmeeE5GfGVt7F1y0LXyZw5dbeYj7s9o3VEUjfjItK0r6KFYuicUk
13 | 1kmZ6EUCgYEA7VN3FNc5fBn6qbe95QMD3nTAiNjX0xBhL0UtwSsOd+aoG4JqaSsw
14 | N5R+4tPLmJ+BoEpNK/ymAR/jcpKzm88rNJNz3841q/tRTLEgP8bVzk4AVQ3UZ8ig
15 | kmFK8ttlAvppZnN+4FvKmk50Q5v+FAXdB/S6u3S9vZsBrciZcSGjZIMCgYEAzvQn
16 | U4MSAwkltnzjuyMoF1cmvzBRuA9L25EiJUUui+dbWbb8BSU5qUgTDROGTnHI740w
17 | PEZIPUEcjRdk8AcPuD0vBC/fYULxvpcwN1Q5D2YGoJxsPJp+LcSZPJn6xTZojmqJ
18 | 3aXpJ/NQSkRMUwCtLQv41u221J1rnxw1RfTmLl8CgYAV9KXMoMipqYGeF+iSej/u
19 | YaC6SE1XMmm7RMwh1cjl4MnmmZ8ckalJSwyeEXgBa6hDWvxeuGXnLrsNC3NgU78s
20 | gwOyTdJ7UanIzY4tOEjpaB/xvnDLFS19vVCAvTlQGDiOCNtRCEzrD50D8DeGRLCZ
21 | HtPzqa4wD1oNaMSBSdpi3wKBgQCnr7EFu9gmWY0TNlKX2T6s2tLsa0xrpQlEGW7f
22 | YBT9CzM7mEbQLH9yKJI3MDDM8ulrIK2KyS/TYiSuNdx1mGMmV3z3GYsYFdQnJ/3L
23 | dxTc40BPdy9EU7IVh4zaS7Gjhhhl/PFEhSBMXJwb8Qce4hdvvpmcHPTdhcgkHgkU
24 | bADuZQKBgQCy+98Z1AOh8ht8iS5EAewmU1eZhh2EALx4yoq55HhBR7wWc1g9f17m
25 | H0EAiDEFAJsd8dxM4uS+GyQ/imJGFKKJp8f2Xnvig0sEgEodNm2mRrsxi/kD6M6T
26 | 11zOJE8gKSAhOoMpEVcKg4XYVswxFJ6d63KmbC8qBboHVd4zNC+Jog==
27 | -----END RSA PRIVATE KEY-----
28 |
--------------------------------------------------------------------------------
/sdk/src/test/resources/pki/ugly.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oVirt/ovirt-engine-sdk-java/0bdd5c9fd7ccc9b83a59b9d353b12c92b79079e8/sdk/src/test/resources/pki/ugly.jks
--------------------------------------------------------------------------------
/sdk/src/test/resources/pki/ugly.key:
--------------------------------------------------------------------------------
1 | -----BEGIN PRIVATE KEY-----
2 | MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCVMXkCYQnoBTxO
3 | IlnzzYTaKc5MFRQZNZhlAKm53I09W+ohbr91cZIYeQiUWOrc/PUqyXBasmxApUsh
4 | GfF6OEbOD40DzV7hqd20cHYU2+E+9Qius+Tzrxm9Y0/0PGPlJFsFnXtiPToA221u
5 | ZtVKdEz+HyxK/z4w3basuMWBOsEWyREkPQ9m1hLKzVsliNYWZj0CQaeBmo5t/Glf
6 | yRVm8srw1HMiul8VwlVhE1AjBfPXFDAH58Qgb416o56JGlBkQzlNJew+D2mQKx7N
7 | lueVjRu3mGTS9u1ac3pHSpvb9T5TyfxjCvWGizb+82qQYVE7WfJK0zyGCCwxHxam
8 | WC3ymKA5AgMBAAECggEADz7b98NEyOHoFK/r8z74KXcGLr4krKLObNvRfD2ubSu8
9 | VChGBlFRtZCAsPAZJ/Xtc67b/VioOT7q23oUNAIWMi5ioZXV8UdzcWHgnycM8GsH
10 | tRqK9d/ZyIGihPm614qMhpleJ17MU5QYraRyfUY/K+SxmQRWLZYqeaH0BM2lN5ey
11 | aJXLREjUpyPtpPPlshLVKTHrbP7keCIRjxYWvDnyz0xlXm2zQzreWJTew3oMcVtG
12 | ymkZ3CCWPZz5KYAJt/WshyAGqi3n+JG1H9u0FIXGbZZu278cWCIUDzX40kfo47ty
13 | v3iWf2yPYVjpbQWqja+69DPSO+qnKELIx3O4NKYtEQKBgQDEUztrdBY7sKHrxH72
14 | ySJb6W4f52UtlxL7BRYR9H0J4mOfudUblyArbzrMWtfxUxqcpgv15V7za8emlQQU
15 | qVdGBRKkDtu38/r8zyaDzh+atoWEjkz+wJylTTZls3yUFmCYKusYdvhLRoRaPIGW
16 | 4MpzLpkpZGSJjsuEwedxPk30pQKBgQDCir04rtFjbmXQhBwBP2g5KzW/OXwAldSc
17 | ERbd5aWwMHQ9m8WWBwThOLVo+OMNNA4PK5TsktCY51NH3beJ+qEpV0Sjze7Xx6AI
18 | PwJqa/VSstSM7bNe0semGcRk7+gzwLSQVdAzmq0mvrrf75p6gLMFtPLXxr3ul7Or
19 | MGBjsyslBQKBgHfrGy1scDQvlQgtMxxNCUa5FAI61kt9ryNTHQMEoufJt+6VlT1Q
20 | F19QhsrSZnrKt0OeDUo6u7/WQtJWzXJNabikWpmJVd5MEjAf3DfATP+0o2OvhApL
21 | 3qL9wc9nTh4qeQAZnxaHfOyF+0wfD0z4q9ClUvq8jsiTR28k/djnJLjdAoGBAK1F
22 | KuGIewCHfHFqqRLHacm5XaaSyYov6OyUH/zFJHy3u2CAFEzatZLvkkwLmRbSbU8/
23 | ruXCob3+EuPoayeerdoHWyBWM8vGhheyHzGwNBFTLBLVR7RGIgIj4xNPxk4J7gi8
24 | FbNQqbXfnMwFOV6wsEJ99ukOn24ZebIYZVGHa/8NAoGBAIyEoyezSEg1xaPUSWQF
25 | UxIqSr/wYUg2c369WBpKW9b3uNC1mfxfVOljPbhUOTce36h7s/IRLD9NDsYX3pQC
26 | qFsuR/an+KEDKJ0gN4BmHnU6N9+8q5GpGEAVvxtilL82VJBYsA0TC8JKSlu9uhXG
27 | ZUKpXXXYSdtcnDsiKhVah5Xz
28 | -----END PRIVATE KEY-----
29 |
--------------------------------------------------------------------------------
/sdk/src/test/resources/pki/ugly.p12:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oVirt/ovirt-engine-sdk-java/0bdd5c9fd7ccc9b83a59b9d353b12c92b79079e8/sdk/src/test/resources/pki/ugly.p12
--------------------------------------------------------------------------------