Getting Started with the FUJITSU K5 API on a Windows Workstation

Updated 01/09/2017

K5 is built using one of the most open, secure and scalable cloud platforms available in the market today –Openstack. Due to this it means every function you see displayed in the portal (and some you don’t) are all available to consume via a REST API. For more information on REST APIs take a look at https://en.wikipedia.org/wiki/Representational_state_transfer.

REST APIs require you to programmatically interact with them, meaning you need to write code or use a specific tool to enable you to send or receive information. The interaction with K5 REST APIs is performed using Linux command line/code, so requires a basic understanding and comfortable with using the Linux command line and understanding code syntax.

Cygwin
A tool such as Cygwin, can be used to provide a Linux command line environment on a MS Windows workstation. Cygwin (pronounced SIG-win) is a Unix-like environment and command-line interface for Microsoft Windows, providing native integration of Windows-based applications, data, and other system resources with applications, software tools, and data of the Unix-like environment. (See the end of this blog for details of using MobaXterm as an alternative to Cygwin)

cURL
In order to submit the REST API commands from within the Cygwin environment, the Linux tool cURL is used. This is a command-line tool that lets you send HTTP requests and receive responses. For some practical examples using cURL visit http://www.thegeekstuff.com/2012/04/curl-examples/

JQ
JQ is a lightweight and flexible command-line JSON processor, that can be used to slice, filter, map and transform structured data passed to it. Its use is recommend and included in K5 API examples across the guides to filter, structure and present the result of submitted API commands in JSON format.

 

Installing Cygwin including cURL & JQ

1. Download the latest 64-bit version of Cygwin for Windows from make and run ‘setup-x86_64.exe’ to begin the install.

2. On the ‘Cygwin Setup’ screen click ‘Next’

3. On ‘Choose Installation Type’ screen select ‘Install from Internet’ and click ‘Next’

4. On ‘Choose Installation Directory’ screen, accept the default ‘Root Directory’ and ‘All Users (RECOMMENDED)’ and click ‘Next’

5. On ‘Select Local Package Directory’, accept the default and click ‘Next’

6. On ‘Select Connection Type’ screen, select ‘Use Internet Explorer Proxy Settings’ and click ‘Next’

7. On ‘Choose Download Site(s)’ screen, select anyone of the sites, click ‘Add’ and then ‘Next’

8. On ‘Select Package’ screen, enter ‘curl’ into the ‘Search’ box. NOTE: Do not click hit the ‘Return’ key as this progress the install wizard to the next screen.

9. In the results, expand ‘Net’ then click on ‘Default’ till it changes to ‘Install’.11. Next, enter ‘gcc’ into the ‘Search’ box, click ‘Default’ next to ‘Devel’ to install all compiles (a GCC C compiler is required if you want to try just individual components)

10. Next, enter ‘jq’ into the ‘Search’ box, expand ‘text ‘ and change ‘Default’ to install

11. If you would also like to install the Openstack CLI tools later, then I would also recommend installing

  • wget – expand web and change ‘Default’ to ‘Install’
  • pip –  expand python | python2-pip and change ‘Skip’ to <versionnumber>
  • python2-devel – expand python and change ‘Skip’ to <versionnumber>

(OPTIONAL) Other Linux components that you may be familiar with or likely to use can also be searched for and added in the same way.

E.g.

  • To install the editor VIM, enter ‘VIM’ into the ‘Search’ box, then in the results, expand ‘Editors’, click on ‘Default’ to change it to ‘Install’ and click ‘Next’.
  • To install Make, enter ‘make’ into the ‘Search’ box, in the results expand ‘Devel’, click on ‘Skip’ for the package ‘make: The GNU version of the “make” utility’, till it changes to a version number.

Once all packages are selected click ‘Next’.

12. For any “Resolving Dependencies” screens that may appear, click ‘Next’. The installation then begins and typically completes in around 10 to 15 minutes

13. Once installed, on the ‘Installation Status and Create Icons’ screen, accept defaults and click ‘Finish’ to complete the install

14. Cygwin can now be opened by double clicking on the ‘Cygwin64 Terminal’ desktop icon

 

To configure CURL to work in conjunction with a Proxy Server, perform the following:

1. Within Cygwin, using an editor of choice to create the file ‘.curlrc’ in the default ‘home’ folder, e.g. ‘vim .curlrc’
2. Edit this file to add the following information:

proxy-user=”<username>:<password>”    e.g. proxy-user=”smithd:Password!”

proxy=”{PROXY URL>:<PORT>”                    e.g. proxy=”proxy.acme.com:80″

E.g. Within VIM, press ‘i’ to enter ‘Edit Mode’ and then enter the following two lines, replacing and with your credentials (there is no need to enter a domain) :

Hit the ‘Esc’ key, then press the ‘Shift’ and “:” keys together. This should result in command line colon for VIM being displayed in the bottom left hand side of the screen, indicating ‘Edit Mode’ has been exited. Enter ‘wq’ to save and exit VIM

 

Configure K5 REST API  Working Environment

The final step is to build the API working environment. This is documented within the Fujitsu K5 IaaS User Guide. Alternatively, you may want to review the blog https://www.k5developercenter.com/simplifying-retrieving-an-authentication-token-in-fujitsus-k5-cloud-service, in which a script can be downloaded to set up the environment for you. Just note the section towards the end of this other blog about configuring the script to either construct the endpoints automatically to include version & project information (default) or as per the FJ guides (optional). If you are new to K5 API and are looking to follow the guides, then it my be worth setting ‘EPFULL=false’ while you get started 🙂

 

I’ve decided to leave the below example files within this updated blog for reference purposes, for anyone who is already using these templates or for those people who would prefer to follow along with the FJ guides. Personally I have already switched over to using the above script.

Init.sh file template:

and below for example get_token.sh

 

***********************Updated 19/04/17***********************
As an alternative to Cygwin, you may want to use a free utility called MobaXterm. This is quicker to install and setup, and also includes a SSH client.

To install:
1. Download the MobaXterm Installer from http://download.mobatek.net/10220170312132617/MobaXterm_Installer_v10.2.zip
2. Extract download zip file and run MobaXterm_installer.msi
3. Welcome | Next
4. License | tick ‘I accept…’ | Next
5. Accept default destination folder | Next
6. Click ‘Install’
7. Click ‘Finish’
8. Browse to http://mobaxterm.mobatek.net/plugins.html
9. Download and copy the curl plugin to the MobaXterm folder C:\Program Files (x86)\Mobatek\MobaXterm
a. Other plugins can be added depending on your requirements. Typically I also install :
DnsUtils Git, Gvim, OpenSSL, Python, Zip

10. Click on Start menu, locate and click on MobaXterm to open the utility
11. Within MobaXterm window, click on ‘Start Local Terminal’
12. Install JQ by entering the command: apt-get install jq

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s