Skip to content
dougsland edited this page Jan 25, 2012 · 67 revisions

Welcome to the ovirt-restapi-scripts wiki!

About

ovirt-restapi-scripts is a collection of scripts that I have created to manage my oVirt/RHEV 3.0 environment (using REST API)

License

GPLv2

Download

https://github.com/dougsland/ovirt-restapi-scripts

Scripts

NAME: getNumberOf.py
DESCRIPTION: Get the Number of [datacenters, hosts, clusters, storagedomains, templates, roles, networks, tags, groups and vms].

EXAMPLE:

$ python getNumberOf.py
Connecting to: https://192.168.123.176:8443/api/datacenters
Number of datacenters 2

Connecting to: https://192.168.123.176:8443/api/hosts
Number of hosts 1

Connecting to: https://192.168.123.176:8443/api/clusters
Number of clusters 1

Connecting to: https://192.168.123.176:8443/api/storagedomains
Number of storagedomains 0

Connecting to: https://192.168.123.176:8443/api/templates
Number of templates 1

Connecting to: https://192.168.123.176:8443/api/roles
Number of roles 12

Connecting to: https://192.168.123.176:8443/api/networks
Number of networks 2

Connecting to: https://192.168.123.176:8443/api/tags
Number of tags 1

Connecting to: https://192.168.123.176:8443/api/groups
Number of groups 1

Connecting to: https://192.168.123.176:8443/api/vms
Number of vms 0


NAME: searchClusters.py
DESCRIPTION: Search a cluster entry

EXAMPLE:

$ python searchClusters.py Default
Connecting to: https://192.168.123.176:8443/api/clusters?search=Default
id: 99408929-82cf-4dc7-a532-9d998063fa95
href: /api/clusters/99408929-82cf-4dc7-a532-9d998063fa95
name: Default
description: The default server cluster
link rel: networks
link href: /api/clusters/99408929-82cf-4dc7-a532-9d998063fa95/networks
link rel: permissions
link href: /api/clusters/99408929-82cf-4dc7-a532-9d998063fa95/permissions
data_center id: c6a1fb7a-ca1f-11e0-9c91-5254006cd06b
data_center href: /api/datacenters/c6a1fb7a-ca1f-11e0-9c91-5254006cd06b
memory_policy -> overcommit -> percent: 100
memory_policy -> transparent_hugepages -> enabled: false
version minor: 0
version major: 3
error_handling -> on_error: migrate


NAME: searchDataCenters.py
DESCRIPTION: Search a datacenter entry

EXAMPLE:

$ python searchDataCenters.py SuperDataCenter
Connecting to: https://192.168.123.176:8443/api/datacenters?search=SuperDataCenter
id: c0b0069f-c126-4e86-9df2-512ab4511be1
href: /api/datacenters/c0b0069f-c126-4e86-9df2-512ab4511be1
name: SuperDataCenter
description: Super
link ref: storagedomains
link href: /api/datacenters/c0b0069f-c126-4e86-9df2-512ab4511be1/storagedomains
link ref: permissions
link href: /api/datacenters/c0b0069f-c126-4e86-9df2-512ab4511be1/permissions
storage_type: nfs
version minor: 0
version major: 3
supported_versions minor: 0
supported_versions major: 3
status: uninitialized

id: 001d11c0-0f3c-4af6-9976-89bb07f0c9fd
href: /api/datacenters/001d11c0-0f3c-4af6-9976-89bb07f0c9fd
name: SuperDataCenter2
description: None
link ref: storagedomains
link href: /api/datacenters/001d11c0-0f3c-4af6-9976-89bb07f0c9fd/storagedomains
link ref: permissions
link href: /api/datacenters/001d11c0-0f3c-4af6-9976-89bb07f0c9fd/permissions
storage_type: nfs
version minor: 0
version major: 3
supported_versions minor: 0
supported_versions major: 3
status: uninitialized


NAME: createDataCenter.py
DESCRIPTION: Create a datacenter entry

EXAMPLE:

$ python createDataCenter.py my-super-datacenter nfs
Creating datacenter my-super-datacenter
Storage type: nfs
Connecting to: https://192.168.123.176:8443/api/datacenters
Done!


NAME: createHost.py
DESCRIPTION: Create a RHEL-H host entry

