├── .automation ├── build-rpm.sh ├── build-srpm.sh └── generate-setup-files.sh ├── .copr └── Makefile ├── .github ├── CODEOWNERS └── workflows │ ├── build.yaml │ └── tests.yaml ├── .gitignore ├── CHANGES.adoc ├── LICENSE.txt ├── MANIFEST.in ├── PKG-INFO.in ├── README.adoc ├── examples ├── add_affinity_label.py ├── add_bond.py ├── add_cluster.py ├── add_data_center.py ├── add_disks.py ├── add_fence_agent.py ├── add_floating_disk.py ├── add_group.py ├── add_host.py ├── add_independet_vm.py ├── add_instance_type.py ├── add_iscsi_data_storage_domain.py ├── add_logical_network.py ├── add_lun_disk_to_vm.py ├── add_mac_pool.py ├── add_nfs_data_storage_domain.py ├── add_nfs_iso_storage_domain.py ├── add_openstack_image_provider.py ├── add_role.py ├── add_tag.py ├── add_template.py ├── add_user_ssh_public_key.py ├── add_vm.py ├── add_vm_disk.py ├── add_vm_from_template_version.py ├── add_vm_nic.py ├── add_vm_pool.py ├── add_vm_snapshot.py ├── add_vm_with_sysprep.py ├── add_vnc_console.py ├── assign_affinity_label_to_vm.py ├── assign_network_to_cluster.py ├── assign_permission.py ├── assign_permission_to_vms.py ├── assign_tag_to_vm.py ├── asynchronous_inventory.py ├── attach_nfs_data_storage_domain.py ├── attach_nfs_iso_storage_domain.py ├── backup_vm.py ├── cancel_transfer.py ├── change_host_cluster.py ├── change_master.py ├── change_vm_cd.py ├── checkpoints.py ├── checksum_disk.py ├── checksum_image.py ├── clone_vm_from_snapshot.py ├── connection_builder.py ├── data_center_maintenance.py ├── deactivate_disk_attachment.py ├── delete_disks.py ├── disable_compression.py ├── download_disk.py ├── download_disk_snapshot.py ├── download_vm_ovf.py ├── enable_serial_console.py ├── export_template.py ├── export_template_as_ova.py ├── export_vm.py ├── export_vm_as_ova.py ├── extend_disk.py ├── fix_dup_nic_macs.py ├── follow_vm_links.py ├── get_display_ticket.py ├── get_vm_ip.py ├── helpers │ ├── __init__.py │ ├── common.py │ ├── imagetransfer.py │ ├── jobs.py │ └── units.py ├── image_transfer.py ├── import_glance_image.py ├── import_template_from_ova.py ├── import_vm.py ├── import_vm_from_ova.py ├── import_vm_from_vmware.py ├── list_affinity_labels.py ├── list_cluster_networks.py ├── list_disk_snapshots.py ├── list_glance_images.py ├── list_host_statistics.py ├── list_roles.py ├── list_storage_domains.py ├── list_tags.py ├── list_tags_of_vm.py ├── list_vm_disks.py ├── list_vm_snapshots.py ├── list_vms.py ├── ovirt.conf ├── page_vms.py ├── pin_vm.py ├── poll_events.py ├── print_vm_mac_duplicates.py ├── reduce_disk.py ├── register_vm.py ├── remove_host.py ├── remove_numa_nodes_from_vm.py ├── remove_tag.py ├── remove_vm.py ├── reprovision_stateless_vm_in_pool.py ├── search_vms.py ├── set_vm_lease_storage_domain.py ├── set_vm_serial_number.py ├── show_summary.py ├── sparsify_disk.py ├── start_vm.py ├── start_vm_with_boot_devices.py ├── start_vm_with_cloud_init.py ├── stop_vm.py ├── test_connection.py ├── unassign_tag_to_vm.py ├── update_data_center.py ├── update_fencing_options.py ├── update_quota_limits.py ├── upgrade_host.py ├── upload_disk.py ├── upload_from_ova.py ├── upload_ova_as_vm_or_template.py └── vm_backup.py ├── ext ├── ov_xml_module.c ├── ov_xml_module.h ├── ov_xml_reader.c ├── ov_xml_reader.h ├── ov_xml_utils.c ├── ov_xml_utils.h ├── ov_xml_writer.c ├── ov_xml_writer.h └── xml.c ├── lib └── ovirtsdk4 │ ├── __init__.py │ ├── http.py │ ├── reader.py │ ├── readers.py │ ├── service.py │ ├── services.py │ ├── types.py │ ├── version.py.in │ ├── writer.py │ └── writers.py ├── pdoc └── custom.css ├── python-ovirt-engine-sdk4.spec.in ├── setup.py.in ├── tests ├── __init__.py ├── pki │ ├── README.adoc │ ├── ca.crt │ ├── localhost.crt │ ├── localhost.key │ ├── server.crt │ ├── server.key │ ├── ugly.crt │ └── ugly.key ├── server.py ├── test_affinity_group_reader.py ├── test_check_types.py ├── test_cluster_reader.py ├── test_cluster_service.py ├── test_connection_create.py ├── test_connection_error.py ├── test_datacenter_service.py ├── test_enum.py ├── test_fault_reader.py ├── test_invalid_authentication.py ├── test_iscsi_discover.py ├── test_network_reader.py ├── test_network_writer.py ├── test_read_link.py ├── test_reader.py ├── test_setupnetworks.py ├── test_sso_writer.py ├── test_storage_domain_service.py ├── test_vm_reader.py ├── test_vm_service.py ├── test_writer.py ├── test_xml_reader.py └── test_xml_writer.py └── tox.ini /.automation/build-rpm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | source $(dirname "$(readlink -f "$0")")/build-srpm.sh 4 | 5 | # Install build dependencies 6 | dnf builddep -y rpmbuild/SRPMS/*src.rpm 7 | 8 | # Build binary package 9 | rpmbuild \ 10 | --define "_topmdir rpmbuild" \ 11 | --define "_rpmdir rpmbuild" \ 12 | --rebuild rpmbuild/SRPMS/*src.rpm 13 | 14 | # Move RPMs to exported artifacts 15 | [[ -d $ARTIFACTS_DIR ]] || mkdir -p $ARTIFACTS_DIR 16 | find rpmbuild -iname \*rpm | xargs mv -t $ARTIFACTS_DIR 17 | cp $TARBALL $ARTIFACTS_DIR 18 | -------------------------------------------------------------------------------- /.automation/build-srpm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | source $(dirname "$(readlink -f "$0")")/generate-setup-files.sh 4 | 5 | TARBALL="ovirt-engine-sdk-python-${PACKAGE_VERSION}.tar.gz" 6 | 7 | find . -not -name '*.spec' -not -name '*.in' -not -name ${TARBALL} -type f \ 8 | | tar --files-from /proc/self/fd/0 -czf "${TARBALL}" python-ovirt-engine-sdk4.spec 9 | 10 | # Directory, where build artifacts will be stored, should be passed as the 1st parameter 11 | ARTIFACTS_DIR=${1:-exported-artifacts} 12 | 13 | # Prepare source archive 14 | [[ -d rpmbuild ]] || mkdir -p rpmbuild 15 | 16 | rpmbuild \ 17 | -D "_topdir rpmbuild" \ 18 | -ts ${TARBALL} 19 | -------------------------------------------------------------------------------- /.automation/generate-setup-files.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | VERSION="4.6.3" 4 | MILESTONE=master 5 | # MILESTONE= 6 | RPM_RELEASE="0.1.$MILESTONE.$(date -u +%Y%m%d%H%M%S)" 7 | # RPM_RELEASE=1 8 | 9 | PACKAGE_NAME="python-ovirt-engine-sdk4" 10 | 11 | RPM_VERSION=${VERSION} 12 | PACKAGE_VERSION=${VERSION} 13 | [ -n "${MILESTONE}" ] && PACKAGE_VERSION+="_${MILESTONE}" 14 | 15 | GENERATED_FILES=" 16 | lib/ovirtsdk4/version.py 17 | setup.py 18 | PKG-INFO 19 | python-ovirt-engine-sdk4.spec 20 | " 21 | 22 | for gen_file in ${GENERATED_FILES} ; do 23 | sed \ 24 | -e "s|@RPM_VERSION@|${RPM_VERSION}|g" \ 25 | -e "s|@RPM_RELEASE@|${RPM_RELEASE}|g" \ 26 | -e "s|@PACKAGE_NAME@|${PACKAGE_NAME}|g" \ 27 | -e "s|@PACKAGE_VERSION@|${PACKAGE_VERSION}|g" \ 28 | < ${gen_file}.in > ${gen_file} 29 | done 30 | 31 | -------------------------------------------------------------------------------- /.copr/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: installdeps srpm 2 | 3 | installdeps: 4 | dnf -y install git gzip python3-devel rpm-build sed 5 | 6 | srpm: installdeps 7 | ./.automation/build-srpm.sh 8 | cp rpmbuild/SRPMS/*.src.rpm $(outdir) 9 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # https://help.github.com/en/articles/about-code-owners 2 | # Default reviewers for everything 3 | * @oliel @mnecas 4 | -------------------------------------------------------------------------------- /.github/workflows/tests.yaml: -------------------------------------------------------------------------------- 1 | name: tests 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | branches: [main] 8 | workflow_dispatch: 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | strategy: 14 | matrix: 15 | include: 16 | - name: centos-stream-9 17 | shortcut: c9s 18 | container-name: el9stream 19 | packages: 20 | - gcc 21 | - libxml2-devel 22 | - python3 23 | - python3-pip 24 | - python3-devel 25 | - python3-setuptools 26 | - python3.11 27 | - python3.11-pip 28 | - python3.11-devel 29 | - python3.11-setuptools 30 | - python3.12 31 | - python3.12-pip 32 | - python3.12-devel 33 | - python3.12-setuptools 34 | - name: centos-stream-10 35 | shortcut: c10s 36 | container-name: el10stream 37 | packages: 38 | - gcc 39 | - libxml2-devel 40 | - python3 41 | - python3-pip 42 | - python3-devel 43 | - python3-setuptools 44 | 45 | name: ${{ matrix.name }} 46 | 47 | container: 48 | image: quay.io/ovirt/buildcontainer:${{ matrix.container-name }} 49 | 50 | steps: 51 | - name: Checkout sources 52 | uses: ovirt/checkout-action@main 53 | 54 | - name: Install dependencies 55 | run: | 56 | dnf install -y ${{ join(matrix.packages, ' ') }} 57 | python3 -m venv /venv 58 | source /venv/bin/activate 59 | python3 -m pip install tox 60 | 61 | - name: Run tests 62 | run: | 63 | source /venv/bin/activate 64 | .automation/generate-setup-files.sh 65 | tox -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated files 2 | PKG-INFO 3 | setup.py 4 | version.py 5 | 6 | # Byte-compiled / optimized / DLL files 7 | __pycache__/ 8 | *.py[cod] 9 | *$py.class 10 | 11 | # C extensions 12 | *.so 13 | 14 | # Distribution / packaging 15 | .Python 16 | build/ 17 | develop-eggs/ 18 | dist/ 19 | downloads/ 20 | eggs/ 21 | .eggs/ 22 | lib/ 23 | lib64/ 24 | parts/ 25 | sdist/ 26 | var/ 27 | wheels/ 28 | share/python-wheels/ 29 | *.egg-info/ 30 | .installed.cfg 31 | *.egg 32 | MANIFEST 33 | 34 | # PyInstaller 35 | # Usually these files are written by a python script from a template 36 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 37 | *.manifest 38 | *.spec 39 | 40 | # Installer logs 41 | pip-log.txt 42 | pip-delete-this-directory.txt 43 | 44 | # Unit test / coverage reports 45 | htmlcov/ 46 | .tox/ 47 | .nox/ 48 | .coverage 49 | .coverage.* 50 | .cache 51 | nosetests.xml 52 | coverage.xml 53 | *.cover 54 | *.py,cover 55 | .hypothesis/ 56 | .pytest_cache/ 57 | cover/ -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE.txt 2 | include README.adoc 3 | recursive-include ext *.c *.h 4 | recursive-include examples *.py 5 | -------------------------------------------------------------------------------- /PKG-INFO.in: -------------------------------------------------------------------------------- 1 | Metadata-Version: 1.1 2 | Name: ovirt-engine-sdk-python 3 | Version: @RPM_VERSION@ 4 | Summary: Python SDK for oVirt Engine API 5 | Home-page: UNKNOWN 6 | Author: Michael Pasternak, Juan Hernandez, Ondra Machacek, Ori Liel, Martin Necas 7 | Author-email: mishka8520@yahoo.com, juan.hernandez@redhat.com, omachace@redhat.com, oliel@redhat.com, mnecas@redhat.com 8 | License: ASL2 9 | Description: UNKNOWN 10 | Platform: UNKNOWN 11 | Classifier: Development Status :: 5 - Production/Stable 12 | Classifier: Environment :: Console 13 | Classifier: Intended Audience :: Developers 14 | Classifier: Intended Audience :: System Administrators 15 | Classifier: License :: OSI Approved :: Apache Software License 16 | Classifier: Operating System :: OS Independent 17 | Classifier: Programming Language :: Python :: 2.7 18 | Classifier: Programming Language :: Python :: 3 19 | -------------------------------------------------------------------------------- /examples/add_affinity_label.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example will connect to the server and create a new affinity label: 28 | 29 | # Create the connection to the server: 30 | connection = sdk.Connection( 31 | url='https://engine40.example.com/ovirt-engine/api', 32 | username='admin@internal', 33 | password='redhat123', 34 | ca_file='ca.pem', 35 | debug=True, 36 | log=logging.getLogger(), 37 | ) 38 | 39 | # Get the reference to the affinity labels service: 40 | affinity_labels_service = connection.system_service().affinity_labels_service() 41 | 42 | # Use the "add" method to create a affinity label: 43 | affinity_labels_service.add( 44 | types.AffinityLabel( 45 | name='my_affinity_label', 46 | ), 47 | ) 48 | 49 | # Close the connection to the server: 50 | connection.close() 51 | -------------------------------------------------------------------------------- /examples/add_cluster.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example will connect to the server and create a new cluster: 28 | 29 | # Create the connection to the server: 30 | connection = sdk.Connection( 31 | url='https://engine40.example.com/ovirt-engine/api', 32 | username='admin@internal', 33 | password='redhat123', 34 | ca_file='ca.pem', 35 | debug=True, 36 | log=logging.getLogger(), 37 | ) 38 | 39 | # Get the reference to the clusters service: 40 | clusters_service = connection.system_service().clusters_service() 41 | 42 | # Use the "add" method to create a cluster: 43 | clusters_service.add( 44 | types.Cluster( 45 | name='mycluster', 46 | description='My cluster', 47 | cpu=types.Cpu( 48 | architecture=types.Architecture.X86_64, 49 | type='Intel Conroe Family', 50 | ), 51 | data_center=types.DataCenter( 52 | name='mydc', 53 | ), 54 | ), 55 | ) 56 | 57 | # Close the connection to the server: 58 | connection.close() 59 | -------------------------------------------------------------------------------- /examples/add_data_center.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example will connect to the server and create a new data center: 28 | 29 | # Create the connection to the server: 30 | connection = sdk.Connection( 31 | url='https://engine40.example.com/ovirt-engine/api', 32 | username='admin@internal', 33 | password='redhat123', 34 | ca_file='ca.pem', 35 | debug=True, 36 | log=logging.getLogger(), 37 | ) 38 | 39 | # Get the reference to the data centers service: 40 | dcs_service = connection.system_service().data_centers_service() 41 | 42 | # Use the "add" method to create a new data center: 43 | dc = dcs_service.add( 44 | types.DataCenter( 45 | name='mydc', 46 | description='My data center', 47 | local=False, 48 | ), 49 | ) 50 | 51 | # Close the connection to the server: 52 | connection.close() 53 | -------------------------------------------------------------------------------- /examples/add_floating_disk.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | import time 25 | 26 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 27 | 28 | # This example will connect to the server and create a new `floating` 29 | # disk, one that isn't attached to any virtual machine. 30 | 31 | # Create the connection to the server: 32 | connection = sdk.Connection( 33 | url='https://engine40.example.com/ovirt-engine/api', 34 | username='admin@internal', 35 | password='redhat123', 36 | ca_file='ca.pem', 37 | debug=True, 38 | log=logging.getLogger() 39 | ) 40 | 41 | # Get the reference to the disks service: 42 | disks_service = connection.system_service().disks_service() 43 | 44 | # Add the disk. Note that the size of the disk, the `provisioned_size` 45 | # attribute, is specified in bytes, so to create a disk of 10 GiB the 46 | # value should be 10 * 2^30. 47 | disk = disks_service.add( 48 | types.Disk( 49 | name='mydisk', 50 | description='My disk', 51 | format=types.DiskFormat.COW, 52 | provisioned_size=10 * 2**30, 53 | storage_domains=[ 54 | types.StorageDomain( 55 | name='mydata' 56 | ) 57 | ] 58 | ) 59 | ) 60 | 61 | # Wait till the disk is completely created: 62 | disk_service = disks_service.disk_service(disk.id) 63 | while True: 64 | time.sleep(5) 65 | disk = disk_service.get() 66 | if disk.status == types.DiskStatus.OK: 67 | break 68 | 69 | # Close the connection to the server: 70 | connection.close() 71 | -------------------------------------------------------------------------------- /examples/add_group.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example will connect to the server and add a group from a directory service: 28 | # Create the connection to the server: 29 | connection = sdk.Connection( 30 | url='https://engine40.example.com/ovirt-engine/api', 31 | username='admin@internal', 32 | password='redhat123', 33 | ca_file='ca.pem', 34 | debug=True, 35 | log=logging.getLogger(), 36 | ) 37 | 38 | # Get the reference to the groups service: 39 | groups_service = connection.system_service().groups_service() 40 | 41 | # Use the "add" method to add group from a directory service. 42 | # Please note that domain name is name of the authorization provider (authz): 43 | group = groups_service.add( 44 | types.Group( 45 | name='mygroup', 46 | domain=types.Domain( 47 | name='internal-authz' 48 | ), 49 | ), 50 | ) 51 | 52 | # Close the connection to the server: 53 | connection.close() 54 | -------------------------------------------------------------------------------- /examples/add_host.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | import time 22 | 23 | import ovirtsdk4 as sdk 24 | import ovirtsdk4.types as types 25 | 26 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 27 | 28 | # This example will connect to the server and add a new host: 29 | # Create the connection to the server: 30 | connection = sdk.Connection( 31 | url='https://engine40.example.com/ovirt-engine/api', 32 | username='admin@internal', 33 | password='redhat123', 34 | ca_file='ca.pem', 35 | debug=True, 36 | log=logging.getLogger(), 37 | ) 38 | 39 | # Get the reference to the hosts service: 40 | hosts_service = connection.system_service().hosts_service() 41 | 42 | # Add the host: 43 | host = hosts_service.add( 44 | types.Host( 45 | name='myhost', 46 | description='My host', 47 | address='node40.example.com', 48 | root_password='redhat123', 49 | cluster=types.Cluster( 50 | name='mycluster', 51 | ), 52 | ), 53 | ) 54 | 55 | # Wait till the host is up: 56 | host_service = hosts_service.host_service(host.id) 57 | while True: 58 | time.sleep(5) 59 | host = host_service.get() 60 | if host.status == types.HostStatus.UP: 61 | break 62 | 63 | # Close the connection to the server: 64 | connection.close() 65 | -------------------------------------------------------------------------------- /examples/add_independet_vm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 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 | 31 | # Create the connection to the server: 32 | connection = sdk.Connection( 33 | url='https://engine40.example.com/ovirt-engine/api', 34 | username='admin@internal', 35 | password='redhat123', 36 | ca_file='ca.pem', 37 | debug=True, 38 | log=logging.getLogger(), 39 | ) 40 | 41 | # Get the reference to the "vms" service: 42 | vms_service = connection.system_service().vms_service() 43 | 44 | # Use the "clone" parameter of the "add" method to request that the 45 | # disks of the new virtual machine are independent of the template. 46 | vms_service.add( 47 | types.Vm( 48 | name='myclonedvm', 49 | cluster=types.Cluster( 50 | name='mycluster', 51 | ), 52 | template=types.Template( 53 | name='mytemplate', 54 | ), 55 | ), 56 | clone=True, 57 | ) 58 | 59 | # Close the connection to the server: 60 | connection.close() 61 | -------------------------------------------------------------------------------- /examples/add_instance_type.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example will connect to the server and create a new instance type: 28 | 29 | # Create the connection to the server: 30 | connection = sdk.Connection( 31 | url='https://engine40.example.com/ovirt-engine/api', 32 | username='admin@internal', 33 | password='redhat123', 34 | ca_file='ca.pem', 35 | debug=True, 36 | log=logging.getLogger(), 37 | ) 38 | 39 | # Get the reference to the instance types service: 40 | instance_types_service = connection.system_service().instance_types_service() 41 | 42 | # Add the instance type. Note that the size of the memory, the `memory` 43 | # attribute, is specified in bytes, so to create a instance type with 44 | # 2 GiB of memory the value should be 2 * 2^30. 45 | instance_types_service.add( 46 | types.InstanceType( 47 | name='myinstancetype', 48 | description='My instance type', 49 | memory=2 * 2**30, 50 | high_availability=types.HighAvailability( 51 | enabled=True, 52 | ), 53 | cpu=types.Cpu( 54 | topology=types.CpuTopology( 55 | cores=2, 56 | sockets=2, 57 | ), 58 | ), 59 | ), 60 | ) 61 | 62 | # Close the connection to the server: 63 | connection.close() 64 | -------------------------------------------------------------------------------- /examples/add_logical_network.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2017 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example will connect to the server and create new logical network. 28 | 29 | # Create the connection to the server: 30 | connection = sdk.Connection( 31 | url='https://engine40.example.com/ovirt-engine/api', 32 | username='admin@internal', 33 | password='redhat123', 34 | ca_file='ca.pem', 35 | debug=True, 36 | log=logging.getLogger(), 37 | ) 38 | 39 | # Get the reference to the networks service: 40 | networks_service = connection.system_service().networks_service() 41 | 42 | # Use the "add" method to create new VM logical network in data center 43 | # called "mydc", with VLAN tag 100 and MTU 1500. 44 | network = networks_service.add( 45 | network=types.Network( 46 | name='mynetwork', 47 | description='My logical network', 48 | data_center=types.DataCenter( 49 | name='mydc' 50 | ), 51 | vlan=types.Vlan(id='100'), 52 | usages=[types.NetworkUsage.VM], 53 | mtu=1500, 54 | ), 55 | ) 56 | 57 | # Close the connection to the server: 58 | connection.close() 59 | -------------------------------------------------------------------------------- /examples/add_lun_disk_to_vm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2017 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example will connect to the server and add LUN disk to virtual machine 28 | 29 | # Create the connection to the server: 30 | connection = sdk.Connection( 31 | url='https://engine/ovirt-engine/api', 32 | username='admin@internal', 33 | password='123456', 34 | ca_file='ca.pem', 35 | debug=True, 36 | log=logging.getLogger(), 37 | ) 38 | 39 | # Locate the virtual machines service and use it to find the virtual 40 | # machine: 41 | vms_service = connection.system_service().vms_service() 42 | vm = vms_service.list(search='name=myvm')[0] 43 | 44 | # Locate the service that manages the disk attachments of the virtual 45 | # machine: 46 | disk_attachments_service = vms_service.vm_service(vm.id).disk_attachments_service() 47 | 48 | # Use the "add" method of the disk attachments service to add the LUN disk. 49 | disk_attachment = disk_attachments_service.add( 50 | types.DiskAttachment( 51 | disk=types.Disk( 52 | name='myiscsidisk', 53 | lun_storage=types.HostStorage( 54 | type=types.StorageType.ISCSI, 55 | logical_units=[ 56 | types.LogicalUnit( 57 | address='192.168.1.1', 58 | port=3260, 59 | target='iqn.2017-05.org.ovirt:storage', 60 | id='36001405d6c6cbba754c4b568d843ff6a', 61 | username='username', 62 | password='password', 63 | ) 64 | ], 65 | ), 66 | ), 67 | interface=types.DiskInterface.VIRTIO, 68 | bootable=False, 69 | active=True, 70 | ), 71 | ) 72 | 73 | # Close the connection to the server: 74 | connection.close() 75 | -------------------------------------------------------------------------------- /examples/add_mac_pool.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example will connect to the server, create a new MAC address pool 28 | # and assign it to a clusterr: 29 | 30 | # Create the connection to the server: 31 | connection = sdk.Connection( 32 | url='https://engine41.example.com/ovirt-engine/api', 33 | username='admin@internal', 34 | password='redhat123', 35 | ca_file='ca.pem', 36 | debug=True, 37 | log=logging.getLogger(), 38 | ) 39 | 40 | # Get the reference to the service that manages the MAC address pools: 41 | pools_service = connection.system_service().mac_pools_service() 42 | 43 | # Add a new MAC pool: 44 | pool = pools_service.add( 45 | types.MacPool( 46 | name='mymacpool', 47 | ranges=[ 48 | types.Range( 49 | from_='02:00:00:00:00:00', 50 | to='02:00:00:01:00:00', 51 | ), 52 | ], 53 | ), 54 | ) 55 | 56 | # Find the service that manages clusters, as we need it in order to 57 | # find the cluster where we want to set the MAC pool: 58 | clusters_service = connection.system_service().clusters_service() 59 | 60 | # Find the cluster: 61 | cluster = clusters_service.list(search='name=mycluster')[0] 62 | 63 | # Find the service that manages the cluster, as we need it in order to 64 | # do the update: 65 | cluster_service = clusters_service.cluster_service(cluster.id) 66 | 67 | # Update the cluster so that it uses the new MAC pool: 68 | cluster_service.update( 69 | types.Cluster( 70 | mac_pool=types.MacPool( 71 | id=pool.id, 72 | ), 73 | ), 74 | ) 75 | 76 | # Close the connection to the server: 77 | connection.close() 78 | -------------------------------------------------------------------------------- /examples/add_nfs_data_storage_domain.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | import time 22 | 23 | import ovirtsdk4 as sdk 24 | import ovirtsdk4.types as types 25 | 26 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 27 | 28 | # This example will connect to the server and create a new NFS data 29 | # storage domain, that won't be initially attached to any data center. 30 | 31 | # Create the connection to the server: 32 | connection = sdk.Connection( 33 | url='https://engine40.example.com/ovirt-engine/api', 34 | username='admin@internal', 35 | password='redhat123', 36 | ca_file='ca.pem', 37 | debug=True, 38 | log=logging.getLogger(), 39 | ) 40 | 41 | # Get the reference to the storage domains service: 42 | sds_service = connection.system_service().storage_domains_service() 43 | 44 | # Create a new NFS storage domain: 45 | sd = sds_service.add( 46 | types.StorageDomain( 47 | name='mydata', 48 | description='My data', 49 | type=types.StorageDomainType.DATA, 50 | host=types.Host( 51 | name='myhost', 52 | ), 53 | storage=types.HostStorage( 54 | type=types.StorageType.NFS, 55 | address='server0.example.com', 56 | path='/nfs/ovirt/40/mydata', 57 | ), 58 | ), 59 | ) 60 | 61 | # Wait till the storage domain is unattached: 62 | sd_service = sds_service.storage_domain_service(sd.id) 63 | while True: 64 | time.sleep(5) 65 | sd = sd_service.get() 66 | if sd.status == types.StorageDomainStatus.UNATTACHED: 67 | break 68 | 69 | # Close the connection to the server: 70 | connection.close() 71 | -------------------------------------------------------------------------------- /examples/add_nfs_iso_storage_domain.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | import time 22 | 23 | import ovirtsdk4 as sdk 24 | import ovirtsdk4.types as types 25 | 26 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 27 | 28 | # This example will connect to the server and create a new NFS ISO 29 | # storage domain, that won't be initially attached to any data center. 30 | 31 | # Create the connection to the server: 32 | connection = sdk.Connection( 33 | url='https://engine40.example.com/ovirt-engine/api', 34 | username='admin@internal', 35 | password='redhat123', 36 | ca_file='ca.pem', 37 | debug=True, 38 | log=logging.getLogger(), 39 | ) 40 | 41 | # Get the reference to the storage domains service: 42 | sds_service = connection.system_service().storage_domains_service() 43 | 44 | # Use the "add" method to create a new NFS storage domain: 45 | sd = sds_service.add( 46 | types.StorageDomain( 47 | name='myiso', 48 | description='My ISO', 49 | type=types.StorageDomainType.ISO, 50 | host=types.Host( 51 | name='myhost', 52 | ), 53 | storage=types.HostStorage( 54 | type=types.StorageType.NFS, 55 | address='server0.example.com', 56 | path='/nfs/ovirt/40/myiso', 57 | ), 58 | ), 59 | ) 60 | 61 | # Wait till the storage domain is unattached: 62 | sd_service = sds_service.storage_domain_service(sd.id) 63 | while True: 64 | time.sleep(5) 65 | sd = sd_service.get() 66 | if sd.status == types.StorageDomainStatus.UNATTACHED: 67 | break 68 | 69 | # Close the connection to the server: 70 | connection.close() 71 | -------------------------------------------------------------------------------- /examples/add_openstack_image_provider.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2017 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example will connect to the server and add a Glance storage 28 | # domain: 29 | 30 | # Create the connection to the server: 31 | connection = sdk.Connection( 32 | url='https://engine40.example.com/ovirt-engine/api', 33 | username='admin@internal', 34 | password='redhat123', 35 | ca_file='ca.pem', 36 | debug=True, 37 | log=logging.getLogger(), 38 | ) 39 | 40 | # The name of the storage domain: 41 | name = 'myglance' 42 | 43 | # Get the root of the services tree: 44 | system_service = connection.system_service() 45 | 46 | # Get the list of OpenStack image providers (a.k.a. Glance providers) 47 | # that match the name that we want to use: 48 | providers_service = system_service.openstack_image_providers_service() 49 | providers = [ 50 | provider for provider in providers_service.list() 51 | if provider.name == name 52 | ] 53 | 54 | # If there is no such provider, then add it: 55 | if len(providers) == 0: 56 | providers_service.add( 57 | provider=types.OpenStackImageProvider( 58 | name=name, 59 | description='My Glance', 60 | url='http://glance.ovirt.org:9292', 61 | requires_authentication=False 62 | ) 63 | ) 64 | 65 | # Note that the provider that we are using in this example is public 66 | # and doesn't require any authentication. If your provider requires 67 | # authentication then you will need to specify additional security 68 | # related attributes: 69 | # 70 | # types.OpenStackImageProvider( 71 | # name=name, 72 | # description='My private Glance', 73 | # url='http://myglance', 74 | # requires_authentication=True, 75 | # authentication_url='http://mykeystone', 76 | # username='myuser', 77 | # password='mypassword', 78 | # tenant_name='mytenant' 79 | # ) 80 | 81 | # Close the connection to the server: 82 | connection.close() 83 | -------------------------------------------------------------------------------- /examples/add_role.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example will connect to the server and create new role: 28 | # Create the connection to the server: 29 | connection = sdk.Connection( 30 | url='https://engine40.example.com/ovirt-engine/api', 31 | username='admin@internal', 32 | password='redhat123', 33 | ca_file='ca.pem', 34 | debug=True, 35 | log=logging.getLogger(), 36 | ) 37 | 38 | # Get the reference to the roles service: 39 | roles_service = connection.system_service().roles_service() 40 | 41 | # Use the "add" method to create new role (note that you need to pass 42 | # permit id not the name, when creating new role): 43 | role = roles_service.add( 44 | types.Role( 45 | name='myrole', 46 | administrative=False, 47 | description='My custom role to create virtual machines', 48 | permits=[ 49 | # create_vm permit 50 | types.Permit(id='1'), 51 | # login permit 52 | types.Permit(id='1300'), 53 | ], 54 | ), 55 | ) 56 | 57 | # Close the connection to the server: 58 | connection.close() 59 | -------------------------------------------------------------------------------- /examples/add_tag.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example will connect to the server and create new tag: 28 | # Create the connection to the server: 29 | connection = sdk.Connection( 30 | url='https://engine40.example.com/ovirt-engine/api', 31 | username='admin@internal', 32 | password='redhat123', 33 | ca_file='ca.pem', 34 | debug=True, 35 | log=logging.getLogger(), 36 | ) 37 | 38 | # Get the reference to the tags service: 39 | tags_service = connection.system_service().tags_service() 40 | 41 | # Use the "add" method to create new tag: 42 | tag = tags_service.add( 43 | types.Tag( 44 | name='mytag', 45 | description='My custom tag', 46 | ), 47 | ) 48 | 49 | # Close the connection to the server: 50 | connection.close() 51 | -------------------------------------------------------------------------------- /examples/add_user_ssh_public_key.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example will connect to the server, find a user by name and add a 28 | # public SSH key. 29 | 30 | # Create the connection to the server: 31 | connection = sdk.Connection( 32 | url='https://engine41.example.com/ovirt-engine/api', 33 | username='admin@internal', 34 | password='redhat123', 35 | ca_file='ca.pem', 36 | debug=True, 37 | log=logging.getLogger() 38 | ) 39 | 40 | # Get the reference to the root of the tree of services: 41 | system_service = connection.system_service() 42 | 43 | # Get the reference to the service that manages the users: 44 | users_service = system_service.users_service() 45 | 46 | # Find the user: 47 | user = users_service.list(search='name=myuser')[0] 48 | 49 | # Get the reference to the service that manages the user that we 50 | # found in the previous step: 51 | user_service = users_service.user_service(user.id) 52 | 53 | # Get a reference to the service that manages the public SSH keys 54 | # of the user: 55 | keys_service = user_service.ssh_public_keys_service() 56 | 57 | # Add a new SSH public key: 58 | keys_service.add( 59 | key=types.SshPublicKey( 60 | content='ssh-rsa AAA...mu9 myuser@example.com' 61 | ) 62 | ) 63 | 64 | # Note that the above operation will fail because the example SSH public 65 | # key is not valid, make sure to use a valid key. 66 | 67 | # Close the connection to the server: 68 | connection.close() 69 | -------------------------------------------------------------------------------- /examples/add_vm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example will connect to the server and create a new virtual machine: 28 | 29 | # Create the connection to the server: 30 | connection = sdk.Connection( 31 | url='https://engine40.example.com/ovirt-engine/api', 32 | username='admin@internal', 33 | password='redhat123', 34 | ca_file='ca.pem', 35 | debug=True, 36 | log=logging.getLogger(), 37 | ) 38 | 39 | # Get the reference to the "vms" service: 40 | vms_service = connection.system_service().vms_service() 41 | 42 | # Use the "add" method to create a new virtual machine: 43 | vms_service.add( 44 | types.Vm( 45 | name='myvm', 46 | cluster=types.Cluster( 47 | name='mycluster', 48 | ), 49 | template=types.Template( 50 | name='Blank', 51 | ), 52 | ), 53 | ) 54 | 55 | # Close the connection to the server: 56 | connection.close() 57 | -------------------------------------------------------------------------------- /examples/add_vm_pool.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example will connect to the server and create a new virtual machine 28 | # pool from template: 29 | 30 | # Create the connection to the server: 31 | connection = sdk.Connection( 32 | url='https://engine.example.com/ovirt-engine/api', 33 | username='admin@internal', 34 | password='redhat123', 35 | ca_file='ca.pem', 36 | debug=True, 37 | log=logging.getLogger(), 38 | ) 39 | 40 | # Get the reference to the "vm pools" service: 41 | vm_pools_service = connection.system_service().vm_pools_service() 42 | 43 | # Use the "add" method to create a new virtual machine pool: 44 | vm_pools_service.add( 45 | pool=types.VmPool( 46 | name='myvmpool', 47 | cluster=types.Cluster( 48 | name='mycluster', 49 | ), 50 | template=types.Template( 51 | name='mytemplate', 52 | ), 53 | size=3, 54 | prestarted_vms=1, 55 | max_user_vms=1, 56 | type=types.VmPoolType.AUTOMATIC, 57 | ), 58 | ) 59 | 60 | # Close the connection to the server: 61 | connection.close() 62 | -------------------------------------------------------------------------------- /examples/add_vm_snapshot.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # 4 | # Copyright (c) 2016 Red Hat, Inc. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | import logging 20 | 21 | import ovirtsdk4 as sdk 22 | import ovirtsdk4.types as types 23 | 24 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 25 | 26 | # This example will connect to the server and add a snapshot to an 27 | # existing virtual machine: 28 | 29 | # Create the connection to the server: 30 | connection = sdk.Connection( 31 | url='https://engine40.example.com/ovirt-engine/api', 32 | username='admin@internal', 33 | password='redhat123', 34 | ca_file='ca.pem', 35 | debug=True, 36 | log=logging.getLogger(), 37 | ) 38 | 39 | # Locate the virtual machines service and use it to find the virtual 40 | # machine: 41 | vms_service = connection.system_service().vms_service() 42 | vm = vms_service.list(search='name=myvm')[0] 43 | 44 | # Locate the service that manages the snapshots of the virtual machine: 45 | snapshots_service = vms_service.vm_service(vm.id).snapshots_service() 46 | 47 | # Add the new snapshot: 48 | snapshots_service.add( 49 | types.Snapshot( 50 | description='My snapshot', 51 | ), 52 | ) 53 | 54 | # Close the connection to the server: 55 | connection.close() 56 | -------------------------------------------------------------------------------- /examples/add_vnc_console.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2017 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example checks if a virtual machine has a VNC console, and adds 28 | # it if it doesn't. 29 | 30 | # Create the connection to the server: 31 | connection = sdk.Connection( 32 | url='https://engine40.example.com/ovirt-engine/api', 33 | username='admin@internal', 34 | password='redhat123', 35 | ca_file='ca.pem', 36 | debug=True, 37 | log=logging.getLogger(), 38 | ) 39 | 40 | # Find the virtual machine: 41 | vms_service = connection.system_service().vms_service() 42 | vm = vms_service.list(search='name=myvm')[0] 43 | vm_service = vms_service.vm_service(vm.id) 44 | 45 | # Find the graphics consoles of the virtual machine: 46 | consoles_service = vm_service.graphics_consoles_service() 47 | consoles = consoles_service.list() 48 | 49 | # Add a VNC console if it doesn't exist: 50 | console = next( 51 | (c for c in consoles if c.protocol == types.GraphicsType.VNC), 52 | None 53 | ) 54 | if console is None: 55 | consoles_service.add( 56 | console=types.GraphicsConsole( 57 | protocol=types.GraphicsType.VNC 58 | ) 59 | ) 60 | 61 | # Close the connection to the server: 62 | connection.close() 63 | -------------------------------------------------------------------------------- /examples/assign_affinity_label_to_vm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example will connect to the server and assign affinity label to virtual machine: 28 | 29 | # Create the connection to the server: 30 | connection = sdk.Connection( 31 | url='https://engine40.example.com/ovirt-engine/api', 32 | username='admin@internal', 33 | password='redhat123', 34 | ca_file='ca.pem', 35 | debug=True, 36 | log=logging.getLogger(), 37 | ) 38 | 39 | # Get the reference to the "vms" service: 40 | vms_service = connection.system_service().vms_service() 41 | 42 | # Find the virtual machine: 43 | vm = vms_service.list(search='name=myvm0')[0] 44 | 45 | # Get the reference to the affinity labels service: 46 | affinity_labels_service = connection.system_service().affinity_labels_service() 47 | 48 | # Find the affinity label: 49 | affinity_label = [ 50 | label for label in affinity_labels_service.list() 51 | if label.name == 'my_affinity_label' 52 | ][0] 53 | 54 | # Locate the service that manages the affinity label 55 | # named `my_affinity_label`: 56 | label_service = affinity_labels_service.label_service(affinity_label.id) 57 | 58 | # Get the reference to the service that manages the set 59 | # of virtual machines that have the affinity label 60 | # named `my_affinity_label` assigned: 61 | label_vms_service = label_service.vms_service() 62 | 63 | # Assign affinity label to virtual machine: 64 | label_vms_service.add( 65 | vm=types.Vm( 66 | id=vm.id, 67 | ) 68 | ) 69 | # Close the connection to the server: 70 | connection.close() 71 | -------------------------------------------------------------------------------- /examples/assign_network_to_cluster.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2017 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example will connect to the server and assign 'mynetwork' 28 | # network to cluster 'mycluster': 29 | 30 | # Create the connection to the server: 31 | connection = sdk.Connection( 32 | url='https://engine40.example.com/ovirt-engine/api', 33 | username='admin@internal', 34 | password='redhat123', 35 | ca_file='ca.pem', 36 | debug=True, 37 | log=logging.getLogger(), 38 | ) 39 | 40 | # Locate the networks service and use it to find the network: 41 | networks_service = connection.system_service().networks_service() 42 | network = networks_service.list( 43 | search='name=mynetwork and datacenter=mydc' 44 | )[0] 45 | 46 | # Locate the clusters service and use it to find the cluster: 47 | clusters_service = connection.system_service().clusters_service() 48 | cluster = clusters_service.list(search='name=mycluster')[0] 49 | 50 | # Locate the service that manages the networks of the cluster: 51 | cluster_service = clusters_service.cluster_service(cluster.id) 52 | cluster_networks_service = cluster_service.networks_service() 53 | 54 | # Use the "add" method to assign network to cluster: 55 | cluster_networks_service.add( 56 | network=types.Network( 57 | id=network.id, 58 | required=True, 59 | ), 60 | ) 61 | 62 | # Close the connection to the server: 63 | connection.close() 64 | -------------------------------------------------------------------------------- /examples/assign_permission.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example will connect to the server and assign GlusterAdmin 28 | # role to user on network: 29 | 30 | # Create the connection to the server: 31 | connection = sdk.Connection( 32 | url='https://engine40.example.com/ovirt-engine/api', 33 | username='admin@internal', 34 | password='redhat123', 35 | ca_file='ca.pem', 36 | debug=True, 37 | log=logging.getLogger(), 38 | ) 39 | 40 | # Locate the networks service and use it to find the network: 41 | networks_service = connection.system_service().networks_service() 42 | network = networks_service.list(search='name=mynetwork')[0] 43 | 44 | # Locate the users service and use it to find the user: 45 | users_service = connection.system_service().users_service() 46 | user = users_service.list(search='usrname=myuser@mydomain-authz')[0] 47 | 48 | # Locate the service that manages the permissions of the network: 49 | permissions_service = networks_service.network_service(network.id).permissions_service() 50 | 51 | # Use the "add" method to assign GlusterAdmin role to user on network: 52 | permissions_service.add( 53 | types.Permission( 54 | user=types.User( 55 | id=user.id, 56 | ), 57 | role=types.Role( 58 | name='GlusterAdmin' 59 | ), 60 | ), 61 | ) 62 | 63 | # Close the connection to the server: 64 | connection.close() 65 | -------------------------------------------------------------------------------- /examples/assign_permission_to_vms.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2018 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example will connect to the server and assign UserVmManager 28 | # role to myuser1 on virtual machine name myvm1, myvm2 nad myvm3: 29 | 30 | # List of virtual machine where user should have assigned permission: 31 | MY_VMS = ['myvm1', 'myvm2', 'myvm3'] 32 | 33 | # Username of the user, who we want to assign the permissions: 34 | USERNAME = 'user2@internal-authz' 35 | 36 | # Role which we want to assign to the user on the virtual machines: 37 | ROLENAME = 'UserVmManager' 38 | 39 | # Create the connection to the server: 40 | connection = sdk.Connection( 41 | url='https://engine40.example.com/ovirt-engine/api', 42 | username='admin@internal', 43 | password='redhat123', 44 | ca_file='ca.pem', 45 | debug=True, 46 | log=logging.getLogger(), 47 | ) 48 | 49 | # Locate the users service and use it to find the user: 50 | users_service = connection.system_service().users_service() 51 | user = users_service.list(search='usrname=%s' % USERNAME)[0] 52 | 53 | # Iterate via the list of virtual machines: 54 | for vm_name in MY_VMS: 55 | 56 | # Locate the virtual machine service and use it to find the specific 57 | # virtual machines: 58 | vms_service = connection.system_service().vms_service() 59 | vm = vms_service.list(search='name=%s' % vm_name)[0] 60 | 61 | # Locate the service that manages the permissions of the virtual machine: 62 | permissions_service = vms_service.vm_service(vm.id).permissions_service() 63 | 64 | # Use the "add" method to assign UserVmManager role to user on virtual 65 | # machine: 66 | permissions_service.add( 67 | types.Permission( 68 | user=types.User( 69 | id=user.id, 70 | ), 71 | role=types.Role( 72 | name=ROLENAME, 73 | ), 74 | ), 75 | ) 76 | 77 | # Close the connection to the server: 78 | connection.close() 79 | -------------------------------------------------------------------------------- /examples/assign_tag_to_vm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example will connect to the server and assign tag to virtual machine: 28 | 29 | # Create the connection to the server: 30 | connection = sdk.Connection( 31 | url='https://engine40.example.com/ovirt-engine/api', 32 | username='admin@internal', 33 | password='redhat123', 34 | ca_file='ca.pem', 35 | debug=True, 36 | log=logging.getLogger(), 37 | ) 38 | 39 | # Get the reference to the "vms" service: 40 | vms_service = connection.system_service().vms_service() 41 | 42 | # Find the virtual machine: 43 | vm = vms_service.list(search='name=myvm0')[0] 44 | 45 | # Find the service that manages the vm: 46 | vm_service = vms_service.vm_service(vm.id) 47 | 48 | # Locate the service that manages the tags of the vm: 49 | tags_service = vm_service.tags_service() 50 | 51 | # Assign tag to virtual machine: 52 | tags_service.add( 53 | tag=types.Tag( 54 | name='mytag', 55 | ) 56 | ) 57 | 58 | # Close the connection to the server: 59 | connection.close() 60 | -------------------------------------------------------------------------------- /examples/attach_nfs_data_storage_domain.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | import time 22 | 23 | import ovirtsdk4 as sdk 24 | import ovirtsdk4.types as types 25 | 26 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 27 | 28 | # This example will connect to the server and attach an existing NFS 29 | # data storage domain to a data center. 30 | 31 | # Create the connection to the server: 32 | connection = sdk.Connection( 33 | url='https://engine40.example.com/ovirt-engine/api', 34 | username='admin@internal', 35 | password='redhat123', 36 | ca_file='ca.pem', 37 | debug=True, 38 | log=logging.getLogger(), 39 | ) 40 | 41 | # Locate the service that manages the storage domains and use it to 42 | # search for the storage domain: 43 | sds_service = connection.system_service().storage_domains_service() 44 | sd = sds_service.list(search='name=mydata')[0] 45 | 46 | # Locate the service that manages the data centers and use it to 47 | # search for the data center: 48 | dcs_service = connection.system_service().data_centers_service() 49 | dc = dcs_service.list(search='name=mydc')[0] 50 | 51 | # Locate the service that manages the data center where we want to 52 | # attach the storage domain: 53 | dc_service = dcs_service.data_center_service(dc.id) 54 | 55 | # Locate the service that manages the storage domains that are attached 56 | # to the data centers: 57 | attached_sds_service = dc_service.storage_domains_service() 58 | 59 | # Use the "add" method of service that manages the attached storage 60 | # domains to attach it: 61 | attached_sds_service.add( 62 | types.StorageDomain( 63 | id=sd.id, 64 | ), 65 | ) 66 | 67 | # Wait till the storage domain is active: 68 | attached_sd_service = attached_sds_service.storage_domain_service(sd.id) 69 | while True: 70 | time.sleep(5) 71 | sd = attached_sd_service.get() 72 | if sd.status == types.StorageDomainStatus.ACTIVE: 73 | break 74 | 75 | # Close the connection to the server: 76 | connection.close() 77 | -------------------------------------------------------------------------------- /examples/attach_nfs_iso_storage_domain.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | import time 22 | 23 | import ovirtsdk4 as sdk 24 | import ovirtsdk4.types as types 25 | 26 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 27 | 28 | # This example will connect to the server and attach an existing NFS 29 | # ISO storage domain to a data center. 30 | 31 | # Create the connection to the server: 32 | connection = sdk.Connection( 33 | url='https://engine40.example.com/ovirt-engine/api', 34 | username='admin@internal', 35 | password='redhat123', 36 | ca_file='ca.pem', 37 | debug=True, 38 | log=logging.getLogger(), 39 | ) 40 | 41 | # Locate the service that manages the storage domains and use it to 42 | # search for the storage domain: 43 | sds_service = connection.system_service().storage_domains_service() 44 | sd = sds_service.list(search='name=myiso')[0] 45 | 46 | # Locate the service that manages the data centers and use it to 47 | # search for the data center: 48 | dcs_service = connection.system_service().data_centers_service() 49 | dc = dcs_service.list(search='name=mydc')[0] 50 | 51 | # Locate the service that manages the data center where we want to 52 | # attach the storage domain: 53 | dc_service = dcs_service.data_center_service(dc.id) 54 | 55 | # Locate the service that manages the storage domains that are attached 56 | # to the data centers: 57 | attached_sds_service = dc_service.storage_domains_service() 58 | 59 | # Use the "add" method of service that manages the attached storage 60 | # domains to attach it: 61 | attached_sds_service.add( 62 | types.StorageDomain( 63 | id=sd.id, 64 | ), 65 | ) 66 | 67 | # Wait till the storage domain is active: 68 | attached_sd_service = attached_sds_service.storage_domain_service(sd.id) 69 | while True: 70 | time.sleep(5) 71 | sd = attached_sd_service.get() 72 | if sd.status == types.StorageDomainStatus.ACTIVE: 73 | break 74 | 75 | # Close the connection to the server: 76 | connection.close() 77 | -------------------------------------------------------------------------------- /examples/change_host_cluster.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2018 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | import time 22 | 23 | import ovirtsdk4 as sdk 24 | import ovirtsdk4.types as types 25 | 26 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 27 | 28 | # This example will connect to the server and check change the cluster of the 29 | # host 30 | 31 | # Create the connection to the server: 32 | connection = sdk.Connection( 33 | url='https://engine40.example.com/ovirt-engine/api', 34 | username='admin@internal', 35 | password='123456', 36 | ca_file='ca.pem', 37 | debug=True, 38 | log=logging.getLogger(), 39 | ) 40 | 41 | # Get the reference to the service that manages the hosts: 42 | hosts_service = connection.system_service().hosts_service() 43 | 44 | # Find the host: 45 | host = hosts_service.list(search='name=myhost')[0] 46 | 47 | # Get the reference to the service that manages the host 48 | host_service = hosts_service.host_service(host.id) 49 | 50 | # Put host into maintenance: 51 | if host.status != types.HostStatus.MAINTENANCE: 52 | host_service.deactivate() 53 | # Wait till the host is in maintenance: 54 | while True: 55 | time.sleep(5) 56 | host = host_service.get() 57 | if host.status == types.HostStatus.MAINTENANCE: 58 | break 59 | 60 | # Change the host cluster: 61 | host_service.update( 62 | types.Host( 63 | cluster=types.Cluster(name='mycluster'), 64 | ), 65 | ) 66 | 67 | # Activate the host again: 68 | host_service.activate() 69 | while True: 70 | time.sleep(5) 71 | host = host_service.get() 72 | if host.status == types.HostStatus.UP: 73 | break 74 | 75 | # Close the connection to the server: 76 | connection.close() 77 | -------------------------------------------------------------------------------- /examples/checksum_disk.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Copyright (c) 2020 Red Hat, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | """ 19 | Show how to compute a disk checksum. 20 | 21 | Requires ovirt-imageio-client >= 2.0.10-1 22 | """ 23 | 24 | import json 25 | import ssl 26 | 27 | from contextlib import closing 28 | from http import client 29 | from urllib.parse import urlparse 30 | 31 | from ovirtsdk4 import types 32 | from helpers import common 33 | from helpers import imagetransfer 34 | 35 | parser = common.ArgumentParser(description="Compute disk checksum") 36 | 37 | parser.add_argument("disk_uuid", help="Disk UUID.") 38 | 39 | args = parser.parse_args() 40 | common.configure_logging(args) 41 | 42 | connection = common.create_connection(args) 43 | with closing(connection): 44 | system_service = connection.system_service() 45 | disks_service = connection.system_service().disks_service() 46 | disk_service = disks_service.disk_service(args.disk_uuid) 47 | disk = disk_service.get() 48 | 49 | transfer = imagetransfer.create_transfer( 50 | connection, disk, types.ImageTransferDirection.DOWNLOAD) 51 | try: 52 | url = urlparse(transfer.transfer_url) 53 | con = client.HTTPSConnection( 54 | url.netloc, 55 | context=ssl.create_default_context(cafile=args.cafile)) 56 | with closing(con): 57 | con.request("GET", url.path + "/checksum") 58 | res = con.getresponse() 59 | 60 | if res.status != client.OK: 61 | error = res.read().decode("utf-8", "replace") 62 | raise RuntimeError( 63 | "Error computing checksum: {}".format(error)) 64 | 65 | result = json.loads(res.read()) 66 | print(json.dumps(result, indent=4)) 67 | finally: 68 | imagetransfer.finalize_transfer(connection, transfer, disk) 69 | -------------------------------------------------------------------------------- /examples/checksum_image.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2020 Red Hat, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | """ 19 | Show how to compute an image checksum. 20 | 21 | Requires ovirt-imageio-client >= 2.0.10-1 22 | """ 23 | 24 | import argparse 25 | import json 26 | 27 | from ovirt_imageio import client 28 | 29 | parser = argparse.ArgumentParser(description="Compute image checksum") 30 | 31 | parser.add_argument( 32 | "filename", 33 | help="path to disk image") 34 | 35 | parser.add_argument( 36 | "--member", 37 | help="if filename is an OVA archive, the disk name in the OVA to " 38 | "checksum") 39 | 40 | args = parser.parse_args() 41 | 42 | checksum = client.checksum(args.filename, member=args.member) 43 | print(json.dumps(checksum, indent=2)) 44 | -------------------------------------------------------------------------------- /examples/connection_builder.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | 24 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 25 | 26 | # This example demonstrates how to use multiple connections, using the 27 | # connection builder class and the Python "with" mechanism. 28 | 29 | # Multiple connections can be created just calling the constructor 30 | # multiple times, but then it is necessary to store the connection 31 | # parameters somewhere. The "ConnectionBuilder" class simplifies it a 32 | # bit, as it servers at the place to store these parameters: 33 | builder = sdk.ConnectionBuilder( 34 | url='https://engine40.example.com/ovirt-engine/api', 35 | username='admin@internal', 36 | password='redhat123', 37 | ca_file='ca.pem', 38 | debug=True, 39 | log=logging.getLogger(), 40 | ) 41 | 42 | # Creating the connection builder doesn't do anything, it just stores 43 | # the parameter. To actually create the connection it is necessary to 44 | # call the "build" method, and it is very convenient to combine this 45 | # with the "with" mechanism of Python: 46 | with builder.build() as connection: 47 | for vm in connection.system_service().vms_service().list(): 48 | print(vm.name) 49 | 50 | # The connection has been closed automatically. If there is the need to 51 | # create another connection, the builder object can be reused: 52 | with builder.build() as connection: 53 | for host in connection.system_service().hosts_service().list(): 54 | print(host.name) 55 | -------------------------------------------------------------------------------- /examples/delete_disks.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Copyright (c) 2022 Red Hat, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | """ 19 | Show how to delete many disks created by the 'add_disks.py' example easily, 20 | based on their description. 21 | """ 22 | 23 | import sys 24 | from contextlib import closing 25 | 26 | from helpers import common 27 | from helpers.common import progress 28 | 29 | parser = common.ArgumentParser(description="Delete disks by a given description") 30 | 31 | parser.add_argument( 32 | "--sd-name", 33 | required=True, 34 | help="Name of the storage domain.") 35 | 36 | parser.add_argument( 37 | "--description", 38 | default="Created by add_disks.py", 39 | help="The description of the disks to be deleted.") 40 | 41 | args = parser.parse_args() 42 | 43 | progress("Connecting...") 44 | connection = common.create_connection(args) 45 | with closing(connection): 46 | storage_domains_service = connection.system_service().storage_domains_service() 47 | found_sd = storage_domains_service.list(search=f'name={args.sd_name}') 48 | if not found_sd: 49 | raise RuntimeError(f"Couldn't find storage domain {args.sd_name}") 50 | 51 | sd = found_sd[0] 52 | sd_service = storage_domains_service.storage_domain_service(sd.id) 53 | sd_disks_service = sd_service.disks_service() 54 | 55 | # StorageDomainDisksService.list has no 'search' parameter and ignores 56 | # query={'name': 'spam'} so we have to do the filtering ourselves 57 | disks = [disk for disk in sd_disks_service.list() 58 | if disk.description == args.description] 59 | 60 | if not disks: 61 | progress("No disks were found") 62 | sys.exit(1) 63 | 64 | for i, disk in enumerate(disks, start=1): 65 | progress(f"Removing disk {disk.id} ({i}/{len(disks)})") 66 | sd_disks_service.disk_service(disk.id).remove() 67 | 68 | progress("All disks were removed") 69 | -------------------------------------------------------------------------------- /examples/disable_compression.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | 24 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 25 | 26 | # This example shows how to disable compression of the responses sent by 27 | # the server: 28 | 29 | # Create the connection to the server: 30 | connection = sdk.Connection( 31 | url='https://engine40.example.com/ovirt-engine/api', 32 | username='admin@internal', 33 | password='redhat123', 34 | ca_file='ca.pem', 35 | compress=False, 36 | debug=True, 37 | log=logging.getLogger(), 38 | ) 39 | 40 | # By disabling compression you can debug the communication, 41 | # as communication will be visible in plain text and won't 42 | # be raw compressed. Note that compression is automatically 43 | # disabled in case user pass debug parameter set to `true`. 44 | 45 | # Get some data: 46 | api = connection.system_service().get() 47 | print(api.product_info.version.full_version) 48 | 49 | # Close the connection to the server: 50 | connection.close() 51 | -------------------------------------------------------------------------------- /examples/download_vm_ovf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2017 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | import ovirtsdk4 as sdk 22 | 23 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 24 | 25 | # This example fetches the specified VM configuration data and 26 | # saves it into an OVF file. 27 | 28 | 29 | def get_connection(): 30 | # Create the connection to the server: 31 | return sdk.Connection( 32 | url='https://engine40.example.com/ovirt-engine/api', 33 | username='admin@internal', 34 | password='redhat123', 35 | ca_file='ca.pem', 36 | debug=True, 37 | log=logging.getLogger(), 38 | ) 39 | 40 | 41 | if __name__ == "__main__": 42 | 43 | # Set VM name 44 | vm_name = 'myvm' 45 | 46 | # Create a connection to the server: 47 | connection = get_connection() 48 | 49 | # Get a reference to the root service: 50 | system_service = connection.system_service() 51 | 52 | # Get the reference to the "vms" service: 53 | vms_service = system_service.vms_service() 54 | 55 | # Locate VM service 56 | try: 57 | vm = vms_service.list(search="name=%s" % vm_name, all_content=True)[0] 58 | ovf_filename = "%s.ovf" % vm.id 59 | with open(ovf_filename, "wb") as ovf_file: 60 | ovf_file.write(vm.initialization.configuration.data.encode("utf-8")) 61 | finally: 62 | # Close the connection to the server: 63 | connection.close() 64 | -------------------------------------------------------------------------------- /examples/enable_serial_console.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example will connect to the server, find a virtual machine and enable the 28 | # serial console if it isn't enabled yet: 29 | 30 | # Create the connection to the server: 31 | connection = sdk.Connection( 32 | url='https://engine41.example.com/ovirt-engine/api', 33 | username='admin@internal', 34 | password='redhat123', 35 | ca_file='ca.pem', 36 | debug=True, 37 | log=logging.getLogger(), 38 | ) 39 | 40 | # Find the virtual machine. Note the use of the `all_content` parameter, it is 41 | # required in order to obtain additional information that isn't retrieved by 42 | # default, like the configuration of the serial console. 43 | vms_service = connection.system_service().vms_service() 44 | vm = vms_service.list(search='name=myvm', all_content=True)[0] 45 | 46 | # Check if the serial console is enabled, and if it isn't then update the 47 | # virtual machine to enable it: 48 | if not vm.console.enabled: 49 | vm_service = vms_service.vm_service(vm.id) 50 | vm_service.update( 51 | types.Vm( 52 | console=types.Console( 53 | enabled=True 54 | ) 55 | ) 56 | ) 57 | 58 | # Close the connection to the server: 59 | connection.close() 60 | -------------------------------------------------------------------------------- /examples/export_template.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2017 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example shows how to export a virtual machine template to 28 | # an export storage domain. 29 | 30 | # Create the connection to the server: 31 | connection = sdk.Connection( 32 | url='https://engine40.example.com/ovirt-engine/api', 33 | username='admin@internal', 34 | password='redhat123', 35 | ca_file='/etc/pki/ovirt-engine/ca.pem', 36 | debug=True, 37 | log=logging.getLogger() 38 | ) 39 | 40 | # Get the reference to the root of the services tree: 41 | system_service = connection.system_service() 42 | 43 | # Find the virtual machine template: 44 | templates_service = system_service.templates_service() 45 | template = templates_service.list(search='name=mytemplate')[0] 46 | 47 | # Export the virtual machine template. Note that the 'exclusive' 48 | # parameter is optional, and only required if you want to overwrite 49 | # a virtual machine template that has already been exported before. 50 | template_service = templates_service.template_service(template.id) 51 | template_service.export( 52 | exclusive=True, 53 | storage_domain=types.StorageDomain( 54 | name='myexport' 55 | ) 56 | ) 57 | 58 | # Close the connection to the server: 59 | connection.close() 60 | -------------------------------------------------------------------------------- /examples/export_template_as_ova.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2017 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | # This example shows how to export a virtual machine template as 26 | # a Virtual Appliance (OVA) file to a specified path on a host. 27 | 28 | # Create the connection to the server: 29 | connection = sdk.Connection( 30 | url='https://engine40.example.com/ovirt-engine/api', 31 | username='admin@internal', 32 | password='redhat123', 33 | ca_file='/etc/pki/ovirt-engine/ca.pem', 34 | debug=True, 35 | log=logging.getLogger(), 36 | ) 37 | 38 | # Find the virtual machine template: 39 | templates_service = connection.system_service().templates_service() 40 | template = templates_service.list(search='name=mytemplate')[0] 41 | template_service = templates_service.template_service(template.id) 42 | 43 | # Find the host where the OVA will be exported: 44 | hosts_service = connection.system_service().hosts_service() 45 | host = hosts_service.list(search='name=myhost')[0] 46 | 47 | # Export the virtual machine template. Note that the 'filename' 48 | # parameter is optional, and only required if you want to specify 49 | # a name for the generated OVA file that is different from 50 | # .ova. 51 | # Note that this operation is only available since version 4.2.3 52 | # of the engine and since version 4.2.5 of the SDK. 53 | template_service.export_to_path_on_host( 54 | host=types.Host(id=host.id), 55 | directory='/tmp', 56 | filename='mytemplate2.ova' 57 | ) 58 | 59 | # Close the connection to the server: 60 | connection.close() 61 | -------------------------------------------------------------------------------- /examples/export_vm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2017 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 26 | 27 | # This example shows how to export a virtual machine to an export storage 28 | # domain. 29 | 30 | # Create the connection to the server: 31 | connection = sdk.Connection( 32 | url='https://engine40.example.com/ovirt-engine/api', 33 | username='admin@internal', 34 | password='redhat123', 35 | ca_file='ca.pem', 36 | debug=True, 37 | log=logging.getLogger() 38 | ) 39 | 40 | # Get the reference to the root of the services tree: 41 | system_service = connection.system_service() 42 | 43 | # Find the virtual machine: 44 | vms_service = system_service.vms_service() 45 | vm = vms_service.list(search='name=myvm')[0] 46 | 47 | # Export the virtual machine. Note that the 'exclusive' parameter is 48 | # optional, and only required if you want to overwrite a virtual machine 49 | # that has already been exported before. 50 | vm_service = vms_service.vm_service(vm.id) 51 | vm_service.export( 52 | exclusive=True, 53 | discard_snapshots=True, 54 | storage_domain=types.StorageDomain( 55 | name='myexport' 56 | ) 57 | ) 58 | 59 | # Close the connection to the server: 60 | connection.close() 61 | -------------------------------------------------------------------------------- /examples/export_vm_as_ova.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2017 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | import ovirtsdk4.types as types 24 | 25 | # This example shows how to export a virtual machine as a Virtual 26 | # Appliance (OVA) file to a specified path on a host. 27 | 28 | # Create the connection to the server: 29 | connection = sdk.Connection( 30 | url='https://engine40.example.com/ovirt-engine/api', 31 | username='admin@internal', 32 | password='redhat123', 33 | ca_file='/etc/pki/ovirt-engine/ca.pem', 34 | debug=True, 35 | log=logging.getLogger(), 36 | ) 37 | 38 | # Find the virtual machine: 39 | vms_service = connection.system_service().vms_service() 40 | vm = vms_service.list(search='name=myvm')[0] 41 | vm_service = vms_service.vm_service(vm.id) 42 | 43 | # Find the host: 44 | hosts_service = connection.system_service().hosts_service() 45 | host = hosts_service.list(search='name=myhost')[0] 46 | 47 | # Export the virtual machine. Note that the 'filename' parameter is 48 | # optional, and only required if you want to specify a name for the 49 | # generated OVA file that is different from .ova. 50 | # Note that this operation is only available since version 4.2 of 51 | # the engine and since version 4.2 of the SDK. 52 | vm_service.export_to_path_on_host( 53 | host=types.Host(id=host.id), 54 | directory='/tmp', 55 | filename='myvm2.ova' 56 | ) 57 | 58 | # Close the connection to the server: 59 | connection.close() 60 | -------------------------------------------------------------------------------- /examples/follow_vm_links.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Copyright (c) 2016 Red Hat, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | import logging 21 | 22 | import ovirtsdk4 as sdk 23 | 24 | logging.basicConfig(level=logging.DEBUG, filename='example.log') 25 | 26 | # This example will connect to the server, retrieve the detail of a 27 | # virtual machine and then it will follow the link to the permissions 28 | # of the virtual machine: 29 | 30 | # Create the connection to the server: 31 | connection = sdk.Connection( 32 | url='https://engine40.example.com/ovirt-engine/api', 33 | username='admin@internal', 34 | password='redhat123', 35 | ca_file='ca.pem', 36 | debug=True, 37 | log=logging.getLogger(), 38 | ) 39 | 40 | # Get the reference to the service that manages virtual machines: 41 | vms_service = connection.system_service().vms_service() 42 | 43 | # Find the virtual machine: 44 | vm = vms_service.list(search='name=myvm')[0] 45 | 46 | # When the server returns a virtual machine it will return links to 47 | # related objects, like the cluster, the templates and the permissions, 48 | # something like this: 49 | # 50 | # 51 | # 52 | #