Class: Fog::Compute::RackspaceV2::Mock
- Inherits:
-
Rackspace::Service
- Object
- Rackspace::Service
- Fog::Compute::RackspaceV2::Mock
- Includes:
- Rackspace::MockData
- Defined in:
- lib/fog/rackspace/requests/compute_v2/get_vnc_console.rb,
lib/fog/rackspace/compute_v2.rb,
lib/fog/rackspace/requests/compute_v2/get_image.rb,
lib/fog/rackspace/requests/compute_v2/get_flavor.rb,
lib/fog/rackspace/requests/compute_v2/get_server.rb,
lib/fog/rackspace/requests/compute_v2/get_keypair.rb,
lib/fog/rackspace/requests/compute_v2/get_network.rb,
lib/fog/rackspace/requests/compute_v2/list_images.rb,
lib/fog/rackspace/requests/compute_v2/stop_server.rb,
lib/fog/rackspace/requests/compute_v2/create_image.rb,
lib/fog/rackspace/requests/compute_v2/delete_image.rb,
lib/fog/rackspace/requests/compute_v2/list_flavors.rb,
lib/fog/rackspace/requests/compute_v2/list_servers.rb,
lib/fog/rackspace/requests/compute_v2/set_metadata.rb,
lib/fog/rackspace/requests/compute_v2/start_server.rb,
lib/fog/rackspace/requests/compute_v2/attach_volume.rb,
lib/fog/rackspace/requests/compute_v2/create_server.rb,
lib/fog/rackspace/requests/compute_v2/delete_server.rb,
lib/fog/rackspace/requests/compute_v2/list_keypairs.rb,
lib/fog/rackspace/requests/compute_v2/list_metadata.rb,
lib/fog/rackspace/requests/compute_v2/list_networks.rb,
lib/fog/rackspace/requests/compute_v2/reboot_server.rb,
lib/fog/rackspace/requests/compute_v2/rescue_server.rb,
lib/fog/rackspace/requests/compute_v2/resize_server.rb,
lib/fog/rackspace/requests/compute_v2/update_server.rb,
lib/fog/rackspace/requests/compute_v2/create_keypair.rb,
lib/fog/rackspace/requests/compute_v2/create_network.rb,
lib/fog/rackspace/requests/compute_v2/delete_keypair.rb,
lib/fog/rackspace/requests/compute_v2/delete_network.rb,
lib/fog/rackspace/requests/compute_v2/get_attachment.rb,
lib/fog/rackspace/requests/compute_v2/list_addresses.rb,
lib/fog/rackspace/requests/compute_v2/rebuild_server.rb,
lib/fog/rackspace/requests/compute_v2/unrescue_server.rb,
lib/fog/rackspace/requests/compute_v2/update_metadata.rb,
lib/fog/rackspace/requests/compute_v2/list_attachments.rb,
lib/fog/rackspace/requests/compute_v2/delete_attachment.rb,
lib/fog/rackspace/requests/compute_v2/get_metadata_item.rb,
lib/fog/rackspace/requests/compute_v2/set_metadata_item.rb,
lib/fog/rackspace/requests/compute_v2/list_images_detail.rb,
lib/fog/rackspace/requests/compute_v2/list_flavors_detail.rb,
lib/fog/rackspace/requests/compute_v2/delete_metadata_item.rb,
lib/fog/rackspace/requests/compute_v2/revert_resize_server.rb,
lib/fog/rackspace/requests/compute_v2/confirm_resize_server.rb,
lib/fog/rackspace/requests/compute_v2/change_server_password.rb,
lib/fog/rackspace/requests/compute_v2/list_addresses_by_network.rb
Overview
class Real
Constant Summary collapse
- RESPONSE_BODY =
{ "addresses" => { "public"=>[{"version"=>6, "addr"=>"2001:4800:7811:0513:0fe1:75e8:ff04:760b"}, {"version"=>4, "addr"=>"166.78.18.176"}], "private"=>[{"version"=>4, "addr"=>"10.181.129.68"}] } }
Constants included from Rackspace::MockData
Rackspace::MockData::NOT_FOUND_ID
Instance Method Summary collapse
- #attach_volume(server_id, volume_id, device) ⇒ Object
- #change_server_password(server_id, password) ⇒ Object
- #confirm_resize_server(server_id) ⇒ Object
- #create_image(server_id, name, options = {}) ⇒ Object
- #create_keypair(key_name, attributes = nil) ⇒ Object
- #create_network(label, cidr) ⇒ Object
- #create_server(name, image_id, flavor_id, min_count, max_count, options = {}) ⇒ Object
- #delete_attachment(server_id, volume_id) ⇒ Object
- #delete_image(image_id) ⇒ Object
- #delete_keypair(key_name) ⇒ Object
- #delete_metadata_item(collection, obj_id, key) ⇒ Object
- #delete_network(id) ⇒ Object
- #delete_server(server_id) ⇒ Object
- #get_attachment(server_id, volume_id) ⇒ Object
- #get_flavor(flavor_id) ⇒ Object
- #get_image(image_id) ⇒ Object
- #get_keypair(key_name) ⇒ Object
- #get_metadata_item(collection, obj_id, key) ⇒ Object
- #get_network(id) ⇒ Object
- #get_server(server_id) ⇒ Object
- #get_vnc_console(server_id, console_type) ⇒ Object
-
#initialize(options) ⇒ Mock
constructor
A new instance of Mock.
- #list_addresses(server_id) ⇒ Object
- #list_addresses_by_network(server_id, network_id) ⇒ Object
- #list_attachments(server_id) ⇒ Object
- #list_flavors ⇒ Object
- #list_flavors_detail ⇒ Object
- #list_images(options = {}) ⇒ Object
- #list_images_detail(options = {}) ⇒ Object
- #list_keypairs ⇒ Object
- #list_metadata(collection, obj_id) ⇒ Object
- #list_networks ⇒ Object
- #list_servers ⇒ Object
- #reboot_server(server_id, type) ⇒ Object
- #rebuild_server(server_id, image_id, options = {}) ⇒ Object
- #request(params) ⇒ Object
- #rescue_server(server_id) ⇒ Object
- #resize_server(server_id, flavor_id) ⇒ Object
- #response(params = {}) ⇒ Object
- #revert_resize_server(server_id) ⇒ Object
- #set_metadata(collection, obj_id, metadata = {}) ⇒ Object
- #set_metadata_item(collection, obj_id, key, value) ⇒ Object
- #start_server(server_id) ⇒ Object
- #stop_server(server_id) ⇒ Object
- #unrescue_server(server_id) ⇒ Object
- #update_metadata(collection, obj_id, metadata = {}) ⇒ Object
- #update_server(server_id, name) ⇒ Object
Methods included from Rackspace::MockData
#data, ipv4_address, ipv6_address, keep, slice, stringify, uuid, zulu_time
Methods inherited from Rackspace::Service
#authenticate, #endpoint_uri, #region, #request_without_retry, #service_name, #service_net?
Constructor Details
#initialize(options) ⇒ Mock
Returns a new instance of Mock.
127 128 129 |
# File 'lib/fog/rackspace/compute_v2.rb', line 127 def initialize() @rackspace_api_key = [:rackspace_api_key] end |
Instance Method Details
#attach_volume(server_id, volume_id, device) ⇒ Object
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 74 |
# File 'lib/fog/rackspace/requests/compute_v2/attach_volume.rb', line 40 def attach_volume(server_id, volume_id, device) volume = self.data[:volumes][volume_id] server = self.data[:servers][server_id] if server.nil? || volume.nil? raise Fog::Compute::RackspaceV2::NotFound else self.data[:volume_attachments] << { "device" => device, "serverId" => server_id, "volumeId" => volume_id, "id" => volume_id, } volume["attachments"] << { "volumeId" => volume_id, "serverId" => server_id, "device" => device, "id" => volume_id, } body = { "volumeAttachment" => { "serverId" => server_id, "volumeId" => volume_id, "device" => device, "id" => volume_id, } } volume["status"] = "in-use" response(:body => body) end end |
#change_server_password(server_id, password) ⇒ Object
32 33 34 |
# File 'lib/fog/rackspace/requests/compute_v2/change_server_password.rb', line 32 def change_server_password(server_id, password) response(:status => 202) end |
#confirm_resize_server(server_id) ⇒ Object
33 34 35 36 37 |
# File 'lib/fog/rackspace/requests/compute_v2/confirm_resize_server.rb', line 33 def confirm_resize_server(server_id) server = self.data[:servers][server_id] server["status"] = "ACTIVE" response(:status => 204) end |
#create_image(server_id, name, options = {}) ⇒ Object
38 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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/fog/rackspace/requests/compute_v2/create_image.rb', line 38 def create_image(server_id, name, = {}) image_id = Fog::Rackspace::MockData.uuid image = { "OS-DCF:diskConfig" => "AUTO", "created" => "2012-02-28T19:38:57Z", "id" => image_id, "links" => [ { "href" => "https://dfw.servers.api.rackspacecloud.com/v2/010101/images/#{image_id}", "rel" => "self" }, { "href" => "https://dfw.servers.api.rackspacecloud.com/010101/images/#{image_id}", "rel" => "bookmark" }, { "href" => "https://dfw.servers.api.rackspacecloud.com/010101/images/#{image_id}", "rel" => "alternate", "type" => "application/vnd.openstack.image" } ], "metadata" => { "arch" => "x86-64", "auto_disk_config" => "True", "com.rackspace__1__build_core" => "1", "com.rackspace__1__build_managed" => "0", "com.rackspace__1__build_rackconnect" => "0", "com.rackspace__1__options" => "0", "com.rackspace__1__visible_core" => "1", "com.rackspace__1__visible_managed" => "0", "com.rackspace__1__visible_rackconnect" => "0", "image_type" => "base", "org.openstack__1__architecture" => "x64", "org.openstack__1__os_distro" => "org.ubuntu", "org.openstack__1__os_version" => "11.10", "os_distro" => "ubuntu", "os_type" => "linux", "os_version" => "11.10", "rax_managed" => "false", "rax_options" => "0" }, "minDisk" => 10, "minRam" => 256, "name" => "Ubuntu 11.10", "progress" => 100, "status" => "SAVING", "updated" => "2012-02-28T19:39:05Z" } self.data[:images][image_id] = image response( :status => 202, :headers => {"Location" => "/#{image_id}"} ) end |
#create_keypair(key_name, attributes = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fog/rackspace/requests/compute_v2/create_keypair.rb', line 44 def create_keypair(key_name, attributes = nil) # 409 response when already existing raise Fog::Compute::RackspaceV2::ServiceError if not self.data[:keypairs].select { |k| key_name.include? k['keypair']['name'] }.first.nil? if attributes.is_a?(String) Fog::Logger.deprecation "Passing the public key as the 2nd arg is deprecated, please pass a hash of attributes." end k = self.data[:keypair] k['name'] = key_name self.data[:keypairs] << { 'keypair' => k } response( :status => 200, :body => { 'keypair' => k } ) end |
#create_network(label, cidr) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/fog/rackspace/requests/compute_v2/create_network.rb', line 23 def create_network(label, cidr) network_id = Fog::Rackspace::MockData.uuid self.data[:networks][network_id] = { 'id' => network_id, 'label' => label, 'cidr' => cidr } response(:body => { 'network' => self.data[:networks][network_id] }) end |
#create_server(name, image_id, flavor_id, min_count, max_count, options = {}) ⇒ Object
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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/fog/rackspace/requests/compute_v2/create_server.rb', line 134 def create_server(name, image_id, flavor_id, min_count, max_count, ={}) server_id = Fog::Rackspace::MockData.uuid public_ip4 = Fog::Rackspace::MockData.ipv4_address public_ip6 = Fog::Rackspace::MockData.ipv6_address private_ip4 = Fog::Rackspace::MockData.ipv4_address private_ip6 = Fog::Rackspace::MockData.ipv6_address admin_pass = Fog::Mock.random_letters(12) flavor = self.data[:flavors][flavor_id] image = self.data[:images][image_id] server = { "OS-DCF:diskConfig" => "AUTO", "OS-EXT-STS:power_state" => 1, "OS-EXT-STS:task_state" => nil, "OS-EXT-STS:vm_state" => "active", "accessIPv4" => public_ip4, "accessIPv6" => public_ip6, "addresses" => { "private" => [ { "addr" => private_ip4, "version" => 4 } ], "public" => [ { "addr" => public_ip4, "version" => 4 }, { "addr" => public_ip6, "version" => 6 } ] }, "created" => "2012-07-28T15:32:25Z", "flavor" => Fog::Rackspace::MockData.keep(flavor, "id", "links"), "hostId" => Fog::Mock.random_hex(56), "id" => server_id, "image" => Fog::Rackspace::MockData.keep(image, "id", "links"), "links" => [ { "href" => "https://dfw.servers.api.rackspacecloud.com/v2/010101/servers/#{server_id}", "rel" => "self", }, { "href" => "https://dfw.servers.api.rackspacecloud.com/010101/servers/#{server_id}", "rel" => "bookmark", } ], "metadata" => {}, "name" => name, "progress" => 100, "rax-bandwidth:bandwidth" => [ { "audit_period_end" => "2012-08-16T14:12:00Z", "audit_period_start" => "2012-08-16T06:00:00Z", "bandwidth_inbound" => 39147845, "bandwidth_outbound" => 13390651, "interface" => "public", }, { "audit_period_end" => "2012-08-16T14:12:00Z", "audit_period_start" => "2012-08-16T06:00:00Z", "bandwidth_inbound" => 24229191, "bandwidth_outbound" => 84, "interface" => "private", } ], "status" => "ACTIVE", "tenant_id" => "010101", "updated" => "2012-07-28T15:37:09Z", "user_id" => "170454", :volume_ids => [], } # add in additional networks if [:networks] [:networks].each do |network| net_label = self.data[:networks][network[:uuid]]["label"] server["addresses"] = { net_label => []} end end self.data[:servers][server_id] = server response = { "server" => { "OS-DCF:diskConfig" => "AUTO", "adminPass" => admin_pass, "id" => server_id, "links" => [ { "href" => "https://dfw.servers.api.rackspacecloud.com/v2/010101/servers/#{server_id}", "rel" => "self" }, { "href" => "https://dfw.servers.api.rackspacecloud.com/010101/servers/#{server_id}", "rel" => "bookmark" } ] } } response(:body => response) end |
#delete_attachment(server_id, volume_id) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fog/rackspace/requests/compute_v2/delete_attachment.rb', line 24 def (server_id, volume_id) volume = self.data[:volumes][volume_id] server = self.data[:servers][server_id] if volume.nil? || server.nil? raise Fog::Compute::RackspaceV2::NotFound else self.data[:volume_attachments].delete_if { |v| v["serverId"] == server_id && v["volumeId"] == volume_id } volume["attachments"].delete_if { |v| v["serverId"] == server_id && v["volumeId"] == volume_id } response(:status => 204) end end |
#delete_image(image_id) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/fog/rackspace/requests/compute_v2/delete_image.rb', line 23 def delete_image(image_id) raise Fog::Compute::RackspaceV2::NotFound.new if image_id == Fog::Rackspace::MockData::NOT_FOUND_ID response = Excon::Response.new response.status = 202 response.body = "" end |
#delete_keypair(key_name) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/fog/rackspace/requests/compute_v2/delete_keypair.rb', line 23 def delete_keypair(key_name) if self.data[:keypairs].select { |k| key_name.include? k['keypair']['name'] }.empty? raise Fog::Compute::RackspaceV2::NotFound else self.data[:keypairs].reject! { |k| key_name.include? k['keypair']['name'] } response(:status => 202) end end |
#delete_metadata_item(collection, obj_id, key) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/fog/rackspace/requests/compute_v2/delete_metadata_item.rb', line 25 def (collection, obj_id, key) raise Fog::Compute::RackspaceV2::NotFound if obj_id == 0 response = Excon::Response.new response.body = "" response.status = 204 response end |
#delete_network(id) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/fog/rackspace/requests/compute_v2/delete_network.rb', line 11 def delete_network(id) unless self.data[:networks].key?(id) raise Fog::Compute::RackspaceV2::NotFound end response(:body => '', :status => 202) end |
#delete_server(server_id) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/fog/rackspace/requests/compute_v2/delete_server.rb', line 23 def delete_server(server_id) self.data[:servers].delete(server_id) volumes = self.data[:volumes].values volumes.each do |v| v["attachments"].delete_if { |a| a["serverId"] == server_id } v["status"] = "available" if v["attachments"].empty? end response(:status => 204) end |
#get_attachment(server_id, volume_id) ⇒ Object
30 31 32 33 34 |
# File 'lib/fog/rackspace/requests/compute_v2/get_attachment.rb', line 30 def (server_id, volume_id) = self.data[:volume_attachments].find { |v| v["serverId"] == server_id && v["volumeId"] == volume_id } response(:body => {"volumeAttachment" => }) end |
#get_flavor(flavor_id) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/fog/rackspace/requests/compute_v2/get_flavor.rb', line 32 def get_flavor(flavor_id) flavor = self.data[:flavors][flavor_id] if flavor.nil? raise Fog::Compute::RackspaceV2::NotFound else response(:body => {"flavor" => flavor}) end end |
#get_image(image_id) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/fog/rackspace/requests/compute_v2/get_image.rb', line 36 def get_image(image_id) image = self.data[:images][image_id] if image.nil? raise Fog::Compute::RackspaceV2::NotFound else response(:body => {"image" => image}) end end |
#get_keypair(key_name) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/fog/rackspace/requests/compute_v2/get_keypair.rb', line 28 def get_keypair(key_name) key = self.data[:keypairs].select { |k| key_name.include? k['keypair']['name'] }.first if key.nil? raise Fog::Compute::RackspaceV2::NotFound end response(:body => key, :status => 200) end |
#get_metadata_item(collection, obj_id, key) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/fog/rackspace/requests/compute_v2/get_metadata_item.rb', line 27 def (collection, obj_id, key) raise Fog::Compute::RackspaceV2::NotFound if obj_id == 0 response = Excon::Response.new response.status = 202 response.body = {"meta" => {"environment" => "dev"}} response end |
#get_network(id) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/fog/rackspace/requests/compute_v2/get_network.rb', line 11 def get_network(id) unless self.data[:networks].key?(id) raise Fog::Compute::RackspaceV2::NotFound end response(:body => { 'network' => self.data[:networks][id] }) end |
#get_server(server_id) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fog/rackspace/requests/compute_v2/get_server.rb', line 50 def get_server(server_id) server = self.data[:servers][server_id] if server.nil? raise Fog::Compute::RackspaceV2::NotFound else server_response = Fog::Rackspace::MockData.keep(server, 'id', 'name', 'hostId', 'created', 'updated', 'status', 'progress', 'user_id', 'tenant_id', 'links', 'metadata', 'accessIPv4', 'accessIPv6', 'OS-DCF:diskConfig', 'rax-bandwidth:bandwidth', 'addresses', 'flavor', 'image') server_response['image']['links'].map! { |l| l.delete("type"); l } response(:body => {"server" => server_response}) end end |
#get_vnc_console(server_id, console_type) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fog/rackspace/requests/compute_v2/get_vnc_console.rb', line 31 def get_vnc_console(server_id, console_type) response = Excon::Response.new response.status = 200 response.body = { "console" => { "url" => "http://192.168.27.100:6080/vnc_auto.html?token=c3606020-d1b7-445d-a88f-f7af48dd6a20", "type" => "novnc" } } response end |
#list_addresses(server_id) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fog/rackspace/requests/compute_v2/list_addresses.rb', line 24 def list_addresses(server_id) raise Fog::Compute::RackspaceV2::NotFound.new if server_id == 0 response = Excon::Response.new response.status = 200 response.body = { "addresses" => { "public"=>[{"version"=>6, "addr"=>"2001:4800:7811:0513:0fe1:75e8:ff04:760b"}, {"version"=>4, "addr"=>"166.78.18.176"}], "private"=>[{"version"=>4, "addr"=>"10.181.129.68"}] } } response end |
#list_addresses_by_network(server_id, network_id) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/fog/rackspace/requests/compute_v2/list_addresses_by_network.rb', line 38 def list_addresses_by_network(server_id, network_id) raise Fog::Compute::RackspaceV2::NotFound.new if server_id == 0 response = Excon::Response.new response.status = 200 response.body = { network_id => RESPONSE_BODY["addresses"][network_id] } response end |
#list_attachments(server_id) ⇒ Object
30 31 32 33 |
# File 'lib/fog/rackspace/requests/compute_v2/list_attachments.rb', line 30 def (server_id) volumes_array = self.data[:volume_attachments].select { |va| va["serverId"] == server_id } response(:body => {"volumeAttachments" => volumes_array}) end |
#list_flavors ⇒ Object
28 29 30 31 |
# File 'lib/fog/rackspace/requests/compute_v2/list_flavors.rb', line 28 def list_flavors flavors = self.data[:flavors].values.map { |f| Fog::Rackspace::MockData.keep(f, 'id', 'name', 'links') } response(:body => {"flavors" => flavors}) end |
#list_flavors_detail ⇒ Object
31 32 33 34 |
# File 'lib/fog/rackspace/requests/compute_v2/list_flavors_detail.rb', line 31 def list_flavors_detail flavors = self.data[:flavors].values.map { |f| Fog::Rackspace::MockData.keep(f, 'id', 'name', 'links') } response(:body => {"flavors" => flavors}) end |
#list_images(options = {}) ⇒ Object
38 39 40 41 |
# File 'lib/fog/rackspace/requests/compute_v2/list_images.rb', line 38 def list_images( = {}) images = self.data[:images].values response(:body => {"images" => images}) end |
#list_images_detail(options = {}) ⇒ Object
45 46 47 48 |
# File 'lib/fog/rackspace/requests/compute_v2/list_images_detail.rb', line 45 def list_images_detail( = {}) images = self.data[:images].values response(:body => {"images" => images}) end |
#list_keypairs ⇒ Object
28 29 30 31 |
# File 'lib/fog/rackspace/requests/compute_v2/list_keypairs.rb', line 28 def list_keypairs response( :status => 200, :body => { 'keypairs' => self.data[:keypairs] }) end |
#list_metadata(collection, obj_id) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/fog/rackspace/requests/compute_v2/list_metadata.rb', line 26 def (collection, obj_id) raise Fog::Compute::RackspaceV2::NotFound if obj_id == 0 response = Excon::Response.new response.status = 202 response.body = { "metadata"=>{"tag"=>"database"} } response end |
#list_networks ⇒ Object
11 12 13 14 |
# File 'lib/fog/rackspace/requests/compute_v2/list_networks.rb', line 11 def list_networks networks = self.data[:networks].values response(:body => { 'networks' => networks }) end |
#list_servers ⇒ Object
49 50 51 52 |
# File 'lib/fog/rackspace/requests/compute_v2/list_servers.rb', line 49 def list_servers servers = self.data[:servers].values.map { |s| Fog::Rackspace::MockData.keep(s, 'id', 'name', 'hostId', 'created', 'updated', 'status', 'progress', 'user_id', 'tenant_id', 'links', 'metadata') } response(:body => {"servers" => servers}) end |
#reboot_server(server_id, type) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fog/rackspace/requests/compute_v2/reboot_server.rb', line 30 def reboot_server(server_id, type) body = { "reboot" => { "type" => type.upcase } } response( :body => body, :status => 202 ) end |
#rebuild_server(server_id, image_id, options = {}) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/fog/rackspace/requests/compute_v2/rebuild_server.rb', line 61 def rebuild_server(server_id, image_id, ={}) server = self.data[:servers][server_id] response( :body => {"server" => server}, :status => 202 ) end |
#request(params) ⇒ Object
131 132 133 |
# File 'lib/fog/rackspace/compute_v2.rb', line 131 def request(params) Fog::Mock.not_implemented end |
#rescue_server(server_id) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/fog/rackspace/requests/compute_v2/rescue_server.rb', line 33 def rescue_server(server_id) server = self.data[:servers][server_id] server["status"] = "RESCUE" admin_pass = Fog::Mock.random_letters(12) server_response = { 'adminPass' => admin_pass } response(:status => 200, :body => server_response) end |
#resize_server(server_id, flavor_id) ⇒ Object
36 37 38 39 40 |
# File 'lib/fog/rackspace/requests/compute_v2/resize_server.rb', line 36 def resize_server(server_id, flavor_id) server = self.data[:servers][server_id] server["status"] = "VERIFY_RESIZE" response(:status => 202) end |
#response(params = {}) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/fog/rackspace/compute_v2.rb', line 135 def response(params={}) body = params[:body] || {} status = params[:status] || 200 headers = params[:headers] || {} response = Excon::Response.new(:body => body, :headers => headers, :status => status) if params.key?(:expects) && ![*params[:expects]].include?(response.status) raise(Excon::Errors.status_error(params, response)) else response end end |
#revert_resize_server(server_id) ⇒ Object
34 35 36 37 38 |
# File 'lib/fog/rackspace/requests/compute_v2/revert_resize_server.rb', line 34 def revert_resize_server(server_id) server = self.data[:servers][server_id] server["status"] = "ACTIVE" response(:status => 202) end |
#set_metadata(collection, obj_id, metadata = {}) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/fog/rackspace/requests/compute_v2/set_metadata.rb', line 28 def (collection, obj_id, = {}) raise Fog::Compute::RackspaceV2::NotFound if obj_id == 0 response = Excon::Response.new response.status = 202 response.body = {"metadata"=>{"environment"=>"dev"}} response end |
#set_metadata_item(collection, obj_id, key, value) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/fog/rackspace/requests/compute_v2/set_metadata_item.rb', line 29 def (collection, obj_id, key, value) raise Fog::Compute::RackspaceV2::NotFound if obj_id == 0 response = Excon::Response.new response.status = 202 response.body = {"meta" => {key => value}} response end |
#start_server(server_id) ⇒ Object
31 32 33 34 35 |
# File 'lib/fog/rackspace/requests/compute_v2/start_server.rb', line 31 def start_server(server_id) server = self.data[:servers][server_id] server["status"] = "ACTIVE" response(:status => 202) end |
#stop_server(server_id) ⇒ Object
32 33 34 35 36 |
# File 'lib/fog/rackspace/requests/compute_v2/stop_server.rb', line 32 def stop_server(server_id) server = self.data[:servers][server_id] server["status"] = "SHUTOFF" response(:status => 202) end |
#unrescue_server(server_id) ⇒ Object
32 33 34 35 36 |
# File 'lib/fog/rackspace/requests/compute_v2/unrescue_server.rb', line 32 def unrescue_server(server_id) server = self.data[:servers][server_id] server["status"] = "ACTIVE" response(:status => 202) end |
#update_metadata(collection, obj_id, metadata = {}) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/fog/rackspace/requests/compute_v2/update_metadata.rb', line 28 def (collection, obj_id, = {}) raise Fog::Compute::RackspaceV2::NotFound if obj_id == 0 response = Excon::Response.new response.status = 202 response.body = {"metadata" => {"environment" => "dev", "tag" => "database"}} response end |
#update_server(server_id, name) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fog/rackspace/requests/compute_v2/update_server.rb', line 30 def update_server(server_id, name) server = self.data[:servers][server_id] name.each_pair {|k,v| server[k] = v } if name.is_a?(Hash) server['name'] = name if name.is_a?(String) server_response = Fog::Rackspace::MockData.keep(server, 'id', 'name', 'hostId', 'created', 'updated', 'status', 'progress', 'user_id', 'tenant_id', 'links', 'metadata', 'accessIPv4', 'accessIPv6', 'OS-DCF:diskConfig', 'rax-bandwidth:bandwidth', 'addresses', 'flavor', 'links', 'image') response( :status => 200, :body => {'server' => server_response} ) end |