Class: Fog::Compute::OpenStack::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/openstack/requests/compute/add_fixed_ip.rb,
lib/fog/openstack/compute.rb,
lib/fog/openstack/requests/compute/get_quota.rb,
lib/fog/openstack/requests/compute/get_usage.rb,
lib/fog/openstack/requests/compute/get_limits.rb,
lib/fog/openstack/requests/compute/list_hosts.rb,
lib/fog/openstack/requests/compute/set_tenant.rb,
lib/fog/openstack/requests/compute/get_address.rb,
lib/fog/openstack/requests/compute/list_images.rb,
lib/fog/openstack/requests/compute/list_usages.rb,
lib/fog/openstack/requests/compute/create_image.rb,
lib/fog/openstack/requests/compute/delete_image.rb,
lib/fog/openstack/requests/compute/get_metadata.rb,
lib/fog/openstack/requests/compute/list_flavors.rb,
lib/fog/openstack/requests/compute/list_servers.rb,
lib/fog/openstack/requests/compute/list_tenants.rb,
lib/fog/openstack/requests/compute/list_volumes.rb,
lib/fog/openstack/requests/compute/pause_server.rb,
lib/fog/openstack/requests/compute/set_metadata.rb,
lib/fog/openstack/requests/compute/update_quota.rb,
lib/fog/openstack/requests/compute/attach_volume.rb,
lib/fog/openstack/requests/compute/create_flavor.rb,
lib/fog/openstack/requests/compute/create_server.rb,
lib/fog/openstack/requests/compute/create_volume.rb,
lib/fog/openstack/requests/compute/delete_flavor.rb,
lib/fog/openstack/requests/compute/delete_server.rb,
lib/fog/openstack/requests/compute/delete_volume.rb,
lib/fog/openstack/requests/compute/detach_volume.rb,
lib/fog/openstack/requests/compute/list_metadata.rb,
lib/fog/openstack/requests/compute/reboot_server.rb,
lib/fog/openstack/requests/compute/rescue_server.rb,
lib/fog/openstack/requests/compute/resize_server.rb,
lib/fog/openstack/requests/compute/resume_server.rb,
lib/fog/openstack/requests/compute/update_server.rb,
lib/fog/openstack/requests/compute/list_addresses.rb,
lib/fog/openstack/requests/compute/list_key_pairs.rb,
lib/fog/openstack/requests/compute/list_snapshots.rb,
lib/fog/openstack/requests/compute/migrate_server.rb,
lib/fog/openstack/requests/compute/rebuild_server.rb,
lib/fog/openstack/requests/compute/server_actions.rb,
lib/fog/openstack/requests/compute/suspend_server.rb,
lib/fog/openstack/requests/compute/unpause_server.rb,
lib/fog/openstack/requests/compute/create_key_pair.rb,
lib/fog/openstack/requests/compute/delete_key_pair.rb,
lib/fog/openstack/requests/compute/delete_metadata.rb,
lib/fog/openstack/requests/compute/delete_snapshot.rb,
lib/fog/openstack/requests/compute/get_vnc_console.rb,
lib/fog/openstack/requests/compute/release_address.rb,
lib/fog/openstack/requests/compute/remove_fixed_ip.rb,
lib/fog/openstack/requests/compute/update_metadata.rb,
lib/fog/openstack/requests/compute/allocate_address.rb,
lib/fog/openstack/requests/compute/get_host_details.rb,
lib/fog/openstack/requests/compute/associate_address.rb,
lib/fog/openstack/requests/compute/get_image_details.rb,
lib/fog/openstack/requests/compute/get_console_output.rb,
lib/fog/openstack/requests/compute/get_flavor_details.rb,
lib/fog/openstack/requests/compute/get_quota_defaults.rb,
lib/fog/openstack/requests/compute/get_security_group.rb,
lib/fog/openstack/requests/compute/get_server_details.rb,
lib/fog/openstack/requests/compute/get_server_volumes.rb,
lib/fog/openstack/requests/compute/get_volume_details.rb,
lib/fog/openstack/requests/compute/list_address_pools.rb,
lib/fog/openstack/requests/compute/list_all_addresses.rb,
lib/fog/openstack/requests/compute/list_images_detail.rb,
lib/fog/openstack/requests/compute/reset_server_state.rb,
lib/fog/openstack/requests/compute/server_diagnostics.rb,
lib/fog/openstack/requests/compute/list_flavors_detail.rb,
lib/fog/openstack/requests/compute/list_servers_detail.rb,
lib/fog/openstack/requests/compute/live_migrate_server.rb,
lib/fog/openstack/requests/compute/disassociate_address.rb,
lib/fog/openstack/requests/compute/get_snapshot_details.rb,
lib/fog/openstack/requests/compute/list_security_groups.rb,
lib/fog/openstack/requests/compute/revert_resize_server.rb,
lib/fog/openstack/requests/compute/confirm_resize_server.rb,
lib/fog/openstack/requests/compute/create_security_group.rb,
lib/fog/openstack/requests/compute/delete_security_group.rb,
lib/fog/openstack/requests/compute/list_public_addresses.rb,
lib/fog/openstack/requests/compute/change_server_password.rb,
lib/fog/openstack/requests/compute/create_volume_snapshot.rb,
lib/fog/openstack/requests/compute/list_private_addresses.rb,
lib/fog/openstack/requests/compute/create_security_group_rule.rb,
lib/fog/openstack/requests/compute/delete_security_group_rule.rb

Overview

class Real

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/fog/openstack/compute.rb', line 211

def initialize(options={})
  @openstack_username = options[:openstack_username]
  @openstack_tenant   = options[:openstack_tenant]
  @openstack_auth_uri = URI.parse(options[:openstack_auth_url])

  @auth_token = Fog::Mock.random_base64(64)
  @auth_token_expiration = (Time.now.utc + 86400).iso8601

  management_url = URI.parse(options[:openstack_auth_url])
  management_url.port = 8774
  management_url.path = '/v1.1/1'
  @openstack_management_url = management_url.to_s

  identity_public_endpoint = URI.parse(options[:openstack_auth_url])
  identity_public_endpoint.port = 5000
  @openstack_identity_public_endpoint = identity_public_endpoint.to_s
end

Instance Attribute Details

#auth_tokenObject (readonly)

Returns the value of attribute auth_token.



160
161
162
# File 'lib/fog/openstack/compute.rb', line 160

def auth_token
  @auth_token
end

#auth_token_expirationObject (readonly)

Returns the value of attribute auth_token_expiration.



161
162
163
# File 'lib/fog/openstack/compute.rb', line 161

