class Fog::Compute::OpenStack::Mock

Public Class Methods

data() click to toggle source
# File lib/fog/openstack/compute.rb, line 160
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'     => []
        }
      },
      :servers => {},
      :key_pairs => {},
      :security_groups => {},
      :addresses => {}
    }
  end
end
new(options={}) click to toggle source
# File lib/fog/openstack/compute.rb, line 195
def initialize(options={})
  @openstack_username = options[:openstack_username]
  @openstack_tenant   = options[:openstack_tenant]
end
reset() click to toggle source
# File lib/fog/openstack/compute.rb, line 191
def self.reset
  @data = nil
end

Public Instance Methods

add_fixed_ip(server_id, network_id) click to toggle source
# File lib/fog/openstack/requests/compute/add_fixed_ip.rb, line 23
def add_fixed_ip(server_id, network_id)
  true
end
allocate_address() click to toggle source
# 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) click to toggle source
# 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
change_server_password(server_id, admin_password) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/fog/openstack/requests/compute/create_flavor.rb, line 46
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[:disc],
      "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,
      "OS-FLV-EXT-DATA:ephemeral" => attributes[:ephemeral] || 0,
      "ram" => attributes[:ram],
      "id" => 11,
      "swap" => attributes[:swap] || ""
    }
  }
  response
end
create_image(server_id, name, metadata={}) click to toggle source
# File lib/fog/openstack/requests/compute/create_image.rb, line 20
def create_image(server_id, name, metadata={})
  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'  => 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) click to toggle source
# 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) click to toggle source
# File lib/fog/openstack/requests/compute/create_security_group.rb, line 25
def create_security_group(name, description)
  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" => "139",
    "Date" => Date.new}
  response.body = {
    "security_groups" => [{
      "rules" => [],
      "tenant_id" => "d5183375ab0343f3a0b4b05f547aefc2",
      "id" => 999,
      "name" => name,
      "description" => description
    }]
  }
  response
end
create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group_id=nil) click to toggle source
# 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-63a90344-7c4d-42e2-936c-fd748bced1b3",
    "Content-Type" => "application/json",
    "Content-Length" => "163",
    "Date" => Date.new
  }
  response.body = {
    "security_group_rule" => {
      "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
      },
      "id"=>1
    }
  }
  response
end
create_server(name, image_ref, flavor_ref, options = {}) click to toggle source
# File lib/fog/openstack/requests/compute/create_server.rb, line 44
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'
  }

  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={}) click to toggle source
# 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),
      'displayName'        => name,
      'displayDescription' => description,
      'size'               => size,
      'status'             => 'creating',
      'snapshotId'         => '4',
      'volumeType'         => nil,
      'availabilityZone'   => 'nova',
      'createdAt'          => Time.now,
      'attchments'         => []
    }
  }
  response
end
credentials() click to toggle source
# File lib/fog/openstack/compute.rb, line 208
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
data() click to toggle source
# File lib/fog/openstack/compute.rb, line 200
def data
  self.class.data["#{@openstack_username}-#{@openstack_tenant}"]
end
delete_flavor(flavor_id) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/fog/openstack/requests/compute/delete_metadata.rb, line 18
def delete_metadata(collection_name, parent_id, key)
  response = Excon::Response.new
  response.status = 204
  response
end
delete_security_group(security_group_id) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
disassociate_address(server_id, ip_address) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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, 'links' => [] },
    '2' => { 'id' => '2', 'name' => '512 server', 'ram' => 512, 'disk' => 20, 'links' => [] },
    '3' => { 'id' => '3', 'name' => '1GB server', 'ram' => 1024, 'disk' => 40, 'links' => [] },
    '4' => { 'id' => '4', 'name' => '2GB server', 'ram' => 2048, 'disk' => 80, 'links' => [] },
    '5' => { 'id' => '5', 'name' => '4GB server', 'ram' => 4096, 'disk' => 160, 'links' => [] },
    '6' => { 'id' => '6', 'name' => '8GB server', 'ram' => 8192, 'disk' => 320, 'links' => [] },
    '7' => { 'id' => '7', 'name' => '15.5GB server', 'ram' => 15872, 'disk' => 620, '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) click to toggle source
# 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) click to toggle source
# 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_metadata(collection_name, parent_id, key) click to toggle source
# File lib/fog/openstack/requests/compute/get_metadata.rb, line 18
def get_metadata(collection_name, parent_id, key)
  response = Excon::Response.new
  response.status = 200
  response.body = { 'meta' => {} }
  response
end
get_quota(tenant_id) click to toggle source
# 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' => {
      'metadata_items' => 128,
      'injected_file_content_bytes' => 10240,
      'injected_files' => 5,
      'gigabytes' => 1000,
      'ram' => 51200,
      'floating_ips' => 10,
      'instances' => 10,
      'volumes' => 10,
      'cores' => 20,
      'id' => tenant_id
    }
  }
  response
