Example Scripts¶
In this section we present a a number of scripts that may inspire you to utilize the scriting abilities of cloudmesh. A script can be started with
cm sriptname.cm
Comment¶
At this time comments are only detected based on the first characters in a line. A comment line starts either with #, // or /*.
# test comment 1
// test comment 2
/* test comment 3 */
Terminal Commands¶
banner "prints a banner with this text"
echo "prints this text"
color ON
echo -r BLACK "prints in black "
echo -r BLUE "prints in blue"
echo -r GREEN "prints in green"
Variables¶
#
# TESTING VARIABLES
#
# Listing the variables
var list
# Get the time and print a banner with the time
var a=now
var b=date
var username=cloudmesh.profile.username
var list
banner $a
# replace $a in comment
echo $username
echo $a
echo $b
Group¶
register remote kilo
# show the defaults
cm default
vm default
banner "GROUP A"
# boot 3 vms in goup a
default group=group_a
vm boot
vm boot
vm boot
vm list
banner "GROUP B"
# boot 3 vms in group b
default group=group_b
vm boot
vm boot
vm boot
vm list
# delete all vms in group_a
vm delete group_a
banner "GROUP C"
default group=group_c
# create three vms in group_c
py n = 3
py for i in range(0,n): cm vm boot
vm list
# Cleanup
vm delete group_b
vm delete group_c
Keys¶
banner KEYS
key delete --all --force
# TODO: does ~ expansion works?
key add --name=test-key ~/.ssh/id_rsa.pub
key list
key list --format=json
key list --format=yaml
key list --source=cloudmesh
key list --source=ssh
key list --source=git
key get test-key
default cloud
key upload test-key
key map
# key delete --select
key delete --all --force
VMs¶
banner -r BLUE VM
banner -r BLUE -c "-" Setup
var cloud=kilo
var username=cloudmesh.profile.username
var tenant=cloudmesh.clouds.$cloud.credentials.OS_TENANT_NAME
var keyname="$username-key"
echo "Username: $username"
echo "Keyname: $keyname"
register remote
default cloud=$cloud
default cloud
banner -r BLUE -c "-" "VM List"
vm refresh
vm list
key add --name $keyname ~/.ssh/id_rsa.pub
key list
key upload $keyname
default key=$keyname
default flavor=m1.small
default image=Ubuntu-14.04-64
#default flavor=2
#default image=9eb8416d-1313-4748-a832-5fe0ecbbdffc
default list --cloud=$cloud
vm default
vm boot
vm refresh
vm ip assign
vm list
vm status
default login_key=~/.ssh/id_rsa
# TODO: Monitor state change to check if the vm can be logged in
# vm login
# vm ssh uname -a
#--key=~/.ssh/id_rsa
# according to scripts/secgroup.cm
# setting secgrup rule to allow ssh login
# secgroup rules-add --tenant=$tenant default 22 22 tcp 0.0.0.0/0
# however this seems having problem now
#default login_key=/home/mangirish/indiakey/id_rsa
#vm login --key=~/.ssh/id_rsa testvm
#vm list --format=json
#vm list --format=yaml
Copy¶
default cloud=kilo
! rm -r ~/cm_sync
! mkdir -p ~/cm_sync/put
! echo "sample text" >> ~/cm_sync/put/file.txt
banner SYNC_FROM_LOCAL_TO_REMOTE
sync put ~/cm_sync/put sync_dir
banner SYNC_FROM_REMOTE_TO_LOCAL
sync get sync_dir ~/cm_sync/get
Security Groups¶
default cloud=kilo
var username=cloudmesh.profile.username
var tenant=cloudmesh.clouds.$cloud.credentials.OS_TENANT_NAME
var keyname="$username-key"
key load
key upload
secgroup create --tenant=$tenant test-secgroup-01
banner LIST_SECURITY_GROUPS
secgroup list --tenant=$tenant
banner SECURITY_GROUP_ADD_RULES
secgroup rules-add --tenant=$tenant test-secgroup-01 80 80 tcp 0.0.0.0/0
secgroup rules-add --tenant=$tenant test-secgroup-01 443 443 udp 0.0.0.0/0
banner LIST_SECURITY_GROUP_RULES
secgroup rules-list --tenant=$tenant test-secgroup-01
banner SECURITY_GROUP_DELETE_RULE
secgroup rules-delete --tenant=$tenant test-secgroup-01 80 80 tcp 0.0.0.0/0
secgroup rules-list --tenant=$tenant test-secgroup-01
banner DELETE_SECURITY_GROUP
secgroup delete --tenant=$tenant test-secgroup-01
banner LIST_SECURITY_GROUPS
secgroup list --tenant=$tenant
Nova¶
banner NOVA
# this command should be avoided and you should use the vm command instead.
# It is the same as ! nova ... but reads the configuration from the
# cloudmesh.yaml file
nova set kilo
nova info
nova list
nova image-list
Network¶
## lines that do not work but should are commented out for now with ##
banner SET_DEFAULT_CLOUD_AND_GROUP
var cloud=kilo
var username=cloudmesh.profile.username
var tenant=cloudmesh.clouds.$cloud.credentials.OS_TENANT_NAME
var keyname="$username-key"
echo "Username: $username"
echo "Keyname: $keyname"
default group=demo_group
banner FLOATING_IP_LIST
network list floating ip
banner FLOATING_POOL_LIST
network list floating pool
banner CREATE_FLOATING_IP
network create floating
network list floating
banner LIST_VM_DEFAULTS
vm default
banner CREATE_VM
vm boot
vm refresh
vm list
banner ASSOCIATE_FLOATING_IP_AUTO_DETECT
network associate floating --instance=goshenoy
banner FLOATING_IP_LIST
network list floating ip
banner DISASSOCIATE_FLOATING_IP
network disassociate floating --instance=goshenoy
banner DELETE_GROUP
group delete demo_group
banner DEFAULT_GROUP
default group=demo_group
banner CREATE_VM
vm boot
vm refresh
vm list
banner ASSOCIATE_FLOATING_IP_WITH_GROUP
network associate floating --group=demo_group
banner DISASSOCIATE_FLOATING_IP_WITH_GROUP
network disassociate floating --group=demo_group
banner DELETE_GROUP
group delete demo_group
HPC¶
default cloud=general
default group=test
default cluster=india
banner HPC
hpc info
hpc queue
hpc run ~/test.sh --group=test1
hpc run ~/test.sh --group=test1
hpc status --job=6
hpc delete all --group=test1
Cluster¶
banner SET_DEFAULT_CLOUD_AND_GROUP
var cloud=kilo
var group=demo_group
var key=cloudmesh.keys.keylist.keyname
var username=cloudmesh.profile.username
default cloud=$cloud
default group=$group
default key=$key
banner LIST_VM_DEFAULTS
vm default
banner CREATE_VM
vm boot
vm refresh
vm boot
vm refresh
vm list
banner CREATE_VIRTUAL_CLUSTER
network create cluster --group=$group