def auth_token_expiration
  @auth_token_expiration
end

#current_tenantObject (readonly)

Returns the value of attribute current_tenant.



163
164
165
# File 'lib/fog/openstack/compute.rb', line 163

def current_tenant
  @current_tenant
end

#current_userObject (readonly)

Returns the value of attribute current_user.



162
163
164
# File 'lib/fog/openstack/compute.rb', line 162

def current_user
  @current_user
end

Class Method Details

.dataObject



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
# File 'lib/fog/openstack/compute.rb', line 165

def self.data
  @data ||= Hash.new do |hash, key|
    hash[key] = {
      :last_modified => {
        :images  => {},
        :servers => {},
        :key_pairs => {},
        :security_groups => {},
        :addresses => {}
      },
      :images  => {
        "0e09fbd6-43c5-448a-83e9-0d3d05f9747e" => {
          "id"=>"0e09fbd6-43c5-448a-83e9-0d3d05f9747e",
          "name"=>"cirros-0.3.0-x86_64-blank",
          'progress'  => 100,
          'status'    => "ACTIVE",
          'updated'   => "",
          'minRam'    => 0,
          'minDisk'   => 0,
          'metadata'  => {},
          'links'     => [{"href"=>"http://nova1:8774/v1.1/admin/images/1", "rel"=>"self"}, {"href"=>"http://nova1:8774/admin/images/2", "rel"=>"bookmark"}]
        }
      },
      :servers => {},
      :key_pairs => {},
      :security_groups => {},
      :addresses => {},
      :quota => {
        'metadata_items' => 128,
        'key_pairs' => 10,
        'injected_file_content_bytes' => 10240,
        'injected_file_path_bytes' => 256,
        'injected_files' => 5,
        'ram' => 51200,
        'floating_ips' => 10,
        'instances' => 10,
        'cores' => 20,
      }
    }
  end
end

.resetObject



207
208
209
# File 'lib/fog/openstack/compute.rb', line 207

def self.reset
  @data = nil
end

Instance Method Details

#add_fixed_ip(server_id, network_id) ⇒ Object



23
24
25
# File 'lib/fog/openstack/requests/compute/add_fixed_ip.rb', line 23

def add_fixed_ip(server_id, network_id)
  true
end

#allocate_addressObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fog/openstack/requests/compute/allocate_address.rb', line 19

def allocate_address
  response = Excon::Response.new
  response.status = 200
  response.headers = {
    "X-Compute-Request-Id" => "req-d4a21158-a86c-44a6-983a-e25645907f26",
    "Content-Type" => "application/json",
    "Content-Length" => "105",
    "Date"=> Date.new
  }
  response.body = {
    "floating_ip" => {
      "instance_id" => nil,
      "ip" => "192.168.27.132",
      "fixed_ip" => nil,
      "id" => 4,
      "pool"=>"nova"
    }
  }
  response
end

#associate_address(server_id, ip_address) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/fog/openstack/requests/compute/associate_address.rb', line 14

def associate_address(server_id, ip_address)
  response = Excon::Response.new
  response.status = 202
  response.headers = {
    "Content-Type" => "text/html, charset=UTF-8",
    "Content-Length" => "0",
    "Date"=> Date.new
  }
  response
end

#attach_volume(volume_id, server_id, device) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/fog/openstack/requests/compute/attach_volume.rb', line 24

def attach_volume(volume_id, server_id, device)
  response = Excon::Response.new
  response.status = 200
  response.body ={ "volumeAttachment" => {
                     "id"       => volume_id,
                     "volumeId" => volume_id
                    }
                 }
  response
end

#change_server_password(server_id, admin_password) ⇒ Object



15
16
17
18
19
# File 'lib/fog/openstack/requests/compute/change_server_password.rb', line 15

def change_server_password(server_id, admin_password)
  response = Excon::Response.new
  response.status = 202
  response
end

#confirm_resize_server(server_id) ⇒ Object



15
16
17
18
19
# File 'lib/fog/openstack/requests/compute/confirm_resize_server.rb', line 15

def confirm_resize_server(server_id)
  response = Excon::Response.new
  response.status = 204
  response
end

#create_flavor(attributes) ⇒ 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
74
75
76
77
78
79
80
81
# File 'lib/fog/openstack/requests/compute/create_flavor.rb', line 47

def create_flavor(attributes)
  response = Excon::Response.new
  response.status = 200
  response.headers = {
    "X-Compute-Request-Id" => "req-fdc6f99e-55a2-4ab1-8904-0892753828cf",
    "Content-Type" => "application/json",
    "Content-Length" => "356",
    "Date" => Date.new
  }
  response.body = {
    "flavor" => {
      "vcpus" => attributes[:vcpus],
      "disk" => attributes[:disk],
      "name" => attributes[:name],
      "links" => [
        {
          "href" => "http://192.168.27.100:8774/v1.1/6733e93c5f5c4eb1bcabc6902ba208d6/flavors/11",
          "rel" => "self"
        },
        {
          "href" => "http://192.168.27.100:8774/6733e93c5f5c4eb1bcabc6902ba208d6/flavors/11",
          "rel" => "bookmark"
        }
      ],
      "rxtx_factor" => attributes[:rxtx_factor] || 1.0,
      "OS-FLV-EXT-DATA:ephemeral" => attributes[:ephemeral] || 0,
      "os-flavor-access:is_public" => attributes[:is_public] || false,
      "OS-FLV-DISABLED:disabled" => attributes[:disabled] || false,
      "ram" => attributes[:ram],
      "id" => "11",
      "swap" => attributes[:swap] || ""
    }
  }
  response
end

#create_image(server_id, name, metadata = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fog/openstack/requests/compute/create_image.rb', line 20

def create_image(server_id, name, ={})
  response = Excon::Response.new
  response.status = 202

  img_id=Fog::Mock.random_numbers(6).to_s

  data = {
    'id'        => img_id,
    'server'     => {"id"=>"3", "links"=>[{"href"=>"http://nova1:8774/admin/servers/#{server_id}", "rel"=>"bookmark"}]},
    'links'     => [{"href"=>"http://nova1:8774/v1.1/admin/images/#{img_id}", "rel"=>"self"}, {"href"=>"http://nova1:8774/admin/images/#{img_id}", "rel"=>"bookmark"}],
    'metadata'  =>  || {},
    'name'      => name || "server_#{rand(999)}",
    'progress'  => 0,
    'status'    => 'SAVING',
    'minDisk'   => 0,
    'minRam'    => 0,
    'updated'   => "",
    'created'   => ""
  }
  self.data[:last_modified][:images][data['id']] = Time.now
  self.data[:images][data['id']] = data
  response.body = { 'image' => data }
  response

