fog-maestrodev 1.18.0.20131121075022 → 1.18.0.20131122203507
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/fog.gemspec +2 -2
- data/lib/fog/aws/models/auto_scaling/configuration.rb +1 -0
- data/lib/fog/aws/models/compute/flavors.rb +10 -0
- data/lib/fog/aws/models/glacier/vault.rb +1 -1
- data/lib/fog/aws/parsers/auto_scaling/describe_launch_configurations.rb +3 -0
- data/lib/fog/aws/requests/auto_scaling/create_launch_configuration.rb +1 -0
- data/lib/fog/aws/requests/dns/get_change.rb +1 -1
- data/lib/fog/aws/storage.rb +2 -1
- data/lib/fog/core/errors.rb +3 -3
- data/lib/fog/dreamhost/dns.rb +2 -4
- data/lib/fog/google/compute.rb +72 -62
- data/lib/fog/google/models/compute/zones.rb +1 -1
- data/lib/fog/google/requests/compute/delete_disk.rb +19 -2
- data/lib/fog/google/requests/compute/delete_server.rb +3 -3
- data/lib/fog/google/requests/compute/get_disk.rb +26 -2
- data/lib/fog/google/requests/compute/get_image.rb +3 -3
- data/lib/fog/google/requests/compute/get_server.rb +1 -0
- data/lib/fog/google/requests/compute/insert_disk.rb +37 -2
- data/lib/fog/google/requests/compute/insert_firewall.rb +2 -1
- data/lib/fog/google/requests/compute/insert_image.rb +1 -1
- data/lib/fog/google/requests/compute/insert_server.rb +31 -22
- data/lib/fog/google/requests/compute/list_disks.rb +8 -2
- data/lib/fog/google/requests/compute/list_images.rb +2 -2
- data/lib/fog/google/requests/compute/list_machine_types.rb +2 -2
- data/lib/fog/google/requests/compute/list_servers.rb +2 -2
- data/lib/fog/google/requests/compute/list_zone_operations.rb +1 -1
- data/lib/fog/google/requests/compute/list_zones.rb +1 -1
- data/lib/fog/hp.rb +1 -1
- data/lib/fog/hp/README.md +57 -0
- data/lib/fog/hp/articles/auth_caching.md +23 -0
- data/lib/fog/hp/docs/connect.md +152 -0
- data/lib/fog/hp/docs/install.md +133 -0
- data/lib/fog/hp/examples/block_storage.md +296 -0
- data/lib/fog/hp/examples/block_storage_v2.md +446 -0
- data/lib/fog/hp/examples/cdn.md +54 -0
- data/lib/fog/hp/examples/compute.md +794 -0
- data/lib/fog/hp/examples/compute_v2.md +848 -0
- data/lib/fog/hp/examples/getting_started_examples.md +30 -0
- data/lib/fog/hp/examples/networking.md +472 -0
- data/lib/fog/hp/examples/object_storage.md +387 -0
- data/lib/fog/json.rb +6 -3
- data/lib/fog/openstack/identity.rb +2 -3
- data/lib/fog/openstack/image.rb +1 -4
- data/lib/fog/openstack/metering.rb +1 -4
- data/lib/fog/openstack/network.rb +1 -3
- data/lib/fog/openstack/requests/compute/add_flavor_access.rb +1 -1
- data/lib/fog/openstack/requests/compute/allocate_address.rb +1 -1
- data/lib/fog/openstack/requests/compute/attach_volume.rb +1 -1
- data/lib/fog/openstack/requests/compute/boot_from_snapshot.rb +1 -1
- data/lib/fog/openstack/requests/compute/create_flavor.rb +1 -1
- data/lib/fog/openstack/requests/compute/create_key_pair.rb +1 -1
- data/lib/fog/openstack/requests/compute/create_security_group.rb +1 -1
- data/lib/fog/openstack/requests/compute/create_security_group_rule.rb +1 -1
- data/lib/fog/openstack/requests/compute/create_volume.rb +1 -1
- data/lib/fog/openstack/requests/compute/create_volume_snapshot.rb +1 -1
- data/lib/fog/openstack/requests/compute/list_tenants.rb +1 -1
- data/lib/fog/openstack/requests/compute/remove_flavor_access.rb +1 -1
- data/lib/fog/openstack/requests/compute/update_quota.rb +1 -1
- data/lib/fog/openstack/requests/identity/create_ec2_credential.rb +1 -1
- data/lib/fog/openstack/requests/identity/create_role.rb +1 -1
- data/lib/fog/openstack/requests/identity/create_user.rb +1 -1
- data/lib/fog/openstack/requests/identity/update_user.rb +1 -1
- data/lib/fog/openstack/requests/image/update_image_members.rb +1 -1
- data/lib/fog/openstack/requests/orchestration/create_stack.rb +2 -2
- data/lib/fog/openstack/requests/orchestration/update_stack.rb +1 -1
- data/lib/fog/openstack/requests/volume/create_volume.rb +1 -1
- data/lib/fog/openstack/requests/volume/create_volume_snapshot.rb +1 -1
- data/lib/fog/openstack/volume.rb +1 -4
- data/lib/fog/rackspace/compute_v2.rb +1 -0
- data/lib/fog/rackspace/examples/queues/claim_messages.rb +60 -0
- data/lib/fog/rackspace/examples/queues/create_queue.rb +45 -0
- data/lib/fog/rackspace/examples/queues/delete_message.rb +72 -0
- data/lib/fog/rackspace/examples/queues/delete_queue.rb +53 -0
- data/lib/fog/rackspace/examples/queues/list_messages.rb +64 -0
- data/lib/fog/rackspace/examples/queues/post_message.rb +59 -0
- data/lib/fog/rackspace/models/queues/claim.rb +2 -0
- data/lib/fog/rackspace/models/queues/message.rb +5 -5
- data/lib/fog/rackspace/models/queues/queue.rb +1 -1
- data/lib/fog/rackspace/service.rb +1 -1
- data/lib/fog/riakcs.rb +2 -2
- data/lib/fog/riakcs/provisioning.rb +1 -3
- data/lib/fog/riakcs/requests/provisioning/create_user.rb +2 -2
- data/lib/fog/riakcs/requests/provisioning/get_user.rb +1 -1
- data/lib/fog/riakcs/requests/provisioning/list_users.rb +1 -1
- data/lib/fog/riakcs/requests/usage/get_usage.rb +1 -1
- data/lib/fog/riakcs/usage.rb +0 -2
- data/lib/fog/vsphere/compute.rb +1 -0
- data/lib/fog/vsphere/models/compute/datastore.rb +1 -0
- data/lib/fog/vsphere/requests/compute/list_datastores.rb +9 -8
- data/lib/fog/vsphere/requests/compute/set_vm_customvalue.rb +19 -0
- data/lib/tasks/changelog_task.rb +0 -1
- data/tests/google/models/compute/disk_tests.rb +5 -0
- data/tests/google/models/compute/disks_tests.rb +5 -0
- data/tests/google/models/compute/server_tests.rb +3 -0
- data/tests/google/models/compute/servers_tests.rb +5 -0
- data/tests/google/requests/compute/disk_tests.rb +2 -1
- data/tests/google/requests/compute/firewall_tests.rb +1 -0
- data/tests/google/requests/compute/image_tests.rb +3 -0
- data/tests/google/requests/compute/network_tests.rb +1 -0
- data/tests/google/requests/compute/operation_tests.rb +1 -0
- data/tests/google/requests/compute/server_tests.rb +2 -3
- data/tests/google/requests/compute/zone_tests.rb +1 -6
- data/tests/helpers/mock_helper.rb +3 -4
- data/tests/rackspace/models/queues/message_tests.rb +16 -0
- data/tests/vsphere/requests/compute/set_vm_customvalue_tests.rb +21 -0
- metadata +29 -3
- data/lib/fog/hp/README_HP.rdoc +0 -61
@@ -0,0 +1,794 @@
|
|
1
|
+
# Examples for working with HP Cloud Compute Service v12.12
|
2
|
+
|
3
|
+
The HP Cloud Extensions to Ruby Fog libary provides Compute services support using two abstractions: a model layer and a request layer. Both layers are detailed below. The code samples on this page can be executed from within a Ruby console (IRB):
|
4
|
+
|
5
|
+
irb
|
6
|
+
|
7
|
+
This page discusses the following topics:
|
8
|
+
|
9
|
+
* [Connecting to the Service](https://github.com/fog/fog/blob/master/lib/fog/hp/docs/connect.md)
|
10
|
+
|
11
|
+
**Model Layer Examples**
|
12
|
+
|
13
|
+
* [Model Server Operations](#model-server-operations)
|
14
|
+
* [Model Server Metadata Operations](#model-server-metadata-operations)
|
15
|
+
* [Model Flavor Operations](#model-flavor-operations)
|
16
|
+
* [Model Image Operations](#model-image-operations)
|
17
|
+
* [Model Image Metadata Operations](#model-image-metadata-operations)
|
18
|
+
* [Model Keypair Operations](#model-keypair-operations)
|
19
|
+
* [Model Security Groups Operations](#model-security-groups-operations)
|
20
|
+
* [Model Address Operations](#model-address-operations)
|
21
|
+
|
22
|
+
**Request Layer Examples**
|
23
|
+
|
24
|
+
* [Request Server Operations](#request-server-operations)
|
25
|
+
* [Request Server Metadata Operations](#request-server-metadata-operations)
|
26
|
+
* [Request Flavor Operations](#request-flavor-operations)
|
27
|
+
* [Request Image Operations](#request-image-operations)
|
28
|
+
* [Request Image Metadata Operations](#request-image-metadata-operations)
|
29
|
+
* [Request Keypair Operations](#request-keypair-operations)
|
30
|
+
* [Request Security Groups Operations](#request-security-groups-operations)
|
31
|
+
* [Request Address Operations](#request-address-operations)
|
32
|
+
|
33
|
+
|
34
|
+
## Model Server Operations
|
35
|
+
|
36
|
+
1. List all available servers for an account:
|
37
|
+
|
38
|
+
servers = conn.servers
|
39
|
+
servers.size # returns no. of servers
|
40
|
+
# display servers in a tabular format
|
41
|
+
conn.servers.table([:id, :name, :state, :created_at])
|
42
|
+
|
43
|
+
2. Obtain the details of a particular server:
|
44
|
+
|
45
|
+
server = conn.servers.get(server_id)
|
46
|
+
server.name # returns name of the server
|
47
|
+
server.flavor_id # returns id of the flavor used to create the server
|
48
|
+
server.image_id # returns id of the image used to create the server
|
49
|
+
server.addresses # returns a hash of public and private IP addresses
|
50
|
+
server.created_at # returns the date the server was created
|
51
|
+
server.state # returns the state of the server e.g. ACTIVE, BUILD
|
52
|
+
|
53
|
+
3. Create a new server:
|
54
|
+
|
55
|
+
new_server = conn.servers.create(
|
56
|
+
:name => "My Shiny Server",
|
57
|
+
:flavor_id => 1,
|
58
|
+
:image_id => 2,
|
59
|
+
:key_name => "<key_name>",
|
60
|
+
:security_groups => ["aaa"]
|
61
|
+
)
|
62
|
+
new_server.id # returns the id of the server
|
63
|
+
new_server.name # => "My Shiny Server"
|
64
|
+
new_server.state # returns the state of the server e.g. BUILD
|
65
|
+
new_server.private_ip_address # returns the private ip address
|
66
|
+
new_server.public_ip_address # returns the public ip address, if any assigned
|
67
|
+
|
68
|
+
4. Create a new Windows server instance and retrieve the encrypted password:
|
69
|
+
|
70
|
+
win_server = conn.servers.create(
|
71
|
+
:name => "My Windows Server",
|
72
|
+
:flavor_id => 1,
|
73
|
+
:image_id => 3, # Make sure it is a Windows image
|
74
|
+
:key_name => "<key_name>",
|
75
|
+
:security_groups => ["aaa"]
|
76
|
+
)
|
77
|
+
win_server.id # returns the id of the server
|
78
|
+
# Retrieve the encrypted password
|
79
|
+
win_server.windows_password
|
80
|
+
# => "Im6ZJ8auyMRnkJ24KKWQvTgWDug1s ... y0uY1BcHLJ5OrkEPHhQoQntIKOoQ=\n"
|
81
|
+
**Note**: You must retrieve the Windows password immediately after you create the Windows instance. Also, make sure you have a security rule defined to open RDP port 3389 so that you can connect to the Windows server.
|
82
|
+
|
83
|
+
5. Create a new Linux-based persistent server with a bootable volume:
|
84
|
+
|
85
|
+
conn.servers.create(
|
86
|
+
:flavor_id => 103,
|
87
|
+
:name => "MyPersistentServer",
|
88
|
+
:block_device_mapping =>
|
89
|
+
[{ 'volume_size' => '', # ignored
|
90
|
+
'volume_id' => "111111",
|
91
|
+
'delete_on_termination' => '0',
|
92
|
+
'device_name' => 'vda'
|
93
|
+
}]
|
94
|
+
)
|
95
|
+
**Note**: In *block_device_mapping*, *volume_size* is ignored; it is automatically retrieved from the specified bootable volume. To delete the bootable volume after the server instance is killed you can set *delete_on_termination* to `1`. To preserve the bootable volume, set it to `0` as shown above.
|
96
|
+
|
97
|
+
6. Create a new Linux-based server with advanced personalization options:
|
98
|
+
|
99
|
+
new_server = conn.servers.create(
|
100
|
+
:name => "My Personalized Server",
|
101
|
+
:flavor_id => 1,
|
102
|
+
:image_id => 2,
|
103
|
+
:key_name => "<key_name>",
|
104
|
+
:security_groups => ["aaa"],
|
105
|
+
:config_drive => true,
|
106
|
+
:user_data_encoded => ["This is some encoded user data"].pack('m'),
|
107
|
+
:personality => [{
|
108
|
+
'contents' => File.read("/path/to/sample.txt"),
|
109
|
+
'path' => "/path/to/sample.txt"
|
110
|
+
}]
|
111
|
+
)
|
112
|
+
new_server.id # returns the id of the server
|
113
|
+
new_server.name # => "My Personalized Server"
|
114
|
+
|
115
|
+
# Note: that un-encoded user data can also be provided by setting the user_data property
|
116
|
+
# although, encoding the data on the client is faster and efficient
|
117
|
+
new_server = conn.servers.new(
|
118
|
+
:name => "My Personalized Server",
|
119
|
+
...
|
120
|
+
...
|
121
|
+
)
|
122
|
+
new_server.user_data = "This is some un-encoded user data"
|
123
|
+
new_server.save
|
124
|
+
|
125
|
+
The personalization options are:
|
126
|
+
|
127
|
+
*config_drive*
|
128
|
+
: Disk accessible to the server that contains a FAT filesystem. If `config_drive` parameter is set to `true` at the time of server creation, the configuration drive is created.
|
129
|
+
|
130
|
+
*user_data_encoded* or *user_data*
|
131
|
+
: Allows additional metadata to be inserted during server creation by supplying a Base64-encoded string in the `user_data_encoded` parameter, or by providing an unencoded string with the `user_data` attribute. Note that encoding the data on the client is faster and more efficient.
|
132
|
+
|
133
|
+
*personality*
|
134
|
+
: Allows files to be injected into the server instance after its creation. The file `contents` are Base64 encoded and injected into the location specified by `path`.
|
135
|
+
|
136
|
+
**Note**: The above personalization options are not supported on Windows server instances.
|
137
|
+
|
138
|
+
7. Get console output:
|
139
|
+
|
140
|
+
server = conn.servers.get(server_id)
|
141
|
+
server.console_output(5) # 5 lines of console output are returned
|
142
|
+
|
143
|
+
8. Get VNC console:
|
144
|
+
|
145
|
+
server = conn.servers.get(server_id)
|
146
|
+
server.vnc_console_url('novnc') # URL to access the VNC console of a server from a browser
|
147
|
+
|
148
|
+
9. Reboot a server:
|
149
|
+
|
150
|
+
server = conn.servers.get(server_id)
|
151
|
+
server.reboot # soft reboot by default
|
152
|
+
|
153
|
+
server.reboot("HARD") # hard reboot also possible
|
154
|
+
|
155
|
+
10. Change password for a server:
|
156
|
+
|
157
|
+
server = conn.servers.get(server_id)
|
158
|
+
server.change_password("new_password")
|
159
|
+
|
160
|
+
11. Delete an existing server:
|
161
|
+
|
162
|
+
server = conn.servers.get(server_id)
|
163
|
+
server.destroy
|
164
|
+
|
165
|
+
## Model Server Metadata Operations
|
166
|
+
|
167
|
+
1. Create a server with some metadata:
|
168
|
+
|
169
|
+
myserver = conn.servers.create(
|
170
|
+
:flavor_id => 1,
|
171
|
+
:image_id => 2,
|
172
|
+
:name => "myserver",
|
173
|
+
:metadata => {'Meta1' => 'MetaValue1', 'Meta2' => 'MetaValue2'}
|
174
|
+
)
|
175
|
+
|
176
|
+
2. Get the metadata item:
|
177
|
+
|
178
|
+
myserver.metadata.get("Meta1")
|
179
|
+
|
180
|
+
3. Update the metadata:
|
181
|
+
|
182
|
+
myserver.metadata.update({"Meta2" => "MetaValue2"})
|
183
|
+
|
184
|
+
4. Set the metadata:
|
185
|
+
|
186
|
+
myserver.metadata.set({"Meta3" => "MetaValue3"})
|
187
|
+
|
188
|
+
5. Set the metadata explicitly:
|
189
|
+
|
190
|
+
m = myserver.metadata.new
|
191
|
+
m.key = "Meta4"
|
192
|
+
m.value = "Value4"
|
193
|
+
m.save
|
194
|
+
|
195
|
+
6. Update the metadata:
|
196
|
+
|
197
|
+
m = myserver.metadata.get("Meta3")
|
198
|
+
m.value = "UpdValue3"
|
199
|
+
m.save
|
200
|
+
|
201
|
+
7. List metadata:
|
202
|
+
|
203
|
+
myserver.metadata.all
|
204
|
+
|
205
|
+
8. Delete metadata:
|
206
|
+
|
207
|
+
m = myserver.metadata.get("Meta3")
|
208
|
+
m.destroy
|
209
|
+
|
210
|
+
## Model Flavor Operations
|
211
|
+
|
212
|
+
1. List all available flavors:
|
213
|
+
|
214
|
+
flavors = conn.flavors
|
215
|
+
flavors.size # returns no. of flavors
|
216
|
+
# display flavors in a tabular format
|
217
|
+
conn.flavors.table([:id, :name, :ram, :disk])
|
218
|
+
|
219
|
+
2. Obtain the details of a particular flavor:
|
220
|
+
|
221
|
+
flavor = conn.flavors.get(flavor_id) # get the flavor
|
222
|
+
flavor.name # returns the name of the flavor eg: m1.tiny, m1.small etc.
|
223
|
+
flavor.ram # returns the ram memory in bytes for the flavor, eg: 4096
|
224
|
+
flavor.disk # returns the disk size in GB for the flavor, eg: 80
|
225
|
+
flavor.cores # returns no. of cores for the flavor, eg: 0.25
|
226
|
+
|
227
|
+
## Model Image Operations
|
228
|
+
|
229
|
+
1. List all available images:
|
230
|
+
|
231
|
+
images = conn.images
|
232
|
+
images.size # returns no. of images
|
233
|
+
# display images in a tabular format
|
234
|
+
conn.images.table([:id, :name, :status, :created_at])
|
235
|
+
|
236
|
+
2. Obtain the details of a particular image:
|
237
|
+
|
238
|
+
image = conn.images.get(image_id) # get the image
|
239
|
+
image.name # returns name of the image
|
240
|
+
image.created_at # returns the date the image was created
|
241
|
+
image.status # returns the state of the image e.g. ACTIVE
|
242
|
+
|
243
|
+
3. Create a new snapshot image based on an existing server:
|
244
|
+
|
245
|
+
myserver.create_image("My Image")
|
246
|
+
|
247
|
+
4. Delete an existing snapshot image:
|
248
|
+
|
249
|
+
image = conn.images.get(image_id)
|
250
|
+
image.destroy
|
251
|
+
|
252
|
+
## Model Image Metadata Operations
|
253
|
+
|
254
|
+
1. Create an image snapshot with some metadata:
|
255
|
+
|
256
|
+
myserver.create_image("My Image", {"ImgMeta1" => "ImgMeta1Value"})
|
257
|
+
|
258
|
+
2. Get the metadata item:
|
259
|
+
|
260
|
+
myimage = conn.images.get(image_id)
|
261
|
+
myimage.metadata.get("ImgMeta1")
|
262
|
+
|
263
|
+
3. Update the metadata:
|
264
|
+
|
265
|
+
myimage.metadata.update({"ImgMeta2" => "ImgMetaValue2"})
|
266
|
+
|
267
|
+
4. Set the metadata:
|
268
|
+
|
269
|
+
myimage.metadata.set({"ImgMeta3" => "ImgMetaValue3"})
|
270
|
+
|
271
|
+
5. Set the metadata explicitly:
|
272
|
+
|
273
|
+
m = myimage.metadata.new
|
274
|
+
m.key = "ImgMeta4"
|
275
|
+
m.value = "ImgMetaValue4"
|
276
|
+
m.save
|
277
|
+
|
278
|
+
6. Update the metadata:
|
279
|
+
|
280
|
+
m = myimage.metadata.get("ImgMeta3")
|
281
|
+
m.value = "ImgUpdValue3"
|
282
|
+
m.save
|
283
|
+
|
284
|
+
7. List metadata:
|
285
|
+
|
286
|
+
myimage.metadata.all
|
287
|
+
|
288
|
+
8. Delete metadata:
|
289
|
+
|
290
|
+
m = myimage.metadata.get("ImgMeta3")
|
291
|
+
m.destroy
|
292
|
+
|
293
|
+
## Model Keypair Operations
|
294
|
+
|
295
|
+
1. List all available keypairs:
|
296
|
+
|
297
|
+
keypairs = conn.key_pairs
|
298
|
+
keypairs.size # returns no. of keypairs
|
299
|
+
# display keypairs in a tabular format
|
300
|
+
conn.key_pairs.table([:name, :public_key])
|
301
|
+
|
302
|
+
2. Obtain the details of a particular keypair:
|
303
|
+
|
304
|
+
keypair = conn.key_pairs.get(key_name) # get the keypair
|
305
|
+
keypair.name # returns name of the keypair
|
306
|
+
keypair.public_key # returns the public key of the keypair
|
307
|
+
# NOTE: Due to security considerations, the private key is not available on subsequent gets
|
308
|
+
keypair.private_key # => nil
|
309
|
+
|
310
|
+
3. Create a new keypair:
|
311
|
+
|
312
|
+
keypair = conn.key_pairs.create(:name => "mykey")
|
313
|
+
keypair.name # returns name of the keypair
|
314
|
+
keypair.public_key # returns the public key of the keypair
|
315
|
+
keypair.private_key # returns the private key of the keypair
|
316
|
+
|
317
|
+
4. Export a keypair to a file:
|
318
|
+
|
319
|
+
keypair = conn.key_pairs.create(:name => "mykey2")
|
320
|
+
keypair.write # => "Key file built: /Users/xxxxx/.ssh/mykey2.pem"
|
321
|
+
|
322
|
+
# Alternatively, you can pass in a path to export the key
|
323
|
+
keypair.write("/Users/xxxxx/Downloads/mykey2.pem")
|
324
|
+
|
325
|
+
5. Import a public key to create a new keypair:
|
326
|
+
|
327
|
+
keypair = conn.key_pairs.create(:name => "mykey", :public_key => "public key material")
|
328
|
+
keypair.name # returns name of the keypair
|
329
|
+
|
330
|
+
6. Delete an existing keypair:
|
331
|
+
|
332
|
+
keypair = conn.key_pairs.get(key_name)
|
333
|
+
keypair.destroy
|
334
|
+
|
335
|
+
## Model Security Groups Operations
|
336
|
+
|
337
|
+
1. List all available security groups:
|
338
|
+
|
339
|
+
sgroups = conn.security_groups
|
340
|
+
sgroups.size # returns no. of security groups
|
341
|
+
# display security groups in a tabular format
|
342
|
+
conn.security_groups.table([:id, :name, :description])
|
343
|
+
|
344
|
+
2. Obtain the details of a particular security group:
|
345
|
+
|
346
|
+
sgroup = conn.security_groups.get(sgroup_id) # get the security group
|
347
|
+
sgroup.name # returns name of the security group
|
348
|
+
sgroup.description # returns description of the security group
|
349
|
+
|
350
|
+
3. Create a new security group:
|
351
|
+
|
352
|
+
sgroup = conn.security_groups.create(:name => "mysgroup", :description => "my new sec group")
|
353
|
+
sgroup.name # returns name of the security group
|
354
|
+
|
355
|
+
4. Create a rule for an existing security group:
|
356
|
+
|
357
|
+
sgroup = conn.security_groups.get(sgroup_id) # get the security group
|
358
|
+
sgroup.create_rule(80..80) # allow port 80. defaults to protocol tcp at 0.0.0.0/0
|
359
|
+
sgroup.create_rule(-1..-1, "icmp", "0.0.0.0/0") # allow icmp
|
360
|
+
# show all rules
|
361
|
+
sgroup = conn.security_groups.get(sgroup_id) # get the security group
|
362
|
+
sgroup.rules
|
363
|
+
|
364
|
+
5. Delete a rule from an existing security group:
|
365
|
+
|
366
|
+
sgroup = conn.security_groups.get(sgroup_id) # get the security group
|
367
|
+
sgroup.delete_rule(sgroup_rule_id)
|
368
|
+
|
369
|
+
6. Delete an existing security group:
|
370
|
+
|
371
|
+
sgroup = conn.security_groups.get(sgroup_id) # get the security group
|
372
|
+
sgroup.destroy
|
373
|
+
|
374
|
+
## Model Address Operations
|
375
|
+
|
376
|
+
1. List all available floating IP addresses:
|
377
|
+
|
378
|
+
addresses = conn.addresses
|
379
|
+
addresses.size # returns no. of addresses
|
380
|
+
# display addresses in a tabular format
|
381
|
+
conn.addresses.table([:id, :ip, :fixed_ip, :instance_id])
|
382
|
+
|
383
|
+
2. Obtain the details of a particular address:
|
384
|
+
|
385
|
+
address = conn.addresses.get(address_id) # get the address
|
386
|
+
address.ip # returns the ip address
|
387
|
+
|
388
|
+
3. Create or allocating a new address:
|
389
|
+
|
390
|
+
address = conn.addresses.create # allocates an ip address from the pool
|
391
|
+
address.ip # returns the ip address
|
392
|
+
|
393
|
+
4. Associate a server to an existing address:
|
394
|
+
|
395
|
+
address = conn.addresses.get(address_id) # get the address
|
396
|
+
server = conn.servers.get(server_id) # get the server
|
397
|
+
address.server = server # associate the server
|
398
|
+
address.instance_id # returns the id of the server
|
399
|
+
|
400
|
+
5. Disassociate a server from an existing address:
|
401
|
+
|
402
|
+
address = conn.addresses.get(address_id) # get the address
|
403
|
+
address.server = nil # disassociate the server
|
404
|
+
address.instance_id # => nil
|
405
|
+
|
406
|
+
6. Delete (release) an existing address:
|
407
|
+
|
408
|
+
address = conn.addresses.get(address_id) # get the address
|
409
|
+
address.destroy # releases the ip address to the pool
|
410
|
+
|
411
|
+
## Request Server Operations
|
412
|
+
|
413
|
+
1. List all available servers for an account:
|
414
|
+
|
415
|
+
response = conn.list_servers
|
416
|
+
response.body['servers'] # returns an array of server hashes
|
417
|
+
response.headers # returns the headers
|
418
|
+
response.body['servers'][0]['name'] # returns the name of the server
|
419
|
+
|
420
|
+
2. List all available servers with additional details:
|
421
|
+
|
422
|
+
response = conn.list_servers_detail
|
423
|
+
response.body['servers'] # returns an array of server hashes
|
424
|
+
response.body['servers'][0]['name'] # returns the name of the server
|
425
|
+
|
426
|
+
3. Obtain the details of a particular server:
|
427
|
+
|
428
|
+
response = conn.get_server_details(server_id)
|
429
|
+
server = response.body['server']
|
430
|
+
server['name'] # returns the name of the server
|
431
|
+
server['flavor'] # returns the flavor used to create the server
|
432
|
+
server['image'] # returns the image used to create the server
|
433
|
+
server['addresses'] # returns the public and private addresses
|
434
|
+
server['status'] # returns the state of the server e.g. ACTIVE
|
435
|
+
|
436
|
+
4. Create a new server:
|
437
|
+
|
438
|
+
response = conn.create_server(
|
439
|
+
"My Shiny Server",
|
440
|
+
flavor_id,
|
441
|
+
image_id,
|
442
|
+
{
|
443
|
+
'security_groups' => ["SecGroup1, SecGroup2"],
|
444
|
+
'key_name' => "<key_name>"
|
445
|
+
}
|
446
|
+
)
|
447
|
+
server = response.body['server']
|
448
|
+
server['id'] # returns the id of the new server
|
449
|
+
server['name'] # => "My Shiny Server"
|
450
|
+
server['status'] # returns the state of the server e.g. BUILD
|
451
|
+
|
452
|
+
5. Create a new Windows server and retrieve the encrypted password:
|
453
|
+
|
454
|
+
# Make sure to use a Windows image
|
455
|
+
response = conn.create_server("My Windows Server", flavor_id, image_id)
|
456
|
+
win_server = response.body['server']
|
457
|
+
server_id = win_server['id'] # returns the id of the new server
|
458
|
+
# Retrieve the encrypted password
|
459
|
+
conn.get_windows_password(server_id)
|
460
|
+
# => "Im6ZJ8auyMRnkJ24KKWQvTgWDug1s ... y0uY1BcHLJ5OrkEPHhQoQntIKOoQ=\n"
|
461
|
+
**Note**: You must retrieve the Windows password immediately after you create the Windows instance. Also, make sure you have a security rule defined to open RDP port 3389 so that you can connect to the Windows server.
|
462
|
+
|
463
|
+
6. Create a new Linux-based persistent server with a bootable volume
|
464
|
+
|
465
|
+
conn.create_persistent_server(
|
466
|
+
"MyBootableServer",
|
467
|
+
103,
|
468
|
+
[{ "volume_size"=>"", # ignored
|
469
|
+
"volume_id"=>"65904",
|
470
|
+
"delete_on_termination"=>"0",
|
471
|
+
"device_name"=>"vda"
|
472
|
+
}] ,
|
473
|
+
{
|
474
|
+
'security_groups' => ["mysecgroup"],
|
475
|
+
'key_name' => "<key_pair>"
|
476
|
+
}
|
477
|
+
)
|
478
|
+
**Note**: In *block_device_mapping*, *volume_size* is ignored; it is automatically retrieved from the specified bootable volume. To delete the bootable volume after the server instance is killed you can set *delete_on_termination* to `1`. To preserve the bootable volume, set it to `0` as shown above.
|
479
|
+
|
480
|
+
7. Create a new Linux-based server with advanced personalisation options:
|
481
|
+
|
482
|
+
response = conn.create_server(
|
483
|
+
"My Shiny Server",
|
484
|
+
flavor_id,
|
485
|
+
image_id,
|
486
|
+
{
|
487
|
+
'security_groups' => ["SecGroup1, SecGroup2"],
|
488
|
+
'key_name' => "<key_name>",
|
489
|
+
'config_drive' => true,
|
490
|
+
'user_data_encoded' => ["This is some encoded user data"].pack('m'),
|
491
|
+
'personality' => [{
|
492
|
+
'contents' => File.read("/path/to/sample.txt"),
|
493
|
+
'path' => "/path/to/sample.txt"
|
494
|
+
}]
|
495
|
+
}
|
496
|
+
)
|
497
|
+
server = response.body['server']
|
498
|
+
server['id'] # returns the id of the new server
|
499
|
+
|
500
|
+
The personalization options are:
|
501
|
+
|
502
|
+
*config_drive*
|
503
|
+
: Disk accessible to the server that contains a FAT filesystem. If `config_drive` parameter is set to `true` at the time of server creation, the configuration drive is created.
|
504
|
+
|
505
|
+
*user_data_encoded*
|
506
|
+
: Allows additional metadata to be inserted during server creation by supplying a Base64-encoded string in the `user_data_encoded` parameter.
|
507
|
+
|
508
|
+
*personality*
|
509
|
+
: Allows files to be injected into the server instance after its creation. The file `contents` are Base64 encoded and injected into the location specified by `path`.
|
510
|
+
|
511
|
+
**Note**: The above personalization options are not supported on Windows server instances.
|
512
|
+
|
513
|
+
8. Update the name for a server:
|
514
|
+
|
515
|
+
conn.update_server(server_id, {'name' => "My Cool Server"})
|
516
|
+
response = conn.get_server_details(server_id)
|
517
|
+
response.body['server']['name'] # => "My Cool Server"
|
518
|
+
|
519
|
+
9. Change the password for a server:
|
520
|
+
|
521
|
+
conn.change_password_server(server_id, "new_password")
|
522
|
+
|
523
|
+
10. List both public and private addresses of a particular server:
|
524
|
+
|
525
|
+
response = conn.list_server_addresses(server_id)
|
526
|
+
|
527
|
+
11. List all the private addresses of a particular server:
|
528
|
+
|
529
|
+
response = conn.list_server_private_addresses(server_id, "private") # where "private" is the network name
|
530
|
+
|
531
|
+
12. List all the public addresses of a particular server:
|
532
|
+
|
533
|
+
response = conn.list_server_public_addresses(server_id, "private") # where "private" is the network name
|
534
|
+
|
535
|
+
13. Get console output:
|
536
|
+
|
537
|
+
response = conn.get_console_output(server_id, 5)
|
538
|
+
# => 5 lines of console output are returned
|
539
|
+
|
540
|
+
14. Get VNC console:
|
541
|
+
|
542
|
+
response = conn.get_vnc_console(server_id, 'novnc')
|
543
|
+
# => Url to access the VNC console of a server from a browser
|
544
|
+
|
545
|
+
15. Reboot a server:
|
546
|
+
|
547
|
+
response = conn.reboot_server(server_id, 'HARD') # Hard reboot a server
|
548
|
+
response = conn.reboot_server(server_id, 'SOFT') # Soft reboot a server
|
549
|
+
|
550
|
+
16. Delete an existing server:
|
551
|
+
|
552
|
+
conn.delete_server(server_id)
|
553
|
+
|
554
|
+
## Request Server Metadata Operations
|
555
|
+
|
556
|
+
1. Create a server and pass it some metadata at creation:
|
557
|
+
|
558
|
+
response = conn.create_server(
|
559
|
+
"myserver", 1, 2,
|
560
|
+
{'metadata' =>
|
561
|
+
{'Meta1' => 'MetaValue1', 'Meta2' => 'MetaValue2'}
|
562
|
+
}
|
563
|
+
)
|
564
|
+
response.body['server']['metadata']
|
565
|
+
# => {"Meta1"=>"MetaValue1", "Meta2"=>"MetaValue2"}
|
566
|
+
|
567
|
+
2. List the existing metadata:
|
568
|
+
|
569
|
+
response = conn.list_metadata("servers", server_id)
|
570
|
+
response.body['metadata']
|
571
|
+
# => {"Meta1"=>"MetaValue1", "Meta2"=>"MetaValue2"}
|
572
|
+
|
573
|
+
3. Set new values to the existing metadata:
|
574
|
+
|
575
|
+
response = conn.set_metadata("servers", server_id, {"MetaNew1" => "MetaNewValue1"})
|
576
|
+
response.body['metadata']
|
577
|
+
# => {"MetaNew1"=>"MetaNewValue1"}
|
578
|
+
|
579
|
+
4. Update the existing metadata:
|
580
|
+
|
581
|
+
response = conn.update_metadata("servers", server_id, {"Meta2" => "MetaValue2"})
|
582
|
+
response.body['metadata']
|
583
|
+
# => {"Meta2"=>"MetaValue2"}
|
584
|
+
|
585
|
+
5. Get a metadata item:
|
586
|
+
|
587
|
+
response = conn.get_meta("servers", server_id, "Meta1")
|
588
|
+
response.body['meta']
|
589
|
+
# => {"Meta1"=>"MetaValue1"}
|
590
|
+
|
591
|
+
6. Set a new metadata item or update an existing metadata item:
|
592
|
+
|
593
|
+
response = conn.update_meta("servers", server_id, "Meta1", "MetaUpdated1")
|
594
|
+
response.body['meta']
|
595
|
+
# => {"Meta1"=>"MetaUpdated1"}
|
596
|
+
|
597
|
+
7. Delete a metadata item:
|
598
|
+
|
599
|
+
conn.delete_meta("servers", server_id, "Meta1")
|
600
|
+
|
601
|
+
## Request Flavor Operations
|
602
|
+
|
603
|
+
1. List all available flavors:
|
604
|
+
|
605
|
+
response = conn.list_flavors
|
606
|
+
response.body['flavors'] # returns an array of flavor hashes
|
607
|
+
response.headers # returns the headers for the flavors
|
608
|
+
response.body['flavors'][0]['name'] # returns the name of the flavor
|
609
|
+
|
610
|
+
2. List all available flavors with additional details:
|
611
|
+
|
612
|
+
response = conn.list_flavors_detail
|
613
|
+
response.body['flavors'] # returns an array of flavor hashes
|
614
|
+
|
615
|
+
3. Obtain the details of a particular flavor:
|
616
|
+
|
617
|
+
response = conn.get_flavor_details(flavor_id)
|
618
|
+
flavor = response.body['flavor']
|
619
|
+
flavor['name'] # returns the name of the flavor
|
620
|
+
flavor['disk'] # returns the disk size of the flavor
|
621
|
+
flavor['ram'] # returns the ram size of the flavor
|
622
|
+
|
623
|
+
## Request Image Operations
|
624
|
+
|
625
|
+
1. List all available images:
|
626
|
+
|
627
|
+
response = conn.list_images
|
628
|
+
response.body['images'] # returns an array of image hashes
|
629
|
+
response.headers # returns the headers for the images
|
630
|
+
response.body['images'][0]['name'] # returns the name of the image
|
631
|
+
|
632
|
+
2. List all available images with additional details:
|
633
|
+
|
634
|
+
response = conn.list_images_detail
|
635
|
+
response.body['images'] # returns an array of image hashes
|
636
|
+
response.body['images'][0]['name'] # returns the name of the image
|
637
|
+
|
638
|
+
3. Obtain the details of a particular image:
|
639
|
+
|
640
|
+
response = conn.get_image_details(image_id)
|
641
|
+
image = response.body['image']
|
642
|
+
image['name'] # returns name of the image
|
643
|
+
image['status'] # returns the state of the image e.g. ACTIVE
|
644
|
+
image['created'] # returns the creation date of the image
|
645
|
+
image['updated'] # returns the update date of the image
|
646
|
+
|
647
|
+
3. Create a new snapshot image based on an existing server:
|
648
|
+
|
649
|
+
conn.create_image(server_id, "My Image") # creates an snapshot image from the server referenced by "server_id"
|
650
|
+
|
651
|
+
4. Delete an existing snapshot image:
|
652
|
+
|
653
|
+
conn.delete_image(image_id)
|
654
|
+
|
655
|
+
## Request Image Metadata Operations
|
656
|
+
|
657
|
+
1. Create an image and pass it some metadata at creation:
|
658
|
+
|
659
|
+
conn.create_image(server_id, "myimage", {'Meta1' => 'MetaValue1', 'Meta2' => 'MetaValue2'})
|
660
|
+
|
661
|
+
2. List the existing metadata:
|
662
|
+
|
663
|
+
response = conn.list_metadata("images", image_id)
|
664
|
+
response.body['metadata']
|
665
|
+
# => {"Meta1"=>"MetaValue1", "Meta2"=>"MetaValue2"}
|
666
|
+
|
667
|
+
3. Set new values to the existing metadata:
|
668
|
+
|
669
|
+
response = conn.set_metadata("images", image_id, {"MetaNew1" => "MetaNewValue1"})
|
670
|
+
response.body['metadata']
|
671
|
+
# => {"MetaNew1"=>"MetaNewValue1"}
|
672
|
+
|
673
|
+
4. Update the existing metadata:
|
674
|
+
|
675
|
+
response = conn.update_metadata("images", image_id, {"Meta2" => "MetaValue2"})
|
676
|
+
response.body['metadata']
|
677
|
+
# => {"Meta2"=>"MetaValue2"}
|
678
|
+
|
679
|
+
5. Get a metadata item:
|
680
|
+
|
681
|
+
response = conn.get_meta("images", image_id, "Meta1")
|
682
|
+
response.body['meta']
|
683
|
+
# => {"Meta1"=>"MetaValue1"}
|
684
|
+
|
685
|
+
6. Update a metadata item:
|
686
|
+
|
687
|
+
response = conn.update_meta("images", image_id, "Meta1", "MetaUpdated1")
|
688
|
+
response.body['meta']
|
689
|
+
# => {"Meta1"=>"MetaUpdated1"}
|
690
|
+
|
691
|
+
7. Delete a metadata item:
|
692
|
+
|
693
|
+
conn.delete_meta("images", image_id, "Meta1")
|
694
|
+
|
695
|
+
## Request Keypair Operations
|
696
|
+
|
697
|
+
1. List all available keypairs:
|
698
|
+
|
699
|
+
response = conn.list_key_pairs
|
700
|
+
response.body['keypairs'] # returns an array of keypair hashes
|
701
|
+
response.headers # returns the headers
|
702
|
+
response.body['keypairs'][0]['keypair']['name'] # returns the name of the keypair
|
703
|
+
|
704
|
+
2. Create a new keypair:
|
705
|
+
|
706
|
+
response = conn.create_key_pair("mykey")
|
707
|
+
keypair = response.body['keypair']
|
708
|
+
keypair['name'] # returns the name of the keypair
|
709
|
+
keypair['public_key'] # returns the public key of the keypair
|
710
|
+
keypair['private_key'] # returns the private key of the keypair
|
711
|
+
|
712
|
+
3. Import a public key to create a new keypair:
|
713
|
+
|
714
|
+
response = conn.create_key_pair("mykey", "public key material")
|
715
|
+
keypair = response.body['keypair']
|
716
|
+
keypair['name'] # returns the name of the keypair
|
717
|
+
|
718
|
+
4. Delete an existing keypair:
|
719
|
+
|
720
|
+
conn.delete_key_pair(key_name)
|
721
|
+
|
722
|
+
## Request Security Groups Operations
|
723
|
+
|
724
|
+
1. List all available security groups:
|
725
|
+
|
726
|
+
response = conn.list_security_groups
|
727
|
+
response.body['security_groups'] # returns an array of security groups hashes
|
728
|
+
response.headers # returns the headers
|
729
|
+
response.body['security_groups'][0]['name'] # returns the name of the security group
|
730
|
+
|
731
|
+
2. Obtain the details of a particular security group:
|
732
|
+
|
733
|
+
response = conn.get_security_group(sgroup_id) # get the security group
|
734
|
+
sgroup = response.body['security_group']
|
735
|
+
sgroup['name'] # returns the name of the security group
|
736
|
+
|
737
|
+
3. Create a new security group:
|
738
|
+
|
739
|
+
response = conn.create_security_group("mysgroup", "my new sec group")
|
740
|
+
sgroup = response.body['security_group']
|
741
|
+
sgroup['name'] # => "mysgroup"
|
742
|
+
|
743
|
+
4. Create a rule for an existing security group:
|
744
|
+
|
745
|
+
response = create_security_group_rule(sgroup_id, "tcp", "80", "80", "0.0.0.0/0") # allow port 80, tcp at 0.0.0.0/0
|
746
|
+
sg_rule = response.body['security_group_rule']
|
747
|
+
sg_rule['id'] # returns the id of the security group rule
|
748
|
+
sg_rule['parent_group_id'] # returns the id of the security group to which the rule belongs to
|
749
|
+
sg_rule['from_port'] # => 80
|
750
|
+
sg_rule['to_port'] # => 80
|
751
|
+
sg_rule['ip_protocol'] # => tcp
|
752
|
+
sg_rule['ip_range']['cidr'] # => 0.0.0.0/0
|
753
|
+
|
754
|
+
5. Delete an existing security group rule:
|
755
|
+
|
756
|
+
conn.delete_security_group_rule(sg_rule_id)
|
757
|
+
|
758
|
+
6. Delete an existing security group:
|
759
|
+
|
760
|
+
conn.delete_security_group(sgroup_id)
|
761
|
+
|
762
|
+
## Request Address Operations
|
763
|
+
|
764
|
+
1. List all available floating ip addresses:
|
765
|
+
|
766
|
+
response = conn.list_addresses
|
767
|
+
response.body['addresses'] # returns an array of address hashes
|
768
|
+
response.headers # returns the headers
|
769
|
+
response.body['addresses'][0]['id'] # returns the id of the address
|
770
|
+
|
771
|
+
2. Obtain the details of a particular address:
|
772
|
+
|
773
|
+
response = conn.get_address(address_id) # get the address
|
774
|
+
response.body['address']['ip'] # returns the ip address
|
775
|
+
|
776
|
+
3. Create (allocate) a new address:
|
777
|
+
|
778
|
+
response = conn.allocate_address # allocates an ip address from the pool
|
779
|
+
response.body['address']['ip'] # returns the ip address
|
780
|
+
|
781
|
+
4. Associate a server to an existing address:
|
782
|
+
|
783
|
+
conn.associate_address(server_id, ip_address)
|
784
|
+
|
785
|
+
5. Disassociate a server from an existing address:
|
786
|
+
|
787
|
+
conn.disassociate_address(server_id, ip_address)
|
788
|
+
|
789
|
+
6. Delete (release) an existing address:
|
790
|
+
|
791
|
+
conn.release_address(address_id) # releases the ip address to the pool
|
792
|
+
|
793
|
+
---------
|
794
|
+
[Documentation Home](https://github.com/fog/fog/blob/master/lib/fog/hp/README.md) | [Examples](https://github.com/fog/fog/blob/master/lib/fog/hp/examples/getting_started_examples.md)
|