end
get_quota_defaults(tenant_id) click to toggle source
# 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' => {
      'metadata_items' => 128,
      'injected_file_content_bytes' => 10240,
      'injected_files' => 5,
      'gigabytes' => 1000,
      'ram' => 51200,
      'floating_ips' => 10,
      'instances' => 10,
      'volumes' => 10,
      'cores' => 20,
      'id' => tenant_id
    }
  }
  response
end
get_security_group(security_group_id) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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',
      'displayName'        => Fog::Mock.random_letters(rand(8) + 5),
      'displayDescription' => Fog::Mock.random_letters(rand(12) + 10),
      'size'               => 3,
      'volumeId'           => '4',
      'status'             => 'online',
      'createdAt'          => Time.now
    }
  }
  response
end
get_usage(tenant_id, date_start, date_end) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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',
      'displayName'        => Fog::Mock.random_letters(rand(8) + 5),
      'displayDescription' => Fog::Mock.random_letters(rand(12) + 10),
      'size'               => 3,
      'volumeType'         => nil,
      'snapshotId'         => '4',
      'status'             => 'online',
      'availabilityZone'   => 'nova',
      'createdAt'          => Time.now,
      'attchments'         => []
    }
  }
  response
end
list_addresses(server_id) click to toggle source
# 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_addresses() click to toggle source
# 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_flavors() click to toggle source
# 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' => [] },
      { 'name' => '512 server', 'id' => '2', 'links' => [] },
      { 'name' => '1GB server', 'id' => '3', 'links' => [] },
      { 'name' => '2GB server', 'id' => '4', 'links' => [] },
      { 'name' => '4GB server', 'id' => '5', 'links' => [] },
      { 'name' => '8GB server', 'id' => '6', 'links' => [] },
      { 'name' => '15.5GB server', 'id' => '7', 'links' => [] }
    ]
  }
  response
end
list_flavors_detail() click to toggle source
# 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' => [
      { 'name' => '256 server', 'id' => '1', 'ram' => 256, 'disk' => 10, 'links' => [] },
      { 'name' => '512 server', 'id' => '2', 'ram' => 512, 'disk' => 20, 'links' => [] },
      { 'name' => '1GB server', 'id' => '3', 'ram' => 1024, 'disk' => 40, 'links' => [] },
      { 'name' => '2GB server', 'id' => '4', 'ram' => 2048, 'disk' => 80, 'links' => [] },
      { 'name' => '4GB server', 'id' => '5', 'ram' => 4096, 'disk' => 160, 'links' => [] },
      { 'name' => '8GB server', 'id' => '6', 'ram' => 8192, 'disk' => 320, 'links' => [] },
      { 'name' => '15.5GB server', 'id' => '7', 'ram' => 15872, 'disk' => 620, 'links' => [] }
    ]
  }
  response
end
list_hosts() click to toggle source
# 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_images() click to toggle source
# 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_detail() click to toggle source
# 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_pairs() click to toggle source
# 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) click to toggle source
# File lib/fog/openstack/requests/compute/list_metadata.rb, line 18
def list_metadata(collection_name, parent_id)
  response = Excon::Response.new
  response.status = 200
  response.body = {}
  response
end
list_private_addresses(server_id) click to toggle source
# 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) click to toggle source
# 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_groups() click to toggle source
# File lib/fog/openstack/requests/compute/list_security_groups.rb, line 17
def list_security_groups
  response = Excon::Response.new
  response.status = 200
  response.headers = {
    "X-Compute-Request-Id" => "req-#{Fog::Mock.random_base64(36)}",
    "Content-Type" => "application/json",
    "Date" => Date.new
  }
  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_base64(36)
      },
      { "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_base64(36)
      } ],
      "tenant_id" => @openstack_tenant,
      "id" => Fog::Mock.random_base64(36),
      "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_base64(36)
      } ],
    "tenant_id" => @openstack_tenant,
    "id" => Fog::Mock.random_base64(36),
    "name" => "test",
    "description" => "this is a test"
    }
  ]
  response.body = { 'security_groups' => self.data[:security_groups] }
  response