end

#create_key_pair(key_name, public_key = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fog/openstack/requests/compute/create_key_pair.rb', line 27

def create_key_pair(key_name, public_key = nil)
  response = Excon::Response.new
  response.status = 200
  response.headers = {
    "X-Compute-Request-Id" => "req-c373a42c-2825-4e60-8d34-99416ea850be",
    "Content-Type" => "application/json",
    "Content-Length" => "1289",
    "Date" => Date.new}
  response.body = {
    "keypair" => {
      "public_key" => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDCdAZLjljntJbLVVkNHjWFSoKen2nZbk39ZfqhZJOMdeFdz02GWBS45rcuboeGg/gozKRwsLu4N6NLPlYtbK/NapJIvgO/djBp+FQG1QZNtLPsx7j4hVJac3yISGms+Xtu4cEv6j5sFDzAgTQbWez0Z1+9qOq9ngdaoW+YClfQ== vagrant@nova\n",
      "private_key" => "-----BEGIN RSA PRIVATE KEY-----\nMIICXgIBAAKBgQDCdAZLjljn1tJbLVVkNHjWFSoKen2nZbk39ZfqhZJOMdeFdz02\nGWBS45rcuHboeGg/gozKRwsLu4N6NLPlYtbK/NapJIvgO/djBp+FQG1QZNtLPsx7\nj4hVJac3yISGms+Xtu4cEv6j5sFDzAgTQbWez0Z1+9qOq9ngdaoW+YClfQIDAQAB\nAoGBALBoT9m1vuQ82EONQf2RONqHAsfUzi/SMhEZRgOlv9AemXZkcWyl4uPvxmtd\nEcreiTystAtCHjw7lhCExXthipevUjtIAAt+b3pMn6Oyjad3IRvde6atMdjrje43\n/nftYtuXYyJTsvwEvLYqSioLQ0Nn/XDKhOpcM5tejDHOH35lAkEA+H4r7y9X521u\nIABVAezBWaT/wvdMjx5cwfyYEQjnI1bxfRIqkgoY5gDDBdVbT75UTsHHbHLORQcw\nRjRvS2zgewJBAMhT6eyMonJvHHvC5RcchcY+dWkscIKoOzeyUKMb+7tERQa9/UN2\njYb+jdM0VyL0ruLFwYtl2m34gfmhcXgIvGcCQGzKMEnjHEUBr7jq7EyPbobkqeSd\niDMQQ+PZxmmO0EK0ib0L+v881HG926PuKK/cz+Q7Cif8iznFT+ksg50t6YkCQQC9\nwfcAskqieSuS9A9LcCIrojhXctf0e+T0Ij2N89DlF4sHEuqXf/IZ4IB5gsfTfdE3\nUDnAkK9yogaEbu/r0uKbAkEAy5kl71bIqvKTKsY2mES9ziVxfftl/9UIi5LI+QHb\nmC/c6cTrGVCM71fi2GMxGgBeEea4+7xwoWTL4CxA00kmTg==\n-----END RSA PRIVATE KEY-----\n",
      "user_id" => "admin",
      "name" => key_name,
      "fingerprint" => "97:86:f4:15:68:0c:7b:a7:e5:8f:f0:bd:1f:27:65:ad"
    }
  }
  response
end

#create_security_group(name, description) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fog/openstack/requests/compute/create_security_group.rb', line 25

def create_security_group(name, description)
  tenant_id = Fog::Identity.new(:provider => 'OpenStack').current_tenant['id']
  security_group_id = Fog::Mock.random_numbers(2).to_i
  self.data[:security_groups][security_group_id] = {
    'tenant_id' => tenant_id,
    'rules'     => [],
    'id'        => security_group_id,
    'name'      => name,
    'description' => description
  }

  response = Excon::Response.new
  response.status = 200
  response.headers = {
    'X-Compute-Request-Id' => "req-#{Fog::Mock.random_hex(32)}",
    'Content-Type'   => 'application/json',
    'Content-Length' => Fog::Mock.random_numbers(3).to_s,
    'Date'           => Date.new}
  response.body = {
    'security_group' => self.data[:security_groups][security_group_id]
  }
  response
end

#create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group_id = nil) ⇒ Object



29
30
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/openstack/requests/compute/create_security_group_rule.rb', line 29

def create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group_id=nil)
  response = Excon::Response.new
  response.status = 200
  response.headers = {
    'X-Compute-Request-Id' => "req-#{Fog::Mock.random_hex(32)}",
    'Content-Type'   => 'application/json',
    'Content-Length' => Fog::Mock.random_numbers(3).to_s,
    'Date' => Date.new
  }
  rule = {
    'id' => Fog::Mock.random_numbers(2).to_i,
    'from_port'   => from_port,
    'group'       => group_id || {},
    'ip_protocol' => ip_protocol,
    'to_port'     => to_port,
    'parent_group_id' => parent_group_id,
    'ip_range' => {
      'cidr'   => cidr
    }
  }
  self.data[:security_groups][parent_group_id]['rules'].push(rule)
  response.body = {
    'security_group_rule' => rule
  }
  response
end

#create_server(name, image_ref, flavor_ref, options = {}) ⇒ Object



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
# File 'lib/fog/openstack/requests/compute/create_server.rb', line 54

