Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Create an IBM Cloud instance with the Linux command line

Boas Betzler, Senior Technical Staff, IBM
Boas Betzler is a senior technical staff member and member of the IBM Academy of Technology. He has worldwide responsibility for the image center of both the public IBM Compute Cloud and the IBM Shared Private Production Cloud.
Du Li Juan , Staff Software Engineer, IBM
Du Li Juan joined IBM as the L3 team lead for IBM GTS Platform Integration and Deployment Services and assumed responsibility of development and support for the service automation solutions based on Lotus Domino technologies. In her current role, she works on best practices for the IBM Smart Business Development and Test Cloud.

Summary:  Learn how to use the command line from Linux® to create an instance in the IBM® SmartCloud Enterprise environment. This article shows you how to configure the instance to use the command line, and the steps to create the instance using the command line. The author also shows you how to create multiple instances with a simple script.

Date:  24 Jan 2011 (Published 05 Jan 2011)
Level:  Introductory PDF:  A4 and Letter (22KB | 6 pages)Get Adobe® Reader®
Also available in:   Korean  Japanese

Activity:  45391 views
Comments:  

The IBM SmartCloud Enterprise provides on demand development and test infrastructure services for enterprises. This environment enables reduced costs and time savings on development and test efforts by eliminating the need for organizations to set up and run project infrastructure. It also provides capabilities that make it easy to engage administrative features such as provisioning an instance, creating an image, creating storage volumes, and adding IP addresses.

The graphical user interface (GUI), HTTP REST API, and the command line tool are the three methods available to interface with the IBM Cloud:

  • The GUI is the most commonly used method.
  • The HTTP REST API provides a programming language that lets users create calls from their own applications or third-party applications to interact with the cloud.
  • The command line tool is an efficient way to help users perform some administrative tasks, especially repetitive tasks.

This article addresses using the command line (CL) tool in Linux (the command line tool supports both Windows™ and Linux®). See the article for using the command line on Windows. This article shows how to configure an instance to use the command line tool, how to install the CL tool, and how to use the CL tool to manage other instances and resources. Scripts can be created based on the CL tool commands to perform repetitive command execution. An example script for creating multiple instances is illustrated.

Configuring an instance to use the command line tool

Choose one instance to install the command line tool. For example, if you have a SUSE instance named SUSE Test 001. Use PuTTY to access the instance. (The SSH demo video, under the Account tab shows you how to use PuTTy to access a Linux instance.) The default user in a new created Linux instance is idcuser and by default this ID can run many Linux commands as root. To uncover the Linux commands this ID can run, use sudo -l to check:

idcuser@vhost0925:~/cloud/commandline> sudo -l
User idcuser may run the following commands on this host:
    (ALL) ALL
    (ALL) NOPASSWD: ALL

(ALL) ALL means user idcuser can run all commands as root. (ALL) NOPASSWD means no password is needed when you run the commands. Just simply add sudo before the command so that the user can execute the command as root (this example shows you how to use sudo to open yast as root):

idcuser@vhost0925:~/test> sudo /sbin/yast

