Class: Fog::Compute::HP::Mock
- Inherits:
-
Object
- Object
- Fog::Compute::HP::Mock
- Defined in:
- lib/rackspace-fog/hp/compute.rb,
lib/rackspace-fog/hp/requests/compute/get_address.rb,
lib/rackspace-fog/hp/requests/compute/list_images.rb,
lib/rackspace-fog/hp/requests/compute/create_image.rb,
lib/rackspace-fog/hp/requests/compute/delete_image.rb,
lib/rackspace-fog/hp/requests/compute/list_flavors.rb,
lib/rackspace-fog/hp/requests/compute/list_servers.rb,
lib/rackspace-fog/hp/requests/compute/create_server.rb,
lib/rackspace-fog/hp/requests/compute/delete_server.rb,
lib/rackspace-fog/hp/requests/compute/reboot_server.rb,
lib/rackspace-fog/hp/requests/compute/resize_server.rb,
lib/rackspace-fog/hp/requests/compute/update_server.rb,
lib/rackspace-fog/hp/requests/compute/list_addresses.rb,
lib/rackspace-fog/hp/requests/compute/list_key_pairs.rb,
lib/rackspace-fog/hp/requests/compute/rebuild_server.rb,
lib/rackspace-fog/hp/requests/compute/create_key_pair.rb,
lib/rackspace-fog/hp/requests/compute/delete_key_pair.rb,
lib/rackspace-fog/hp/requests/compute/release_address.rb,
lib/rackspace-fog/hp/requests/compute/allocate_address.rb,
lib/rackspace-fog/hp/requests/compute/associate_address.rb,
lib/rackspace-fog/hp/requests/compute/get_image_details.rb,
lib/rackspace-fog/hp/requests/compute/get_flavor_details.rb,
lib/rackspace-fog/hp/requests/compute/get_security_group.rb,
lib/rackspace-fog/hp/requests/compute/get_server_details.rb,
lib/rackspace-fog/hp/requests/compute/list_images_detail.rb,
lib/rackspace-fog/hp/requests/compute/list_flavors_detail.rb,
lib/rackspace-fog/hp/requests/compute/list_servers_detail.rb,
lib/rackspace-fog/hp/requests/compute/disassociate_address.rb,
lib/rackspace-fog/hp/requests/compute/list_security_groups.rb,
lib/rackspace-fog/hp/requests/compute/create_security_group.rb,
lib/rackspace-fog/hp/requests/compute/delete_security_group.rb,
lib/rackspace-fog/hp/requests/compute/list_server_addresses.rb,
lib/rackspace-fog/hp/requests/compute/revert_resized_server.rb,
lib/rackspace-fog/hp/requests/compute/change_password_server.rb,
lib/rackspace-fog/hp/requests/compute/confirm_resized_server.rb,
lib/rackspace-fog/hp/requests/compute/create_security_group_rule.rb,
lib/rackspace-fog/hp/requests/compute/delete_security_group_rule.rb,
lib/rackspace-fog/hp/requests/compute/list_server_public_addresses.rb,
lib/rackspace-fog/hp/requests/compute/list_server_private_addresses.rb
Class Method Summary collapse
Instance Method Summary collapse
- #allocate_address ⇒ Object
- #associate_address(server_id, ip_address) ⇒ Object
- #change_password_server(server_id, admin_password) ⇒ Object
- #confirm_resized_server(server_id) ⇒ Object
- #create_image(server_id, name, metadata = {}) ⇒ Object
- #create_key_pair(key_name, public_key = nil) ⇒ Object
- #create_security_group(name, description) ⇒ Object
- #create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group_id = nil) ⇒ Object
- #create_server(name, flavor_id, image_id, options = {}) ⇒ Object
- #data ⇒ Object
- #delete_image(image_id) ⇒ Object
- #delete_key_pair(key_name) ⇒ Object
- #delete_security_group(security_group_id) ⇒ Object
- #delete_security_group_rule(security_group_rule_id) ⇒ Object
- #delete_server(server_id) ⇒ Object
- #disassociate_address(server_id, ip_address) ⇒ Object
- #get_address(address_id) ⇒ Object
- #get_flavor_details(flavor_id) ⇒ Object
- #get_image_details(image_id) ⇒ Object
- #get_security_group(security_group_id) ⇒ Object
- #get_server_details(server_id) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #list_addresses ⇒ Object
- #list_flavors ⇒ Object
- #list_flavors_detail ⇒ Object
- #list_images ⇒ Object
- #list_images_detail ⇒ Object
- #list_key_pairs ⇒ Object
- #list_security_groups ⇒ Object
- #list_server_addresses(server_id) ⇒ Object
- #list_server_private_addresses(server_id, network_name) ⇒ Object
- #list_server_public_addresses(server_id, network_name) ⇒ Object
- #list_servers ⇒ Object
- #list_servers_detail ⇒ Object
- #reboot_server(server_id, type = 'SOFT') ⇒ Object
- #rebuild_server(server_id, image_ref, name, admin_pass = nil, metadata = nil, personality = nil) ⇒ Object
- #release_address(address_id) ⇒ Object
- #reset_data ⇒ Object
-
#resize_server(server_id, flavor_id) ⇒ Object
FIXME: should probably transition instead of skipping to VERIFY_RESIZE.
- #revert_resized_server(server_id) ⇒ Object
- #update_server(server_id, options) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
93 94 95 |
# File 'lib/rackspace-fog/hp/compute.rb', line 93 def initialize(={}) @hp_account_id = [:hp_account_id] end |
Class Method Details
.data ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rackspace-fog/hp/compute.rb', line 70 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :last_modified => { :images => {}, :key_pairs => {}, :security_groups => {}, :servers => {}, :addresses => {} }, :images => {}, :key_pairs => {}, :security_groups => {}, :servers => {}, :addresses => {} } end end |
.reset ⇒ Object
89 90 91 |
# File 'lib/rackspace-fog/hp/compute.rb', line 89 def self.reset @data = nil end |
Instance Method Details
#allocate_address ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rackspace-fog/hp/requests/compute/allocate_address.rb', line 30 def allocate_address response = Excon::Response.new response.status = 200 data = { 'instance_id' => Fog::HP::Mock.instance_id.to_i, 'ip' => Fog::HP::Mock.ip_address, 'fixed_ip' => Fog::HP::Mock.ip_address, 'id' => Fog::Mock.random_numbers(3).to_i } self.data[:last_modified][:addresses][data['id']] = Time.now self.data[:addresses][data['id']] = data response.body = { 'floating_ip' => data } response end |
#associate_address(server_id, ip_address) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rackspace-fog/hp/requests/compute/associate_address.rb', line 21 def associate_address(server_id, ip_address) response = Excon::Response.new if server = self.data[:servers][server_id] data = {"version"=>4, "addr"=>"#{ip_address}"} if server['addresses']['private'] server['addresses']['private'] << data else server['addresses']['private'] = data end response.status = 202 else #raise Fog::Compute::HP::NotFound response.status = 500 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#change_password_server(server_id, admin_password) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rackspace-fog/hp/requests/compute/change_password_server.rb', line 15 def change_password_server(server_id, admin_password) response = Excon::Response.new if list_servers_detail.body['servers'].detect {|_| _['id'] == server_id} if admin_password response.body = { 'changePassword' => { 'adminPass' => admin_password }} end response.status = 202 else #raise Fog::Compute::HP::NotFound response.status = 500 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#confirm_resized_server(server_id) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rackspace-fog/hp/requests/compute/confirm_resized_server.rb', line 20 def confirm_resized_server(server_id) response = Excon::Response.new response.status = 204 self.data[:servers][server_id].delete('old_flavorId') self.data[:last_modified][:servers][server_id] = Time.now self.data[:servers][server_id]['status'] = 'ACTIVE' response end |
#create_image(server_id, name, metadata = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rackspace-fog/hp/requests/compute/create_image.rb', line 34 def create_image(server_id, name, = {}) response = Excon::Response.new response.status = 202 image_id = Fog::Mock.random_numbers(6).to_s data = { 'id' => image_id, 'server' => {"id"=>"3", "links"=>[{"href"=>"http://nova1:8774/v1.1/servers/#{server_id}", "rel"=>"bookmark"}]}, 'links' => [{"href"=>"http://nova1:8774/v1.1/tenantid/images/#{image_id}", "rel"=>"self"}, {"href"=>"http://nova1:8774/tenantid/images/#{image_id}", "rel"=>"bookmark"}], 'metadata' => || {}, 'name' => name || "image_#{rand(999)}", 'progress' => 0, 'status' => 'SAVING', 'updated' => "", 'created' => "" } self.data[:last_modified][:images][data['id']] = Time.now self.data[:images][data['id']] = data response.headers = {'Content-Length' => '0', 'Content-Type' => 'text/html; charset=UTF-8', 'Date' => Time.now, 'Location' => "http://nova1:8774/v1.1/images/#{@image_id}"} response.body = "" # { 'image' => data } no data is sent response end |
#create_key_pair(key_name, public_key = nil) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rackspace-fog/hp/requests/compute/create_key_pair.rb', line 51 def create_key_pair(key_name, public_key = nil) response = Excon::Response.new unless self.data[:key_pairs][key_name] response.status = 200 private_key, new_public_key = Fog::HP::Mock.key_material new_public_key = public_key if public_key # if public key was passed in data = { 'public_key' => new_public_key, 'fingerprint' => Fog::HP::Mock.key_fingerprint, 'name' => key_name } self.data[:last_modified][:key_pairs][key_name] = Time.now self.data[:key_pairs][key_name] = { 'keypair' => data } if public_key response.body = { 'keypair' => data.merge({'user_id' => Fog::HP::Mock.user_id,}) } else response.body = { 'keypair' => data.merge({'private_key' => private_key, 'user_id' => Fog::HP::Mock.user_id,}) } end else #raise Fog::Compute::HP::NotFound response.status = 400 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#create_security_group(name, description) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rackspace-fog/hp/requests/compute/create_security_group.rb', line 52 def create_security_group(name, description) # all spaces are removed name = name.strip description = description.strip response = Excon::Response.new if self.data[:security_groups].detect {|_,v| v['name'] == name} response.status = 400 response.body = { "badRequest" => {"message" => "Security group #{name} already exists", "code" => 400}} raise(Excon::Errors.status_error({:expects => 200}, response)) else response.status = 200 data = { 'rules' => [], 'id' => Fog::Mock.random_numbers(3).to_i, 'tenant_id' => Fog::HP::Mock.user_id.to_s, 'name' => name, 'description' => description } self.data[:last_modified][:security_groups][data['id']] = Time.now self.data[:security_groups][data['id']] = data response.body = { 'security_group' => data } end response end |
#create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group_id = nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rackspace-fog/hp/requests/compute/create_security_group_rule.rb', line 45 def create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group_id=nil) response = Excon::Response.new group = self.data[:security_groups][parent_group_id] if group group['rules'] ||= [] response.status = 200 data = { 'from_port' => from_port.to_i, 'group' => {}, 'ip_protocol' => ip_protocol, 'to_port' => to_port.to_i, 'parent_group_id' => parent_group_id, 'ip_range' => { 'cidr' => cidr }, 'id' => Fog::Mock.random_numbers(3).to_i } group['rules'][data['id']] = data response.body = { 'security_group_rule' => data } response else raise Fog::Compute::HP::NotFound end end |
#create_server(name, flavor_id, image_id, options = {}) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/rackspace-fog/hp/requests/compute/create_server.rb', line 100 def create_server(name, flavor_id, image_id, = {}) response = Excon::Response.new response.status = 202 #if options['security_groups'] # sec_group_name = options['security_groups'][0] #else # sec_group_name = "default" #end data = { 'addresses' => { "private"=>[{"version"=>4, "addr"=>Fog::HP::Mock.ip_address}] }, 'flavor' => {"id"=>"#{flavor_id}", "links"=>[{"href"=>"http://nova1:8774/admin/flavors/#{flavor_id}", "rel"=>"bookmark"}]}, 'id' => Fog::Mock.random_numbers(6).to_i, 'image' => {"id"=>"#{image_id}", "links"=>[{"href"=>"http://nova1:8774/admin/images/#{image_id}", "rel"=>"bookmark"}]}, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/servers/5", "rel"=>"self"}, {"href"=>"http://nova1:8774/admin/servers/5", "rel"=>"bookmark"}], 'hostId' => "123456789ABCDEF01234567890ABCDEF", 'metadata' => ['metadata'] || {}, 'name' => name || "server_#{rand(999)}", 'accessIPv4' => ['accessIPv4'] || "", 'accessIPv6' => ['accessIPv6'] || "", 'progress' => 0, 'status' => 'BUILD', 'created' => "2012-01-01T13:32:20Z", 'updated' => "2012-01-01T13:32:20Z", 'user_id' => Fog::HP::Mock.user_id.to_s, 'tenant_id' => Fog::HP::Mock.user_id.to_s, 'uuid' => "95253a45-9ead-43c6-90b3-65da2ef048b3", 'config_drive' => "", #'security_groups' => [{"name"=>"#{sec_group_name}", "links"=>[{"href"=>"http://nova1:8774/v1.1/admin//os-security-groups/111", "rel"=>"bookmark"}], "id"=>111}], 'key_name' => ['key_name'] || "" } self.data[:last_modified][:servers][data['id']] = Time.now self.data[:servers][data['id']] = data response.body = { 'server' => data.merge({'adminPass' => 'password'}) } response end |
#data ⇒ Object
97 98 99 |
# File 'lib/rackspace-fog/hp/compute.rb', line 97 def data self.class.data[@hp_account_id] end |
#delete_image(image_id) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rackspace-fog/hp/requests/compute/delete_image.rb', line 23 def delete_image(image_id) response = Excon::Response.new if image = list_images_detail.body['images'].detect {|_| _['id'] == image_id} if image['status'] == 'SAVING' response.status = 409 raise(Excon::Errors.status_error({:expects => 202}, response)) else self.data[:last_modified][:images].delete(image_id) self.data[:images].delete(image_id) response.status = 202 end response else response.status = 500 raise(Excon::Errors.status_error({:expects => 202}, response)) end end |
#delete_key_pair(key_name) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rackspace-fog/hp/requests/compute/delete_key_pair.rb', line 23 def delete_key_pair(key_name) response = Excon::Response.new if self.data[:key_pairs][key_name] self.data[:last_modified][:key_pairs].delete(key_name) self.data[:key_pairs].delete(key_name) response.status = 202 response.body = "202 Accepted\n\nThe request is accepted for processing.\n\n " response else raise Fog::Compute::HP::NotFound end end |
#delete_security_group(security_group_id) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rackspace-fog/hp/requests/compute/delete_security_group.rb', line 25 def delete_security_group(security_group_id) response = Excon::Response.new if self.data[:security_groups][security_group_id] self.data[:last_modified][:security_groups].delete(security_group_id) self.data[:security_groups].delete(security_group_id) response.status = 202 response.body = "202 Accepted\n\nThe request is accepted for processing.\n\n " response else raise Fog::Compute::HP::NotFound end end |
#delete_security_group_rule(security_group_rule_id) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rackspace-fog/hp/requests/compute/delete_security_group_rule.rb', line 24 def delete_security_group_rule(security_group_rule_id) response = Excon::Response.new sg_rule = nil self.data[:security_groups].each do |_, sgv| if sgv['rules'] sg_rule = sgv['rules'].delete_if { |r| !r.nil? && r['id'] == security_group_rule_id } break if sg_rule end end if sg_rule && !sg_rule.empty? response.status = 202 response.body = "202 Accepted\n\nThe request is accepted for processing.\n\n " response else raise Fog::Compute::HP::NotFound end end |
#delete_server(server_id) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rackspace-fog/hp/requests/compute/delete_server.rb', line 23 def delete_server(server_id) response = Excon::Response.new if server = list_servers_detail.body['servers'].detect {|_| _['id'] == server_id} if server['status'] == 'BUILD' response.status = 409 raise(Excon::Errors.status_error({:expects => 202}, response)) else self.data[:last_modified][:servers].delete(server_id) self.data[:servers].delete(server_id) response.status = 204 end response else raise Fog::Compute::HP::NotFound end end |
#disassociate_address(server_id, ip_address) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rackspace-fog/hp/requests/compute/disassociate_address.rb', line 21 def disassociate_address(server_id, ip_address) response = Excon::Response.new if server = self.data[:servers][server_id] data = server['addresses']['private'].reject {|a| a['addr'] == ip_address} self.data[:servers][server_id]['addresses']['private'] = data response.status = 202 else #raise Fog::Compute::HP::NotFound response.status = 500 raise(Excon::Errors.status_error({:expects => 200}, response)) end response end |
#get_address(address_id) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rackspace-fog/hp/requests/compute/get_address.rb', line 31 def get_address(address_id) response = Excon::Response.new if address = self.data[:addresses][address_id] response.status = 200 response.body = { 'floating_ip' => address } response else raise Fog::Compute::HP::NotFound end end |
#get_flavor_details(flavor_id) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rackspace-fog/hp/requests/compute/get_flavor_details.rb', line 27 def get_flavor_details(flavor_id) response = Excon::Response.new flavor = { 1 => { 'name' => 'standard.xsmall', 'ram' => 1024, 'disk' => 30, 'id' => 1, 'rxtx_quota' => 0, 'vcpus' => 1, 'rxtx_cap' => 0, 'swap' => 0, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/1", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/1", "rel"=>"bookmark"}] }, 2 => { 'name' => 'standard.small', 'ram' => 2048, 'disk' => 60, 'id' => 2, 'rxtx_quota' => 0, 'vcpus' => 2, 'rxtx_cap' => 0, 'swap' => 0, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/2", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/2", "rel"=>"bookmark"}] }, 3 => { 'name' => 'standard.medium', 'ram' => 4096, 'disk' => 120, 'id' => 3, 'rxtx_quota' => 0, 'vcpus' => 2, 'rxtx_cap' => 0, 'swap' => 0, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/3", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/3", "rel"=>"bookmark"}] }, 4 => { 'name' => 'standard.large', 'ram' => 8192, 'disk' => 240, 'id' => 4, 'rxtx_quota' => 0, 'vcpus' => 4, 'rxtx_cap' => 0, 'swap' => 0, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/4", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/4", "rel"=>"bookmark"}] }, 5 => { 'name' => 'standard.xlarge', 'ram' => 16384, 'disk' => 480, 'id' => 5, 'rxtx_quota' => 0, 'vcpus' => 4, 'rxtx_cap' => 0, 'swap' => 0, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/5", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/5", "rel"=>"bookmark"}] }, 6 => { 'name' => 'standard.2xlarge', 'ram' => 32768, 'disk' => 960, 'id' => 6, 'rxtx_quota' => 0, 'vcpus' => 8, 'rxtx_cap' => 0, 'swap' => 0, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/6", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/6", "rel"=>"bookmark"}] } }[flavor_id] if flavor response.status = 200 response.body = { 'flavor' => flavor } response else raise Fog::Compute::HP::NotFound end end |
#get_image_details(image_id) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rackspace-fog/hp/requests/compute/get_image_details.rb', line 28 def get_image_details(image_id) response = Excon::Response.new if image = list_images_detail.body['images'].detect {|_| _['id'] == image_id} response.status = [200, 203][rand(1)] response.body = { 'image' => image } response else raise Fog::Compute::HP::NotFound end end |
#get_security_group(security_group_id) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rackspace-fog/hp/requests/compute/get_security_group.rb', line 43 def get_security_group(security_group_id) response = Excon::Response.new if sec_group = self.data[:security_groups][security_group_id] response.status = 200 response.body = { 'security_group' => sec_group } response else raise Fog::Compute::HP::NotFound end end |
#get_server_details(server_id) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rackspace-fog/hp/requests/compute/get_server_details.rb', line 38 def get_server_details(server_id) response = Excon::Response.new if server = list_servers_detail.body['servers'].detect {|_| _['id'] == server_id} response.status = [200, 203][rand(1)] response.body = { 'server' => server } response else raise Fog::Compute::HP::NotFound end end |
#list_addresses ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/rackspace-fog/hp/requests/compute/list_addresses.rb', line 28 def list_addresses response = Excon::Response.new addresses = [] addresses = self.data[:addresses].values unless self.data[:addresses].nil? response.status = 200 response.body = { 'floating_ips' => addresses } response end |
#list_flavors ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rackspace-fog/hp/requests/compute/list_flavors.rb', line 25 def list_flavors response = Excon::Response.new response.status = 200 response.body = { 'flavors' => [ { 'name' => 'standard.xsmall', 'id' => 1, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/1", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/1", "rel"=>"bookmark"}] }, { 'name' => 'standard.small', 'id' => 2, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/2", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/2", "rel"=>"bookmark"}] }, { 'name' => 'standard.medium', 'id' => 3, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/3", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/3", "rel"=>"bookmark"}] }, { 'name' => 'standard.large', 'id' => 4, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/4", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/4", "rel"=>"bookmark"}] }, { 'name' => 'standard.xlarge', 'id' => 5, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/5", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/5", "rel"=>"bookmark"}] }, { 'name' => 'standard.2xlarge', 'id' => 6, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/6", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/6", "rel"=>"bookmark"}] } ] } response end |
#list_flavors_detail ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rackspace-fog/hp/requests/compute/list_flavors_detail.rb', line 27 def list_flavors_detail response = Excon::Response.new response.status = 200 response.body = { 'flavors' => [ { 'name' => 'standard.xsmall', 'ram' => 1024, 'disk' => 30, 'id' => 1, 'rxtx_quota' => 0, 'vcpus' => 1, 'rxtx_cap' => 0, 'swap' => 0, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/1", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/1", "rel"=>"bookmark"}] }, { 'name' => 'standard.small', 'ram' => 2048, 'disk' => 60, 'id' => 2, 'rxtx_quota' => 0, 'vcpus' => 2, 'rxtx_cap' => 0, 'swap' => 0, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/2", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/2", "rel"=>"bookmark"}] }, { 'name' => 'standard.medium', 'ram' => 4096, 'disk' => 120, 'id' => 3, 'rxtx_quota' => 0, 'vcpus' => 2, 'rxtx_cap' => 0, 'swap' => 0, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/3", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/3", "rel"=>"bookmark"}] }, { 'name' => 'standard.large', 'ram' => 8192, 'disk' => 240, 'id' => 4, 'rxtx_quota' => 0, 'vcpus' => 4, 'rxtx_cap' => 0, 'swap' => 0, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/4", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/4", "rel"=>"bookmark"}] }, { 'name' => 'standard.xlarge', 'ram' => 16384, 'disk' => 480, 'id' => 5, 'rxtx_quota' => 0, 'vcpus' => 4, 'rxtx_cap' => 0, 'swap' => 0, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/5", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/5", "rel"=>"bookmark"}] }, { 'name' => 'standard.2xlarge', 'ram' => 32768, 'disk' => 960, 'id' => 6, 'rxtx_quota' => 0, 'vcpus' => 8, 'rxtx_cap' => 0, 'swap' => 0, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/6", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/6", "rel"=>"bookmark"}] } ] } response end |
#list_images ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rackspace-fog/hp/requests/compute/list_images.rb', line 25 def list_images response = Excon::Response.new data = list_images_detail.body['images'] images = [] for image in data images << image.reject { |key, value| !['id', 'name'].include?(key) } end response.status = [200, 203][rand(1)] response.body = { 'images' => images } response end |
#list_images_detail ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rackspace-fog/hp/requests/compute/list_images_detail.rb', line 28 def list_images_detail response = Excon::Response.new images = self.data[:images].values for image in images case image['status'] when 'SAVING' if Time.now - self.data[:last_modified][:images][image['id']] >= Fog::Mock.delay image['status'] = 'ACTIVE' end end end response.status = [200, 203][rand(1)] response.body = { 'images' => images.map {|image| image.reject {|key, value| !['id', 'name', 'links', 'metadata', 'progress' ,'status', 'created', 'updated'].include?(key)}} } response end |
#list_key_pairs ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rackspace-fog/hp/requests/compute/list_key_pairs.rb', line 30 def list_key_pairs response = Excon::Response.new key_pairs = [] key_pairs = self.data[:key_pairs].values unless self.data[:key_pairs].nil? response.status = [200, 203][rand(1)] response.body = { 'keypairs' => key_pairs } response end |
#list_security_groups ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rackspace-fog/hp/requests/compute/list_security_groups.rb', line 40 def list_security_groups response = Excon::Response.new sec_groups = [] sec_groups = self.data[:security_groups].values unless self.data[:security_groups].nil? response.status = 200 response.body = { 'security_groups' => sec_groups } response end |
#list_server_addresses(server_id) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rackspace-fog/hp/requests/compute/list_server_addresses.rb', line 28 def list_server_addresses(server_id) response = Excon::Response.new if server = list_servers_detail.body['servers'].detect {|_| _['id'] == server_id} response.status = 200 response.body = { 'addresses' => server['addresses'] } response else raise Fog::Compute::HP::NotFound end end |
#list_server_private_addresses(server_id, network_name) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rackspace-fog/hp/requests/compute/list_server_private_addresses.rb', line 37 def list_server_private_addresses(server_id, network_name) response = Excon::Response.new if server = list_servers_detail.body['servers'].detect {|_| _['id'] == server_id} private_address = [] data = nil data = server['addresses']["#{network_name}"][0] if server['addresses']["#{network_name}"] if data private_address << data end response.status = 200 response.body = { 'private' => private_address } response else raise Fog::Compute::HP::NotFound end end |
#list_server_public_addresses(server_id, network_name) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rackspace-fog/hp/requests/compute/list_server_public_addresses.rb', line 37 def list_server_public_addresses(server_id, network_name) response = Excon::Response.new if server = list_servers_detail.body['servers'].detect {|_| _['id'] == server_id} # return everything except the first address data = server['addresses']["#{network_name}"] if data data.delete_at(0) public_address = data end response.status = 200 response.body = { 'public' => public_address } response else raise Fog::Compute::HP::NotFound end end |
#list_servers ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rackspace-fog/hp/requests/compute/list_servers.rb', line 26 def list_servers response = Excon::Response.new data = list_servers_detail.body['servers'] servers = [] for server in data servers << server.reject { |key, value| !['id', 'name', 'links', 'uuid'].include?(key) } end response.status = [200, 203][rand(1)] response.body = { 'servers' => servers } response end |
#list_servers_detail ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rackspace-fog/hp/requests/compute/list_servers_detail.rb', line 35 def list_servers_detail response = Excon::Response.new servers = self.data[:servers].values for server in servers case server['status'] when 'BUILD' if Time.now - self.data[:last_modified][:servers][server['id']] > Fog::Mock.delay * 2 server['status'] = 'ACTIVE' end end end response.status = [200, 203][rand(1)] response.body = { 'servers' => servers } response end |
#reboot_server(server_id, type = 'SOFT') ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/rackspace-fog/hp/requests/compute/reboot_server.rb', line 21 def reboot_server(server_id, type = 'SOFT') response = Excon::Response.new if list_servers_detail.body['servers'].detect {|_| _['id'] == server_id} response.status = 202 response else raise Fog::Compute::HP::NotFound end end |
#rebuild_server(server_id, image_ref, name, admin_pass = nil, metadata = nil, personality = nil) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/rackspace-fog/hp/requests/compute/rebuild_server.rb', line 22 def rebuild_server(server_id, image_ref, name, admin_pass=nil, =nil, personality=nil) response = get_server_details(server_id) response.body['server']['status'] = "REBUILD" response.status = 202 response end |
#release_address(address_id) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rackspace-fog/hp/requests/compute/release_address.rb', line 23 def release_address(address_id) response = Excon::Response.new if self.data[:addresses][address_id] self.data[:last_modified][:addresses].delete(address_id) self.data[:addresses].delete(address_id) response.status = 202 response.body = "202 Accepted\n\nThe request is accepted for processing.\n\n " else raise Fog::Compute::HP::NotFound end response end |
#reset_data ⇒ Object
101 102 103 |
# File 'lib/rackspace-fog/hp/compute.rb', line 101 def reset_data self.class.data.delete(@hp_account_id) end |
#resize_server(server_id, flavor_id) ⇒ Object
FIXME: should probably transition instead of skipping to VERIFY_RESIZE
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rackspace-fog/hp/requests/compute/resize_server.rb', line 22 def resize_server(server_id, flavor_id) response = Excon::Response.new response.status = 202 # keep track of this for reverts self.data[:servers][server_id]['old_flavorId'] = self.data[:servers][server_id]['flavorId'] self.data[:servers][server_id]['flavorId'] = flavor_id self.data[:last_modified][:servers][server_id] = Time.now self.data[:servers][server_id]['status'] = 'VERIFY_RESIZE' response end |
#revert_resized_server(server_id) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rackspace-fog/hp/requests/compute/revert_resized_server.rb', line 20 def revert_resized_server(server_id) response = Excon::Response.new response.status = 202 self.data[:servers][server_id]['flavorId'] = self.data[:servers][server_id]['old_flavorId'] self.data[:servers][server_id].delete('old_flavorId') self.data[:last_modified][:servers][server_id] = Time.now self.data[:servers][server_id]['status'] = 'ACTIVE' response end |
#update_server(server_id, options) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rackspace-fog/hp/requests/compute/update_server.rb', line 26 def update_server(server_id, ) response = Excon::Response.new if server = list_servers_detail.body['servers'].detect {|_| _['id'] == server_id} if ['name'] server['name'] = ['name'] end response.status = 200 response else raise Fog::Compute::HP::NotFound end end |