def create_server(name, image_ref, flavor_ref, options = {})
  response = Excon::Response.new
  response.status = 202

  data = {
    'addresses'  => {},
    'flavor'     => {"id" => flavor_ref, "links"=>[{"href"=>"http://nova1:8774/admin/flavors/1", "rel"=>"bookmark"}]},
    'id'         => Fog::Mock.random_numbers(6).to_s,
    'image'      => {"id" => image_ref, "links"=>[{"href"=>"http://nova1:8774/admin/images/#{image_ref}", "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'   => options['metadata'] || {},
    'name'       => name || "server_#{rand(999)}",
    'accessIPv4' => options['accessIPv4'] || "",
    'accessIPv6' => options['accessIPv6'] || "",
    'progress'   => 0,
    'status'     => 'BUILD',
    'created'    => '2012-09-27T00:04:18Z',
    'updated'    => '2012-09-27T00:04:27Z',
  }

  self.data[:last_modified][:servers][data['id']] = Time.now
  self.data[:servers][data['id']] = data
  response.body = { 'server' => data.merge({'adminPass' => 'password'}) }
  response
end

#create_volume(name, description, size, options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fog/openstack/requests/compute/create_volume.rb', line 31

def create_volume(name, description, size, options={})
  response = Excon::Response.new
  response.status = 202
  response.body = {
    'volume' => {
      'id'                  => Fog::Mock.random_numbers(2),
      'display_name'        => name,
      'display_description' => description,
      'size'                => size,
      'status'              => 'creating',
      'snapshot_id'         => '4',
      'volume_type'         => nil,
      'availability_zone'   => 'nova',
      'created_at'          => Time.now,
      'attachments'          => []
    }
  }
  response
end

#create_volume_snapshot(volume_id, name, description, force = false) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fog/openstack/requests/compute/create_volume_snapshot.rb', line 27

def create_volume_snapshot(volume_id, name, description, force=false)
  response = Excon::Response.new
  response.status = 202
  response.body = {
    "snapshot"=> {
       "status"=>"creating",
       "display_name"=>name,
       "created_at"=>Time.now,
       "display_description"=>description,
       "volume_id"=>volume_id,
       "id"=>"5",
       "size"=>1
    }
  }
  response
end

#credentialsObject



237
238
239
240
241
242
243
# File 'lib/fog/openstack/compute.rb', line 237

def credentials
  { :provider                 => 'openstack',
    :openstack_auth_url       => @openstack_auth_uri.to_s,
    :openstack_auth_token     => @auth_token,
    :openstack_management_url => @openstack_management_url,
    :openstack_identity_endpoint => @openstack_identity_public_endpoint }
end

#dataObject



229
230
231
# File 'lib/fog/openstack/compute.rb', line 229

def data
  self.class.data["#{@openstack_username}-#{@openstack_tenant}"]
end

#delete_flavor(flavor_id) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/fog/openstack/requests/compute/delete_flavor.rb', line 15

def delete_flavor(flavor_id)
  response = Excon::Response.new
  response.status = 202
  response.headers = {
    "Content-Type" => "text/html; charset=UTF-8",
    "Content-Length" => "0",
    "Date" => Date.new
  }
  response
end

#delete_image(image_id) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fog/openstack/requests/compute/delete_image.rb', line 18

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 = 400
    raise(Excon::Errors.status_error({:expects => 202}, response))
  end

end

#delete_key_pair(key_name) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/openstack/requests/compute/delete_key_pair.rb', line 17

def delete_key_pair(key_name)
  response = Excon::Response.new
  response.status = 202
  response.headers = {
    "Content-Type" => "text/html; charset=UTF-8",
    "Content-Length" => "0",
    "Date" => Date.new
  }
  response.body = {}
  response
end

#delete_metadata(collection_name, parent_id, key) ⇒ Object



18
19
20
21
22
# File 'lib/fog/openstack/requests/compute/delete_metadata.rb', line 18

def (collection_name, parent_id, key)
  response = Excon::Response.new
  response.status = 204
  response
end

#delete_security_group(security_group_id) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/openstack/requests/compute/delete_security_group.rb', line 17

def delete_security_group(security_group_id)
  response = Excon::Response.new
  response.status = 202
  response.headers = {
    "Content-Type" => "text/html; charset=UTF-8",
    "Content-Length" => "0",
    "Date" => Date.new
  }
  response.body = {}
  response
end

#delete_security_group_rule(security_group_rule_id) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/openstack/requests/compute/delete_security_group_rule.rb', line 17

def delete_security_group_rule(security_group_rule_id)
  response = Excon::Response.new
  response.status = 202
  response.headers = {
    "Content-Type" => "text/html; charset=UTF-8",
    "Content-Length" => "0",
    "Date" => Date.new
  }
  response.body = {}
  response
end

#delete_server(server_id) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fog/openstack/requests/compute/delete_server.rb', line 18

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 => 204}, 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::OpenStack::NotFound
  end
end

#delete_snapshot(snapshot_id) ⇒ Object



17
18
19
20
21
# File 'lib/fog/openstack/requests/compute/delete_snapshot.rb', line 17

def delete_snapshot(snapshot_id)
  response = Excon::Response.new
  response.status = 204
  response
end

#delete_volume(volume_id) ⇒ Object



17
18
19
20
21
# File 'lib/fog/openstack/requests/compute/delete_volume.rb', line 17

def delete_volume(volume_id)
  response = Excon::Response.new
  response.status = 204
  response
end

#detach_volume(server_id, attachment_id) ⇒ Object



17
18
19
20
21
# File 'lib/fog/openstack/requests/compute/detach_volume.rb', line 17

def detach_volume(server_id, attachment_id)
  response = Excon::Response.new
  response.status = 202
  response
end

#disassociate_address(server_id, ip_address) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/fog/openstack/requests/compute/disassociate_address.rb', line 14

def disassociate_address(server_id, ip_address)
  response = Excon::Response.new
  response.status = 202
  response.headers = {
    "Content-Type" => "text/html, charset=UTF-8",
    "Content-Length" => "0",
    "Date"=> Date.new
  }
  response
end

#get_address(address_id) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fog/openstack/requests/compute/get_address.rb', line 18

def get_address(address_id)
  response = Excon::Response.new
  response.status = 200
  response.headers = {
    "X-Compute-Request-Id" => "req-d4a21158-a86c-44a6-983a-e25645907f26",
    "Content-Type" => "application/json",
    "Content-Length" => "105",
    "Date"=> Date.new
  }
  response.body = {
    "floating_ip" => {
      "instance_id" => nil,
      "ip" => "192.168.27.129",
      "fixed_ip" => nil,
      "id" => 1,
      "pool" => "nova"
    }
  }
  response
end

#get_console_output(server_id, log_length) ⇒ Object



19
20
21
22
23
# File 'lib/fog/openstack/requests/compute/get_console_output.rb', line 19

def get_console_output(server_id, log_length)
  response = Excon::Response.new
  response.status = 200
  response
end

#get_flavor_details(flavor_ref) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fog/openstack/requests/compute/get_flavor_details.rb', line 18

def get_flavor_details(flavor_ref)
  response = Excon::Response.new
  flavor = {
    '1' => { 'id' => '1', 'name' => '256 server', 'ram' => 256, 'disk' => 10, 'swap' => '1', 'vcpus' => 1, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] },
    '2' => { 'id' => '2', 'name' => '512 server', 'ram' => 512, 'disk' => 20, 'swap' => '1', 'vcpus' => 2, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] },
    '3' => { 'id' => '3', 'name' => '1GB server', 'ram' => 1024, 'disk' => 40, 'swap' => '2', 'vcpus' => 2, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] },
    '4' => { 'id' => '4', 'name' => '2GB server', 'ram' => 2048, 'disk' => 80, 'swap' => '4', 'vcpus' => 4, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] },
    '5' => { 'id' => '5', 'name' => '4GB server', 'ram' => 4096, 'disk' => 160, 'swap' => '8', 'vcpus' => 8, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] },
    '6' => { 'id' => '6', 'name' => '8GB server', 'ram' => 8192, 'disk' => 320, 'swap' => '16', 'vcpus' => 16, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] },
    '7' => { 'id' => '7', 'name' => '15.5GB server', 'ram' => 15872, 'disk' => 620, 'swap' => '32', 'vcpus' => 32, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] }
  }[flavor_ref]
  if flavor
    response.status = 200
    response.body = {
      'flavor' => flavor
    }
    response
  else
    raise Fog::Compute::OpenStack::NotFound
  end
