Class: Fog::Compute::IBM::Mock
- Inherits:
-
Object
- Object
- Fog::Compute::IBM::Mock
- Defined in:
- lib/rackspace-fog/ibm/compute.rb,
lib/rackspace-fog/ibm/requests/compute/get_key.rb,
lib/rackspace-fog/ibm/requests/compute/get_image.rb,
lib/rackspace-fog/ibm/requests/compute/list_keys.rb,
lib/rackspace-fog/ibm/requests/compute/create_key.rb,
lib/rackspace-fog/ibm/requests/compute/delete_key.rb,
lib/rackspace-fog/ibm/requests/compute/list_vlans.rb,
lib/rackspace-fog/ibm/requests/compute/modify_key.rb,
lib/rackspace-fog/ibm/requests/compute/clone_image.rb,
lib/rackspace-fog/ibm/requests/compute/get_request.rb,
lib/rackspace-fog/ibm/requests/compute/list_images.rb,
lib/rackspace-fog/ibm/requests/compute/create_image.rb,
lib/rackspace-fog/ibm/requests/compute/delete_image.rb,
lib/rackspace-fog/ibm/requests/compute/get_instance.rb,
lib/rackspace-fog/ibm/requests/compute/get_location.rb,
lib/rackspace-fog/ibm/requests/compute/create_address.rb,
lib/rackspace-fog/ibm/requests/compute/delete_address.rb,
lib/rackspace-fog/ibm/requests/compute/list_addresses.rb,
lib/rackspace-fog/ibm/requests/compute/list_instances.rb,
lib/rackspace-fog/ibm/requests/compute/list_locations.rb,
lib/rackspace-fog/ibm/requests/compute/create_instance.rb,
lib/rackspace-fog/ibm/requests/compute/delete_instance.rb,
lib/rackspace-fog/ibm/requests/compute/modify_instance.rb,
lib/rackspace-fog/ibm/requests/compute/get_image_manifest.rb,
lib/rackspace-fog/ibm/requests/compute/get_image_agreement.rb,
lib/rackspace-fog/ibm/requests/compute/list_address_offerings.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#activate_instance(instance_id) ⇒ Object
Sets instance status to Active if it’s not already set.
- #address_exists?(address_id) ⇒ Boolean
- #clone_image(image_id, name, description) ⇒ Object
- #create_address(location_id, offering_id = "20001223", options = {}) ⇒ Object
- #create_image(instance_id, name, description) ⇒ Object
- #create_instance(name, image_id, instance_type, location, options = {}) ⇒ Object
-
#create_key(name, public_key = nil) ⇒ Object
SmartCloud returns the private key when create_key is called We need to store both the private and public key for later use.
- #data ⇒ Object
- #delete_address(address_id) ⇒ Object
- #delete_image(image_id) ⇒ Object
- #delete_instance(instance_id) ⇒ Object
- #delete_key(key_name) ⇒ Object
-
#deleteable?(instance_id) ⇒ Boolean
we can’t delete the instance if it doesn’t exist, or is in an invalid state.
- #get_image(image_id) ⇒ Object
-
#get_image_agreement(image_id) ⇒ Object
TODO: Fix this so they work.
-
#get_image_manifest(image_id) ⇒ Object
TODO: Create a data store for this.
- #get_instance(instance_id) ⇒ Object
- #get_key(key_name) ⇒ Object
- #get_location(location_id) ⇒ Object
- #get_request(request_id) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
-
#instance_active?(instance_id) ⇒ Boolean
Checks if an instance is Active.
-
#instance_exists?(instance_id) ⇒ Boolean
Checks if an instance exists.
- #key_exists?(name) ⇒ Boolean
- #list_address_offerings ⇒ Object
- #list_addresses ⇒ Object
- #list_images ⇒ Object
- #list_instances ⇒ Object
- #list_keys ⇒ Object
- #list_locations ⇒ Object
- #list_vlans ⇒ Object
- #location_exists?(location_id) ⇒ Boolean
- #modify_instance(instance_id, params = {}) ⇒ Object
- #modify_key(key_name, params = {}) ⇒ Object
- #reset_data ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
112 113 114 115 116 |
# File 'lib/rackspace-fog/ibm/compute.rb', line 112 def initialize(={}) @ibm_username = [:ibm_username] @ibm_password = [:ibm_password] @data = self.class.data[@ibm_username] end |
Class Method Details
.data ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rackspace-fog/ibm/compute.rb', line 86 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :instances => {}, :images => populate_images, :keys => {}, :locations => populate_locations, :private_keys => {}, :addresses => {} } end end |
.populate_images ⇒ Object
118 119 120 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 |
# File 'lib/rackspace-fog/ibm/compute.rb', line 118 def self.populate_images images = {} images["20010001"] = { "name"=>"SUSE Linux Enterprise Server 11 SP1 for x86", "manifest"=>"https://www-147.ibm.com/cloud/enterprise/ram.ws/RAMSecure/artifact/{6CD09CE4-E99B-D72F-6C29-233C9B2A1676}/1.0/parameters.xml", "state"=>1, "visibility"=>"PUBLIC", "owner"=>"SYSTEM", "platform"=>"SUSE Linux Enterprise Server/11 SP1", "location"=>"41", "createdTime"=>1282466781000, "supportedInstanceTypes"=> [{"detail"=>"Copper - 32 bit (vCPU: 1, RAM: 2 GiB, Disk: 60 GiB)", "label"=>"Copper 32 bit", "price"=>{"rate"=>0.095, "unitOfMeasure"=>"UHR ", "countryCode"=>"897", "effectiveDate"=>-1, "currencyCode"=>"USD", "pricePerQuantity"=>1}, "id"=>"COP32.1/2048/60"}, {"detail"=>"Bronze - 32 bit (vCPU: 1, RAM: 2 GiB, Disk: 235 GiB)", "label"=>"Bronze 32 bit", "price"=>{"rate"=>0.115, "unitOfMeasure"=>"UHR ", "countryCode"=>"897", "effectiveDate"=>-1, "currencyCode"=>"USD", "pricePerQuantity"=>1}, "id"=>"BRZ32.1/2048/60*175"}, {"detail"=>"Silver - 32 bit (vCPU: 2, RAM: 4 GiB, Disk: 410 GiB)", "label"=>"Silver 32 bit", "price"=>{"rate"=>0.2, "unitOfMeasure"=>"UHR ", "countryCode"=>"897", "effectiveDate"=>-1, "currencyCode"=>"USD", "pricePerQuantity"=>1}, "id"=>"SLV32.2/4096/60*350"}, {"detail"=>"Gold - 32 bit (vCPU: 4, RAM: 4 GiB, Disk: 410 GiB)", "label"=>"Gold 32 bit", "price"=>{"rate"=>0.33, "unitOfMeasure"=>"UHR ", "countryCode"=>"897", "effectiveDate"=>-1, "currencyCode"=>"USD", "pricePerQuantity"=>1}, "id"=>"GLD32.4/4096/60*350"}], "productCodes"=>["rtpSr7dKs9ARDmuPy6WPgV"], "documentation"=>"https://www-147.ibm.com/cloud/enterprise/ram.ws/RAMSecure/artifact/{6CD09CE4-E99B-D72F-6C29-233C9B2A1676}/1.0/GettingStarted.html", "id"=>"20010001", "description"=>"Suse Linux 32 bit" } images end |
.populate_locations ⇒ Object
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 |
# File 'lib/rackspace-fog/ibm/compute.rb', line 154 def self.populate_locations locations = {} locations["41"] = { "state"=>1, "location"=>"RTP", "capabilities"=>[ {"entries"=>{"EXT3"=>["ext3"], "RAW"=>["raw"]}, "id"=>"oss.storage.format"}, {"entries"=>{}, "id"=>"oss.instance.spec.i386"}, {"entries"=>{}, "id"=>"oss.instance.spec.x86_64"}, {"entries"=>{}, "id"=>"oss.storage.availabilityarea"}], "name"=>"Raleigh, U.S.A", "id"=>"41", "description"=>"This data center is located in Raleigh, North Carolina, U.S.A. The services provided are: Guest Instances, Image Capture, Persistent Storage, Reserved IP, Private VLAN/VPN." } locations["61"] = { "state"=>1, "location"=>"EHN", "capabilities"=>[ {"entries"=>{"EXT3"=>["ext3"], "RAW"=>["raw"]}, "id"=>"oss.storage.format"}, {"entries"=>{}, "id"=>"oss.instance.spec.i386"}, {"entries"=>{}, "id"=>"oss.instance.spec.x86_64"}, {"entries"=>{}, "id"=>"oss.storage.availabilityarea"}], "name"=>"Ehningen, Germany", "id"=>"61", "description"=>"This data center is located in Ehningen(near Baden-Wurttemberg), Germany. The services provided are: Guest Instances, Image Capture, Persistent Storage, Reserved IP, Private VLAN/VPN." } locations["82"] = { "state"=>1, "location"=>"us-co-dc1", "capabilities"=>[ {"entries"=>{"EXT3"=>["ext3"], "RAW"=>["raw"]}, "id"=>"oss.storage.format"}, {"entries"=>{}, "id"=>"oss.instance.spec.i386"}, {"entries"=>{}, "id"=>"oss.instance.spec.x86_64"}, {"entries"=>{}, "id"=>"oss.storage.availabilityarea"}], "name"=>"Boulder1, U.S.A", "id"=>"82", "description"=>"This data center is located in Boulder(near Denver), Colorado, U.S.A. The services provided are: Guest Instances, Image Capture, Persistent Storage, Reserved IP, Private VLAN/VPN." } locations["101"] = { "state"=>1, "location"=>"ca-on-dc1", "capabilities"=>[ {"entries"=>{"EXT3"=>["ext3"], "RAW"=>["raw"]}, "id"=>"oss.storage.format"}, {"entries"=>{}, "id"=>"oss.instance.spec.i386"}, {"entries"=>{}, "id"=>"oss.instance.spec.x86_64"}, {"entries"=>{}, "id"=>"oss.storage.availabilityarea"}], "name"=>"Markham, Canada", "id"=>"101", "description"=>"This data center is located in Markham(near Toronto), Ontario, Canada. The services provided are: Guest Instances, Image Capture, Persistent Storage, Reserved IP, Private VLAN/VPN." } locations["121"] = { "state"=>1, "location"=>"ap-jp-dc1", "capabilities"=>[ {"entries"=>{"EXT3"=>["ext3"], "RAW"=>["raw"]}, "id"=>"oss.storage.format"}, {"entries"=>{}, "id"=>"oss.instance.spec.i386"}, {"entries"=>{}, "id"=>"oss.instance.spec.x86_64"}, {"entries"=>{}, "id"=>"oss.storage.availabilityarea"}], "name"=>"Makuhari, Japan", "id"=>"121", "description"=>"This data center is located in Makuhari(near Tokoyo), Japan. The services provided are: Guest Instances, Image Capture, Persistent Storage, Reserved IP, Private VLAN/VPN." } locations["141"] = { "state"=>1, "location"=>"ap-sg-dc1", "capabilities"=>[ {"entries"=>{"EXT3"=>["ext3"], "RAW"=>["raw"]}, "id"=>"oss.storage.format"}, {"entries"=>{}, "id"=>"oss.instance.spec.i386"}, {"entries"=>{}, "id"=>"oss.instance.spec.x86_64"}, {"entries"=>{}, "id"=>"oss.storage.availabilityarea"}], "name"=>"Singapore, Singapore", "id"=>"141", "description"=>"This data center is located in Singapore. The services provided are: Guest Instances, Image Capture, Persistent Storage, Reserved IP, Private VLAN/VPN." } locations end |
.reset ⇒ Object
99 100 101 |
# File 'lib/rackspace-fog/ibm/compute.rb', line 99 def self.reset @data = nil end |
Instance Method Details
#activate_instance(instance_id) ⇒ Object
Sets instance status to Active if it’s not already set.
64 65 66 |
# File 'lib/rackspace-fog/ibm/requests/compute/get_instance.rb', line 64 def activate_instance(instance_id) self.data[:instances][instance_id]["status"] = 5 unless instance_active? instance_id end |
#address_exists?(address_id) ⇒ Boolean
39 40 41 |
# File 'lib/rackspace-fog/ibm/requests/compute/delete_address.rb', line 39 def address_exists?(address_id) self.data[:addresses].key? address_id end |
#clone_image(image_id, name, description) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rackspace-fog/ibm/requests/compute/clone_image.rb', line 32 def clone_image(image_id, name, description) response = Excon::Response.new if image_exists? image_id id = Fog::IBM::Mock.instance_id self.data[:images][id] = self.data[:images][image_id].merge('id' => id, 'name' => name, 'description' => description) response.status = 200 response.body = { "ImageID" => id } else response.status = 404 end response end |
#create_address(location_id, offering_id = "20001223", options = {}) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/rackspace-fog/ibm/requests/compute/create_address.rb', line 38 def create_address(location_id, offering_id="20001223", ={}) address = Fog::IBM::Mock.create_address(location_id, offering_id, ) self.data[:addresses][address['id']] = address response = Excon::Response.new response.status = 200 response.body = address response end |
#create_image(instance_id, name, description) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rackspace-fog/ibm/requests/compute/create_image.rb', line 40 def create_image(instance_id, name, description) response = Excon::Response.new if instance_exists? instance_id image = Fog::IBM::Mock.private_image(name, description) self.data[:images][image["id"]] = image response.status = 200 response.body = image else response.status = 404 end response end |
#create_instance(name, image_id, instance_type, location, options = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rackspace-fog/ibm/requests/compute/create_instance.rb', line 60 def create_instance(name, image_id, instance_type, location, ={}) response = Excon::Response.new # Since we want to test error conditions, we have a little regex that traps specially formed # instance type strings. case name when /FAIL:\ (\d{3})/ response.status = $1.to_i raise Excon::Errors.status_error({:expects => 200}, response) else instance = Fog::IBM::Mock.create_instance(name, image_id, instance_type, location, ) self.data[:instances][instance['id']] = instance response.status = 200 response.body = {"instances" => [ instance ]} response end end |
#create_key(name, public_key = nil) ⇒ Object
SmartCloud returns the private key when create_key is called We need to store both the private and public key for later use
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rackspace-fog/ibm/requests/compute/create_key.rb', line 37 def create_key(name, public_key=nil) response = Excon::Response.new response.status = 200 attributes = { "keyName" => name, "lastModifiedTime" => Fog::IBM::Mock.launch_time, "default" => false, "instanceIds" => [], } if public_key.nil? private_key = Fog::IBM::Mock.key_material public_key = private_key.public_key response.body = attributes.merge("keyMaterial" => private_key.to_s) else response.body = { 'success' => true } end self.data[:keys][name] = attributes.merge("keyMaterial" => public_key.to_s) self.data[:private_keys][name] = attributes.merge("keyMaterial" => private_key.to_s) response end |
#data ⇒ Object
103 104 105 |
# File 'lib/rackspace-fog/ibm/compute.rb', line 103 def data self.class.data[@ibm_username] end |
#delete_address(address_id) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rackspace-fog/ibm/requests/compute/delete_address.rb', line 27 def delete_address(address_id) response = Excon::Response.new if address_exists? address_id self.data[:addresses].delete address_id response.status = 200 response.body = { "success" => true } else response.status = 404 end response end |
#delete_image(image_id) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rackspace-fog/ibm/requests/compute/delete_image.rb', line 26 def delete_image(image_id) response = Excon::Response.new # TODO: We should probably check that an image is deleteable. # i.e. that the user has appropriate permissions if image_exists? image_id self.data[:images].delete image_id response.status = 200 response.body = {"success"=>true} else response.status = 404 end response end |
#delete_instance(instance_id) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rackspace-fog/ibm/requests/compute/delete_instance.rb', line 27 def delete_instance(instance_id) response = Excon::Response.new if deleteable? instance_id # remove from memoreeeez. self.data[:instances].delete instance_id response.body = { 'success' => true } response.status = 200 else # TODO: we should really return a 412 if the instance is in an invalid state, and a 404 if it doesn't exist. response.status = 404 end response end |
#delete_key(key_name) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rackspace-fog/ibm/requests/compute/delete_key.rb', line 26 def delete_key(key_name) response = Excon::Response.new if key_exists? key_name self.data[:keys].delete(key_name) response.status = 200 response.body = {"success"=>true} else response.status = 404 end response end |
#deleteable?(instance_id) ⇒ Boolean
we can’t delete the instance if it doesn’t exist, or is in an invalid state.
42 43 44 45 46 47 |
# File 'lib/rackspace-fog/ibm/requests/compute/delete_instance.rb', line 42 def deleteable?(instance_id) return false unless instance_exists? instance_id instance = self.data[:instances][instance_id] return false if [0, 1, 7, 14, 15].include?(instance["status"].to_i) true end |
#get_image(image_id) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rackspace-fog/ibm/requests/compute/get_image.rb', line 47 def get_image(image_id) response = Excon::Response.new if image_exists? image_id response.status = 200 response.body = self.data[:images][image_id] else response.status = 404 end response end |
#get_image_agreement(image_id) ⇒ Object
TODO: Fix this so they work.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rackspace-fog/ibm/requests/compute/get_image_agreement.rb', line 33 def get_image_agreement(image_id) response = Excon::Response.new response.status = 200 response.body = {"text"=> "test, operating system is SUSE Linux Enterprise Server/11 SP1 - English\n\nYour access to and use of the Service, including all selected options, are governed by the terms of the Agreement signed between your Enterprise and IBM. Each Service is also governed by one or more Attachments (including, for example, Image Terms Attachments). Applicable Attachments are part of the Agreement between you and IBM and include Attachments for Services you acquire after the Agreement was signed. The Agreement also references applicable IBM and third party end user license agreements that govern the use of IBM software and operating system software provided as part of an Image.\n\nYou are responsible for complying with the terms of the Agreement (including applicable Attachments) and applicable license agreements. You may review the terms for the Service by 1) obtaining information regarding the Agreement from your Account Administrator and 2) accessing the Asset Catalog to review specific Image Terms and end user license agreements for IBM and third party software provided as part of an Image. ", "id"=>"20020159", "attachments"=> [{"label"=>"Service Description for Developement & Test Service", "url"=> "https://www-147.ibm.com/cloud/enterprise/static/internal_user_agreement.pdf", "type"=>0}, {"label"=>"Smart Business on the IBM Public Cloud Agreement", "url"=> "https://www-147.ibm.com/cloud/enterprise/static/internal_user_agreement.pdf", "type"=>1}, {"label"=> "End User License for SUSE 10.2 Linux Enterprise Server software", "url"=> "https://www.novell.com/licensing/eula/sles_10/sles_10_english.pdf", "type"=>2}, {"label"=> "End User License for SUSE 11.0 Linux Enterprise Server software", "url"=>"https://www.novell.com/licensing/eula/sles_11/sles_11_en.pdf", "type"=>2}, {"label"=>"End User License for RedHat Linux RHEL software", "url"=>"https://www.redhat.com/licenses/", "type"=>2}]} response end |
#get_image_manifest(image_id) ⇒ Object
TODO: Create a data store for this.
28 29 30 31 32 33 34 |
# File 'lib/rackspace-fog/ibm/requests/compute/get_image_manifest.rb', line 28 def get_image_manifest(image_id) response = Excon::Response.new response.status = 200 response.body = {"manifest"=> "<?xml version=\"1.0\" encoding=\"UTF-8\"?><parameters xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"platform:/resource/com.ibm.ccl.devcloud.client/schema/parameters.xsd\">\n\t<firewall>\n\t\t<rule>\n\t\t\t<source>0.0.0.0/0</source>\n\t\t\t<minport>1</minport>\n\t\t\t<maxport>65535</maxport>\n\t\t</rule>\n\t</firewall>\n</parameters>"} response end |
#get_instance(instance_id) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rackspace-fog/ibm/requests/compute/get_instance.rb', line 46 def get_instance(instance_id) response = Excon::Response.new if instance_exists? instance_id activate_instance(instance_id) # Set it to Active if it's not running response.status = 200 response.body = self.data[:instances][instance_id] else raise Fog::Compute::IBM::NotFound end response end |
#get_key(key_name) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rackspace-fog/ibm/requests/compute/get_key.rb', line 31 def get_key(key_name) response = Excon::Response.new if key_exists? key_name response.status = 200 response.body = self.data[:keys][key_name] else response.status = 404 end response end |
#get_location(location_id) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rackspace-fog/ibm/requests/compute/get_location.rb', line 37 def get_location(location_id) response = Excon::Response.new if location_exists? location_id response.status = 200 response.body = self.data[:locations][location_id] else response.status = 404 end response end |
#get_request(request_id) ⇒ Object
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/rackspace-fog/ibm/requests/compute/get_request.rb', line 47 def get_request(request_id) response = Excon::Response.new response.status = 200 response.body = {"instances"=> [{"name"=>"test from fog", "location"=>"101", "keyName"=>"mykey", "primaryIP"=> {"type"=>0, "ip"=>"42.42.42.42 ", "hostname"=>"42.42.42.42 "}, "productCodes"=>[], "requestId"=>"75364", "imageId"=>"20020159", "launchTime"=>1304012220770, "id"=>"75064", "volumes"=>[], "instanceType"=>"SLV32.2/4096/60*350", "requestName"=>"test from fog", "secondaryIP"=>[], "status"=>1, "software"=> [{"name"=>"SUSE Linux Enterprise Server", "type"=>"OS", "version"=>"11 SP1"}], "expirationTime"=>1367084229205, "owner"=>"[email protected]"}]} response end |
#instance_active?(instance_id) ⇒ Boolean
Checks if an instance is Active
69 70 71 |
# File 'lib/rackspace-fog/ibm/requests/compute/get_instance.rb', line 69 def instance_active?(instance_id) self.data[:instances][instance_id]["status"] == 5 end |
#instance_exists?(instance_id) ⇒ Boolean
Checks if an instance exists
59 60 61 |
# File 'lib/rackspace-fog/ibm/requests/compute/get_instance.rb', line 59 def instance_exists?(instance_id) self.data[:instances].key? instance_id end |
#key_exists?(name) ⇒ Boolean
42 43 44 |
# File 'lib/rackspace-fog/ibm/requests/compute/get_key.rb', line 42 def key_exists?(name) self.data[:keys].key? name end |
#list_address_offerings ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rackspace-fog/ibm/requests/compute/list_address_offerings.rb', line 38 def list_address_offerings response = Excon::Response.new response.status = 200 response.body = {"addresses"=> [{"price"=> {"pricePerQuantity"=>1, "effectiveDate"=>1302566400000, "rate"=>0.01, "countryCode"=>"897", "unitOfMeasure"=>"UHR", "currencyCode"=>"USD"}, "location"=>"101", "ipType"=>0, "id"=>"20001223"}]} response end |
#list_addresses ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rackspace-fog/ibm/requests/compute/list_addresses.rb', line 35 def list_addresses # Loop through addresses and update states and values if they aren't set self.data[:addresses].values.each do |address| address['state'] = 2 if address['state'] == 0 address['ip'] = Fog::IBM::Mock.ip_address if address['ip'].empty? address['mode'] = 0 unless address.key? 'mode' address['hostname'] = Fog::IBM::Mock.hostname unless address.key? 'hostname' address['type'] = 1 unless address.key? 'type' end response = Excon::Response.new response.status = 200 response.body = { 'addresses' => self.data[:addresses].values } response end |
#list_images ⇒ Object
48 49 50 51 52 53 |
# File 'lib/rackspace-fog/ibm/requests/compute/list_images.rb', line 48 def list_images response = Excon::Response.new response.status = 200 response.body = {'images' => self.data[:images].values} response end |
#list_instances ⇒ Object
47 48 49 50 51 52 |
# File 'lib/rackspace-fog/ibm/requests/compute/list_instances.rb', line 47 def list_instances response = Excon::Response.new response.status = 200 response.body = { 'instances' => self.data[:instances].values } response end |
#list_keys ⇒ Object
47 48 49 50 51 52 |
# File 'lib/rackspace-fog/ibm/requests/compute/list_keys.rb', line 47 def list_keys response = Excon::Response.new response.status = 200 response.body = {'keys' => self.data[:keys].values} response end |
#list_locations ⇒ Object
27 28 29 30 31 32 |
# File 'lib/rackspace-fog/ibm/requests/compute/list_locations.rb', line 27 def list_locations response = Excon::Response.new response.status = 200 response.body = { "locations" => self.data[:locations].values } response end |
#list_vlans ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/rackspace-fog/ibm/requests/compute/list_vlans.rb', line 34 def list_vlans response = Excon::Response.new response.status = 200 response.body = {"vlan"=> [{"location"=>"101", "id"=>"75321", "name"=>"FOG-VLAN1"}]} response end |
#location_exists?(location_id) ⇒ Boolean
48 49 50 |
# File 'lib/rackspace-fog/ibm/requests/compute/get_location.rb', line 48 def location_exists?(location_id) self.data[:locations].key? location_id end |
#modify_instance(instance_id, params = {}) ⇒ 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 |
# File 'lib/rackspace-fog/ibm/requests/compute/modify_instance.rb', line 39 def modify_instance(instance_id, params={}) response = Excon::Response.new if instance_exists? instance_id if params['state'] == 'restart' self.data[:instances][instance_id]["status"] = "8" response.status = 200 response.body = { "success" => true } elsif params['type'] == 'attach' || params['type'] == 'detach' if Fog::Storage[:ibm].volume_exists?(params['volume_id']) # TODO: Update the instance in the data hash, assuming IBM ever gets this feature working properly. response.status = 415 else response.status = 404 end elsif params['name'] self.data[:instances][instance_id]["name"] = params['name'] response.status = 200 response.body = { "success" => true } elsif params['expirationTime'] self.data[:instances][instance_id]["expirationTime"] = params['expirationTime'] response.status = 200 response.body = { 'expirationTime' => params['expirationTime'] } end else response.status = 404 end response end |
#modify_key(key_name, params = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rackspace-fog/ibm/requests/compute/modify_key.rb', line 28 def modify_key(key_name, params={}) response = Excon::Response.new if key_exists? key_name if params['public_key'] self.data[:keys][key_name]['keyMaterial'] = public_key self.data[:keys][key_name]['lastModifiedTime'] = Fog::IBM::Mock.launch_time end if params['default'] self.data[:keys].values.each do |key| key['default'] = false end self.data[:keys][key_name]['default'] = true end response.status = 200 response.body = {"success"=>true} else response.status = 404 end response end |
#reset_data ⇒ Object
107 108 109 110 |
# File 'lib/rackspace-fog/ibm/compute.rb', line 107 def reset_data self.class.data.delete(@ibm_username) @data = self.class.data[@ibm_username] end |