dropdown menu

POWERVC - API PYTHON


API calls can be done through Python as well.
(I did not test these, just collected, I used curl)

1. get token id (with any method)
With openstack command a token can be requested (make sure you use the same user later, as token is valid for that user)

openstack token issue

---------------------------------

2. get tenant id
(we will need the id of IBM Default Tenant)
(for v3 tenant and project are interchangeable)

IBM default tenant: tenant_id="3dd716cc52c617bface86421017afd1d"

#!/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/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()


---------------------------------

3. get VMs and id

#!/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

    tenant_id = raw_input("Please enter PowerVC Tenant ID : ")
    print "Tenant ID = "+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+"/servers", 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()


---------------------------------

List details of all servers:
"GET", "/powervc/openstack/compute/v2/"+tenant_id+"/servers/detail"

List networks details:
"GET", "/powervc/openstack/network/v2.0/networks",

We will get Unix network id: d93e1f57-958e-47de-b94e-f90ce5277fd9

List details only of 1 specified network:
"GET", "/powervc/openstack/network/v2.0/networks/d93e1f57-958e-47de-b94e-f90ce5277fd9"



1 comment:

What is an API Call said...

API calls are the backbone of modern software systems, enabling seamless communication and integration between applications. They empower developers to leverage external services, access data, and build innovative solutions. APIs drive digital transformation, enhance collaboration, and create rich user experiences, making them indispensable in today's interconnected world.