end

#get_host_details(host) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fog/openstack/requests/compute/get_host_details.rb', line 18

def get_host_details(host)

  response = Excon::Response.new
  response.status = 200
  response.body = { "host" => [
      { "resource" => {
          "project" => "(total)",
          "memory_mb" => 64427,
          "host" => "cn28.la-1-3.morphcloud.net",
          "cpu" => 12,
          "disk_gb" => 1608
          }
      }, 
      { "resource" => {
          "project" => "(used_now)",
          "memory_mb" => 1753,
          "host" => "cn28.la-1-3.morphcloud.net",
          "cpu" => 3,
          "disk_gb" => 33
        }
      }, 
      { "resource" => {
          "project" => "(used_max)",
          "memory_mb" => 7168,
          "host" => "cn28.la-1-3.morphcloud.net",
          "cpu" => 3,
          "disk_gb" => 45
        }
      },
      { "resource" => {
          "project" => "bf8301f5164f4790889a1bc2bfb16d99",
          "memory_mb" => 5120,
          "host" => "cn28.la-1-3.morphcloud.net",
          "cpu" => 2,
          "disk_gb" => 35
        }
      },
      { "resource" => {
          "project" => "3bb4d0301c5f47d5b4d96a361fcf96f4",
          "memory_mb" => 2048,
          "host" => "cn28.la-1-3.morphcloud.net",
          "cpu" => 1,
          "disk_gb" => 10
        }
      }
    ]
  }
  response

  
end

#get_image_details(image_id) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/openstack/requests/compute/get_image_details.rb', line 18

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::OpenStack::NotFound
  end
end

#get_limitsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
# File 'lib/fog/openstack/requests/compute/get_limits.rb', line 19

def get_limits
  rate_limits = [
    { 'regex' => '.*',
      'limit' => [
        { 'next-available' => '2012-11-22T16:13:44Z',
          'unit'           => 'MINUTE',
          'verb'           => 'POST',
          'remaining'      => 9,
          'value'          => 10 },
        { 'next-available' => '2012-11-23T00:46:14Z',
          'unit'           => 'MINUTE',
          'verb'           => 'PUT',
          'remaining'      => 10,
          'value' => 10 },
        { 'next-available' => '2012-11-22T16:14:30Z',
          'unit'           => 'MINUTE',
          'verb'           => 'DELETE',
          'remaining'      => 99,
          'value'          => 100 } ],
        'uri' => '*' },
    { 'regex' => '^/servers',
      'limit' => [
        { 'next-available' => '2012-11-23T00:46:14Z',
          'unit'           => 'DAY',
          'verb'           => 'POST',
          'remaining'      => 50,
          'value'          => 50} ],
      'uri'=>'*/servers' },
    { 'regex' => '.*changes-since.*',
      'limit' => [
        { 'next-available' => '2012-11-23T00:46:14Z',
          'unit'           => 'MINUTE',
          'verb'           => 'GET',
          'remaining'      => 3,
          'value'          => 3 } ],
      'uri' => '*changes-since*' }
  ]

  absolute_limits = {
    # Max
    'maxServerMeta'            => 128,
    'maxTotalInstances'        => 10,
    'maxPersonality'           => 5,
    'maxImageMeta'             => 128,
    'maxPersonalitySize'       => 10240,
    'maxSecurityGroupRules'    => 20,
    'maxTotalKeypairs'         => 100,
    'maxSecurityGroups'        => 10,
    'maxTotalCores'            => 20,
    'maxTotalFloatingIps'      => 10,
    'maxTotalRAMSize'          => 51200,

    # Used
    'totalCoresUsed'           => -1,
    'totalRAMUsed'             => -2048,
    'totalInstancesUsed'       => -1,
    'totalSecurityGroupsUsed'  => 0,
    'totalKeyPairsUsed'        => 0
  }


  Excon::Response.new(
    :status => 200,
    :body => {
      'limits' => {
        'rate'     => rate_limits,
        'absolute' => absolute_limits }
    }
  )
end

#get_metadata(collection_name, parent_id, key) ⇒ Object



18
19
20
21
22
23
# File 'lib/fog/openstack/requests/compute/get_metadata.rb', line 18

def (collection_name, parent_id, key)
  response = Excon::Response.new
  response.status = 200
  response.body = { 'meta' => {} }
  response
end

#get_quota(tenant_id) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/fog/openstack/requests/compute/get_quota.rb', line 18

def get_quota(tenant_id)
  response = Excon::Response.new
  response.status = 200
  response.body = {
    'quota_set' => (self.data[:quota_updated] or self.data[:quota]).merge({'id' => tenant_id})
  }
  response
end

#get_quota_defaults(tenant_id) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/fog/openstack/requests/compute/get_quota_defaults.rb', line 18

def get_quota_defaults(tenant_id)
  response = Excon::Response.new
  response.status = 200
  response.body = {
    'quota_set' => self.data[:quota].merge({'id' => tenant_id})
  }
  response
end

#get_security_group(security_group_id) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fog/openstack/requests/compute/get_security_group.rb', line 17

def get_security_group(security_group_id)
  response = Excon::Response.new
  response.status = 200
  response.headers = {
    "X-Compute-Request-Id" => "req-63a90344-7c4d-42e2-936c-fd748bced1b3",
    "Content-Type" => "application/json",
    "Content-Length" => "167",
    "Date" => Date.new
  }
  response.body = {
    "security_group" => {
      "rules" => [{
        "from_port" => 44,
        "group" => {},
        "ip_protocol" => "tcp",
        "to_port" => 55,
        "parent_group_id" => 1,
        "ip_range" => {
          "cidr" => "10.10.10.10/24"
        }, "id"=>1
      }],
      "tenant_id" => "d5183375ab0343f3a0b4b05f547aefc2",
      "id"=>security_group_id,
      "name"=>"default",
      "description"=>"default"
    }
  }
  response
end

