Este conteúdo não está disponível no idioma selecionado.
Chapter 4. Quick Start Examples
The examples in this section show you how to use the REST API to set up a basic Red Hat Virtualization environment and to create a virtual machine. In addition to the standard prerequisites, these examples require the following:
A networked and configured Red Hat Virtualization installation.
An ISO file containing the virtual machine operating system you want to install. This chapter uses CentOS 7 for the installation ISO example.
The API examples use curl to demonstrate API requests with a client application. You can use any application that sends HTTP requests.
Important
The HTTP request headers in this example omit the Host and Authorization headers. However, these fields are mandatory and require data specific to your installation of Red Hat Virtualization.
The curl examples use admin@internal for the user name, mypassword for the password, /etc/pki/ovirt-engine/ca.pem for the certificate location, and myengine.example.com for the host name. You must replace them with the correct values for your environment.
Red Hat Virtualization generates a unique identifier for the id attribute for each resource. Identifier codes in this example will differ from the identifier codes in your Red Hat Virtualization environment.
In many examples, some attributes of the results returned by the API have been omitted, for brevity. See, for example, the Cluster reference for a complete list of attributes.
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Important
When neither the header nor the URL prefix are used, the server will automatically select a version. The default is version 4. You can change the default version using the ENGINE_API_DEFAULT_VERSION configuration parameter:
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Changing this parameter affects all users of the API that do not specify the version explicitly.
The entry point provides a user with links to the collections in a virtualization environment. The rel attribute of each collection link provides a reference point for each link. The next step in this example examines the data center collection, which is available through the datacenters link.
The entry point also contains other data such as product_info, special_objects and summary. This data is covered in chapters outside this example.
Copiar o linkLink copiado para a área de transferência!
Red Hat Virtualization creates a Default data center on installation. This example uses the Default data center as the basis for the virtual environment.
The following request retrieves a representation of the data centers:
GET /ovirt-engine/api/datacenters HTTP/1.1
Accept: application/xml
GET /ovirt-engine/api/datacenters HTTP/1.1
Accept: application/xml
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Copiar o linkLink copiado para a área de transferência!
Red Hat Virtualization creates a Default hosts cluster on installation. This example uses the Default cluster to group resources in your Red Hat Virtualization environment.
The following request retrieves a representation of the cluster collection:
GET /ovirt-engine/api/clusters HTTP/1.1
Accept: application/xml
GET /ovirt-engine/api/clusters HTTP/1.1
Accept: application/xml
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Copy to ClipboardCopied!Toggle word wrapToggle overflow
The networks link is a reference to the service that manages the networks associated to this cluster. The next section examines the networks collection in more detail.
Copiar o linkLink copiado para a área de transferência!
Red Hat Virtualization creates a default ovirtmgmt network on installation. This network acts as the management network for Red Hat Virtualization Manager to access hosts.
This network is associated with the Default cluster and is a member of the Default data center. This example uses the ovirtmgmt network to connect the virtual machines.
The following request retrieves the list of logical networks:
GET /ovirt-engine/api/networks HTTP/1.1
Accept: application/xml
GET /ovirt-engine/api/networks HTTP/1.1
Accept: application/xml
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Copiar o linkLink copiado para a área de transferência!
An NFS data storage domain is an exported NFS share attached to a data center and provides storage for virtualized guest images. Creation of a new storage domain requires a POST request, with the storage domain representation included, sent to the URL of the storage domain collection.
You can enable the wipe after delete option by default on the storage domain. To configure this specify wipe_after_delete in the POST request. This option can be edited after the domain is created, but doing so will not change the wipe after delete property of disks that already exist.
The request should be like this:
POST /ovirt-engine/api/storagedomains HTTP/1.1
Accept: application/xml
Content-type: application/xml
POST /ovirt-engine/api/storagedomains HTTP/1.1
Accept: application/xml
Content-type: application/xml
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Copy to ClipboardCopied!Toggle word wrapToggle overflow
The server uses host myhost to create a NFS data storage domain called mydata with an export path of mynfs.example.com:/exports/mydata. The API also returns the following representation of the newly created storage domain resource (of type StorageDomain):
Copiar o linkLink copiado para a área de transferência!
An NFS ISO storage domain is a mounted NFS share attached to a data center and provides storage for DVD/CD-ROM ISO and virtual floppy disk (VFD) image files. Creation of a new storage domain requires a POST request, with the storage domain representation included, sent to the URL of the storage domain collection:
The request should be like this:
POST /ovirt-engine/api/storagedomains HTTP/1.1
Accept: application/xml
Content-type: application/xml
POST /ovirt-engine/api/storagedomains HTTP/1.1
Accept: application/xml
Content-type: application/xml
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Copy to ClipboardCopied!Toggle word wrapToggle overflow
The server uses host myhost to create a NFS ISO storage domain called myisos with an export path of mynfs.example.com:/exports/myisos. The API also returns the following representation of the newly created storage domain resource (of type StorageDomain):
Copiar o linkLink copiado para a área de transferência!
The following example creates a virtual machine called myvm on the Default cluster using the virtualization environment’s Blank template as a basis. The request also defines the virtual machine’s memory as 512 MiB and sets the boot device to a virtual hard disk.
The request should be contain an object of type Vm describing the virtual machine to create:
POST /ovirt-engine/api/vms HTTP/1.1
Accept: application/xml
Content-type: application/xml
POST /ovirt-engine/api/vms HTTP/1.1
Accept: application/xml
Content-type: application/xml
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Copiar o linkLink copiado para a área de transferência!
The boot media for the following virtual machine example requires a CD-ROM or DVD ISO image for an operating system installation. This example uses a CentOS 7 image.
ISO images must be available in the myisos ISO domain for the virtual machines to use. You can use ImageTransfer to create an image transfer and ImageTransfers to upload the ISO image.
Once the ISO image is uploaded, an API can be used to request the list of files from the ISO storage domain:
GET /ovirt-engine/api/storagedomains/006/files HTTP/1.1
Accept: application/xml
GET /ovirt-engine/api/storagedomains/006/files HTTP/1.1
Accept: application/xml
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Copy to ClipboardCopied!Toggle word wrapToggle overflow
An API user attaches the CentOS-7-x86_64-Minimal.iso to the example virtual machine. Attaching an ISO image is equivalent to using the Change CD button in the administration or user portal applications.
The request should be like this:
PUT /ovirt-engine/api/vms/007/cdroms/00000000-0000-0000-0000-000000000000 HTTP/1.1
Accept: application/xml
Content-type: application/xml
PUT /ovirt-engine/api/vms/007/cdroms/00000000-0000-0000-0000-000000000000 HTTP/1.1
Accept: application/xml
Content-type: application/xml
Copy to ClipboardCopied!Toggle word wrapToggle overflow
The request body should be an object of type Cdrom containing an inner file attribute to indicate the identifier of the ISO (or floppy) image:
Copiar o linkLink copiado para a área de transferência!
The virtual environment is complete and the virtual machine contains all necessary components to function. This example starts the virtual machine using the start method.
The request should be like this:
POST /ovirt-engine/api/vms/007/start HTTP/1.1
Accept: application/xml
Content-type: application/xml
POST /ovirt-engine/api/vms/007/start HTTP/1.1
Accept: application/xml
Content-type: application/xml
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Copy to ClipboardCopied!Toggle word wrapToggle overflow
The additional request body sets the virtual machine’s boot device to CD-ROM for this boot only. This enables the virtual machine to install the operating system from the attached ISO image. The boot device reverts back to disk for all future boots.
Ajudamos os usuários da Red Hat a inovar e atingir seus objetivos com nossos produtos e serviços com conteúdo em que podem confiar. Explore nossas atualizações recentes.
Tornando o open source mais inclusivo
A Red Hat está comprometida em substituir a linguagem problemática em nosso código, documentação e propriedades da web. Para mais detalhes veja o Blog da Red Hat.
Sobre a Red Hat
Fornecemos soluções robustas que facilitam o trabalho das empresas em plataformas e ambientes, desde o data center principal até a borda da rede.