Top Level Namespace
Defined Under Namespace
Modules: Excon, Fog, Google, Libvirt, VAppStatus, Vmfusion
Classes: AWS, Atmos, BareMetalCloud, Bluebox, Brightbox, Clodo, CloudSigma, Cloudstack, DNSMadeEasy, DNSimple, DigitalOcean, Dreamhost, Dynect, Ecloud, Glesys, GoGrid, HP, Hash, IBM, IPAddr, InternetArchive, Joyent, Linode, Local, Ninefold, NonLoaded, OpenStack, Openvz, Ovirt, Rackspace, Rage4, RiakCS, Server, Serverlove, StormOnDemand, String, Terremark, TerremarkParser, Vcloud, VcloudDirector, VcloudDirectorParser, Voxel, Vsphere, XenServer, Zerigo
Constant Summary
collapse
- INTERNET =
'00000000-0000-0000-0000-000000000000'
- SERVICE_NET =
UUID for Rackspace’s service net
'11111111-1111-1111-1111-111111111111'
- SEGMENT_LIMIT =
5368709119.0
- BUFFER_SIZE =
Size of buffer to use for transfers. Use Excon’s default chunk size and if that’s not avaliable we will default to 1 MB
Excon.defaults[:chunk_size] || 1024 * 1024
- CDN =
FIXME: hacks until we can ‘include Fog` in bin
Fog::CDN
- Compute =
Fog::Compute
- DNS =
Fog::DNS
- Storage =
Fog::Storage
Instance Method Summary
collapse
Instance Method Details
#delete_network(network) ⇒ Object
I have notice that cloud networks is slow to acknowledge deleted servers. This method tries to mitigate this.
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/fog/rackspace/examples/compute_v2/delete_network.rb', line 17
def delete_network(network)
attempt = 0
begin
network.destroy
rescue Fog::Compute::RackspaceV2::ServiceError => e
if attempt == 3
puts "Unable to delete #{network.label}"
return false
end
puts "Network #{network.label} Delete Fail Attempt #{attempt}- #{e.inspect}"
attempt += 1
sleep 60
retry
end
return true
end
|
#generate_ssh_key ⇒ Object
Generates a ssh key using the SSHKey library. The private key is avaialble via the ‘.private_key’ and the public key is avaialble via ‘.ssh_public_key’
29
30
31
|
# File 'lib/fog/rackspace/examples/compute_v2/bootstrap_server.rb', line 29
def generate_ssh_key
SSHKey.generate
end
|
#get_object_http_url(container, object, expires, options = {}) ⇒ Object
Get an expiring object http url
Parameters
-
container<~String> - Name of container containing object
-
object<~String> - Name of object to get expiring url for
-
expires<~Time> - An expiry time for this url
Returns
11
12
13
|
# File 'lib/fog/openstack/requests/storage/get_object_http_url.rb', line 11
def get_object_http_url(container, object, expires, options = {})
create_temp_url(container, object, expires, "GET", options.merge(:scheme => "http"))
end
|
#get_user_boolean(prompt) ⇒ Object
13
14
15
16
17
|
# File 'lib/fog/rackspace/examples/queues/list_messages.rb', line 13
def get_user_boolean(prompt)
str = get_user_input(prompt)
return false unless str
str.match(/y(es)?/i) ? true : false
end
|
8
9
10
11
|
# File 'lib/fog/rackspace/examples/queues/create_queue.rb', line 8
def get_user_input(prompt)
print "#{prompt}: "
gets.chomp
end
|
12
13
14
15
|
# File 'lib/fog/rackspace/examples/auto_scale/add_policy.rb', line 12
def get_user_input_as_int(prompt)
str = get_user_input(prompt)
str.to_i
end
|
20
21
22
23
24
25
|
# File 'lib/fog/rackspace/examples/storage/storage_metadata.rb', line 20
def print_metadata(object)
object.metadata.each_pair do |key, value|
puts "\t#{key}: #{value}"
end
puts "\n"
end
|
#rackspace_api_key ⇒ Object
21
22
23
|
# File 'lib/fog/rackspace/examples/queues/create_queue.rb', line 21
def rackspace_api_key
Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key")
end
|
#rackspace_username ⇒ Object
15
16
17
|
# File 'lib/fog/rackspace/examples/queues/create_queue.rb', line 15
def rackspace_username
Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username")
end
|
#select_attachment(attachments) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/fog/rackspace/examples/compute_v2/detach_volume.rb', line 25
def select_attachment(attachments)
abort "\nThis server does not contain any volumes in the Chicago region. Try running server_attachments.rb\n\n" if attachments.empty?
puts "\nSelect Volume To Detach:\n\n"
attachments.each_with_index do |attachment, i|
puts "\t #{i}. #{attachment.device}"
end
delete_str = get_user_input "\nEnter Volume Number"
attachments[delete_str.to_i]
end
|
#select_directory(directories) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/fog/rackspace/examples/storage/delete_file.rb', line 13
def select_directory(directories)
abort "\nThere are not any directories with files to delete in the Chicago region. Try running create_file.rb\n\n" if directories.empty?
puts "\nSelect Directory:\n\n"
directories.each_with_index do |dir, i|
puts "\t #{i}. #{dir.key} [#{dir.count} objects]"
end
delete_str = get_user_input "\nEnter Directory Number"
directories[delete_str.to_i]
end
|
#select_file(files) ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/fog/rackspace/examples/storage/delete_file.rb', line 25
def select_file(files)
puts "\nSelect File:\n\n"
files.each_with_index do |file, i|
puts "\t #{i}. #{file.key}"
end
delete_str = get_user_input "\nEnter File Number"
files[delete_str.to_i]
end
|
#select_flavor(flavors, server) ⇒ Object
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/fog/rackspace/examples/compute_v2/resize_server.rb', line 13
def select_flavor(flavors, server)
puts "\nSelect New Flavor Size:\n\n"
flavors.each_with_index do |flavor, i|
next if server.flavor_id == flavor.id
puts "\t #{i}. #{flavor.name}"
end
selected_flavor_str = get_user_input "\nEnter Flavor Number"
flavors[selected_flavor_str.to_i]
end
|
#select_group(groups) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/fog/rackspace/examples/auto_scale/add_policy.rb', line 29
def select_group(groups)
abort "\nThere are not any scaling groups in the Chicago region. Try running create_scaling_group.rb\n\n" if groups.empty?
puts "\nSelect Group For New Policy:\n\n"
groups.each_with_index do |group, i|
config = group.group_config
puts "\t #{i}. #{config.name}"
end
select_str = get_user_input "\nEnter Group Number"
groups[select_str.to_i]
end
|
#select_image(images) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/fog/rackspace/examples/compute_v2/delete_image.rb', line 13
def select_image(snapshot_images)
abort "\nThere are not any images to delete in the Chicago region. Try running create_image.rb\n\n" if snapshot_images.empty?
puts "\nSelect Image To Delete:\n\n"
snapshot_images.each_with_index do |image, i|
puts "\t #{i}. #{image.name}"
end
delete_str = get_user_input "\nEnter Image Number"
snapshot_images[delete_str.to_i]
end
|
#select_message(messages) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/fog/rackspace/examples/queues/delete_message.rb', line 25
def select_message(messages)
abort "\nThere are not any messages in the Chicago region. Try running post_message.rb\n\n" if messages.empty?
puts "\nSelect Message To Delete:\n\n"
messages.each_with_index do |message, i|
puts "\t #{i}. [#{message.id}] #{message.body[0..50]}"
end
delete_str = get_user_input "\nEnter Message Number"
messages[delete_str.to_i]
end
|
#select_policy(policies) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/fog/rackspace/examples/auto_scale/add_webhook.rb', line 37
def select_policy(policies)
abort "\nThere are no policies for this scaling group. Try running add_policy.rb\n\n" if policies.empty?
puts "\nSelect Policy Triggered By Webhook:\n\n"
policies.each_with_index do |policy, i|
puts "\t #{i}. #{policy.name}"
end
select_str = get_user_input "\nEnter Policy Number"
policies[select_str.to_i]
end
|
#select_queue(queues) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/fog/rackspace/examples/queues/delete_queue.rb', line 13
def select_queue(queues)
abort "\nThere are not any queues to delete in the Chicago region. Try running create_queue.rb\n\n" if queues.empty?
puts "\nSelect Queue To Delete:\n\n"
queues.each_with_index do |queue, i|
puts "\t #{i}. #{queue.name}"
end
delete_str = get_user_input "\nEnter Queue Number"
queues[delete_str.to_i]
end
|
#select_server(servers) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/fog/rackspace/examples/compute_v2/create_image.rb', line 13
def select_server(servers)
abort "\nThere are not any servers available to image in the Chicago region. Try running create_server.rb\n\n" if servers.empty?
puts "\nSelect Server To Image:\n\n"
servers.each_with_index do |server, i|
puts "\t #{i}. #{server.name} [#{server.public_ip_address}]"
end
selected_str = get_user_input "\nEnter Server Number"
servers[selected_str.to_i]
end
|
#select_volume(volumes) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/fog/rackspace/examples/block_storage/delete_volume.rb', line 13
def select_volume(volumes)
abort "\nThere are not any volumes to delete in the Chicago region. Try running create_volume.rb\n\n" if volumes.empty?
puts "\nSelect Volume:\n\n"
volumes.each_with_index do |volume, i|
puts "\t #{i}. #{volume.display_name}"
end
selected_str = get_user_input "Enter Volume Type Number"
volumes[selected_str.to_i]
end
|
#select_volume_type(volume_types) ⇒ Object
13
14
15
16
17
18
19
20
21
|
# File 'lib/fog/rackspace/examples/block_storage/create_volume.rb', line 13
def select_volume_type(volume_types)
puts "\nSelect Volume Type:\n\n"
volume_types.each_with_index do |volume_type, i|
puts "\t #{i}. #{volume_type.name}"
end
selected_str = get_user_input "Enter Volume Type Number"
volume_types[selected_str.to_i]
end
|
#select_webhook(webhooks) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/fog/rackspace/examples/auto_scale/delete_webhook.rb', line 50
def select_webhook(webhooks)
abort "\nThere are no webhooks for this policy. Try running add_webhook.rb\n\n" if webhooks.empty?
puts "\nSelect Webhook:\n\n"
webhooks.each_with_index do |webhook, i|
puts "\t #{i}. #{webhook.name}"
end
select_str = get_user_input "\nEnter Webhook Number"
webhooks[select_str.to_i]
end
|
#test ⇒ Object
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/fog/google/examples/create.rb', line 1
def test
connection = Fog::Compute.new({ :provider => "Google" })
name = "fog-smoke-test-#{Time.now.to_i}"
disk = connection.disks.create({
:name => name,
:size_gb => 10,
:zone_name => 'us-central1-a',
:source_image => 'debian-7-wheezy-v20131120',
})
disk.wait_for { disk.ready? }
server = connection.servers.create(defaults = {
:name => "fog-smoke-test-#{Time.now.to_i}",
:disks => [disk],
:machine_type => "n1-standard-1",
:zone_name => "us-central1-a",
:private_key_path => File.expand_path("~/.ssh/id_rsa"),
:public_key_path => File.expand_path("~/.ssh/id_rsa.pub"),
:user => ENV['USER'],
:tags => ["fog"]
})
duration = 0
interval = 5
timeout = 600
start = Time.now
until server.sshable? || duration > timeout
server.reload
sleep(interval.to_f)
duration = Time.now - start
end
raise "Could not bootstrap sshable server." unless server.ssh("whoami")
raise "Cloud note delete server." unless server.destroy
end
|
#wait_for_server_deletion(server) ⇒ Object
8
9
10
11
12
13
14
|
# File 'lib/fog/rackspace/examples/compute_v2/delete_network.rb', line 8
def wait_for_server_deletion(server)
begin
server.wait_for { state = 'DELETED' }
rescue Fog::Compute::RackspaceV2::NotFound => e
end
end
|