end
list_servers() click to toggle source
# File lib/fog/openstack/requests/compute/list_servers.rb, line 18
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() click to toggle source
# File lib/fog/openstack/requests/compute/list_servers_detail.rb, line 18
def list_servers_detail
  response = Excon::Response.new

  servers = self.data[:servers].values
  for server in servers
    case server['status']
    when 'BUILD'
      if Time.now - self.data[:last_modified][:servers][server['id']] > Fog::Mock.delay * 2
        server['status'] = 'ACTIVE'
      end
    end
  end

  response.status = [200, 203][rand(1)]
  response.body = { 'servers' => servers }
  response
end
list_snapshots(detailed=true) click to toggle source
# 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_tenants() click to toggle source
# File lib/fog/openstack/requests/compute/list_tenants.rb, line 19
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) click to toggle source
# 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) click to toggle source
# 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",
      "displayDescription" => "",
      "availabilityZone" => "nova",
      "displayName" => "test 1",
      "attachments" => [{}],
      "volumeType" => nil,
      "snapshotId" => nil,
      "size" => 1,
      "id" => 6,
      "createdAt" => "2012-03-30 05:31:00.655058",
      "metadata" => {} },
    { "status" => "available",
      "displayDescription" => "",
      "availabilityZone" => "nova",
      "displayName" => "test 2",
      "attachments" => [{}],
      "volumeType" => nil,
      "snapshotId" => nil,
      "size" => 1,
      "id" => 8,
      "createdAt" => "2012-03-30 16:14:55.582717",
      "metadata" => {} }
    ]
  response.body = { 'volumes' => self.data[:volumes] }
  response
end
live_migrate_server(server_id, host, block_migration, disk_over_commit) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/fog/openstack/requests/compute/pause_server.rb, line 18
def pause_server(server_id)
  true
end
reboot_server(server_id, type = 'SOFT') click to toggle source
# 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) click to toggle source
# File lib/fog/openstack/requests/compute/rebuild_server.rb, line 22
def rebuild_server(server_id, image_ref, name, admin_pass=nil, metadata=nil, personality=nil)
  response = get_server_details(server_id)
  response.body['server']['status'] = "REBUILD"
  response
end
remove_fixed_ip(server_id, network_id) click to toggle source
# 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) click to toggle source
# File lib/fog/openstack/requests/compute/rescue_server.rb, line 18
def rescue_server(server_id)
  true
end
reset_data() click to toggle source
# File lib/fog/openstack/compute.rb, line 204
def reset_data
  self.class.data.delete("#{@openstack_username}-#{@openstack_tenant}")
end
resize_server(server_id, flavor_ref) click to toggle source
# 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) click to toggle source
# File lib/fog/openstack/requests/compute/resume_server.rb, line 18
def resume_server(server_id)
  true
end
revert_resized_server(server_id) click to toggle source
# 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) click to toggle source
# File lib/fog/openstack/requests/compute/server_actions.rb, line 21
def server_actions(server_id)
  Array.new
end
server_diagnostics(server_id) click to toggle source
# File lib/fog/openstack/requests/compute/server_diagnostics.rb, line 20
def server_diagnostics(server_id)
end
set_metadata(collection_name, parent_id, metadata = {}) click to toggle source
# File lib/fog/openstack/requests/compute/set_metadata.rb, line 20
def set_metadata(collection_name, parent_id, metadata = {})

  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" => metadata }
  response.status = 200
  response

end
set_tenant(tenant) click to toggle source
# File lib/fog/openstack/requests/compute/set_tenant.rb, line 14
def set_tenant(tenant)
  true
end
suspend_server(server_id) click to toggle source
# File lib/fog/openstack/requests/compute/suspend_server.rb, line 18
def suspend_server(server_id)
  true
end
unpause_server(server_id) click to toggle source
# 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 = {}) click to toggle source
# File lib/fog/openstack/requests/compute/update_metadata.rb, line 20
def update_metadata(collection_name, parent_id, metadata = {})

  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" => metadata }
  response.status = 200
  response

end
update_quota(tenant_id, options = {}) click to toggle source
# File lib/fog/openstack/requests/compute/update_quota.rb, line 20
def update_quota(tenant_id, options = {})
  defaults = {
    'metadata_items' => 128,
    'injected_file_content_bytes' => 10240,
    'injected_files' => 5,
    'gigabytes' => 1000,
    'ram' => 51200,
    'floating_ips' => 10,
    'instances' => 10,
    'volumes' => 10,
    'cores' => 20,
    'id' => tenant_id
  }

  defaults.merge options

  response = Excon::Response.new
  response.status = 200
  response.body = { 'quota_set' => options }
  response
end
update_server(server_id, options) click to toggle source
# 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