Class: Fog::Compute::HP::Mock
- Inherits:
-
Object
- Object
- Fog::Compute::HP::Mock
- Includes:
- Utils
- Defined in:
- lib/fog/hp/requests/compute/attach_volume.rb,
lib/fog/hp/compute.rb,
lib/fog/hp/requests/compute/get_meta.rb,
lib/fog/hp/requests/compute/delete_meta.rb,
lib/fog/hp/requests/compute/get_address.rb,
lib/fog/hp/requests/compute/list_images.rb,
lib/fog/hp/requests/compute/update_meta.rb,
lib/fog/hp/requests/compute/create_image.rb,
lib/fog/hp/requests/compute/delete_image.rb,
lib/fog/hp/requests/compute/list_flavors.rb,
lib/fog/hp/requests/compute/list_servers.rb,
lib/fog/hp/requests/compute/set_metadata.rb,
lib/fog/hp/requests/compute/create_server.rb,
lib/fog/hp/requests/compute/delete_server.rb,
lib/fog/hp/requests/compute/detach_volume.rb,
lib/fog/hp/requests/compute/list_metadata.rb,
lib/fog/hp/requests/compute/reboot_server.rb,
lib/fog/hp/requests/compute/resize_server.rb,
lib/fog/hp/requests/compute/update_server.rb,
lib/fog/hp/requests/compute/list_addresses.rb,
lib/fog/hp/requests/compute/list_key_pairs.rb,
lib/fog/hp/requests/compute/rebuild_server.rb,
lib/fog/hp/requests/compute/create_key_pair.rb,
lib/fog/hp/requests/compute/delete_key_pair.rb,
lib/fog/hp/requests/compute/release_address.rb,
lib/fog/hp/requests/compute/update_metadata.rb,
lib/fog/hp/requests/compute/allocate_address.rb,
lib/fog/hp/requests/compute/associate_address.rb,
lib/fog/hp/requests/compute/get_image_details.rb,
lib/fog/hp/requests/compute/get_console_output.rb,
lib/fog/hp/requests/compute/get_flavor_details.rb,
lib/fog/hp/requests/compute/get_security_group.rb,
lib/fog/hp/requests/compute/get_server_details.rb,
lib/fog/hp/requests/compute/list_images_detail.rb,
lib/fog/hp/requests/compute/list_flavors_detail.rb,
lib/fog/hp/requests/compute/list_server_volumes.rb,
lib/fog/hp/requests/compute/list_servers_detail.rb,
lib/fog/hp/requests/compute/disassociate_address.rb,
lib/fog/hp/requests/compute/get_windows_password.rb,
lib/fog/hp/requests/compute/list_security_groups.rb,
lib/fog/hp/requests/compute/create_security_group.rb,
lib/fog/hp/requests/compute/delete_security_group.rb,
lib/fog/hp/requests/compute/list_server_addresses.rb,
lib/fog/hp/requests/compute/revert_resized_server.rb,
lib/fog/hp/requests/compute/change_password_server.rb,
lib/fog/hp/requests/compute/confirm_resized_server.rb,
lib/fog/hp/requests/compute/create_persistent_server.rb,
lib/fog/hp/requests/compute/create_security_group_rule.rb,
lib/fog/hp/requests/compute/delete_security_group_rule.rb,
lib/fog/hp/requests/compute/list_server_public_addresses.rb,
lib/fog/hp/requests/compute/list_server_private_addresses.rb
Overview
:nodoc:all
Class Method Summary collapse
Instance Method Summary collapse
- #allocate_address ⇒ Object
- #associate_address(server_id, ip_address) ⇒ Object
- #attach_volume(server_id, volume_id, device) ⇒ 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_persistent_server(name, flavor_id, block_device_mapping = [], options = {}) ⇒ 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_meta(collection_name, parent_id, key) ⇒ Object
- #delete_security_group(security_group_id) ⇒ Object
- #delete_security_group_rule(security_group_rule_id) ⇒ Object
- #delete_server(server_id) ⇒ Object
- #detach_volume(server_id, volume_id) ⇒ Object
- #disassociate_address(server_id, ip_address) ⇒ Object
- #get_address(address_id) ⇒ Object
- #get_console_output(server_id, num_lines) ⇒ Object
- #get_flavor_details(flavor_id) ⇒ Object
- #get_image_details(image_id) ⇒ Object
- #get_meta(collection_name, parent_id, key) ⇒ Object
- #get_security_group(security_group_id) ⇒ Object
- #get_server_details(server_id) ⇒ Object
- #get_windows_password(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_metadata(collection_name, parent_id) ⇒ 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_server_volumes(server_id) ⇒ 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
- #set_metadata(collection_name, parent_id, metadata = {}) ⇒ Object
- #update_meta(collection_name, parent_id, key, value) ⇒ Object
- #update_metadata(collection_name, parent_id, metadata = {}) ⇒ Object
- #update_server(server_id, options) ⇒ Object
Methods included from Utils
#decrypt_using_private_key, #encrypt_using_public_key, #extract_password_from_log
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/fog/hp/compute.rb', line 153 def initialize(={}) # deprecate hp_account_id if [:hp_account_id] Fog::Logger.deprecation(":hp_account_id is deprecated, please use :hp_access_key instead.") @hp_access_key = .delete(:hp_account_id) end @hp_access_key = [:hp_access_key] unless @hp_access_key raise ArgumentError.new("Missing required arguments: hp_access_key. :hp_account_id is deprecated, please use :hp_access_key instead.") end end |
Class Method Details
.data ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/fog/hp/compute.rb', line 130 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
149 150 151 |
# File 'lib/fog/hp/compute.rb', line 149 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/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/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 |
#attach_volume(server_id, volume_id, device) ⇒ Object
39 40 41 42 43 44 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 70 71 72 73 |
# File 'lib/fog/hp/requests/compute/attach_volume.rb', line 39 def attach_volume(server_id, volume_id, device) response = Excon::Response.new if server = self.data[:servers][server_id] # mock the case when the volume is already attached to the server if server['volumeAttachments'] && server['volumeAttachments'].select {|v| v['id'] == volume_id} response.status = 400 response.body = '{"badRequest": {"message": "Volume status must be available", "code": 400}}' raise(Excon::Errors.status_error({:expects => 200}, response)) else resp_data = { "volumeAttachment" => { "volumeId" => volume_id, "id" => volume_id } } response.body = resp_data response.status = 200 data = { "device" => device, "serverId" => server_id, "id" => volume_id, "volumeId" => volume_id, } if server['volumeAttachments'] server['volumeAttachments'] << data else server['volumeAttachments'] = [data] end end else raise Fog::Compute::HP::NotFound 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/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/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
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fog/hp/requests/compute/create_image.rb', line 31 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"=>server_id, "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' => "2012-01-01T13:32:20Z", 'created' => "2012-01-01T13:32:20Z" } 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/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_persistent_server(name, flavor_id, block_device_mapping = [], options = {}) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/fog/hp/requests/compute/create_persistent_server.rb', line 121 def create_persistent_server(name, flavor_id, block_device_mapping = [], = {}) response = Excon::Response.new if block_device_mapping && !block_device_mapping.empty? if ['security_groups'] sec_group_name = ['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, '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.status = 200 response else response.status = 400 raise(Excon::Errors::BadRequest, "No boot volume or boot image specified") end 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/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/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
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 136 137 138 139 140 141 |
# File 'lib/fog/hp/requests/compute/create_server.rb', line 106 def create_server(name, flavor_id, image_id, = {}) response = Excon::Response.new response.status = 202 if ['security_groups'] sec_group_name = ['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
165 166 167 |
# File 'lib/fog/hp/compute.rb', line 165 def data self.class.data[@hp_access_key] 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/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/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_meta(collection_name, parent_id, key) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fog/hp/requests/compute/delete_meta.rb', line 29 def (collection_name, parent_id, key) if collection_name == "images" then if get_image_details(parent_id) self.data[:images][parent_id]['metadata'].delete(key) else raise Fog::Compute::HP::NotFound end end if collection_name == "servers" then if get_server_details(parent_id) self.data[:servers][parent_id]['metadata'].delete(key) else raise Fog::Compute::HP::NotFound end end response = Excon::Response.new response.status = 204 response end |
#delete_security_group(security_group_id) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/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/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/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 |
#detach_volume(server_id, volume_id) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fog/hp/requests/compute/detach_volume.rb', line 28 def detach_volume(server_id, volume_id) response = Excon::Response.new if server = self.data[:servers][server_id] if server['volumeAttachments'] && server['volumeAttachments'].select {|v| v['volumeId'] == volume_id} data = server['volumeAttachments'].reject {|v| v['volumeId'] == volume_id} self.data[:servers][server_id]['volumeAttachments'] = data response.status = 202 else raise Fog::Compute::HP::NotFound end else raise Fog::Compute::HP::NotFound end response end |
#disassociate_address(server_id, ip_address) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/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/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_console_output(server_id, num_lines) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fog/hp/requests/compute/get_console_output.rb', line 27 def get_console_output(server_id, num_lines) output = "" response = Excon::Response.new if list_servers_detail.body['servers'].detect {|_| _['id'] == server_id} (1..num_lines).each {|i| output += "Console Output Line #{i} \r\n"} response.body = { 'output' => output } response.status = 200 else raise Fog::Compute::HP::NotFound end response 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/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/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_meta(collection_name, parent_id, key) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fog/hp/requests/compute/get_meta.rb', line 30 def (collection_name, parent_id, key) if collection_name == "images" then if get_image_details(parent_id) raise Fog::Compute::HP::NotFound unless midata = self.data[:images][parent_id]['metadata'].fetch(key, nil) else raise Fog::Compute::HP::NotFound end end if collection_name == "servers" then if get_server_details(parent_id) raise Fog::Compute::HP::NotFound unless midata = self.data[:servers][parent_id]['metadata'].fetch(key, nil) else raise Fog::Compute::HP::NotFound end end response = Excon::Response.new response.status = 200 response.body = { 'meta' => { key => midata } } response end |
#get_security_group(security_group_id) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/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/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 |
#get_windows_password(server_id) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fog/hp/requests/compute/get_windows_password.rb', line 25 def get_windows_password(server_id) # need to mock out the private key as well private_key = OpenSSL::PKey::RSA.generate(1024) public_key = private_key.public_key ### The original password is Passw0rd encoded_password = encrypt_using_public_key("Passw0rd", public_key) if list_servers_detail.body['servers'].detect {|_| _['id'] == server_id} # mock output for this call get_console_output(server_id, 400).body['output'] log_output = "start junk [cloud-init] Encrypt random password\n-----BEGIN BASE64-ENCODED ENCRYPTED PASSWORD-----\n#{encoded_password}-----END BASE64-ENCODED ENCRYPTED PASSWORD-----\nend junk [cloud-init] Done\n" encrypted_password = extract_password_from_log(log_output) else raise Fog::Compute::HP::NotFound end end |
#list_addresses ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/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/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/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/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/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/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_metadata(collection_name, parent_id) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fog/hp/requests/compute/list_metadata.rb', line 29 def (collection_name, parent_id) mdata = {} if collection_name == "images" then if get_image_details(parent_id) mdata = self.data[:images][parent_id]['metadata'] else raise Fog::Compute::HP::NotFound end end if collection_name == "servers" then if get_server_details(parent_id) mdata = self.data[:servers][parent_id]['metadata'] else raise Fog::Compute::HP::NotFound end end response = Excon::Response.new response.status = 200 response.body = {'metadata' => mdata} response end |
#list_security_groups ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/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/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/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/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_server_volumes(server_id) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fog/hp/requests/compute/list_server_volumes.rb', line 33 def list_server_volumes(server_id) response = Excon::Response.new volumes = [] if server = self.data[:servers][server_id] volumes = server['volumeAttachments'] response.status = 200 response.body = { 'volumeAttachments' => volumes } 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/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/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/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/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/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
169 170 171 |
# File 'lib/fog/hp/compute.rb', line 169 def reset_data self.class.data.delete(@hp_access_key) 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/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/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 |
#set_metadata(collection_name, parent_id, metadata = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fog/hp/requests/compute/set_metadata.rb', line 31 def (collection_name, parent_id, = {}) if collection_name == "images" then if get_image_details(parent_id) self.data[:images][parent_id]['metadata'] = else raise Fog::Compute::HP::NotFound end end if collection_name == "servers" then if get_server_details(parent_id) self.data[:servers][parent_id]['metadata'] = else raise Fog::Compute::HP::NotFound end end response = Excon::Response.new response.body = { "metadata" => } response.status = 200 response end |
#update_meta(collection_name, parent_id, key, value) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fog/hp/requests/compute/update_meta.rb', line 32 def (collection_name, parent_id, key, value) if collection_name == "images" then if get_image_details(parent_id) self.data[:images][parent_id]['metadata'][key] = value else raise Fog::Compute::HP::NotFound end end if collection_name == "servers" then if get_server_details(parent_id) self.data[:servers][parent_id]['metadata'][key] = value else raise Fog::Compute::HP::NotFound end end response = Excon::Response.new response.body = { "meta" => { key => value } } response.status = 200 response end |
#update_metadata(collection_name, parent_id, metadata = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fog/hp/requests/compute/update_metadata.rb', line 31 def (collection_name, parent_id, = {}) if collection_name == "images" then if get_image_details(parent_id) = self.data[:images][parent_id]['metadata'].merge!() else raise Fog::Compute::HP::NotFound end end if collection_name == "servers" then if get_server_details(parent_id) = self.data[:servers][parent_id]['metadata'].merge!() else raise Fog::Compute::HP::NotFound end end response = Excon::Response.new response.body = { "metadata" => } response.status = 200 response end |
#update_server(server_id, options) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/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 |