Provisioning

A-Synchronous Provisioning & Creating Storage for a Host

This example demonstrates checking an array SRP and service level to determine if there is enough headroom to provision storage of a set size, if so, proceed to creating a storage group with volume. Create a host, port group, and masking view to tie all the elements together, close the session when done.

 1"""docs/source/programmers_guide_src/code/provision-async_create_storage.py"""
 2
 3import PyU4V
 4
 5# Initialise PyU4V connection to Unisphere
 6conn = PyU4V.U4VConn()
 7
 8# Before provisioning storage we are going to check that there is enough
 9# headroom left on the array for our provisioning operations
10REQUESTED_CAPACITY = 10
11
12# Get the available headroom for the SRP and service level required
13headroom_info = conn.wlp.get_headroom(array_id=conn.array_id,
14                                      srp='SRP_1', slo='Diamond')
15
16# Extract the capacity value from the headroom_info REST response
17headroom_capacity = headroom_info[
18    'OLTP'][0]['headroom'][0]['headroomCapacity']
19
20# If the requested capacity of 10GB is less than or equal to the available
21# capacity proceed with the provisioning operations
22if REQUESTED_CAPACITY <= int(headroom_capacity):
23    # Create a non-empty storage group using asynchronous request - we can
24    # wait until the job completes or proceed with operations and check
25    # back at a later time
26    storage_group_async_job = (
27        conn.provisioning.create_non_empty_storage_group(
28            srp_id='SRP_1', storage_group_id='example-sg',
29            service_level='Diamond', num_vols=1,
30            vol_size=REQUESTED_CAPACITY, cap_unit='GB', _async=True))
31
32    # We will wait this time on the results of the storage group create
33    # request
34    conn.common.wait_for_job(operation='Create SG with volume',
35                             job=storage_group_async_job)
36    print('Storage Group created successfully...')
37
38    # Get information on our new storage group
39    storage_group_info = conn.provisioning.get_storage_group(
40        storage_group_name='Example-SG')
41    print('Storage Group details: {details}'.format(
42        details=storage_group_info))
43
44    # Create a Host using supplied initiator IDs, these can be also be
45    # retrieved via the call conn.provisioning.get_available_initiator()
46    initiator_list = ['iqn:2020-test1', 'iqn:2020-test1']
47    host_info = conn.provisioning.create_host(
48        host_name='Example-Host', initiator_list=initiator_list)
49    print('Host created successfully...')
50    print('New Host details: {details}'.format(details=host_info))
51
52    # Create a Port Group using supplied ports, these could be also be
53    # retrieved via the call conn.provisioning.get_port_list()
54    port_group_info = conn.provisioning.create_port_group(
55        port_group_id='Example-PG', director_id='SE-01', port_id='1')
56    print('Port Group created successfully...')
57    print('Port Group details: {details}'.format(details=port_group_info))
58
59    # Create a Masking View and tie all the elements we have created
60    # together
61    masking_view_info = (
62        conn.provisioning.create_masking_view_existing_components(
63            port_group_name='Example-PG', masking_view_name='Example-MV',
64            storage_group_name='Example-SG', host_name='Example-Host'))
65    print('Masking View created...')
66    print('Masking View details: {details}'.format(
67        details=masking_view_info))
68
69# Close the session
70conn.close_session()