Este contenido no está disponible en el idioma seleccionado.
16.4. Retrieving Resources from a Collection
get and list methods.
-
get - Retrieves a single resource from the collection. The item to retrieve is determined based on the name provided as an argument. The
getmethod takes these arguments:name- The name of the resource to retrieve from the collection.id- The globally unique identifier (GUID) of the resource to retrieve from the collection.
-
list - Retrieves any number of resources from the collection. The items to retrieve are determined based on the criteria provided. The
listmethod takes these arguments:**kwargs- A dictionary of additional arguments allowing keyword-based filtering.query- A query written in the same format as that used for searches executed using the Red Hat Storage Console.max- The maximum number of resources to retrieve.case_sensitive- Whether or not search terms are to be treated as case sensitive (TrueorFalse, the default isTrue).
Example 16.1. Retrieving a List of Resources in a Collection Matching a Keyword Based Filter
16.4.1. Retrieving a Specific Resource from a Collection Copiar enlaceEnlace copiado en el portapapeles!
get method.
name parameter of the get method:
cl = api.clusters.get("Default")
cl = api.clusters.get("Default")
cl = api.clusters.get(name="Default")
cl = api.clusters.get(name="Default")
16.4.2. Retrieving a List of Resources from a Collection Copiar enlaceEnlace copiado en el portapapeles!
list method.
Example 16.2. Listing All Clusters
get_name() method provides the name of the cluster and the get_gluster_service() returns true or false based on glusterFS support in the cluster:
Example 16.3. Listing All Hosts
api.hosts.list() provides a dictionary list that contains the host name and the host ID.
h1 (51b29199-3a7f-49e4-b0d5-92afdeea1f15) h2 (4e8c3642-e654-456c-9dff-a240c8a43b1f) host1 (14e3823d-d557-4635-bd9f-0c6157ab7f07)
h1 (51b29199-3a7f-49e4-b0d5-92afdeea1f15)
h2 (4e8c3642-e654-456c-9dff-a240c8a43b1f)
host1 (14e3823d-d557-4635-bd9f-0c6157ab7f07)
Important
list method of a collection is restricted to returning only as many elements as allowed by the SearchResultsLimit configuration key in the Red Hat Storage Console. To ensure that all records in a the list are returned, it is recommended to paginate through the results as illustrated in this example. Alternatively, set the max parameter of the list method to the maximum number of records that you wish to retrieve.
Example 16.4. Listing All Red Hat Storage Volumes
VolumeName: vol1
VolumeName: vol1
Example 16.5. Listing All Users
User name: admin (User ID: fdfc627c-d875-11e0-90f0-83df133b58cc)
User name: admin (User ID: fdfc627c-d875-11e0-90f0-83df133b58cc)
Example 16.6. Listing All Roles
getUsers() function lists all the roles in the Red Hat Storage Console.
for i in api.roles.list(): print i.name
for i in api.roles.list():
print i.name
Example 16.7. Listing All Network Details
nic.get_status().get_state() returns the network status as either up or down.
NIC Name: eth0 IPAddress: 10.70.37.194 MAC Address: 00:1a:4a:46:24:9e netStatus: up
NIC Name: eth0
IPAddress: 10.70.37.194
MAC Address: 00:1a:4a:46:24:9e
netStatus: up
nic.get_ip().set_address()nic.get_ip()set_netmask()nic.get_ip().set_gateway()nic.set_bridged()