#get_server_details(server_id) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/openstack/requests/compute/get_server_details.rb', line 18

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::OpenStack::NotFound
  end
end

#get_snapshot_details(detailed = true) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fog/openstack/requests/compute/get_snapshot_details.rb', line 19

def get_snapshot_details(detailed=true)
  response = Excon::Response.new
  response.status = 200
  response.body = {
    'snapshot' => {
      'id'                 => '1',
      'display_name'        => Fog::Mock.random_letters(rand(8) + 5),
      'display_description' => Fog::Mock.random_letters(rand(12) + 10),
      'size'               => 3,
      'volume_id'           => '4',
      'status'             => 'online',
      'created_at'          => Time.now
    }
  }
  response
end

#get_usage(tenant_id, date_start, date_end) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fog/openstack/requests/compute/get_usage.rb', line 21

def get_usage(tenant_id, date_start, date_end)
    response        = Excon::Response.new
    response.status = 200
    response.body   = {"tenant_usage"=>
                        {"total_memory_mb_usage" => 0.0,
                         "total_vcpus_usage"     => 0.0,
                         "total_hours"           => 0.0,
                         "tenant_id"             => tenant_id,
                         "stop"                  => date_start,
                         "start"                 => date_end,
                         "total_local_gb_usage"  => 0.0,
                         "server_usages" =>[{
                           "hours"       => 0.0,
                           "uptime"      => 69180,
                           "local_gb"    => 0,
                           "ended_at"    => nil,
                           "name"        => "test server",
                           "tenant_id"   => tenant_id,
                           "vcpus"       => 1,
                           "memory_mb"   => 512,
                           "state"       => "active",
                           "flavor"      => "m1.tiny",
                           "started_at"  => "2012-03-05 09:11:44"
                            }
                          ]
                        }
                      }
  response
end

#get_vnc_console(server_id, console_type) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fog/openstack/requests/compute/get_vnc_console.rb', line 26

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

#get_volume_details(detailed = true) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fog/openstack/requests/compute/get_volume_details.rb', line 19

def get_volume_details(detailed=true)
  response = Excon::Response.new
  response.status = 200
  response.body = {
    'volume' => {
      'id'                  => '1',
      'display_name'        => Fog::Mock.random_letters(rand(8) + 5),
      'display_description' => Fog::Mock.random_letters(rand(12) + 10),
      'size'                => 3,
      'volume_type'         => nil,
      'snapshot_id'         => '4',
      'status'              => 'online',
      'availability_zone'   => 'nova',
      'created_at'          => Time.now,
      'attachments'         => []
    }
  }
  response
end

#list_addresses(server_id) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/openstack/requests/compute/list_addresses.rb', line 18

def list_addresses(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 = { 'addresses' => server['addresses'] }
    response
  else
    raise Fog::Compute::OpenStack::NotFound
  end
end

#list_all_addressesObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fog/openstack/requests/compute/list_all_addresses.rb', line 18

def list_all_addresses
  response = Excon::Response.new
  response.status = 200
  response.headers = {
    "X-Compute-Request-Id" => "req-d4a21158-a86c-44a6-983a-e25645907f26",
    "Content-Type" => "application/json",
    "Content-Length" => "378",
    "Date"=> Date.new
  }
  response.body = {
    "floating_ips" => [
      {
        "instance_id" => nil,
        "ip" => "192.168.27.129",
        "fixed_ip" => nil,
        "id" => 1,
        "pool" => "nova"
      },
      {
        "instance_id" => nil,
        "ip" => "192.168.27.130",
        "fixed_ip" => nil,
        "id" => 2,
        "pool" => "nova"
      },
      {
        "instance_id" => nil,
        "ip" => "192.168.27.131",
        "fixed_ip" => nil,
        "id" => 3,
        "pool" => "nova"
      },
      {
        "instance_id" => nil,
        "ip" => "192.168.27.132",
        "fixed_ip" => nil,
        "id" => 4,
        "pool" => "nova"
      }
    ]
  }
  response
end

#list_flavorsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fog/openstack/requests/compute/list_flavors.rb', line 18

def list_flavors
  response = Excon::Response.new
  response.status = 200
  response.body = {
    'flavors' => [
      { 'name' => '256 server', 'id' => '1', 'links' => ['https://itdoesntmatterwhatshere.heh'] },
      { 'name' => '512 server', 'id' => '2', 'links' => ['https://itdoesntmatterwhatshere.heh'] },
      { 'name' => '1GB server', 'id' => '3', 'links' => ['https://itdoesntmatterwhatshere.heh'] },
      { 'name' => '2GB server', 'id' => '4', 'links' => ['https://itdoesntmatterwhatshere.heh'] },
      { 'name' => '4GB server', 'id' => '5', 'links' => ['https://itdoesntmatterwhatshere.heh'] },
      { 'name' => '8GB server', 'id' => '6', 'links' => ['https://itdoesntmatterwhatshere.heh'] },
      { 'name' => '15.5GB server', 'id' => '7', 'links' => ['https://itdoesntmatterwhatshere.heh'] }
    ]
  }
  response
end

#list_flavors_detailObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fog/openstack/requests/compute/list_flavors_detail.rb', line 18

def list_flavors_detail
  response = Excon::Response.new
  response.status = 200
  response.body = {
    'flavors' => [
      { 'id' => '1', 'name' => '256 server', 'ram' => 256, 'disk' => 10, 'swap' => '1', 'vcpus' => 1, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] },
      { 'id' => '2', 'name' => '512 server', 'ram' => 512, 'disk' => 20, 'swap' => '1', 'vcpus' => 2, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] },
      { 'id' => '3', 'name' => '1GB server', 'ram' => 1024, 'disk' => 40, 'swap' => '2', 'vcpus' => 2, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] },
      { 'id' => '4', 'name' => '2GB server', 'ram' => 2048, 'disk' => 80, 'swap' => '4', 'vcpus' => 4, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] },
      { 'id' => '5', 'name' => '4GB server', 'ram' => 4096, 'disk' => 160, 'swap' => '8', 'vcpus' => 8, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] },
      { 'id' => '6', 'name' => '8GB server', 'ram' => 8192, 'disk' => 320, 'swap' => '16', 'vcpus' => 16, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] },
      { 'id' => '7', 'name' => '15.5GB server', 'ram' => 15872, 'disk' => 620, 'swap' => '32', 'vcpus' => 32, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] }
    ]
  }
  response
end

#list_hostsObject



18
19
20
21
22
23
24
25
26
# File 'lib/fog/openstack/requests/compute/list_hosts.rb', line 18