EXAMPLE:
$ python createHost.py myhost 192.168.1.54 T0pSecreT! MyCluster
Creating host myhost
Address: 192.168.1.54
cluster id 3d37ce24-fbce-11e0-9444-5254006cd06b
Connecting to: https://192.168.123.176:8443/api/hosts
Done!


NAME: maintenance-HOST.py
DESCRIPTION: set host to maintenance

EXAMPLE:
$ python maintenance-HOST.py 192.168.1.60
setting maintenance -> host: 192.168.1.60
host id 365cc1ce-0095-11e1-a353-5254006cd06b
Connecting to: https://192.168.123.176:8443/api/hosts/365cc1ce-0095-11e1-a353-5254006cd06b/deactivate
Done!


NAME: activate-HOST.py
DESCRIPTION: activate host

EXAMPLE:
$ python activate-HOST.py 192.168.1.60
setting activate -> host: 192.168.1.60
host id 365cc1ce-0095-11e1-a353-5254006cd06b
Connecting to: https://192.168.123.176:8443/api/hosts/365cc1ce-0095-11e1-a353-5254006cd06b/activate
Done!


NAME: createCluster.py
DESCRIPTION: Create a cluster entry

EXAMPLE:

$ python createDataCenter.py my-datacenter cluster-name
Creating datacenter cluster-name
datacenter id e5cca31a-15ae-4007-a7f7-763a94e151a7
e5cca31a-15ae-4007-a7f7-763a94e151a7
Connecting to: https://192.168.123.176:8443/api/clusters
Done!


NAME: createStorageNFS.py
DESCRIPTION: Create a Storage (NFS) entry

EXAMPLE:

$ python createStorageData.py my_storage nfs 192.168.1.103 /nfs/nfsData 192.168.1.60
Creating storage my_storage
Type: nfs
Address: 192.168.1.103
Path: /nfs/nfsData
host id 365cc1ce-0095-11e1-a353-5254006cd06b
Connecting to: https://192.168.123.176:8443/api/storagedomains
Done!


NAME: approveRHEV-H.py
DESCRIPTION: Approve a RHEV-H host

EXAMPLE:

$ python approveRHEV-H.py my-host-name
Approving host: my-host-name
host id a8d35c42-007f-11e1-a62b-5254006cd06b
Connecting to: https://192.168.123.176:8443/api/hosts/a8d35c42-007f-11e1-a62b-5254006cd06b/approve
Done!


NAME: discover_ISCSI.py
DESCRIPTION: Approve a RHEV-H host

EXAMPLE:

$ python discover_ISCSI.py 192.168.1.60 192.168.1.103
Host: 192.168.1.60
MySan_Address: 192.168.1.103
host id 365cc1ce-0095-11e1-a353-5254006cd06b
Connecting to: https://192.168.123.176:8443/api/hosts/365cc1ce-0095-11e1-a353-5254006cd06b/iscsidiscover
Done!

Response from server:
========================
iscsi/address: 192.168.1.103
status/state: complete
iscsi_target: iqn.1992-04.com.emc:storage.storage.iscsidata


NAME: login_ISCSI.py
DESCRIPTION: login to ISCSI LUN

EXAMPLE:

$ python login_ISCSI.py 192.168.1.60 192.168.1.103 iqn.1992-04.com.emc:storage.storage.iscsidata
Host: 192.168.1.60
MySan_Address: 192.168.1.103
Target: iqn.1992-04.com.emc:storage.storage.iscsidata
host id 365cc1ce-0095-11e1-a353-5254006cd06b
Connecting to: https://192.168.123.176:8443/api/hosts/365cc1ce-0095-11e1-a353-5254006cd06b/iscsilogin
Done!

Response from server:
========================
status/state: complete


NAME: createStorageDataISCSI_FCP.py
DESCRIPTION: Create Storage ISCSI or FCP

EXAMPLE:

$ python createStorageDataISCSI_FCP.py mysuperstorage 192.168.1.60 35000144f71377095 192.168.1.103 3260
iqn.1992-04.com.emc:storage.storage.12g
Creating storage mysuperstorage
host id 365cc1ce-0095-11e1-a353-5254006cd06b
Connecting to: https://192.168.123.176:8443/api/storagedomains
Executing...
Done!