To configure an instance:

  1. Download the CMD line package from the Support tab on the IBM public cloud website and copy in your instance using the scp command.
    1. Go to the Support tab in the IBM Cloud, click Command Line Tool Reference, and when it opens, click Content in the left menu and download DeveloperCloud_CMD_Tool.zip.
    2. Use the scp command to safely copy the tool into your Linux instance. In a Windows systems, use the pscp command to copy the package in your instance.

      To copy the ZIP file to the Linux instance from a Windows system, download a PSCP.exe from the PuTTY website and go to where the PSCP.exe is, like c:/pscp.exe, and then run:
      C:\> pscp –l idcuser –i D:\key\user_pk.ppk –pw ibmcloud D:\ 
      cmd_Tool\DeveloperCloud_CMD_Tool.zip 
      idcuser@10.200.5.217:/home/idcuser/cloud/commandline
      

      To copy the ZIP file to the Linux instance from a Linux system, run the scp command.
      # scp /home/cloud/DeveloperCloud_Tool.zip 
      idcuser@10.200.5.217:/home/idcuser/cloud/commandline
      

  2. Unzip the packages into a new folder and set the execute permission to a scripts files (in other words, give it an .sh extension).
    1. Unzip the command line tool package and type the following command. (Note sudo is added before the command to ensure idcuser can execute the command as root access.)
      idcuser@vhost0925:~/cloud/commandline> sudo unzip -o DeveloperCloud_CMD_Tool.zip
      

    2. Go to the folder where the command line tool is unzipped and check the permission for all files under the folder.

      Run ls –ll to check the permission for all files. If the owner is not idcuser, change the file owner to idcuser. In this example, the command line files are located in the folder commandline. Use –R to change the file owner for all files under this folder.
      idcuser@vhost0925:~/cloud> Sudo chown –R idcuser commandline
      

      If the group is not users, change the file owner to users.
      idcuser@vhost0925:~/cloud> Sudo chgrp –R users commandline
      

    3. Give all users execution permission to all command files so that user can have permission to execute all commands.
      idcuser@vhost0925:~/cloud>  chmod –R a+x  commandline
      

    4. During the execution of commands using the command line tool, logs need be written into the log file, so you must give all users write permission to log files.
      idcuser@vhost0925:~/cloud/commandlin> chmod –R a+w  logs
      

  3. Install the IBM Java™ version from the yast > software management menu.
    1. You must install jdk1.6 to run the command line tool. If your Linux instance is SUSE, use yast to check if jdk1.6 has been installed. Type the Linux command
      idcuser@vhost0925:~/cloud>  sudo /sbin/yast
      

      Search the Java package; if there is no java 1.6, install it manually. Download jdk1.6 and copy it into your instance under /usr directory (use scp in Linux and pscp in Windows). Make sure to add sudo before the command so that you can run as root.
    2. Unzip the Java package and install the package.
      idcuser@vhost0925:/usr/lib64> sudo ./jdk-6u23-linux-x64-rpm.bin
      idcuser@vhost0925:/usr/lib64> sudo rpm -ivh jdk-6u23-linux-amd64.rpm
      

    3. Search to see where the Java package is installed. Go to /usr and type the command; the result shows that Java is installed in /usr/java/jdk1.6.0_23.
      idcuser@vhost0925:/usr> find -name java
      ./share/doc/packages/db/ref/java
      ./share/java
      find: ./share/YaST2/data/support: Permission denied
      ./bin/java
      find: ./lib/man-db: Permission denied
      find: ./lib/bootloader: Permission denied
      ./java
      ./java/jdk1.6.0_23/bin/java
      ./java/jdk1.6.0_23/jre/bin/java
      

  4. Set the Java environment.
    1. Now that we have found the exact path of the Java code, we should export that path to run script commands that work properly. Set JAVA _HOME path:
      export JAVA_HOME=/usr/java/jdk1.6.0_23
      

    2. To set Java environment variables in /etc/profile, add the following in the end of this file so that JAVA_HOME and PATH can be set in the system environment. To edit /etc/profile, type:
      idcuser@vhost0925:/usr> sudo vi /etc/profile
      

      Insert the following code:
      #set java environment
      JAVA_HOME=/usr/java/jdk1.6.0_23
      CLASSPATH=.:$JAVA_HOME/lib/tools.jar
      PATH=$JAVA_HOME/bin:$PATH
      export JAVA_HOME CLASSPATH PATH
      

    3. Use the echo command to check to see if the Java environment is successfully set.
      idcuser@vhost0925:/usr> echo $JAVA_HOME
      idcuser@vhost0925:/usr> echo $PATH
      


Creating an instance

This procedure lets you create an instance with manual processing using shell script commands.

To create an instance using the command line, you need to:

  1. Create a password file on the client system where you use the command line tool.
  2. Find the data center ID.
  3. Find the instance type.
  4. Find the key for the instance.
  5. Create the instance.

Create a password file

Before you use the command line tool, you should first create a password file to prevent your password from being stolen when you type it in a command line.

Enter in the command line:

#./ic-create-password.sh -u <user name> -p <password> -w unlock -g /home/idcuser/pass.txt

You should see:

Executing action: CreatePassword ...
Password File created successfully!
Path : /home/idcuser/pass.txt
File Name : pass.txt
Please do not edit this file!
Created password successfully.
Executing CreatePassword finished

Find the data center ID

The data center is where images and instances are located.

Enter in the command line:

#./ic-describe-locations.sh -u <username> -w <passphrase> -g <password file>

You should see:

Executing action: Describe Locations ...
4 locations!
----------------------------------
ID : 41
Location : RTP
Name : RTP
State : ONLINE
Description : RTP  usrdtsa0a1ccxra
----------------------------------
----------------------------------
ID : 61
Location : EHN
Name : EHN
State : ONLINE
Description :
----------------------------------
----------------------------------
ID : 82
Location : us-co-dc1
Name : us-co-dc1
State : ONLINE
Description : BLD main DC
----------------------------------
Executing Describe Locations finished

Find the instance type

From this command you'll get both the ID and the instance type ID. Enter in the command line:

#./ic-describe-images.sh -u <username> -w <passphrase> -g <password file path>

You should see:

ID : 20003155
    InstanceType ID : BRZ32.1/2048/60*175
    InstanceType ID : COP32.1/2048/60
    InstanceType ID : GLD32.4/4096/60*350
    InstanceType ID : SLV32.2/4096/60*350
ID : 20007821
    InstanceType ID : BRZ32.1/2048/60*175
    InstanceType ID : COP32.1/2048/60
    InstanceType ID : GLD32.4/4096/60*350
    InstanceType ID : SLV32.2/4096/60*350

Find the key for the instance

Enter in the command line:

#./ic-describe-keypairs.sh -u <username> -w <passphrase>  -g <password file path>

Get the key name from the result; you'll need it when creating the instance.

Create the instance

The following parameters are used with the command to create the instance. Be sure to have this information available.

  • -u for username
  • -w for passphrase
  • -g for password file
  • -t for instance type
  • -k for image id
  • -c for key name for access instance
  • -L for datacenter id
  • -n for instance name
  • -d for instance description

Enter in the command line:

#./ic-create-instance.sh -u <username> -w <passphrase> -g <password file path> 
-t <instance type> (for example, COP32.1/2048/60) -k <image id> (for example, 20010002)  
-c <key name> -L <datacenter ID> (for example, 61) 
-n <instance name> (for example, SLES11SP1_32_cmd) -d "CMD line instance" 


Creating multiple instances with your own script file

The example script below lets you create multiple instances on the IBM cloud without the use of the GUI.

This script uses a while loop and lets you create three instances, but you can alter it to create more by changing the limit size (LIMIT=x).

#!/bin/sh
var=0
LIMIT=3
while [ "$var" -lt "$LIMIT" ]
do
echo -n "$var0 " # -n suppresses newline.
res=`sh ic-create-instance.sh -u user@ibm.com -w abcd -g /home/idcuser/pass.txt 
   -t COP32.1/2048/60 -n SLES11SP1-N$var -k 20010002 -c user_key -d "New Instance" 
   -L 61`;
echo $res
var=`expr $var + 1` # var0=$(($var0+1)) also works.
Done

Two things to note about using this script:

  1. The script has to be saved in the script command folder.
  2. Before you create this script, you should know all the required parameters needed to create an instance using the ic-create-instance command.

Creating a private image with this instance

After you successfully configured the command line tool in your instance, save it as a private image, which will have all the configurations you have built for this command line tool. When you want to create instances with the command line tool, use this image to create an instance and the command line tool is automatically attached.

Enter the command line:

#./ic-save-instance.sh 
 -u <username> 
 -w <passphrase> 
 -g <password file path> 
 -l <instance id> (for example, 42828)
 -n <image name> (for example, "SUSE with Command Line Tool") 
 -d <description> (for example, "A SuSe image installed command line tool")


In conclusion

Using the command line tool to administer your instances is very efficient and quite easy; it saves you from many of the "clicking" steps you encounter when using the graphical user interface.

For a Windows client system, see Create an IBM Cloud instance with the Windows command line.


Resources

Learn

Get products and technologies

Discuss

About the authors

Boas Betzler is a senior technical staff member and member of the IBM Academy of Technology. He has worldwide responsibility for the image center of both the public IBM Compute Cloud and the IBM Shared Private Production Cloud.

Du Li Juan joined IBM as the L3 team lead for IBM GTS Platform Integration and Deployment Services and assumed responsibility of development and support for the service automation solutions based on Lotus Domino technologies. In her current role, she works on best practices for the IBM Smart Business Development and Test Cloud.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Cloud computing, Linux
ArticleID=606128
ArticleTitle=Create an IBM Cloud instance with the Linux command line
publish-date=01242011