def list_hosts
  response = Excon::Response.new
  response.status = 200
  response.body = { "hosts" => [
      {"host_name" => "host.test.net", "service"=>"compute"}
    ]
  }
  response
end

#list_imagesObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/openstack/requests/compute/list_images.rb', line 18

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', 'links'].include?(key) }
  end
  response.status = [200, 203][rand(1)]
  response.body = { 'images' => images }
  response
end

#list_images_detailObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fog/openstack/requests/compute/list_images_detail.rb', line 18

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', 'minRam', 'minDisk', 'metadata', 'status', 'updated'].include?(key)}} }
  response
end

#list_key_pairsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fog/openstack/requests/compute/list_key_pairs.rb', line 17

def list_key_pairs
  response = Excon::Response.new
  response.status = 200
  response.headers = {
    "X-Compute-Request-Id" => "req-c373a42c-2825-4e60-8d34-99416ea850be",
    "Content-Type" => "application/json",
    "Content-Length" => "360",
    "Date" => Date.new}
  response.body = {
    "keypairs" => [{
      "keypair" => {
        "public_key" => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDCdAZLjln1tJbLVVkNHjWFSoKen2nZbk39ZfqhZJOMdeFdz02GWBS4rcuHboeGg/gozKRwsLu4N6NLPlYtbK/NapJIvgO/djBp+FG1QZNtLPsx7j4hVJac3yISGms+Xtu4cEv6j5sFDzAgTQbWz0Z1+9qOq9ngdaoW+YClfQ== vagrant@nova\n",
        "name" => "test_key",
        "fingerprint" => "97:86:f4:15:68:0c:7b:a7:e5:8f:f0:bd:1f:27:65:ad"
      }
    }]
  }
  response
end

#list_metadata(collection_name, parent_id) ⇒ Object



18
19
20
21
22
23
# File 'lib/fog/openstack/requests/compute/list_metadata.rb', line 18

def (collection_name, parent_id)
  response = Excon::Response.new
  response.status = 200
  response.body = {}
  response
end

#list_private_addresses(server_id) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/openstack/requests/compute/list_private_addresses.rb', line 18