NAME: activate-Storage.py
DESCRIPTION: Activate Storage

EXAMPLE:

$ python active-Storage.py dcLocalfs localfs datacenter: dcLocalfs storage: localfs dc id 55861b1d-6e12-47a4-a7c7-318271e6ec75 st id ba45d76e-ed92-481c-8a43-58ad191934d9 Connecting to: https://192.168.123.176:8443/api/datacenters/55861b1d-6e12-47a4-a7c7-318271e6ec75/storagedomains/ba45d76e-ed92-481c-8a43-58ad191934d9/activate Executing Done!


NAME: deactivate-Storage.py
DESCRIPTION: deactivate Storage

EXAMPLE:

$ python active-Storage.py dcLocalfs localfs datacenter: dcLocalfs storage: localfs dc id 55861b1d-6e12-47a4-a7c7-318271e6ec75 st id ba45d76e-ed92-481c-8a43-58ad191934d9 Connecting to: https://192.168.123.176:8443/api/datacenters/55861b1d-6e12-47a4-a7c7-318271e6ec75/storagedomains/ba45d76e-ed92-481c-8a43-58ad191934d9/deactivate Executing Done!


NAME: deleteStorage.py
DESCRIPTION: delete Storage

EXAMPLE:

$ python deleteStorage.py dc_iscsi iscsidata datacenter: dc_iscsi storage: iscsidata dc id 8294e814-89a8-414a-817b-c6fed0c3975c st id d03db166-f774-4529-a56f-c79093fdfb87 Connecting to: https://192.168.123.176:8443/api/datacenters/8294e814-89a8-414a-817b-c6fed0c3975c/storagedomains/d03db166-f774-4529-a56f-c79093fdfb87 Executing... Done!


NAME: createStorageDataLocalfs.py
DESCRIPTION: Create Local Storage

EXAMPLE:

$ python createStorageDataLocalfs.py my_local_storage 192.168.1.60 /data/image/rhev Creating storage my_local_storage
host id 365cc1ce-0095-11e1-a353-5254006cd06b
Connecting to: https://192.168.123.176:8443/api/storagedomains
Executing...
Done!


NAME: attachStorageToDataCenter.py
DESCRIPTION: Attach Storage to a DataCenter

EXAMPLE:

$ python attachStorageToDataCenter.py my_storage Default
Attaching storage: my_storage
DataCenter: Default
datacenter id c6a1fb7a-ca1f-11e0-9c91-5254006cd06b
Connecting to: https://192.168.123.176:8443/api/datacenters/c6a1fb7a-ca1f-11e0-9c91-5254006cd06b/storagedomains
Executing...
Done!


NAME: getStorageName.py
DESCRIPTION: get the name of storage

EXAMPLE:

$ python getStorageName.py Connecting to: https://192.168.123.176:8443/api/storagedomains localStorage my_storage iscsi_storage


NAME: python getStorage_alldata.py
DESCRIPTION: get all info about all storage

EXAMPLE:

$ python getStorageName.py
storage domain
==================
id: d2567b8c-e043-47c7-82d1-4489d8217c4f
name: suasdperiscsi
link rel: permissions
link href: /api/storagedomains/d2567b8c-e043-47c7-82d1-4489d8217c4f/permissions
type: data
master: false

storage
==================
type: iscsi
volume_group id: WkqSOJ-8YTZ-ayRR-CnIC-eUd3-GGL7-u7YtqA
logical_unit: 35000144f35002034
address: 192.168.1.103
port: 3260
target: iqn.1992-04.com.emc:storage.storage.iscsi11g
username: None
password:
serial: SEMC_LIFELINE-DISK_EMCDSK-350020-34
vendor_id: EMC
product_id: LIFELINE-DISK
lun_mapping: 0
portal: 192.168.1.103:3260,1
size: 11811160064
paths: 0

available: 6442450944
used: 4294967296
committed: 0
storage_format: v1


NAME: createVM.py
DESCRIPTION: create a virtual machine

EXAMPLE:

$ python createVM.py cluster_ISCSI myNEW_VM 536870912
Creating vm myNEW_VM
Connecting to: https://192.168.123.176:8443/api/vms
Done!


NAME: create_Storage_to_VM.py
DESCRIPTION: create a storage to a virtual machine

