Preview only show first 10 pages with watermark. For full document please download

Working With Powervc Via Its Rest Apis

This set of slides showcases how you can interact with PowerVC via its OpenStack-based REST APIs. It also demonstrates how to mimic the REST APIs made from your web browser in familiar command line utilities like curl.

   EMBED


Share

Transcript

1. Managing PowerVC via REST APIs 1 2. © 2016 IBM Corporation • Types of REST APIs : OpenStack, PowerVC Enhanced OpenStack and PowerVC supported APIs • Example PowerVC APIs: PowerVM, HMCs, and SCGs • PowerVC GUI uses REST APIs • http://www-01.ibm.com/support/knowledgecenter/api/content/nl/en- us/SSXK2N_1.3.2/com.ibm.powervc.standard.help.doc/powervc_pg_kickoff_hmc.html • Secured with https (TLS 1.2) • Can be used on any system running Python 2.7 (do not need PowerVC installed to run APIs) • Need a recent level of Python 2.7 version Overview 3. © 2016 IBM Corporation Basic flow: Authenticate (PowerVC uses TLS 1.2) Use authentication token to make subsequent API calls Example: Display list of PowerVC Networks REST API client Keystone Neutron (Post) Authentication Request Authentication Response – includes the token needed for subsequent requests (Get) list of networks Using authorization token JSON based response A list of networks Working with REST APIs 4. © 2016 IBM Corporation  The easiest way to get started is to observe the PowerVC UI as it makes API calls  Use a browser plugin like Firebug for Firefox or the Chrome Developers Toolkit Getting Started 5. © 2016 IBM Corporation Example: logging in From the PowerVC GUI, log into PowerVC Make sure you have selected the Persist button to see all the requests. The login process sends a POST request to the PowerVC server as the first request Hover over request to see the URL Getting Started 6. © 2016 IBM Corporation Select the Post tab to see the actual JSON data that is sent from the browser in the request to PowerVC Using Firebug you can see the source data or a more readable JSON version. This source data is exactly the same data you would use from your own custom client script or application! Getting Started 7. © 2016 IBM Corporation From the Response tab you can see the entire raw JSON response These are the data your custom client script or application will need to process Getting Started 8. © 2016 IBM Corporation You can also view the response in a more user-friendly JSON display format. Getting Started 9. © 2016 IBM Corporation REST API – Creation of an LPAR  For creating an LPAR/VM you need: – An API token • After authenticating with user/password you get a token – The tenant • A tenant is a project. The terms project or tenant are interchangeable. • The default project is “ibm-default”, but since PowerVC 1.3.1 also other user defined projects are possible. – The IDs of: • The used network • The desired image • The Storage Connectivity Group – Details of the new LPAR, like name, size and so on … 10. © 2016 IBM Corporation REST API – using curl – Get token  Create the following file auth.json with the correct user name and password: {"auth": {"scope": {"project": {"name": "ibm-default", "domain": {"name": "Default"} } }, "identity": {"methods": ["password"], "password": {"user": {"domain": {"name": "Default"}, "name": "userName", "password": "userPassword" } } } } } 11. © 2016 IBM Corporation REST API – using curl – Get token  Use the file auth.json with the following curl command: # curl -1 -k -i -X POST https://<PowerVC URL>:5000/v3/auth/tokens -H "Accept: application/json" -H "Content-Type: application/json" -d @auth.json HTTP/1.1 201 Created Date: Fri, 15 Apr 2016 11:29:38 GMT Server: Apache X-Subject-Token: 35af31a38ca948788b771b5e8fbb0ddc Vary: X-Auth-Token x-openstack-request-id: req-a90f45bc-354e-4e76-8c2e-fda44508c7c1 Content-Length: 4858 Content-Type: application/json {"token": {"methods": ["password"], "roles": [{"id": "b7d2cade8fa1493a962ac7fb926324fe", "name": "admin"}], "expires_at": "2016-04-15T17:29:39.061651Z", "project": {"domain": {"id": "default", "name": "Default"}, "id": "1953082a91d54db8a51fc8a742df46c6", "name": "ibm-default"}, "catalog": [{"endpoints": [{"region_id": "RegionOne", "url": "https://cl- powervc.ibm-tce-cloud.com:35357/v3", "region": "RegionOne", "interface": "a … 12. © 2016 IBM Corporation REST API – using curl – Get tenant  Get the tenant using the token … # curl -1 -k -i -X GET https://powervc:5000/v3/projects -H "X-Auth-Token:<Token>“ HTTP/1.1 200 OK Date: Fri, 15 Apr 2016 12:03:55 GMT Server: Apache Vary: X-Auth-Token x-openstack-request-id: req-caba8d80-e4a0-4b23-a5bf-2f250dcd6949 Content-Length: 725 Content-Type: application/json {"links": {"self": "https://cl-powervc.ibm-tce-cloud.com:5000/v3/projects", "previous": null, "next": null}, "projects": [{"is_domain": false, "description": "IBM Default Tenant", "links": {"self": "https://cl-powervc.ibm-tce- cloud.com:5000/v3/projects/1953082a91d54db8a51fc8a742df46c6"}, "enabled": true, "id": "1953082a91d54db8a51fc8a742df46c6", "parent_id": null, "domain_id": "default", "name": "ibm-default"}, {"is_domain": false, "description": "Service Tenant", "links": {"self": "https://cl-powervc.ibm-tce- cloud.com:5000/v3/projects/d8d34c62047647598eb3fc2caca25027"}, "enabled": true, "id": "d8d34c62047647598eb3fc2caca25027", "parent_id": null, "domain_id": "495548495c1d4cbb928a80a141c3b775", "name": "service"}]} 13. © 2016 IBM Corporation Tipp: REST API – using curl – Get tenant – with JSON parser  To make the output better readable, remove the “-i” and add “| python - mjson.tool” # curl -1 -k -X GET https://powervc:5000/v3/projects -H "X-Auth-Token:<Token>“| python - mjson.tool % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 725 100 725 0 0 1942 0 --:--:-- --:--:-- --:--:-- 1943 { "links": { "next": null, "previous": null, "self": "https://cl-powervc.ibm-tce-cloud.com:5000/v3/projects" }, "projects": [ { "description": "IBM Default Tenant", "domain_id": "default", "enabled": true, "id": "1953082a91d54db8a51fc8a742df46c6", 14. © 2016 IBM Corporation REST API – using curl – Get networks  Get the networks using the token … # curl -1 -k -i -X GET https://powervc:5000//powervc/openstack/network/v2.0/networks -H "X-Auth-Token: <Token>" -H "Content-Type: application/json“ HTTP/1.1 200 OK Date: Fri, 15 Apr 2016 12:08:59 GMT Server: Apache Content-Type: application/json; charset=UTF-8 Content-Length: 767 X-Openstack-Request-Id: req-be727fca-2bee-4f06-9a7b-aa577676ecaa Cache-control: no-cache Pragma: no-cache {"networks": [{"status": "ACTIVE", "subnets": ["749dbcf1-3f63-4e69-9233-c2f6cd38c0b6"], "name": "Cloud Network", "provider:physical_network": "default", "admin_state_up": true, "tenant_id": "1953082a91d54db8a51fc8a742df46c6", "mtu": null, "router:external": false, "shared": true, "provider:network_type": "vlan", "id": "c50d3a61-a2a5-43eb-9c6b- dcf38b4f1dd3", "provider:segmentation_id": 1}, {"status": "ACTIVE", "subnets": ["7b27af7b-3ac4-4bb0-94fe-87a5efd2017d"], "name": "9erNetwork", "provider:physical_network": "default", "admin_state_up": true, "tenant_id": "1953082a91d54db8a51fc8a742df46c6", "mtu": null, "router:external": false, "shared": true, "provider:network_type": "vlan", "id": "f9de96c4-c5eb-4f74-912d-43a658e88e92", "provider:segmentation_id": 2}]} 15. © 2016 IBM Corporation REST API – using curl – Get images  Get the images using the token for the tenant … # curl -1 -k -i -X GET https://powervc:5000/powervc/openstack/compute/v2/<Tenant>/images -H "X-Auth-Token: <Token> " -H "Content-Type: application/json“ HTTP/1.1 200 OK Date: Fri, 15 Apr 2016 12:13:21 GMT Server: Apache Content-Type: application/json Content-Length: 4987 X-Compute-Request-Id: req-cd36fc90-7d0b-473f-b7fd-21c505b6326a Cache-control: no-cache Pragma: no-cache {"images": [{"id": "c3f2de51-385d-4ee7-8a2e-61ca0bf7c58a", "links": [{"href": "https://cl-powervc.ibm-tce- cloud.com:8774/v2/1953082a91d54db8a51fc8a742df46c6/images/c3f2de51-385d-4ee7-8a2e- 61ca0bf7c58a", "rel": "self"}, {"href": "https://cl-powervc.ibm-tce- cloud.com:8774/1953082a91d54db8a51fc8a742df46c6/images/c3f2de51-385d-4ee7-8a2e- 61ca0bf7c58a", "rel": "bookmark"}, {"href": "https://cl-powervc.ibm-tce- cloud.com:9292/images/c3f2de51-385d-4ee7-8a2e-61ca0bf7c58a", "type": "application/vnd.openstack.image", "rel": "alternate"}], "name": "SLES11CI"}, {"id": "a1ad5dfd-e990-4f07-bcb4-10a8a4e25c54", "links": [{"href": "https://cl-powervc.ibm-tce- cloud.com:8774/v2/1953082a91d54db8a51fc8a742df46c6/images/a1ad5dfd-e990-4f07-bcb4- 10a8a4e25c54", "rel": "self"}, {"href": "https://cl-powervc.ibm-tce- cloud.com:8774/1953082a91d54db8a51fc8a742df46c6/images/a1ad5dfd-e990-4f07-bcb4- … 16. © 2016 IBM Corporation REST API – using curl – Get Storage Connectivity Group  Get the SCGs using the token for the tenant … # curl -1 -k -i -X GET https://powervc:5000/powervc/openstack/compute/v2/<Tenant>/storage-connectivity-groups -H "X-Auth-Token: <Token>" -H "Content-Type: application/json“ HTTP/1.1 200 OK Date: Fri, 15 Apr 2016 12:17:07 GMT Server: Apache Content-Type: application/json; charset=UTF-8 Content-Length: 749 X-Compute-Request-Id: req-56b63f94-534f-4853-bc06-8ddb361531e1 Cache-control: no-cache Pragma: no-cache {"storage_connectivity_groups": [{"display_name": "Any host, all VIOS", "id": "6a180ca0- b2a4-483d-a864-0c1f92294e21"}, {"display_name": "Any host in cl-cluster", "id": "be661942-4e87-4517-8678-5cbe3ff79b2b"}, {"display_name": "Belt", "id": "485ed115-5b6d- 429d-bf5c-782428699d9b"}, {"display_name": "vSCSI", "id": "b15e278d-ee5e-41bb-9ab9- 770955c8082a"}, {"display_name": "BB_vSCSI", "id": "5befa22d-5fd1-4f19-ab28- dc374e0e0b21"}, {"display_name": "auto-vscsi_npiv", "id": "a29ba01d-a7ae-47b8-8734- 90ddd769d1a3"}, {"display_name": "Braces", "id": "99bcb22f-c7c0-4020-b07e-af0451b5acdc"}, {"display_name": "vSCSI_NPIV", "id": "edc59fbe-e305-405e-959f-1d1785c55565"}, {"display_name": "auto-vscsi_vscsi", "id": "017a9f94-2cd1-4576-8969-e3203df955d0"}]} 17. © 2016 IBM Corporation REST API – using curl – Deploy a VM  Use all the data to deploy a VM # curl -1 -k -i -X POST https://powervc:5000/powervc/openstack/compute/v2/<Tenant>/servers -H "X-Auth-Token: <Token>" -H "Content-Type: application/json" -d '{"server":{ "name": “MyName", "max_count": 1,"networkId":“<Network ID>", "imageRef": “<Image ID>", "networks":[{"uuid": “<Network ID>"}],"flavor": {"ram":1024,"vcpus":1,"disk": 30,"extra_specs": { "powervm:proc_units":"0.1", "powervm:storage_connectivity_group":“<Storage Connectivity Group ID>"}}}}‘ HTTP/1.1 202 Accepted Date: Fri, 15 Apr 2016 12:20:39 GMT Server: Apache Location: https://cl-powervc.ibm-tce- cloud.com:8774/v2/1953082a91d54db8a51fc8a742df46c6/servers/f312a9f0-2b96-4645-b588- a7d7b2473c71 Content-Type: application/json Content-Length: 474 X-Compute-Request-Id: req-2ace156a-0993-4cd9-8cd8-ce208fcd179d Cache-control: no-cache Pragma: no-cache {"server": {"security_groups": [{"name": "default"}], "OS-DCF:diskConfig": "MANUAL", "id": "f312a9f0-2b96-4645-b588-a7d7b2473c71", "links": [{"href": "https://cl-powervc.ibm- tce-cloud.com:8774/v2/1953082a91d54db8a51fc8a742df46c6/servers/f312a9f0-2b96-4645-b588- a7d7b2473c71", "rel": "self"}, {"href": "https://cl-powervc.ibm-tce- cloud.com:8774/1953082a91d54db8a51fc8a742df46c6/servers/f312a9f0-2b96-4645-b588- a7d7b2473c71", "rel": "bookmark"}], "adminPass": "73kgFCSZXEhW"}} 18. © 2016 IBM Corporation REST API – using curl – List VMs 19. © 2016 IBM Corporation REST API – using curl – List Volume, WWPN and Zoning for VM 20. © 2016 IBM Corporation REST API – using curl – List Volume, WWPN and Zoning for VM 21. © 2016 IBM Corporation REST API – using curl – List Volume, WWPN and Zoning for VM 22. © 2016 IBM Corporation REST API – Using Python – Creation of an LPAR – API token – Get the token … If you did not specify user and password # openstack token issue --os-username=<User> Password: +------------+------------------------------------------------------------------+ | Field | Value | +------------+------------------------------------------------------------------+ | expires | 2016-07-19T19:46:46.961130Z | | id | c400003fc6a24c48b52abe52b7f9a51b | | project_id | 3c10a75d0cd14cb19c1567cccaf76991 | | user_id | 4b0d1b529006c03834a03106992f24c73a31c4b7537d91560e73973c63a685f8 | +------------+------------------------------------------------------------------+ – The token is valid for 4 hours – If you did not source anything and want another project (ex. marketing), use: # openstack token issue --os-username=<user> --os-auth-url=https://cl-powervc.ibm- tce-cloud.com:5000/v3/ --os-project-name=marketing --os-cacert=/etc/pki/tls/certs/ powervc.crt --os-user-domain-name=Default --os-project-domain-name=Default Password: +------------+-----------------------------------------------------------------+ | Field | Value | +------------+-----------------------------------------------------------------+ | expires | 2016-07-19T20:18:56.945144Z | | id | 4c90450a0879471694a4c10f772a2d68 | | project_id | 804682d760974ca9949d55da7efe9662 | | user_id | 4b0d1b529006c03834a03106992f24c73a31c4b7537d91560e73973c63a685f8| +------------+-----------------------------------------------------------------+ 23. © 2016 IBM Corporation REST API – Creation of an LPAR – Tenant  To get the tenant, the following script could be used <tenants>*): #!/usr/bin/python import httplib import json import os import sys def main(): token = raw_input("Please enter PowerVC token : ") print "PowerVC token used = "+token conn = httplib.HTTPSConnection('localhost') headers = {"X-Auth-Token":token, "Content-type":"application/json"} body = "" conn.request("GET", "/powervc/openstack/identity/v2.0/tenants", body, headers) conn.request("GET", "/powervc/openstack/identity/v3/projects", body, headers) response = conn.getresponse() raw_response = response.read() conn.close() json_data = json.loads(raw_response) print json.dumps(json_data, indent=4, sort_keys=True) if __name__ == "__main__": main() 24. © 2016 IBM Corporation REST API – Creation of an LPAR – Tenant The output of the tenants script: # ./tenants Please enter PowerVC token : c192e0016c844d1c865238beb5994aac PowerVC token used = c192e0016c844d1c865238beb5994aac { "links": { "next": null, "previous": null, "self": "https://cl-powervc.ibm-tce-cloud.com/powervc/openstack/identity/v3/projects" }, "projects": [ { "description": "IBM Default Tenant", "domain_id": "default", "enabled": true, "id": "b8b4106dee504ed9b2882bf39db94486", "is_domain": false, … 25. © 2016 IBM Corporation REST API – Creation of an LPAR – Network ID  To get the network IDs, the following script could be used <networks>*): #!/usr/bin/python import httplib import json import os import sys def main(): token = raw_input("Please enter PowerVC token : ") conn = httplib.HTTPSConnection('localhost') headers = {"X-Auth-Token":token, "Content-type":"application/json"} body = "" conn.request("GET", "/powervc/openstack/network/v2.0/networks", body, headers) response = conn.getresponse() raw_response = response.read() conn.close() json_data = json.loads(raw_response) print json.dumps(json_data, indent=4, sort_keys=True) if __name__ == "__main__": main() 26. © 2016 IBM Corporation REST API – Creation of an LPAR – Network ID The output of the networks script: # ./networks Please enter PowerVC token : c192e0016c844d1c865238beb5994aac { "networks": [ { "admin_state_up": true, "id": "8e11a651-c019-4d87-a648-ab7e04842094", "mtu": null, "name": "Cloud Network", "provider:network_type": "vlan", "provider:physical_network": "default", "provider:segmentation_id": 1, "router:external": false, "shared": true, "status": "ACTIVE", "subnets": [ "2d395a1c-e25b-4ed7-b5b7-2c7fdb487c9b" ], "tenant_id": "b8b4106dee504ed9b2882bf39db94486" }, { "admin_state_up": true, "id": "a24cbb7d-65fb-43af-9750-dec63dd50389", "name": "9er Network", … 27. © 2016 IBM Corporation REST API – Creation of an LPAR – Image ID  To get the image IDs, the following script could be used <images>*): #!/usr/bin/python import httplib import json import os import sys def main(): token = raw_input("Please enter PowerVC token : ") tenant_id = raw_input("Please enter PowerVC Tenant ID : ") conn = httplib.HTTPSConnection('localhost') headers = {"X-Auth-Token":token, "Content-type":"application/json"} body = "" conn.request("GET", "/powervc/openstack/compute/v2/"+tenant_id+"/images", body, headers) response = conn.getresponse() raw_response = response.read() conn.close() json_data = json.loads(raw_response) print json.dumps(json_data, indent=4, sort_keys=True) if __name__ == "__main__": main() 28. © 2016 IBM Corporation REST API – Creation of an LPAR – Image ID The output of the images script: # ./images Please enter