def list_private_addresses(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 = { 'private' => server['addresses']['private'] }
    response
  else
    raise Fog::Compute::OpenStack::NotFound
  end
end

#list_public_addresses(server_id) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/openstack/requests/compute/list_public_addresses.rb', line 18

def list_public_addresses(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 = { 'public' => server['addresses']['public'] }
    response
  else
    raise Fog::Compute::OpenStack::NotFound
  end
end

#list_security_groupsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fog/openstack/requests/compute/list_security_groups.rb', line 21

def list_security_groups
  self.data[:security_groups] ||= [
    { "rules" => [
      { "from_port" => 44,
        "group" => {},
        "ip_protocol" => "tcp",
        "to_port" => 55,
        "parent_group_id" => 1,
        "ip_range" => {"cidr"=>"10.10.10.10/24"},
        "id" => Fog::Mock.random_numbers(2).to_i
      },
      { "from_port" => 2,
        "group" => {},
        "ip_protocol" => "tcp",
        "to_port" => 3,
        "parent_group_id" => 1,
        "ip_range" => {"cidr"=>"10.10.10.10/24"},
        "id" => Fog::Mock.random_numbers(2).to_i
      } ],
      "tenant_id" => @openstack_tenant,
      "id" => Fog::Mock.random_numbers(2).to_i,
      "name" => "default",
      "description" => "default"
    },
    {
      "rules" => [
      { "from_port" => 44,
        "group" => {},
        "ip_protocol" => "tcp",
        "to_port" => 55,
        "parent_group_id" => 2,
        "ip_range" => { "cidr"=>"10.10.10.10/24" },
        "id"=> Fog::Mock.random_numbers(2).to_i
      } ],
    "tenant_id" => @openstack_tenant,
    "id" => Fog::Mock.random_numbers(2).to_i,
    "name" => "test",
    "description" => "this is a test"
    }
  ]
  Excon::Response.new(
    :body     => { 'security_groups' => self.data[:security_groups].values },
    :headers  => {
      "X-Compute-Request-Id" => "req-#{Fog::Mock.random_base64(36)}",
      "Content-Type" => "application/json",
      "Date" => Date.new
    },
    :status   => 200
  )
end

#list_serversObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/openstack/requests/compute/list_servers.rb', line 22

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'].include?(key) }
  end
  response.status = [200, 203][rand(1)]
  response.body = { 'servers' => servers }
  response
end

#list_servers_detail(filters = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fog/openstack/requests/compute/list_servers_detail.rb', line 23

def list_servers_detail(filters = {})
  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

#list_snapshots(detailed = true) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/fog/openstack/requests/compute/list_snapshots.rb', line 20

def list_snapshots(detailed=true)
  response = Excon::Response.new
  response.status = 200
  response.body = {
    'snapshots' => [get_snapshot_details.body["snapshot"]]
  }
  response
end

#list_tenantsObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/openstack/requests/compute/list_tenants.rb', line 20

def list_tenants
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = {
    'tenants' => [
      {'id' => '1',
       'description' => 'Has access to everything',
       'enabled' => true,
       'name' => 'admin'},
      {'id' => '2',
       'description' => 'Normal tenant',
       'enabled' => true,
       'name' => 'default'},
      {'id' => '3',
       'description' => 'Disabled tenant',
       'enabled' => false,
       'name' => 'disabled'}
    ]
  }
  response
end

#list_usages(date_start = nil, date_end = nil, detailed = false) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fog/openstack/requests/compute/list_usages.rb', line 23

def list_usages(date_start = nil, date_end = nil, detailed=false)
  params = Hash.new
  response        = Excon::Response.new
  response.status = 200
  response.body   = {"tenant_usages"=>[{
                       "total_memory_mb_usage" => 0.00036124444444444445,
                       "total_vcpus_usage"     => 7.055555555555556e-07,
                       "start"                 => "2012-03-06 05:05:56.349001", 
                       "tenant_id"             => "b97c8abba0c44a0987c63b858a4823e5",
                       "stop"                  => "2012-03-06 05:05:56.349255", 
                       "total_hours"           => 7.055555555555556e-07,
                       "total_local_gb_usage"  => 0.0
                        }
                      ]
                    }
  response
end

#list_volumes(detailed = true) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fog/openstack/requests/compute/list_volumes.rb', line 19

def list_volumes(detailed=true)
  response = Excon::Response.new
  response.status = 200
  self.data[:volumes] ||= [
    { "status" => "available",
      "display_description" => "",
      "availability_zone" => "nova",
      "display_name" => "test 1",
      "attachments" => [{}],
      "volume_type" => nil,
      "snapshot_id" => nil,
      "size" => 1,
      "id" => Fog::Mock.random_hex(32),
      "created_at" => Time.now },
    { "status" => "available",
      "display_description" => "",
      "availability_zone" => "nova",
      "display_name" => "test 2",
      "attachments" => [{}],
      "volume_type" => nil,
      "snapshot_id" => nil,
      "size" => 1,
      "id" => Fog::Mock.random_hex(32),
      "created_at" => Time.now }
    ]
  response.body = { 'volumes' => self.data[:volumes] }
  response
end

#live_migrate_server(server_id, host, block_migration, disk_over_commit) ⇒ Object



22
23
24
25
26
# File 'lib/fog/openstack/requests/compute/live_migrate_server.rb', line 22

def live_migrate_server(server_id, host, block_migration, disk_over_commit)
  response = Excon::Response.new
  response.status = 202
  response
end

#migrate_server(server_id) ⇒ Object



15
16
17
18
19
# File 'lib/fog/openstack/requests/compute/migrate_server.rb', line 15

def migrate_server(server_id)
  response = Excon::Response.new
  response.status = 202
  response
end

#pause_server(server_id) ⇒ Object



18
19
20
# File 'lib/fog/openstack/requests/compute/pause_server.rb', line 18

def pause_server(server_id)
  true
end

#reboot_server(server_id, type = 'SOFT') ⇒ Object



15
16
17
18
19
# File 'lib/fog/openstack/requests/compute/reboot_server.rb', line 15

def reboot_server(server_id, type = 'SOFT')
  response = Excon::Response.new
  response.status = 202
  response
end

#rebuild_server(server_id, image_ref, name, admin_pass = nil, metadata = nil, personality = nil) ⇒ Object



22
23
24
25
26
# File 'lib/fog/openstack/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
end

#release_address(address_id) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/openstack/requests/compute/release_address.rb', line 18

def release_address(address_id)
  response = Excon::Response.new
  response.status = 202
  response.headers = {
    "Content-Type" => "text/html; charset=UTF-8",
    "Content-Length" => "0",
    "Date" => Date.new
  }
  response.body = {}
  response
end

#remove_fixed_ip(server_id, network_id) ⇒ Object



23
24
25
# File 'lib/fog/openstack/requests/compute/remove_fixed_ip.rb', line 23

def remove_fixed_ip(server_id, network_id)
  true
end

#rescue_server(server_id) ⇒ Object



18
19
20
# File 'lib/fog/openstack/requests/compute/rescue_server.rb', line 18

def rescue_server(server_id)
  true
end

#reset_dataObject



233
234
235
# File 'lib/fog/openstack/compute.rb', line 233

def reset_data
  self.class.data.delete("#{@openstack_username}-#{@openstack_tenant}")
end

#reset_server_state(server_id, status) ⇒ Object



15
16
17
18
19
# File 'lib/fog/openstack/requests/compute/reset_server_state.rb', line 15

def reset_server_state(server_id, status)
  response = get_server_details(server_id)
  response.body['server']['status'] = status.upcase
  response
end

#resize_server(server_id, flavor_ref) ⇒ Object



15
16
17
18
19
# File 'lib/fog/openstack/requests/compute/resize_server.rb', line 15

def resize_server(server_id, flavor_ref)
  response = Excon::Response.new
  response.status = 202
  response
end

#resume_server(server_id) ⇒ Object



18
19
20
# File 'lib/fog/openstack/requests/compute/resume_server.rb', line 18

def resume_server(server_id)
  true
end

#revert_resized_server(server_id) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/openstack/requests/compute/revert_resize_server.rb', line 15

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

#server_actions(server_id) ⇒ Object



21
22
23
# File 'lib/fog/openstack/requests/compute/server_actions.rb', line 21

def server_actions(server_id)
  Array.new
end

#server_diagnostics(server_id) ⇒ Object



20
21
# File 'lib/fog/openstack/requests/compute/server_diagnostics.rb', line 20

def server_diagnostics(server_id)
end

#set_metadata(collection_name, parent_id, metadata = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fog/openstack/requests/compute/set_metadata.rb', line 20

def (collection_name, parent_id,  = {})

  if collection_name == "images" then
    if not list_images_detail.body['images'].detect {|_| _['id'] == parent_id}
      raise Fog::Compute::OpenStack::NotFound
    end 
  end

  if collection_name == "servers" then
    if not list_servers_detail.body['servers'].detect {|_| _['id'] == parent_id}
      raise Fog::Compute::OpenStack::NotFound
    end 
  end

  response = Excon::Response.new
  response.body = { "metadata" =>  }
  response.status = 200
  response

end

#set_tenant(tenant) ⇒ Object



14
15
16
# File 'lib/fog/openstack/requests/compute/set_tenant.rb', line 14

def set_tenant(tenant)
  true
end

#suspend_server(server_id) ⇒ Object



18
19
20
# File 'lib/fog/openstack/requests/compute/suspend_server.rb', line 18

def suspend_server(server_id)
  true
end

#unpause_server(server_id) ⇒ Object



18
19
20
# File 'lib/fog/openstack/requests/compute/unpause_server.rb', line 18

def unpause_server(server_id)
  true
end

#update_metadata(collection_name, parent_id, metadata = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/openstack/requests/compute/update_metadata.rb', line 20

def (collection_name, parent_id,  = {})

  if collection_name == "images" then
    if not list_images_detail.body['images'].detect {|_| _['id'] == parent_id}
      raise Fog::Compute::OpenStack::NotFound
    end 
  end

  if collection_name == "servers" then
    if not list_servers_detail.body['servers'].detect {|_| _['id'] == parent_id}
      raise Fog::Compute::OpenStack::NotFound
    end 
  end

  #FIXME join w/ existing metadata here
  response = Excon::Response.new
  response.body = { "metadata" =>  }
  response.status = 200
  response

end

#update_quota(tenant_id, options = {}) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/fog/openstack/requests/compute/update_quota.rb', line 20

def update_quota(tenant_id, options = {})
  self.data[:quota_updated] = self.data[:quota].merge options

  response = Excon::Response.new
  response.status = 200
  response.body = { 'quota_set' => self.data[:quota_updated] }
  response
end

#update_server(server_id, options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fog/openstack/requests/compute/update_server.rb', line 19

def update_server(server_id, options)
  response = Excon::Response.new
  if server = list_servers_detail.body['servers'].detect {|_| _['id'] == server_id}
    if options['name']
      server['name'] = options['name']
    end
    response.status = 200
    response
  else
    raise Fog::Compute::OpenStack::NotFound
  end
end