EXAMPLE:

$ python create_Storage_to_VM.py vm2 iscsiData150g 8589934592 data virtio raw false false
creating storage to vm: vm2
vm id c68a3b52-758d-41fc-984e-542c65bff555
st id 16f653b8-60e4-41ce-82a0-c3dc0da8a657
Connecting to: https://192.168.123.176:8443/api/vms/c68a3b52-758d-41fc-984e-542c65bff555/disks
Done!


NAME: create_NIC_to_VM.py
DESCRIPTION: create a nic to a virtual machine

EXAMPLE:

$ python create_NIC_to_VM.py vm2 nic1 rhevm virtio
creating network to vm: vm2
vm id c68a3b52-758d-41fc-984e-542c65bff555
Connecting to: https://192.168.123.176:8443/api/vms/c68a3b52-758d-41fc-984e-542c65bff555/nics
Done!


NAME: vm_stop.py
DESCRIPTION: stop virtual machine

EXAMPLE:

$ python vm_stop.py fedora16
starting vm: fedora16
vm id 215f74a2-8e23-4043-8b9b-c04a5f5dc4ba
Connecting to: https://192.168.123.176:8443/api/vms/215f74a2-8e23-4043-8b9b-c04a5f5dc4ba/stop
Done!


NAME: vm_start.py
DESCRIPTION: start virtual machine

EXAMPLE:

$ python vm_start.py fedora16
starting vm: fedora16
vm id 215f74a2-8e23-4043-8b9b-c04a5f5dc4ba
Connecting to: https://192.168.123.176:8443/api/vms/215f74a2-8e23-4043-8b9b-c04a5f5dc4ba/start
Done!


NAME: vm_shutdown.py
DESCRIPTION: shutdown virtual machine

EXAMPLE:
$ python vm_shutdown.py fedora16
shutdown vm: fedora16
vm id 215f74a2-8e23-4043-8b9b-c04a5f5dc4ba
Connecting to: https://192.168.123.176:8443/api/vms/215f74a2-8e23-4043-8b9b-c04a5f5dc4ba/shutdown
Done!


NAME: vm_attach_ISO.py
DESCRIPTION: attach ISO to a virtual machine

EXAMPLE:

$ python vm_attach_ISO.py fedora16 Fedora-16-x86_64-DVD.iso vm id 215f74a2-8e23-4043-8b9b-c04a5f5dc4ba Connecting to: https://192.168.123.176:8443/api/vms/215f74a2-8e23-4043-8b9b-c04a5f5dc4ba/cdroms Done!


NAME: vm_run_once_kernel_initrd.py
DESCRIPTION: run once a virtual machine with kernel/initrd changed

EXAMPLE:

$ python vm_run_once_kernel_initrd.py fedora16 kernel_path initrd_path "kernel_parameter1 kernel_parameter2 ..."
starting vm: fedora16
vm id 215f74a2-8e23-4043-8b9b-c04a5f5dc4ba
Connecting to: https://192.168.123.176:8443/api/vms/215f74a2-8e23-4043-8b9b-c04a5f5dc4ba/start
Done!


NAME: listISOFiles.py
DESCRIPTION: List ISO files

EXAMPLE:

$ python listISOFiles.py isoData
Connecting to: https://192.168.123.176:8443/api/storagedomains/41c80117-de4d-4e06-9aa6-d99e498a85a0/files
Executing...
ISO: en_windows_server_2008_datacenter_enterprise_standard_x86_dvd_x14-26710.iso
ISO: RHEL3-U9-re20070529.0-x86_64-AS-disc4-ftp.iso
ISO: RHEL6.0-20100701.0-Server-x86_64-DVD1.iso
ISO: RHEL3-U9-re20070529.0-x86_64-AS-disc2-ftp.iso


NAME: updateDataCenters.py
DESCRIPTION: Update DataCenter entry

EXAMPLE:

$ python updateDataCenters.py DataCenter SuperDataCenter Super
updating datacenter to DataCenter
new name: SuperDataCenter
new description: Super
datacenter id c0b0069f-c126-4e86-9df2-512ab4511be1
Connecting to: https://192.168.123.176:8443/api/datacenters/c0b0069f-c126-4e86-9df2-512ab4511be1
DataCenter updated


