Cloud实战:Manage and Manipulate OpenStack with CLI, SDK and AP

时间:2022-04-22 08:34:52

标签:openstack cli sdk api aws hybrid cloud

 Cloud IN ACTION: Manage and Manipulate OpenStack with CLI, SDK and API

  

 薛*    


Today we are going to experience the three ways to manage and manipulate OpenStack –CLI, SDK and API; and then develop a simple Hybrid Cloud application with Python to exchange data between Amazon Web Services and OpenStack.



API, SDK and CLI

There are three ways you canuse Openstack:

 

RESTful API, you can send the requests directly using HTTP GET or POST via a Web Browser, your program code or using cURL to the service endpoints (APIGateway) of OpenStack and issue your commands. Using the OpenStack APIs, you can launch server instances, create images, assign metadata to instances and images, create storage containers and objects, and complete other actions in the OpenStack-based Cloud.

 

SDK, aka the language-level API. Making the API calls directly could be cumbersome and you have to repeat a lot of template code time and again, and handle the HTTP status code and response carefully. SDK provides the set of lanuage binds in Java, Python, Go and C++ etc, and it can help build the HTTP requests and make the API calls, allowing us to access OpenStack in a manner consistent with high-level language standards such as make function calls.

 

CLI, OpenStack also provied the command-line interfaces with OpenStackClients, along with the natvie Python API bindings for Compute,Identity,Image,Object Store and Block Storage etc. We have used CLI many times during the Openstack installation and configuration.



OpenStack API: Making the RESTful API calls to OpenStack

https://developer.openstack.org/api-guide/quick-start/


Cloud实战:Manage and Manipulate OpenStack with CLI, SDK and AP


// To authenticate with OpenStack KeyStone

// and get the token and service catalog via cURL or Postman

URL: :5000/v2.0/tokens

Method: POST

Headers: Content-Type:application/json

Data: {"auth":{"tenantName":"admin","passwordCredentials":{"username":"admin","password":"ipcc2014"}}}  

 

Response:

The project id: "448c4d583e1240ee93b0800c382fd494";

The token: "gAAAAABZ9hCPjL9D6uz3lqR6spcDgBWaR28VtkVZfGzcVTh-pPXPzvUElKuHLgiAekm7gVObUDGVjXdfM6ZqslYynFIf2aRKLdKZuP2W3Ps8yw70ZRISCFtRxN8wsOh-iEc1-ZUm0rqd9co_m7xSQTqRzFNtKKpAftAHbZYb58d0H2YofvHSUAk"



// To make HTTP requests to Nova with the received token and project ID, and get the instance info

URL: :8774/v2.1/448c4d583e1240ee93b0800c382fd494/servers

Method: GET

Headers:

Accept:application/json

Content-Type:application/json

X-Auth-Token:gAAAAABZ9hCPjL9D6uz3lqR6spcDgBWaR28VtkVZfGzcVTh-pPXPzvUElKuHLgiAekm7gVObUDGVjXdfM6ZqslYynFIf2aRKLdKZuP2W3Ps8yw70ZRISCFtRxN8wsOh-iEc1-ZUm0rqd9co_m7xSQTqRzFNtKKpAftAHbZYb58d0H2YofvHSUAk

 

Response:


OpenStack SDK(Python): Making functional calls with the native Python bindings

https://wiki.openstack.org/wiki/SDKs

https://wiki.openstack.org/wiki/OpenStackClients

 

// To install pip and python-openstackclient

sudo apt-get installpython-pip

sudo apt-get install curl

sudo pip installpython-keystoneclient

sudo pip installpython-novaclient

sudo pip installpython-glanceclient

 

// To list all the images from OpenStack Glance

import keystoneclient.v2_0.client as ksclient

import glanceclient

 

# To authenticate with Keystone and get thetoken and servive catalog

keystone =ksclient.Client(auth_url="http://10.0.0.11:5000/v2.0",