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,848 @@
|
|
1
|
+
# Examples for working with HP Cloud Compute Service v13.5
|
2
|
+
|
3
|
+
The latest HP Cloud deployment, version 13.5, takes advantage of more OpenStack functionality and the compute service uses slightly different commands (often noted by *v2* in the commands) than the previous 12.12 version. Verify which version of HP cloud you are working with.
|
4
|
+
|
5
|
+
The HP Cloud services provides compute support using two abstractions: [a model layer](#ModelLayer) and [a request layer](#RequestLayer). Both layers are detailed below. The code samples on this page can be executed from within a Ruby console (IRB):
|
6
|
+
|
7
|
+
irb
|
8
|
+
|
9
|
+
This page discusses the following topics:
|
10
|
+
|
11
|
+
* [Connecting to the Service](#connecting-to-the-service)
|
12
|
+
|
13
|
+
**Model Layer Examples**
|
14
|
+
|
15
|
+
* [Model Server Operations](#model-server-operations)
|
16
|
+
* [Model Server Volume Operations](#model-server-volume-operations)
|
17
|
+
* [Model Server Metadata Operations](#model-server-metadata-operations)
|
18
|
+
* [Model Flavor Operations](#model-flavor-operations)
|
19
|
+
* [Model Image Operations](#model-image-operations)
|
20
|
+
* [Model Image Metadata Operations](#model-image-metadata-operations)
|
21
|
+
* [Model Keypair Operations](#model-keypair-operations)
|
22
|
+
* [Model Address Operations](#model-address-operations)
|
23
|
+
|
24
|
+
**Request Layer Examples**
|
25
|
+
|
26
|
+
* [Request Server Operations](#request-server-operations)
|
27
|
+
* [Request Server Metadata Operations](#request-server-metadata-operations)
|
28
|
+
* [Request Flavor Operations](#request-flavor-operations)
|
29
|
+
* [Request Image Operations](#request-image-operations)
|
30
|
+
* [Request Image Metadata Operations](#request-image-metadata-operations)
|
31
|
+
* [Request Keypair Operations](#request-keypair-operations)
|
32
|
+
* [Request Address Operations](#request-address-operations)
|
33
|
+
|
34
|
+
## Connecting to the Service
|
35
|
+
|
36
|
+
To connect to the HP Cloud Compute V2 Service, follow these steps:
|
37
|
+
|
38
|
+
1. Enter IRB
|
39
|
+
|
40
|
+
irb
|
41
|
+
|
42
|
+
2. Require the Fog library
|
43
|
+
|
44
|
+
require 'fog'
|
45
|
+
|
46
|
+
3. Establish a connection to the HP Cloud Compute V2 service
|
47
|
+
|
48
|
+
conn = Fog::Compute.new(
|
49
|
+
:provider => "HP",
|
50
|
+
:version => :v2,
|
51
|
+
:hp_access_key => "<your_ACCESS_KEY>",
|
52
|
+
:hp_secret_key => "<your_SECRET_KEY>",
|
53
|
+
:hp_auth_uri => "<IDENTITY_ENDPOINT_URL>",
|
54
|
+
:hp_tenant_id => "<your_TENANT_ID>",
|
55
|
+
:hp_avl_zone => "<your_AVAILABILITY_ZONE>",
|
56
|
+
<other optional parameters>
|
57
|
+
)
|
58
|
+
|
59
|
+
**Note**: You must use the `:hp_access_key` parameter rather than the now-deprecated `:hp_account_id` parameter you might have used in previous Ruby Fog versions.
|
60
|
+
|
61
|
+
You can find the values the access key, secret key, and other values by clicking the [`API Keys`](https://console.hpcloud.com/account/api_keys) button in the [Console Dashboard](https://console.hpcloud.com/dashboard).
|
62
|
+
|
63
|
+
## Model Server Operations
|
64
|
+
|
65
|
+
1. List all available servers for an account:
|
66
|
+
|
67
|
+
servers = conn.servers
|
68
|
+
servers.size # returns no. of servers
|
69
|
+
# display servers in a tabular format
|
70
|
+
conn.servers.table([:id, :name, :state, :created_at])
|
71
|
+
|
72
|
+
2. List servers using a filter:
|
73
|
+
|
74
|
+
servers = conn.servers.all(:name => 'My Shiny Server')
|
75
|
+
|
76
|
+
|
77
|
+
3. Obtain the details of a particular server:
|
78
|
+
|
79
|
+
server = conn.servers.get("<server_id>")
|
80
|
+
server.name # returns name of the server
|
81
|
+
server.flavor_id # returns id of the flavor used to create the server
|
82
|
+
server.image_id # returns id of the image used to create the server
|
83
|
+
server.addresses # returns a hash of public and private IP addresses
|
84
|
+
server.created_at # returns the date the server was created
|
85
|
+
server.state # returns the state of the server e.g. ACTIVE, BUILD
|
86
|
+
|
87
|
+
4. Create a new server:
|
88
|
+
|
89
|
+
new_server = conn.servers.create(
|
90
|
+
:name => "My Shiny Server",
|
91
|
+
:flavor_id => 101,
|
92
|
+
:image_id => "<server_id>"
|
93
|
+
)
|
94
|
+
new_server.id # returns the id of the server
|
95
|
+
new_server.name # => "My Shiny Server"
|
96
|
+
new_server.state # returns the state of the server e.g. BUILD
|
97
|
+
new_server.private_ip_address # returns the private ip address
|
98
|
+
new_server.public_ip_address # returns the public ip address, if any assigned
|
99
|
+
|
100
|
+
5. Create a server by passing in a keypair and security group:
|
101
|
+
|
102
|
+
new_server = conn.servers.create(
|
103
|
+
:name=> "My Shiny Server",
|
104
|
+
:flavor_id => 101,
|
105
|
+
:image_id => "<image_id>",
|
106
|
+
:key_name => "my_keypair",
|
107
|
+
:security_groups => ["My Security Group"]
|
108
|
+
)
|
109
|
+
|
110
|
+
6. Create a server by passing in a network_id:
|
111
|
+
|
112
|
+
new_server = conn.servers.create(
|
113
|
+
:name=> "My Shiny Server",
|
114
|
+
:flavor_id => 101,
|
115
|
+
:image_id => "<image_id>",
|
116
|
+
:key_name => "my_keypair",
|
117
|
+
:security_groups => ["My Security Group"],
|
118
|
+
:networks => ["<network_id>"]
|
119
|
+
)
|
120
|
+
|
121
|
+
7. Create a Linux-based persistent server by passing in a bootable volume:
|
122
|
+
|
123
|
+
new_server = conn.servers.create(
|
124
|
+
:name=> "My Sticky Server",
|
125
|
+
:flavor_id => 104,
|
126
|
+
:block_device_mapping => [{ 'volume_size' => '',
|
127
|
+
'volume_id' => "<volume_id>",
|
128
|
+
'delete_on_termination' => '0',
|
129
|
+
'device_name' => 'vda'
|
130
|
+
}]
|
131
|
+
)
|
132
|
+
**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.
|
133
|
+
|
134
|
+
8. Create a new Linux-based server with advanced personalization options:
|
135
|
+
|
136
|
+
new_server = conn.servers.create(
|
137
|
+
:name => "My Personalized Server",
|
138
|
+
:flavor_id => 1,
|
139
|
+
:image_id => 2,
|
140
|
+
:key_name => "hpdefault",
|
141
|
+
:security_groups => ["aaa"],
|
142
|
+
:config_drive => true,
|
143
|
+
:user_data_encoded => ["This is some encoded user data"].pack('m'),
|
144
|
+
:personality => [{
|
145
|
+
'contents' => File.read("/path/to/sample.txt"),
|
146
|
+
'path' => "/path/to/sample.txt"
|
147
|
+
}]
|
148
|
+
)
|
149
|
+
new_server.id # returns the id of the server
|
150
|
+
new_server.name # => "My Personalised Server"
|
151
|
+
|
152
|
+
# Note: that un-encoded user data can also be provided by setting the user_data property
|
153
|
+
# although, encoding the data on the client is faster and efficient
|
154
|
+
new_server = conn.servers.new(
|
155
|
+
:name => "My Personalized Server",
|
156
|
+
...
|
157
|
+
...
|
158
|
+
)
|
159
|
+
new_server.user_data = "This is some un-encoded user data"
|
160
|
+
new_server.save
|
161
|
+
|
162
|
+
The personalization options are:
|
163
|
+
|
164
|
+
*config_drive*
|
165
|
+
: 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.
|
166
|
+
|
167
|
+
*user_data_encoded* or *user_data*
|
168
|
+
: 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.
|
169
|
+
|
170
|
+
*personality*
|
171
|
+
: 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`.
|
172
|
+
|
173
|
+
**Note**: The above personalization options are not supported on Windows server instances.
|
174
|
+
|
175
|
+
|
176
|
+
9. Create a new Windows server instance and retrieve the encrypted password:
|
177
|
+
|
178
|
+
win_server = conn.servers.create(
|
179
|
+
:name => "My Windows Server",
|
180
|
+
:flavor_id => 1,
|
181
|
+
:image_id => 3, # Make sure it is a Windows image
|
182
|
+
:key_name => "<key_name>",
|
183
|
+
:security_groups => ["<security_group_name>"]
|
184
|
+
)
|
185
|
+
win_server.id # returns the id of the server
|
186
|
+
# Retrieve the encrypted password
|
187
|
+
win_server.windows_password
|
188
|
+
# => "Im6ZJ8auyMRnkJ24KKWQvTgWDug1s ... y0uY1BcHLJ5OrkEPHhQoQntIKOoQ=\n"
|
189
|
+
**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.
|
190
|
+
|
191
|
+
10. Get console output:
|
192
|
+
|
193
|
+
server = conn.servers.get("<server_id>")
|
194
|
+
server.console_output(10) # returns 10 lines of console output
|
195
|
+
|
196
|
+
11. Get VNC console:
|
197
|
+
|
198
|
+
server = conn.servers.get("<server_id>")
|
199
|
+
server.vnc_console_url('novnc') # URL to access the VNC console of a server from a browser
|
200
|
+
|
201
|
+
12. Update a server:
|
202
|
+
|
203
|
+
server = conn.servers.get("<server_id>")
|
204
|
+
server.update_name("My Shiny Server Updated")
|
205
|
+
|
206
|
+
13. Reboot a server:
|
207
|
+
|
208
|
+
server = conn.servers.get("server_id>")
|
209
|
+
server.reboot # soft reboot by default
|
210
|
+
|
211
|
+
server.reboot("HARD") # hard reboot also possible
|
212
|
+
|
213
|
+
14. Rebuild a server:
|
214
|
+
|
215
|
+
server = conn.servers.get("<server_id>")
|
216
|
+
server.rebuild('server_id', 'My Shiny Server Rebuild')
|
217
|
+
|
218
|
+
15. Delete a server:
|
219
|
+
|
220
|
+
server = conn.servers.get("<server_id>").destroy
|
221
|
+
|
222
|
+
|
223
|
+
## Model Server Volume Operations
|
224
|
+
|
225
|
+
1. Attach a volume to a server:
|
226
|
+
|
227
|
+
server = conn.servers.get("<server_id>")
|
228
|
+
server.volume_attachments.create(
|
229
|
+
:server_id => s.id,
|
230
|
+
:volume_id => "<volume id>",
|
231
|
+
:device => "/dev/sdf"
|
232
|
+
)
|
233
|
+
server.reload #reload the server
|
234
|
+
server.volume_attachments.all #list the attachments
|
235
|
+
|
236
|
+
2. Obtain details for an volume attached to a server:
|
237
|
+
|
238
|
+
server = conn.servers.get("<server_id>")
|
239
|
+
server.volume_attachements.get("<volume_id>")
|
240
|
+
|
241
|
+
3. List attached volumes for a server:
|
242
|
+
|
243
|
+
server = conn.servers.get("<server_id>")
|
244
|
+
server.volume_attachments.all
|
245
|
+
|
246
|
+
4. Detach a volume from a server:
|
247
|
+
|
248
|
+
server = conn.servers.get("<server_id>")
|
249
|
+
att_volume = server.volume_attachments.get("<volume_id>")
|
250
|
+
att_volume.destroy # also aliased to att_volume.detach
|
251
|
+
|
252
|
+
## Model Server Metadata Operations
|
253
|
+
|
254
|
+
1. Create a server with some metadata:
|
255
|
+
|
256
|
+
server = conn.servers.create(
|
257
|
+
:flavor_id => 1,
|
258
|
+
:image_id => 2,
|
259
|
+
:name => "myserver",
|
260
|
+
:metadata => {'Meta1' => 'MetaValue1', 'Meta2' => 'MetaValue2'}
|
261
|
+
)
|
262
|
+
|
263
|
+
2. Get the metadata item:
|
264
|
+
|
265
|
+
server.metadata.get("Meta1")
|
266
|
+
|
267
|
+
3. Update the metadata:
|
268
|
+
|
269
|
+
s.metadata.update({"Meta2" => "MetaValue2"})
|
270
|
+
|
271
|
+
4. Set the metadata:
|
272
|
+
|
273
|
+
s.metadata.set({"Meta3" => "MetaValue3"})
|
274
|
+
|
275
|
+
5. Set the metadata explicitly:
|
276
|
+
|
277
|
+
m = myserver.metadata.new
|
278
|
+
m.key = "Meta4"
|
279
|
+
m.value = "Value4"
|
280
|
+
m.save
|
281
|
+
|
282
|
+
6. Update the metadata:
|
283
|
+
|
284
|
+
m = s.metadata.get("Meta1")
|
285
|
+
m.value = "MetaUpdValue1"
|
286
|
+
m.save
|
287
|
+
|
288
|
+
7. List metadata:
|
289
|
+
|
290
|
+
s.metadata.all
|
291
|
+
|
292
|
+
8. Delete metadata:
|
293
|
+
|
294
|
+
m = s.metadata.get("Meta3").destroy
|
295
|
+
|
296
|
+
## Model Flavor Operations
|
297
|
+
|
298
|
+
1. List all available flavors:
|
299
|
+
|
300
|
+
flavors = conn.flavors.all
|
301
|
+
flavors.size # returns no. of flavors
|
302
|
+
# display flavors in a tabular format
|
303
|
+
conn.flavors.table([:id, :name, :ram, :disk])
|
304
|
+
|
305
|
+
2. List flavors using a filter:
|
306
|
+
|
307
|
+
flavors = conn.flavors.all(:limit => 2)
|
308
|
+
|
309
|
+
3. Obtain the details of a particular flavor:
|
310
|
+
|
311
|
+
flavor = conn.flavors.get("<flavor_id>") # get the flavor
|
312
|
+
flavor.name # returns the name of the flavor eg: m1.tiny, m1.small etc.
|
313
|
+
flavor.ram # returns the ram memory in bytes for the flavor, eg: 4096
|
314
|
+
flavor.disk # returns the disk size in GB for the flavor, eg: 80
|
315
|
+
flavor.cores # returns no. of cores for the flavor, eg: 0.25
|
316
|
+
|
317
|
+
## Model Image Operations
|
318
|
+
|
319
|
+
1. List all available images:
|
320
|
+
|
321
|
+
images = conn.images
|
322
|
+
images.size # returns no. of images
|
323
|
+
# display images in a tabular format
|
324
|
+
conn.images.table([:id, :name, :status, :created_at])
|
325
|
+
|
326
|
+
2. Obtain the details of a particular image:
|
327
|
+
|
328
|
+
image = conn.images.get("<image_id>") # get the image
|
329
|
+
image.name # returns name of the image
|
330
|
+
image.created_at # returns the date the image was created
|
331
|
+
image.status # returns the state of the image e.g. ACTIVE
|
332
|
+
|
333
|
+
3. Create a new snapshot image based on an existing server:
|
334
|
+
|
335
|
+
# first, get a server
|
336
|
+
server = conn.servers.get("<server_id>")
|
337
|
+
s.create_image("My Image")
|
338
|
+
|
339
|
+
4. Delete an existing snapshot image:
|
340
|
+
|
341
|
+
image = conn.images.get("<image_id>").destroy
|
342
|
+
|
343
|
+
## Model Image Metadata Operations
|
344
|
+
|
345
|
+
1. Create an image snapshot with some metadata:
|
346
|
+
|
347
|
+
myserver.create_image("My Image", {"ImgMeta1" => "ImgMeta1Value"})
|
348
|
+
|
349
|
+
2. Get the metadata item:
|
350
|
+
|
351
|
+
image = conn.images.get("<image_id>")
|
352
|
+
image.metadata.set({"Meta3" => "MetaValue3"})
|
353
|
+
|
354
|
+
3. Update the metadata:
|
355
|
+
|
356
|
+
image.metadata.update({"Meta2" => "MetaValue2"})
|
357
|
+
|
358
|
+
4. Set the metadata:
|
359
|
+
|
360
|
+
image.metadata.set({"Meta3" => "MetaValue3"})
|
361
|
+
|
362
|
+
5. Set the metadata explicitly:
|
363
|
+
|
364
|
+
m = image.metadata.set("Meta1")
|
365
|
+
m.value = "MetaUpValue1"
|
366
|
+
m.save
|
367
|
+
|
368
|
+
6. Update the metadata:
|
369
|
+
|
370
|
+
m = myimage.metadata.get("ImgMeta3")
|
371
|
+
m.value = "ImgUpdValue3"
|
372
|
+
m.save
|
373
|
+
|
374
|
+
7. List metadata:
|
375
|
+
|
376
|
+
myimage.metadata.all
|
377
|
+
|
378
|
+
8. Delete metadata:
|
379
|
+
|
380
|
+
m = image.metadata.get("ImgMeta3").destroy
|
381
|
+
|
382
|
+
## Model Keypair Operations
|
383
|
+
|
384
|
+
1. List all available keypairs:
|
385
|
+
|
386
|
+
keypairs = conn.key_pairs
|
387
|
+
keypairs.size # returns no. of keypairs
|
388
|
+
# display keypairs in a tabular format
|
389
|
+
conn.key_pairs.table([:name, :public_key])
|
390
|
+
|
391
|
+
2. Obtain the details of a particular keypair:
|
392
|
+
|
393
|
+
keypair = conn.key_pairs.get(key_name) # get the keypair
|
394
|
+
keypair.name # returns name of the keypair
|
395
|
+
keypair.public_key # returns the public key of the keypair
|
396
|
+
# NOTE: Due to security considerations, the private key is not available on subsequent gets
|
397
|
+
keypair.private_key # => nil
|
398
|
+
|
399
|
+
3. Create a new keypair:
|
400
|
+
|
401
|
+
keypair = conn.key_pairs.create(:name => "mykey")
|
402
|
+
keypair.name # returns name of the keypair
|
403
|
+
keypair.public_key # returns the public key of the keypair
|
404
|
+
keypair.private_key # returns the private key of the keypair
|
405
|
+
**Note**: Keypairs with a dot (.) are not allowed.
|
406
|
+
|
407
|
+
4. Export a keypair to a file:
|
408
|
+
|
409
|
+
keypair = conn.key_pairs.create(:name => "mykey2")
|
410
|
+
keypair.write # => "Key file built: /Users/xxxxx/.ssh/mykey2.pem"
|
411
|
+
|
412
|
+
# Alternatively, you can pass in a path to export the key
|
413
|
+
keypair.write("/Users/xxxxx/Downloads/mykey2.pem")
|
414
|
+
|
415
|
+
5. Import a public key to create a new keypair:
|
416
|
+
|
417
|
+
keypair = conn.key_pairs.create(:name => "mykey", :public_key => "public key material")
|
418
|
+
keypair.name # returns name of the keypair
|
419
|
+
|
420
|
+
6. Delete an existing keypair:
|
421
|
+
|
422
|
+
keypair = conn.key_pairs.get(key_name)
|
423
|
+
keypair.destroy
|
424
|
+
|
425
|
+
## Model Address Operations
|
426
|
+
|
427
|
+
1. List all public and private ip addresses for a server:
|
428
|
+
|
429
|
+
address = conn.addresses
|
430
|
+
|
431
|
+
2. Obtain the details of a particular address:
|
432
|
+
|
433
|
+
address = conn.addresses.get("<address_id>") # get the address
|
434
|
+
address.ip # returns the ip address
|
435
|
+
|
436
|
+
3. Create or allocate a new address:
|
437
|
+
|
438
|
+
address = conn.addresses.create # allocates an ip address from the pool
|
439
|
+
address.ip # returns the ip address
|
440
|
+
|
441
|
+
4. Associate a server to an existing address:
|
442
|
+
|
443
|
+
server = conn.servers.get("<server_id>") # get the server
|
444
|
+
address = conn.addresses.get("<address_id>") # get the address
|
445
|
+
address.server = server # associate the server
|
446
|
+
address.reload
|
447
|
+
|
448
|
+
5. Disassociate a server from an existing address:
|
449
|
+
|
450
|
+
address = conn.addresses.get("<address_id>") # get the address
|
451
|
+
address.server = nil # disassociate the server
|
452
|
+
address.instance_id # => nil
|
453
|
+
|
454
|
+
6. Delete (release) an existing address:
|
455
|
+
|
456
|
+
server = conn.servers.get("<server_id>") # get the server
|
457
|
+
address = conn.addresses.get("<address_id>") # get the address
|
458
|
+
address.server = nil # disassociate the server
|
459
|
+
address.reload
|
460
|
+
|
461
|
+
7. Release an address back into the IP pool:
|
462
|
+
|
463
|
+
address = conn.addresses.get("<address_id>").destroy
|
464
|
+
=> true
|
465
|
+
|
466
|
+
## Request Server Operations
|
467
|
+
|
468
|
+
1. List all available servers for an account:
|
469
|
+
|
470
|
+
response = conn.list_servers
|
471
|
+
response.body['servers'] # returns an array of server hashes
|
472
|
+
response.headers # returns the headers
|
473
|
+
response.body['servers'][0]['name'] # returns the name of the server
|
474
|
+
|
475
|
+
2. List all available servers using a filter:
|
476
|
+
|
477
|
+
response = conn.list_servers_detail(:name => 'My Shiny Server')
|
478
|
+
|
479
|
+
3. List all available servers with additional details:
|
480
|
+
|
481
|
+
response = conn.list_servers_detail
|
482
|
+
response.body['servers'] # returns an array of server hashes
|
483
|
+
response.body['servers'][0]['name'] # returns the name of the server
|
484
|
+
|
485
|
+
4. Obtain the details of a particular server:
|
486
|
+
|
487
|
+
response = conn.get_server_details("<server_id>")
|
488
|
+
server = response.body['server']
|
489
|
+
server['name'] # returns the name of the server
|
490
|
+
server['flavor'] # returns the flavor used to create the server
|
491
|
+
server['image'] # returns the image used to create the server
|
492
|
+
server['addresses'] # returns the public and private addresses
|
493
|
+
server['status'] # returns the state of the server e.g. ACTIVE
|
494
|
+
|
495
|
+
5. Create a new server:
|
496
|
+
|
497
|
+
response = conn.create_server(
|
498
|
+
"My Shiny Server",
|
499
|
+
flavor_id,
|
500
|
+
image_id,
|
501
|
+
{
|
502
|
+
'availability_zone' => "az2"
|
503
|
+
}
|
504
|
+
{
|
505
|
+
'security_groups' => ["SecGroup1, SecGroup2"],
|
506
|
+
'key_name' => "MyKeyPair1"
|
507
|
+
}
|
508
|
+
)
|
509
|
+
server = response.body['server']
|
510
|
+
server['id'] # returns the id of the new server
|
511
|
+
server['name'] # => "My Shiny Server"
|
512
|
+
server['status'] # returns the state of the server e.g. BUILD
|
513
|
+
|
514
|
+
6. Create a server by passing in a keypair and security group:
|
515
|
+
|
516
|
+
response = conn.create_server(
|
517
|
+
"My Shiny Server",
|
518
|
+
101,
|
519
|
+
image_id,
|
520
|
+
{
|
521
|
+
'key_name' => "MyKeyPair1",
|
522
|
+
'security_groups' => ["SecGroup1, SecGroup2"],
|
523
|
+
}
|
524
|
+
)
|
525
|
+
server = response.body['server']
|
526
|
+
server['id'] # returns the id of the new server
|
527
|
+
server['name'] # => "My Shiny Server"
|
528
|
+
server['status'] # returns the state of the server e.g. BUILD
|
529
|
+
|
530
|
+
7. Create a server by passing in a network:
|
531
|
+
|
532
|
+
response = conn.create_server(
|
533
|
+
"My Shiny Server",
|
534
|
+
101,
|
535
|
+
image_id,
|
536
|
+
{
|
537
|
+
'networks' => ["My Network"]
|
538
|
+
}
|
539
|
+
)
|
540
|
+
|
541
|
+
|
542
|
+
8. Create a new Windows server and retrieve the encrypted password:
|
543
|
+
|
544
|
+
# Make sure to use a Windows image
|
545
|
+
response = conn.create_server("My Windows Server", "<flavor_id>", "<image_id>")
|
546
|
+
win_server = response.body['server']
|
547
|
+
server_id = win_server['id'] # returns the id of the new server
|
548
|
+
# Retrieve the encrypted password
|
549
|
+
conn.get_windows_password("<server_id>")
|
550
|
+
# => "Im6ZJ8auyMRnkJ24KKWQvTgWDug1s ... y0uY1BcHLJ5OrkEPHhQoQntIKOoQ=\n"
|
551
|
+
**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.
|
552
|
+
|
553
|
+
9. Create a new Linux-based persistent server with a bootable volume
|
554
|
+
|
555
|
+
conn.create_persistent_server(
|
556
|
+
"MyBootableServer",
|
557
|
+
103,
|
558
|
+
[{ "volume_size"=>"", # ignored
|
559
|
+
"volume_id"=>"65904",
|
560
|
+
"delete_on_termination"=>"0",
|
561
|
+
"device_name"=>"vda"
|
562
|
+
}] ,
|
563
|
+
{
|
564
|
+
'security_groups' => ["mysecgroup"],
|
565
|
+
'key_name' => "mykey"
|
566
|
+
}
|
567
|
+
)
|
568
|
+
**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.
|
569
|
+
|
570
|
+
10. Create a new Linux-based server with advanced personalisation options:
|
571
|
+
|
572
|
+
response = conn.create_server(
|
573
|
+
"My Shiny Server",
|
574
|
+
flavor_id,
|
575
|
+
image_id,
|
576
|
+
{
|
577
|
+
'security_groups' => ["SecGroup1, SecGroup2"],
|
578
|
+
'key_name' => "MyKeyPair1",
|
579
|
+
'config_drive' => true,
|
580
|
+
'user_data_encoded' => ["This is some encoded user data"].pack('m'),
|
581
|
+
'personality' => [{
|
582
|
+
'contents' => File.read("/path/to/sample.txt"),
|
583
|
+
'path' => "/path/to/sample.txt"
|
584
|
+
}]
|
585
|
+
}
|
586
|
+
)
|
587
|
+
server = response.body['server']
|
588
|
+
server['id'] # returns the id of the new server
|
589
|
+
|
590
|
+
The personalization options are:
|
591
|
+
|
592
|
+
*config_drive*
|
593
|
+
: 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.
|
594
|
+
|
595
|
+
*user_data_encoded*
|
596
|
+
: Allows additional metadata to be inserted during server creation by supplying a Base64-encoded string in the `user_data_encoded` parameter.
|
597
|
+
|
598
|
+
*personality*
|
599
|
+
: 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`.
|
600
|
+
|
601
|
+
**Note**: The above personalization options are not supported on Windows server instances.
|
602
|
+
|
603
|
+
11. Update the name for a server:
|
604
|
+
|
605
|
+
address = conn.update_server("<server_id>", {'name' => "My Cool Server"})
|
606
|
+
response = conn.get_server_details("<server_id>")
|
607
|
+
response.body['server']['name'] # => "My Cool Server"
|
608
|
+
|
609
|
+
12. Reboot a server (SOFT):
|
610
|
+
|
611
|
+
address = conn.reboot_server("<server_id>", "SOFT")
|
612
|
+
|
613
|
+
13. Reboot a server (HARD):
|
614
|
+
|
615
|
+
address = conn.rebuild_server("<server_id>", "HARD")
|
616
|
+
|
617
|
+
14. Rebuild a server:
|
618
|
+
|
619
|
+
address = conn.reboot_server("<server_id>", "MyRebuiltServer")
|
620
|
+
|
621
|
+
15. List both public and private addresses of a particular server:
|
622
|
+
|
623
|
+
response = conn.list_server_addresses("<server_id>")
|
624
|
+
|
625
|
+
13. Display console output:
|
626
|
+
|
627
|
+
response = conn.get_console_output("<server_id>", 10)
|
628
|
+
# => 10 lines of console output are returned
|
629
|
+
|
630
|
+
14. Get the VNC console for a server:
|
631
|
+
|
632
|
+
response = conn.get_vnc_console("<server_id>")
|
633
|
+
# => Url to access the VNC console of a server from a browser
|
634
|
+
|
635
|
+
16. Delete an existing server:
|
636
|
+
|
637
|
+
conn.delete_server("<server_id>")
|
638
|
+
|
639
|
+
## Request Server Metadata Operations
|
640
|
+
|
641
|
+
1. Create a server and pass it some metadata at creation:
|
642
|
+
|
643
|
+
response = conn.create_server(
|
644
|
+
"myserver", 1, 2,
|
645
|
+
{'metadata' =>
|
646
|
+
{'Meta1' => 'MetaValue1', 'Meta2' => 'MetaValue2'}
|
647
|
+
}
|
648
|
+
)
|
649
|
+
response.body['server']['metadata']
|
650
|
+
# => {"Meta1"=>"MetaValue1", "Meta2"=>"MetaValue2"}
|
651
|
+
|
652
|
+
2. List the existing metadata:
|
653
|
+
|
654
|
+
response = conn.list_metadata("servers", "<server_id>")
|
655
|
+
response.body['metadata']
|
656
|
+
# => {"Meta1"=>"MetaValue1", "Meta2"=>"MetaValue2"}
|
657
|
+
|
658
|
+
3. Set new values to the existing metadata:
|
659
|
+
|
660
|
+
response = conn.set_metadata("servers", "<server_id>", {"MetaNew1" => "MetaNewValue1"})
|
661
|
+
response.body['metadata']
|
662
|
+
# => {"MetaNew1"=>"MetaNewValue1"}
|
663
|
+
|
664
|
+
4. Update the existing metadata:
|
665
|
+
|
666
|
+
response = conn.update_metadata("servers", "<server_id>", {"Meta2" => "MetaValue2"})
|
667
|
+
response.body['metadata']
|
668
|
+
# => {"Meta2"=>"MetaValue2"}
|
669
|
+
|
670
|
+
5. Get a metadata item:
|
671
|
+
|
672
|
+
response = conn.get_meta("servers", "<server_id>", "Meta1")
|
673
|
+
response.body['meta']
|
674
|
+
# => {"Meta1"=>"MetaValue1"}
|
675
|
+
|
676
|
+
6. Set a new metadata item or update an existing metadata item:
|
677
|
+
|
678
|
+
response = conn.update_meta("servers", "<server_id>", "Meta1", "MetaUpdated1")
|
679
|
+
response.body['meta']
|
680
|
+
# => {"Meta1"=>"MetaUpdated1"}
|
681
|
+
|
682
|
+
7. Delete a metadata item:
|
683
|
+
|
684
|
+
conn.delete_meta("servers", "<server_id>", "Meta1")
|
685
|
+
|
686
|
+
## Request Flavor Operations
|
687
|
+
|
688
|
+
1. List all available flavors:
|
689
|
+
|
690
|
+
response = conn.list_flavors
|
691
|
+
response.body['flavors'] # returns an array of flavor hashes
|
692
|
+
response.headers # returns the headers for the flavors
|
693
|
+
response.body['flavors'][0]['name'] # returns the name of the flavor
|
694
|
+
|
695
|
+
2. List all available flavors with additional details:
|
696
|
+
|
697
|
+
response = conn.list_flavors_detail
|
698
|
+
response.body['flavors'] # returns an array of flavor hashes
|
699
|
+
|
700
|
+
3. Obtain the details of a particular flavor:
|
701
|
+
|
702
|
+
response = conn.get_flavor_details("<flavor_id>")
|
703
|
+
flavor = response.body['flavor']
|
704
|
+
flavor['name'] # returns the name of the flavor
|
705
|
+
flavor['disk'] # returns the disk size of the flavor
|
706
|
+
flavor['ram'] # returns the ram size of the flavor
|
707
|
+
|
708
|
+
## Request Image Operations
|
709
|
+
|
710
|
+
1. List all available images:
|
711
|
+
|
712
|
+
response = conn.list_images
|
713
|
+
response.body['images'] # returns an array of image hashes
|
714
|
+
response.headers # returns the headers for the images
|
715
|
+
response.body['images'][0]['name'] # returns the name of the image
|
716
|
+
|
717
|
+
2. List all available images with additional details:
|
718
|
+
|
719
|
+
response = conn.list_images_detail
|
720
|
+
response.body['images'] # returns an array of image hashes
|
721
|
+
response.body['images'][0]['name'] # returns the name of the image
|
722
|
+
|
723
|
+
3. Obtain the details of a particular image:
|
724
|
+
|
725
|
+
response = conn.get_image_details("<image_id>")
|
726
|
+
image = response.body['image']
|
727
|
+
image['name'] # returns name of the image
|
728
|
+
image['status'] # returns the state of the image e.g. ACTIVE
|
729
|
+
image['created'] # returns the creation date of the image
|
730
|
+
image['updated'] # returns the update date of the image
|
731
|
+
|
732
|
+
3. Create a new snapshot image based on an existing server:
|
733
|
+
|
734
|
+
conn.create_image("<server_id>", "My Image") # creates an snapshot image from the server referenced by "server_id"
|
735
|
+
|
736
|
+
4. Delete an existing snapshot image:
|
737
|
+
|
738
|
+
conn.delete_image("<image_id>")
|
739
|
+
|
740
|
+
## Request Image Metadata Operations
|
741
|
+
|
742
|
+
1. Create an image and pass it some metadata at creation:
|
743
|
+
|
744
|
+
conn.create_image("<server_id>", "myimage", {'Meta1' => 'MetaValue1', 'Meta2' => 'MetaValue2'})
|
745
|
+
|
746
|
+
2. List the existing metadata:
|
747
|
+
|
748
|
+
response = conn.list_metadata("images", "<image_id>")
|
749
|
+
response.body['metadata']
|
750
|
+
# => {"Meta1"=>"MetaValue1", "Meta2"=>"MetaValue2"}
|
751
|
+
|
752
|
+
3. Set new values to the existing metadata:
|
753
|
+
|
754
|
+
response = conn.set_metadata("images", "<image_id>", {"MetaNew1" => "MetaNewValue1"})
|
755
|
+
response.body['metadata']
|
756
|
+
# => {"MetaNew1"=>"MetaNewValue1"}
|
757
|
+
|
758
|
+
4. Update the existing metadata:
|
759
|
+
|
760
|
+
response = conn.update_metadata("images", "<image_id>", {"Meta2" => "MetaValue2"})
|
761
|
+
response.body['metadata']
|
762
|
+
# => {"Meta2"=>"MetaValue2"}
|
763
|
+
|
764
|
+
5. Get a metadata item:
|
765
|
+
|
766
|
+
response = conn.get_meta("images", "<image_id>", "Meta1")
|
767
|
+
response.body['meta']
|
768
|
+
# => {"Meta1"=>"MetaValue1"}
|
769
|
+
|
770
|
+
6. Update a metadata item:
|
771
|
+
|
772
|
+
response = conn.update_meta("images", "<image_id>", "Meta1", "MetaUpdated1")
|
773
|
+
response.body['meta']
|
774
|
+
# => {"Meta1"=>"MetaUpdated1"}
|
775
|
+
|
776
|
+
7. Delete a metadata item:
|
777
|
+
|
778
|
+
conn.delete_meta("images", "<image_id>", "Meta1")
|
779
|
+
|
780
|
+
## Request Keypair Operations
|
781
|
+
|
782
|
+
1. List all available keypairs:
|
783
|
+
|
784
|
+
response = conn.list_key_pairs
|
785
|
+
response.body['keypairs'] # returns an array of keypair hashes
|
786
|
+
response.headers # returns the headers
|
787
|
+
response.body['keypairs'][0]['keypair']['name'] # returns the name of the keypair
|
788
|
+
|
789
|
+
2. Create a new keypair:
|
790
|
+
|
791
|
+
response = conn.create_key_pair("mykey")
|
792
|
+
keypair = response.body['keypair']
|
793
|
+
keypair['name'] # returns the name of the keypair
|
794
|
+
keypair['public_key'] # returns the public key of the keypair
|
795
|
+
keypair['private_key'] # returns the private key of the keypair
|
796
|
+
|
797
|
+
3. Obtain a keypair:
|
798
|
+
|
799
|
+
response = conn.get_key_pair("mykey")
|
800
|
+
|
801
|
+
|
802
|
+
4. Import a public key to create a new keypair:
|
803
|
+
|
804
|
+
response = conn.create_key_pair("mykey", "public key material")
|
805
|
+
keypair = response.body['keypair']
|
806
|
+
keypair['name'] # returns the name of the keypair
|
807
|
+
|
808
|
+
4. Delete an existing keypair:
|
809
|
+
|
810
|
+
conn.delete_key_pair("<key_name>")
|
811
|
+
|
812
|
+
## Request Address Operations
|
813
|
+
|
814
|
+
1. List all available floating IP addresses:
|
815
|
+
|
816
|
+
response = conn.list_server_addresses
|
817
|
+
response.body['addresses'] # returns an array of address hashes
|
818
|
+
response.headers # returns the headers
|
819
|
+
response.body['addresses'][0]['id'] # returns the id of the address
|
820
|
+
|
821
|
+
2. List addresses by network for a server:
|
822
|
+
|
823
|
+
response = conn.list_server_addresses_by_network("<address_id>") # get the address
|
824
|
+
|
825
|
+
3. Obtain the details of a particular address:
|
826
|
+
|
827
|
+
response = conn.get_address("<address_id>") # get the address
|
828
|
+
response.body['address']['ip'] # returns the ip address
|
829
|
+
|
830
|
+
3. Create (allocate) a new address:
|
831
|
+
|
832
|
+
response = conn.allocate_address # allocates an ip address from the pool
|
833
|
+
response.body['address']['ip'] # returns the ip address
|
834
|
+
|
835
|
+
4. Associate a server to an existing address:
|
836
|
+
|
837
|
+
conn.associate_address("<server_id>", "<ip_address>")
|
838
|
+
|
839
|
+
5. Disassociate a server from an existing address:
|
840
|
+
|
841
|
+
conn.disassociate_address("<server_id>", "<ip_address>")
|
842
|
+
|
843
|
+
6. Delete (release) an existing address:
|
844
|
+
|
845
|
+
conn.release_address("<address_id>") # releases the ip address to the pool
|
846
|
+
|
847
|
+
---------
|
848
|
+
[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)
|