NAME: deleteCluster.py
DESCRIPTION: Delete a Cluster entry.

EXAMPLE:

$ python deleteCluster.py myoldCluster
Preparing to remove: myoldCluster
cluster id 70903910-0073-11e1-8909-5254006cd06b
connecting to: https://192.168.123.176:8443/api/clusters/70903910-0073-11e1-8909-5254006cd06b
Cluster removed


NAME: deleteDataCenter.py
DESCRIPTION: Delete a datacenter entry.

EXAMPLE:

$ python deleteDataCenter.py SuperDataCenter
Preparing to remove: SuperDataCenter-test
datacenter id 3dd5d8ea-23ba-4bd3-ae72-fc6230e126bd
connecting to: https://192.168.123.176:8443/api/datacenters/3dd5d8ea-23ba-4bd3-ae72-fc6230e126bd
DataCenter removed


NAME: getEvents_alldata.py
DESCRIPTION: Get all Events data.

EXAMPLE:

$ python getEvents_alldata.py
Connecting to: https://192.168.123.176:8443/api/events

id: 3341
href: /api/events/3341
code: 30
severity: normal
time: 2011-09-15T09:24:15.164-04:00
user id: ce2375f6-4fe0-4fc9-8692-6f4b7b50a9d6
user href: /api/users/ce2375f6-4fe0-4fc9-8692-6f4b7b50a9d6

id: 3340
href: /api/events/3340
code: 31
severity: normal
time: 2011-09-15T09:23:38.301-04:00
user id: ce2375f6-4fe0-4fc9-8692-6f4b7b50a9d6
user href: /api/users/ce2375f6-4fe0-4fc9-8692-6f4b7b50a9d6


NAME: getNetworks_alldata.py
DESCRIPTION: Get all network data available.

EXAMPLE:

$ python getNetworks_alldata.py
Connecting to: https://192.168.123.176:8443/api/networks

id: 00000000-0000-0000-0000-000000000009
href: /api/networks/00000000-0000-0000-0000-000000000009
name: rhevm
description: Management Network
data_center id: c6a1fb7a-ca1f-11e0-9c91-5254006cd06b
data_center href: /api/datacenters/c6a1fb7a-ca1f-11e0-9c91-5254006cd06b
stp: false
status -> state: operational

id: 96883b27-3c09-44ee-a317-b8e0a40d87f8
href: /api/networks/96883b27-3c09-44ee-a317-b8e0a40d87f8
name: rhevm
description: Management Network
data_center id: d2d438e3-24e2-4d65-bd69-a725634a3c0f
data_center href: /api/datacenters/d2d438e3-24e2-4d65-bd69-a725634a3c0f
stp: false
status -> state: non_operational


NAME: getClusters_alldata.py
DESCRIPTION: Get all data available in your cluster.

EXAMPLE:

$ python getClusters_alldata.py
Connecting to: https://192.168.123.176:8443/api/clusters

id: 99408929-82cf-4dc7-a532-9d998063fa95
href: /api/clusters/99408929-82cf-4dc7-a532-9d998063fa95
name: Default
description: The default server cluster
link rel: networks
link href: /api/clusters/99408929-82cf-4dc7-a532-9d998063fa95/networks
link rel: permissions
link href: /api/clusters/99408929-82cf-4dc7-a532-9d998063fa95/permissions
data_center id: c6a1fb7a-ca1f-11e0-9c91-5254006cd06b
data_center href: /api/datacenters/c6a1fb7a-ca1f-11e0-9c91-5254006cd06b
memory_policy -> overcommit -> percent: 100
memory_policy -> transparent_hugepages -> enabled: false
version minor: 0
version major: 3
error_handling -> on_error: migrate


NAME: getHosts_alldata.py
DESCRIPTION: Get all data available in your hosts.

EXAMPLE:

$ python getHosts_alldata.py
Connecting to: https://192.168.123.176:8443/api/hosts

