|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | + |
| 4 | +# |
| 5 | +# Copyright (c) 2021 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 import an external template from an |
| 28 | +# OVA file. |
| 29 | + |
| 30 | +# Create a 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 import of external |
| 41 | +# templates: |
| 42 | +system_service = connection.system_service() |
| 43 | +imports_service = system_service.external_template_imports_service() |
| 44 | + |
| 45 | +# Initiate the import of template 'mytemplate' from the OVA file. Note |
| 46 | +# that the .ova file needs to be previously copied to a place where the |
| 47 | +# selected host (the 'myhost' host in this case) can read it. Make also |
| 48 | +# sure that the 'vdsm' user can read it. To do so the easier way is to |
| 49 | +# change the ownership of the directory: |
| 50 | +# |
| 51 | +# chown --recursive 36:36 /mytemplates |
| 52 | +# |
| 53 | +# The 'clone' parameter determines whether the new template is imported |
| 54 | +# as a new entity or not. Default value is 'False', setting it to 'True' |
| 55 | +# allows for importing the same template multiple times. |
| 56 | +# |
| 57 | +# If something fails during the import there will be useful information |
| 58 | +# in the '/var/log/vdsm/import' directory of the selected host. |
| 59 | +imports_service.add( |
| 60 | + types.ExternalTemplateImport( |
| 61 | + template=types.Template( |
| 62 | + name='mytemplate' |
| 63 | + ), |
| 64 | + url='ova:///mytemplates/my.ova', |
| 65 | + cluster=types.Cluster( |
| 66 | + name='mycluster' |
| 67 | + ), |
| 68 | + storage_domain=types.StorageDomain( |
| 69 | + name='mydata' |
| 70 | + ), |
| 71 | + host=types.Host( |
| 72 | + name='myhost' |
| 73 | + ), |
| 74 | + clone=True |
| 75 | + ) |
| 76 | +) |
| 77 | + |
| 78 | +# Close the connection: |
| 79 | +connection.close() |
0 commit comments