Browse code

updates to exercise.sh to use some of the newer apis

Anthony Young authored on 2011/10/18 08:02:24
Showing 1 changed files
... ...
@@ -82,6 +82,15 @@ glance -A $TOKEN index
82 82
 # Let's grab the id of the first AMI image to launch
83 83
 IMAGE=`glance -A $TOKEN index | egrep ami | cut -d" " -f1`
84 84
 
85
+# Security Groups
86
+# ---------------
87
+SECGROUP=test_secgroup
88
+
89
+# List of secgroups:
90
+nova secgroup-list
91
+
92
+# Create a secgroup
93
+nova secgroup-create $SECGROUP "test_secgroup description"
85 94
 
86 95
 # Flavors
87 96
 # -------
... ...
@@ -92,9 +101,9 @@ nova flavor-list
92 92
 # and grab the first flavor in the list to launch
93 93
 FLAVOR=`nova flavor-list | head -n 4 | tail -n 1 | cut -d"|" -f2`
94 94
 
95
-NAME="firstpost"
95
+NAME="myserver"
96 96
 
97
-nova boot --flavor $FLAVOR --image $IMAGE $NAME
97
+nova boot --flavor $FLAVOR --image $IMAGE $NAME --security_groups=$SECGROUP
98 98
 
99 99
 # let's give it 10 seconds to launch
100 100
 sleep 10
... ...
@@ -113,10 +122,47 @@ ping -c1 -w1 $IP || true
113 113
 sleep 5
114 114
 
115 115
 ping -c1 -w1 $IP 
116
+# allow icmp traffic
117
+nova secgroup-add-rule $SECGROUP icmp -1 -1 0.0.0.0/0
118
+
119
+# List rules for a secgroup
120
+nova secgroup-list-rules $SECGROUP
121
+
122
+# allocate a floating ip
123
+nova floating-ip-create
124
+
125
+# store  floating address
126
+FIP=`nova floating-ip-list | grep None | head -1 | cut -d '|' -f2 | sed 's/ //g'`
127
+
128
+# add floating ip to our server
129
+nova add-floating-ip $NAME $FIP
130
+
131
+# sleep for a smidge
132
+sleep 1
133
+
134
+# ping our fip
135
+ping -c1 -w1 $FIP
136
+
137
+# dis-allow icmp traffic
138
+nova secgroup-delete-rule $SECGROUP icmp -1 -1 0.0.0.0/0
139
+
140
+# sleep for a smidge
141
+sleep 1
142
+
143
+# ping our fip
144
+if ( ping -c1 -w1 $FIP); then
145
+    print "Security group failure - ping should not be allowed!"
146
+    exit 1
147
+fi
148
+
149
+# de-allocate the floating ip
150
+nova floating-ip-delete $FIP
116 151
 
117 152
 # shutdown the server
118 153
 nova delete $NAME
119 154
 
155
+# Delete a secgroup
156
+nova secgroup-delete $SECGROUP
157
+
120 158
 # FIXME: validate shutdown within 5 seconds 
121 159
 # (nova show $NAME returns 1 or status != ACTIVE)?
122
-