Getting Started with the FUJITSU K5 API on a Windows Workstation

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 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.

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 and cURL
1. Download the latest 64-bit version of Cygwin for Windows from https://cygwin.com/install.html and run ‘setup-x86_64.exe’ toc 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’.

10. Next, 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 e.g. 4.1-1

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)

(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’

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=”:”    e.g. proxy-user=”smithd:Password!”

proxy=”:”             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

Installation of jq.exe into Cygwin

1. Download the latest ‘Source tarball for jq’ from https://stedolan.github.io/jq/download/
2. Open Cygwin to create home folders for the user
3. Copy the ‘jq-1.5.tar.gz’ file into c:\cygwin64\home\ to make it available within Cygwin
4. Within Cygwin, enter the following to un-compress the file : ‘tar -xvzf jq-1.5.tar.gz’
5. Change folder location to the uncompressed folder e.g. ‘cd /jq-1.5’
6. Next enter ‘./configure’ and wait for the command to complete (approx.. 5 minutes)
7. Then enter the commands ‘make’, followed by ‘make install’

jq.exe should now be installed

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.

See below for an example Init.sh file template:

and below for example get_token.sh

Advertisements

How to use a FUJITSU K5 Key Pair with PuTTY/PSFTP

How to use/convert your K5 Key Pair key to work with Putty

Putty does not natively support the Fujitsu K5 KeyPair PEM file format. In order to use this KeyPair with Putty, it must first be converted to PPK format using the tool PuttyGen. Both Putty and PuttyGen can be downloaded freely from: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

  1. Download the ‘puttygen.exe’ file from the above link and save it somewhere suitable
  2. Double click the ‘puttygen.exe’ file to start the application and select ‘Run’ if prompted with a security warning. (Note: There is no installation of this application)
  3. In the resulting window, under ‘Parameters’ ensure ‘SSH-2RSA’ is specified as the ‘Type PSof key to generate’
  4. Under ‘Actions’, click‘Load’. Then in the ‘Load private key:” window, change the file type drop down box to ‘All Files’.
  5. Next browse to and select your K5 Key Pair PEM file and click ‘Open’, then click ‘OK’ to acknowledge any Notice dialog boxes
  6. Click‘Save private key’, then ‘Yes’ to warning about not having a passphrase to protect the key
  7. Next specify a location for the new file to be created, ensuring the same name is used for the PPK file, as was used for the PEM file. (Note: The .ppk file extension is automatically added to the filename). Click ‘Save’ to create the file and to complete the conversion process
  8. PuttyGen can now be closed

How to connect to a Fujitsu K5 Linux VM using Putty

Once you have a Fujitsu K5 Key Pair in PPK format, it can be used to authenticate with K5, using the common SSH client tool – PuTTY.

  1. Download ‘putty.exe’ from the previous link and save it somewhere suitable
  2. Double click the ‘putty.exe’ file to start the application and select ‘Run’ if prompted with a security warning. (Note: Again there is no installation of this application)
  3. In the resulting window under ‘Session | Host Name (or IP Address)’, enter the public facing IP Address of the Linux VM
  4. Next expand ‘Connection | Data’ and enter the username for the VM, that you are wanting to login with i.e. ‘k5user’ for Win/Centos/Red hat & ‘ubuntu’ for Ubuntu. Note: Ensure that the appropriate Security Group and Firewall rules have been opened to allow a SSH connection from your IP Address. Configuration of this is out of scope of this guide
  5. Then expand ‘Connection | SSH | Auth’ and click the ‘Browse’ button, before browsing to and selecting your PPK file and clicking ‘Open’
  6. At this point, it is a good idea to save this configuration so that it can be re-used again. To do this, skip back to the very top category ‘Session’, and under ‘Saved Sessions’ enter a name for this particular connection and click ‘Save’. This saved session will also be used by the file transfer tool PSFTP, (see next section)
  7. Finally, click ‘Open’ to establish the SSH connection

How to transfer files to a Fujitsu K5 Linux VM using PSFTP

PSFTP is another tool that can be used to securely transfer files to and from a K5 Linux VM. In order to successfully authenticate with the VM using a keypair, PSFTP must reference the name of the saved Putty session, rather than an IP Address or Hostname.

  1. Download the ‘psftp.exe’ file from the earlier link and place it in a folder that is included in the system path e.g. c:\windows\system32.
  2. From a Windows command prompt, enter the command ‘psftp’ followed by the name of the saved putty session e.g.
  3. This will authenticate psftp with the VM using the IP Address, username and keypair information saved within the saved putty session.
  4. Now that psftp is connected, it is possible to navigate both the local workstation and remote Linux VM. Proceed each Windows CMD commands with a “!” character e.g. “!dir” – to list the contents of the current directory.
  5. The ‘put’ command can be used to transfer files to the VM, e.g. in the case of Red Hat, this method can be used to transfer the RHUI agent file to the VM.
  6. Once the file is copied to the VM, the psftp session can be closed by typing ‘Quit’.