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:
- Download the CMD line package from the Support tab on the IBM public cloud website and
copy in your instance using the
scpcommand.- 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.
- Use the
scpcommand to safely copy the tool into your Linux instance. In a Windows systems, use thepscpcommand 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 thescpcommand.# scp /home/cloud/DeveloperCloud_Tool.zip idcuser@10.200.5.217:/home/idcuser/cloud/commandline
- Unzip the packages into a new folder and set the execute permission to a scripts files (in other words, give it an .sh extension).
- Unzip the command line tool package and type the following command. (Note
sudois added before the command to ensureidcusercan execute the command as root access.)idcuser@vhost0925:~/cloud/commandline> sudo unzip -o DeveloperCloud_CMD_Tool.zip
- Go to the folder where the command line tool is unzipped and check the permission for all files under the folder.
Runls –llto check the permission for all files. If the owner is notidcuser, change the file owner toidcuser. In this example, the command line files are located in the foldercommandline. Use–Rto change the file owner for all files under this folder.idcuser@vhost0925:~/cloud> Sudo chown –R idcuser commandline
If the group is notusers, change the file owner tousers.idcuser@vhost0925:~/cloud> Sudo chgrp –R users commandline
- 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
- 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
- Unzip the command line tool package and type the following command. (Note
- Install the IBM Java™ version from the yast > software management menu.
- You must install jdk1.6 to run the command line tool. If your Linux instance is SUSE,
use
yastto check if jdk1.6 has been installed. Type the Linux commandidcuser@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 (usescpin Linux andpscpin Windows). Make sure to addsudobefore the command so that you can run as root. - 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
- 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
- You must install jdk1.6 to run the command line tool. If your Linux instance is SUSE,
use
- Set the Java environment.
- 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 _HOMEpath:export JAVA_HOME=/usr/java/jdk1.6.0_23
- To set Java environment variables in /etc/profile, add the following in the
end of this file so that
JAVA_HOMEandPATHcan 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
- Use the
echocommand to check to see if the Java environment is successfully set.idcuser@vhost0925:/usr> echo $JAVA_HOME idcuser@vhost0925:/usr> echo $PATH
- 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
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:
- Create a password file on the client system where you use the command line tool.
- Find the data center ID.
- Find the instance type.
- Find the key for the instance.
- Create the instance.
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 |
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 |
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
|
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.
The following parameters are used with the command to create the instance. Be sure to have this information available.
-ufor username-wfor passphrase-gfor password file-tfor instance type-kfor image id-cfor key name for access instance-Lfor datacenter id-nfor instance name-dfor 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:
- The script has to be saved in the script command folder.
- Before you create this script, you should know all the required parameters needed to create an instance using the
ic-create-instancecommand.
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") |
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.
Learn
- Find more information about the commands and parameters on the Support tab of
the IBM Cloud page.
See "Command Line Tool Reference Card" and "Command Line Tool Reference"
in the Documentation library list.
-
For more on Release 1.2, listen to the Brian Snitzer podcast.
-
In the developerWorks cloud developer resources, discover and share knowledge and experience of application and services developers building their projects for cloud deployment.
-
The next steps: Find out how to access IBM SmartCloud Enterprise.
Get products and technologies
-
See the product images available on the IBM SmartCloud Enterprise.
Discuss
-
Join a cloud computing group on developerWorks.
-
Read all the great cloud blogs on developerWorks.
-
Join the developerWorks community, a professional network and unified set of community tools for connecting, sharing, and collaborating.
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.