id: beaea688-cd59-11e0-a86f-5254006cd06b
href: /api/hosts/beaea688-cd59-11e0-a86f-5254006cd06b
name: 192.168.1.54
actions: link rel: install
actions: link href: /api/hosts/beaea688-cd59-11e0-a86f-5254006cd06b/install
actions: link rel: activate
actions: link href: /api/hosts/beaea688-cd59-11e0-a86f-5254006cd06b/activate
actions: link rel: fence
actions: link href: /api/hosts/beaea688-cd59-11e0-a86f-5254006cd06b/fence
actions: link rel: deactivate
actions: link href: /api/hosts/beaea688-cd59-11e0-a86f-5254006cd06b/deactivate
actions: link rel: approve
actions: link href: /api/hosts/beaea688-cd59-11e0-a86f-5254006cd06b/approve
actions: link rel: iscsilogin
actions: link href: /api/hosts/beaea688-cd59-11e0-a86f-5254006cd06b/iscsilogin
actions: link rel: iscsidiscover
actions: link href: /api/hosts/beaea688-cd59-11e0-a86f-5254006cd06b/iscsidiscover
actions: link rel: commitnetconfig
actions: link href: /api/hosts/beaea688-cd59-11e0-a86f-5254006cd06b/commitnetconfig
link rel: storage
link href: /api/hosts/beaea688-cd59-11e0-a86f-5254006cd06b/storage
link rel: nics
link href: /api/hosts/beaea688-cd59-11e0-a86f-5254006cd06b/nics
link rel: tags
link href: /api/hosts/beaea688-cd59-11e0-a86f-5254006cd06b/tags
link rel: permissions
link href: /api/hosts/beaea688-cd59-11e0-a86f-5254006cd06b/permissions
link rel: statistics
link href: /api/hosts/beaea688-cd59-11e0-a86f-5254006cd06b/statistics
address: 192.168.1.54
status: non_responsive
cluster id: 99408929-82cf-4dc7-a532-9d998063fa95
cluster href: /api/clusters/99408929-82cf-4dc7-a532-9d998063fa95
port: 54321
storage_manager: false
power_management/enabled: false
ksm: true
transparent_hugepages: true
iscsi -> initiator: iqn.1994-05.com.redhat:3ece8aa1d7f1
cpu -> name: Intel(R) Pentium(R) D CPU 3.00GHz
cpu -> speed: 3000
cpu -> topology -> cores: 2
summary -> active: 0
summary -> migrating: 0
summary -> total: 0


NAME: getDataCenters_alldata.py
DESCRIPTION: Get all data available in your datacenters.

EXAMPLE:

$ python getDataCenters_alldata.py
Connecting to: https://192.168.123.176:8443/api/datacenters

id: c6a1fb7a-ca1f-11e0-9c91-5254006cd06b
href: /api/datacenters/c6a1fb7a-ca1f-11e0-9c91-5254006cd06b
name: Default
description: The default Data Center
link ref: storagedomains
link href: /api/datacenters/c6a1fb7a-ca1f-11e0-9c91-5254006cd06b/storagedomains
link ref: permissions
link href: /api/datacenters/c6a1fb7a-ca1f-11e0-9c91-5254006cd06b/permissions
storage_type: nfs
version minor: 0
version major: 3
supported_versions minor: 0
supported_versions major: 3
status: uninitialized


NAME: summary.py
DESCRIPTION: Shows the same data as /api/summary url.
Also, this script uses minidom XML API (instead of Element Tree as the others examples)

EXAMPLE:

$ python summary.py -i 192.168.123.176 -u [email protected] -p T0pSecreT!
Connecting to: https://192.168.123.176:8443/api
hosts: total 1
hosts: active 1
users: total 1
users: active 1
vms: total 3
vms: active 0
storage_domains: total 1
storage_domains: active 1


NAME: getDataCentersName.py
DESCRIPTION: Get the name of all your DataCenters.

EXAMPLE:

$ python getDataCentersName.py
Connecting to: https://192.168.123.176:8443/api/datacenters
Default
TestDataCenter


NAME: getHostsName.py
DESCRIPTION: Get the name of all your Hosts.

EXAMPLE:

$ python getHostsName.py
Connecting to: https://192.168.123.176:8443/api/hosts
super-server
super-server02


NAME: getClusterName.py
DESCRIPTION: Get the name of all your Clusters.

EXAMPLE:

$ python getClusterName.py
Connecting to: https://192.168.123.176:8443/api/clusters
SuperCluster01
SuperCluster02

Contact/improvements/add your script

dougsland AT redhat DOT com

Clone this wiki locally