假设您能够访问一台 Red Hat Enterprise Linux® 机器或一个 Red Hat 克隆系统(CentOS 或 Scientific Linux),安装下面这个包:
$ sudo yum install -y python-setuptools$ sudo easy_install softlayer
SoftLayer 命令行工具安装在 /usr/bin/sl 中。
配置
要配置该命令行工具:
$ sl config setup
输入您的用户名,您的 API 密钥或密码,然后在询问端点时输入 public。对最后一个问题 Are you sure you want to write settings to "/home/$USER/.softlayer"?[Y/n]: 回答 Y。
确认您输入了正确的信息:
$ sl config show
配置文件详细信息
该命令行工具从配置文件 ($HOME/.softlayer) 加载设置。此配置文件是一个基于 INI 的文件,需要包含 softlayer 部分。有两个必填字段:user">name 和 api_key。您还可以提供一个可选的 endpoint_url 字段。
[softlayer]username = bogdan.darieapi_key=6b8d45d6bfca123925b87344dc29f37523d3b3030407fab21b7d269adabddbd2endpoint_url = https://api.softlayer.com/xmlrpc/v3/
示例
要显示可用命令列表,请输入 sl。
usage: sl <module> [<args>...] sl help <module> sl help <module> <command> sl [-h | --help]SoftLayer Command-line
ClientThe
available modules are:Compute: bmc Bare Metal Cloud cci Cloud Compute Instances image Manages compute and flex images metadata Get details about this machine. Also available with 'my' and 'meta' server Hardware servers sshkey Manage SSH keys on your accountNetworking: dns Domain Name System firewall Firewall rule and security management globalip Global IP address management rwhois RWhoIs operations ssl Manages SSL subnet Subnet ordering and management vlan Manage VLANs on your accountStorage: iscsi View
iSCSI details nas View NAS detailsGeneral: config View and edit configuration for this tool summary Display an overall summary of your account help Show helpSee 'sl help <module>' for more information on a specific module.To use most commands your SoftLayer username and api_key need to be
configured.The easiest way to do that is to use: 'sl config setup'
有多个模块或命令可用。要查看针对 Cloud Computing Instance 的子命令列表,请输入 sl cci。
usage: sl cci [<command>] [<args>...] [options]Manage, delete, order compute instancesThe available commands are: cancel Cancel a running CCI create Order and create a CCI (see `sl cci create-options` for choices) create-options Output available available options when creating a CCI detail Output details about a CCI dns DNS related actions to a CCI edit Edit details of a CCI list List CCI's on the account nic-edit Edit NIC settings pause Pauses an active CCI power-off Powers off a running CCI power-on Boots up a CCI ready Check if a CCI has finished provisioning reboot Reboots a running CCI reload Reload the OS on a CCI based on its
current configuration resume Resumes a paused CCIFor several commands, <identifier> will be asked for. This can be the id,hostname or the ip address for a CCI.
要创建一个 Cloud Computing Instance,需要知道有哪些可用选项:vCPU、RAM、操作系统等。要查看该列表:
sl cci create-options
要创建一个具有 2 个 vCPU、1 GiB RAM 的 Red Hat Enterprise Linux 6 64 位实例(在华盛顿数据中心内),可运行 sl cci create 命令:
$ sl cci create --host=test --domain=softlayer.com -c 2 -m 1024 -o REDHAT_6_64 --hourly --datacenter wdc01This action will incur charges on your account. Continue? [y/N]: y:.........:......................................:: name : value ::.........:......................................:: id : 2811381 :: created : 2013-10-18T13:58:38+03:00 :: guid : e8289dc9-810e-4c4b-81a4-b251adbef803 ::.........:......................................:$ sl cci create --host=test --domain=softlayer.com -c 2 -m 1024 -o REDHAT_6_64 --hourly --datacenter wdc01This action will incur charges on your account. Continue? [y/N]: y:.........:......................................:: name : value ::.........:......................................:: id : 2811381 :: created : 2013-10-18T13:58:38+03:00 :: guid : e8289dc9-810e-4c4b-81a4-b251adbef803 ::.........:......................................:
该实例已创建,并且会立即显示在 sl cci 列表输出中。要知道创建过程何时结束和该实例何时可供访问,请输入:
$ sl cci ready test --wait=600READY
前面的命令返回时,配置过程就完成了,该实例可供立即使用。要显示此实例的根密码,可运行:
$ sl cci detail test --passwords:..............:...............................:: Name : Value ::..............:...............................:: id : 2811381 :: hostname : test.softlayer.com :: status : Active :: state : Running :: datacenter : wdc01 :: os : EL :: os_version : 6.0-64 Minimal for CCI :: cores : 2 :: memory : 1G :: public_ip : 50.97.33.198 :: private_ip : 1
0.57.58.96 :: private_only : False :: private_cpu : False :: created : 2013-10-18T13:58:38+03:00 :: modified : 2013-10-18T14:01:16+03:00 :: vlans : :.........:........:........: :: : : type : number : id : :: : :.........:........:........: :: : : PRIVATE : 1741 : 288748 : :: : : PUBLIC : 1313 : 289775 : :: : :.........:........:........: :: users : :..........:..........: :: : : username : password : :: : :..........:..........: :: : : root : C9yf5rVv : :: : :..........:..........: ::..............:...............................:
要使用 SSH 协议连接到置备的实例:
$ ssh root@50.97.33.198Password:
输入密码后,您将登录到您的实例。