class Fog::Baremetal::OpenStack::Mock

Driver requests

request :get_vendor_passthru_methods

Public Class Methods

data() click to toggle source
# File lib/fog/openstack/baremetal.rb, line 82
def self.data
  @data ||= Hash.new do |hash, key|
    chassis_uuid  = Fog::UUID.uuid
    instance_uuid  = Fog::UUID.uuid
    node_uuid = Fog::UUID.uuid

    hash[key] = {
      :chassis_collection => [
        {
          "created_at" => "2000-01-01T12:00:00",
          "description" => "Sample chassis",
          "extra" => {},
          "links" => [
            {
              "href" => "http://localhost:6385/v1/chassis/eaaca217-e7d8-47b4-bb41-3f99f20eed89",
              "rel" => "self"
            },
            {
              "href" => "http://localhost:6385/chassis/eaaca217-e7d8-47b4-bb41-3f99f20eed89",
              "rel" => "bookmark"
            }
          ],
          "nodes" => [
            {
              "href" => "http://localhost:6385/v1/chassis/eaaca217-e7d8-47b4-bb41-3f99f20eed89/nodes",
              "rel" => "self"
            },
            {
              "href" => "http://localhost:6385/chassis/eaaca217-e7d8-47b4-bb41-3f99f20eed89/nodes",
              "rel" => "bookmark"
            }
          ],
          "updated_at" => "2000-01-01T12:00:00",
          "uuid" => chassis_uuid
          }
        ],
      :drivers => [
        {
          "hosts" => [
            "fake-host"
          ],
          "name" => "sample-driver"
        }
      ],
      :nodes => [{
        "chassis_uuid" => chassis_uuid,
        "console_enabled" => false,
        "created_at" => "2000-01-01T12:00:00",
        "driver" => "sample-driver",
        "driver_info" => {},
        "extra" => {},
        "instance_info" => {},
        "instance_uuid" => instance_uuid,
        "last_error" => nil,
        "links" => [
          {
            "href" => "http://localhost:6385/v1/nodes/1be26c0b-03f2-4d2e-ae87-c02d7f33c123",
            "rel" => "self"
          },
          {
            "href" => "http://localhost:6385/nodes/1be26c0b-03f2-4d2e-ae87-c02d7f33c123",
            "rel" => "bookmark"
          }
        ],
        "maintenance" => false,
        "maintenance_reason" => nil,
        "ports" => [
          {
            "href" => "http://localhost:6385/v1/nodes/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/ports",
            "rel" => "self"
          },
          {
            "href" => "http://localhost:6385/nodes/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/ports",
            "rel" => "bookmark"
          }
        ],
        "power_state" => "power on",
        "properties" => {
          "cpus" => "1",
          "local_gb" => "10",
          "memory_mb" => "1024"
        },
        "provision_state" => "active",
        "provision_updated_at" => "2000-01-01T12:00:00",
        "reservation" => nil,
        "target_power_state" => nil,
        "target_provision_state" => nil,
        "updated_at" => "2000-01-01T12:00:00",
        "uuid" => node_uuid
      }],
      :ports => [{
        "address" => "fe:54:00:77:07:d9",
        "created_at" => "2014-12-23T19:35:30.734116",
        "extra" => {
          "foo" => "bar"
        },
        "links" => [
          {
            "href" => "http://localhost:6385/v1/ports/27e3153e-d5bf-4b7e-b517-fb518e17f34c",
            "rel" => "self"
          },
          {
            "href" => "http://localhost:6385/ports/27e3153e-d5bf-4b7e-b517-fb518e17f34c",
            "rel" => "bookmark"
          }
        ],
        "node_uuid" => "7ae81bb3-dec3-4289-8d6c-da80bd8001ae",
        "updated_at" => "2014-12-23T19:35:30.734119",
        "uuid" => "27e3153e-d5bf-4b7e-b517-fb518e17f34c"
      }]
    }
  end
end
new(options={}) click to toggle source
# File lib/fog/openstack/baremetal.rb, line 200
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 = 9292
  management_url.path = '/v1'
  @openstack_management_url = management_url.to_s

  @data ||= { :users => {} }
  unless @data[:users].find {|u| u['name'] == options[:openstack_username]}
    id = Fog::Mock.random_numbers(6).to_s
    @data[:users][id] = {
      'id'       => id,
      'name'     => options[:openstack_username],
      'email'    => "#{options[:openstack_username]}@mock.com",
      'tenantId' => Fog::Mock.random_numbers(6).to_s,
      'enabled'  => true
    }
  end
end
reset() click to toggle source
# File lib/fog/openstack/baremetal.rb, line 196
def self.reset
  @data = nil
end

Public Instance Methods

create_chassis(attributes) click to toggle source
# File lib/fog/openstack/requests/baremetal/create_chassis.rb, line 29
def create_chassis(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 =  self.data[:chassis_collection].first
  response
end
create_node(attributes) click to toggle source
# File lib/fog/openstack/requests/baremetal/create_node.rb, line 39
def create_node(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 =  self.data[:nodes].first
  response
end
create_port(attributes) click to toggle source
# File lib/fog/openstack/requests/baremetal/create_port.rb, line 31
def create_port(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 =  self.data[:ports].first
  response
end
credentials() click to toggle source
# File lib/fog/openstack/baremetal.rb, line 234
def credentials
  { :provider                 => 'openstack',
    :openstack_auth_url       => @openstack_auth_uri.to_s,
    :openstack_auth_token     => @auth_token,
    :openstack_region         => @openstack_region,
    :openstack_management_url => @openstack_management_url }
end
data() click to toggle source
# File lib/fog/openstack/baremetal.rb, line 226
def data
  self.class.data[@openstack_username]
end
delete_chassis(chassis_uuid) click to toggle source
# File lib/fog/openstack/requests/baremetal/delete_chassis.rb, line 17
def delete_chassis(chassis_uuid)
  response = Excon::Response.new
  response.status = 200
  response
end
delete_node(node_uuid) click to toggle source
# File lib/fog/openstack/requests/baremetal/delete_node.rb, line 17
def delete_node(node_uuid)
  response = Excon::Response.new
  response.status = 200
  response
end
delete_port(port_uuid) click to toggle source
# File lib/fog/openstack/requests/baremetal/delete_port.rb, line 17
def delete_port(port_uuid)
  response = Excon::Response.new
  response.status = 200
  response
end
get_chassis(chassis_uuid) click to toggle source
# File lib/fog/openstack/requests/baremetal/get_chassis.rb, line 15
def get_chassis(chassis_uuid)
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = self.data[:chassis_collection].first
  response
end
get_driver(driver_name) click to toggle source
# File lib/fog/openstack/requests/baremetal/get_driver.rb, line 15
def get_driver(driver_name)
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = self.data[:drivers].first
  response
end
get_driver_properties(driver_name) click to toggle source
# File lib/fog/openstack/requests/baremetal/get_driver_properties.rb, line 17
def get_driver_properties(driver_name)
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = {
    "pxe_deploy_ramdisk" => "UUID (from Glance) of the ramdisk.",
    "ipmi_transit_address" => "transit address for bridged request.",
    "ipmi_terminal_port" => "node's UDP port to connect to.",
    "ipmi_target_channel" => "destination channel for bridged request.",
    "ipmi_transit_channel" => "transit channel for bridged request.",
    "ipmi_local_address" => "local IPMB address for bridged requests. ",
    "ipmi_username" => "username; default is NULL user. Optional.",
    "ipmi_address" => "IP address or hostname of the node. Required.",
    "ipmi_target_address" => "destination address for bridged request.",
    "ipmi_password" => "password. Optional.",
    "pxe_deploy_kernel" => "UUID (from Glance) of the deployment kernel.",
    "ipmi_priv_level" => "privilege level; default is ADMINISTRATOR. ",
    "ipmi_bridging" => "bridging_type."
  }
  response
end
get_node(node_id) click to toggle source
# File lib/fog/openstack/requests/baremetal/get_node.rb, line 15
def get_node(node_id)
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = self.data[:nodes].first
  response
end
get_port(port_id) click to toggle source
# File lib/fog/openstack/requests/baremetal/get_port.rb, line 15
def get_port(port_id)
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = self.data[:ports].first
  response
end
list_chassis(parameters=nil) click to toggle source
# File lib/fog/openstack/requests/baremetal/list_chassis.rb, line 22
def list_chassis(parameters=nil)
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = {
    "chassis" => [
      {
        "description" => "Sample chassis",
        "links" => [
            {
                "href" => "http =>//localhost:6385/v1/chassis/eaaca217-e7d8-47b4-bb41-3f99f20eed89",
                "rel" => "self"
            },
            {
                "href" => "http =>//localhost:6385/chassis/eaaca217-e7d8-47b4-bb41-3f99f20eed89",
                "rel" => "bookmark"
            }
        ],
        "uuid" => Fog::UUID.uuid
      }
    ]
  }
  response
end
list_chassis_detailed(parameters=nil) click to toggle source
# File lib/fog/openstack/requests/baremetal/list_chassis_detailed.rb, line 22
def list_chassis_detailed(parameters=nil)
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = { "chassis" => self.data[:chassis_collection] }
  response
end
list_drivers() click to toggle source
# File lib/fog/openstack/requests/baremetal/list_drivers.rb, line 15
def list_drivers
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = { "drivers" => self.data[:drivers] }
  response
end
list_nodes(parameters=nil) click to toggle source
# File lib/fog/openstack/requests/baremetal/list_nodes.rb, line 22
def list_nodes(parameters=nil)
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = {
    "nodes" => [{
      "instance_uuid"    => Fog::UUID.uuid,
      "maintenance"      => false,
      "power_state"      => "power on",
      "provision_state"  => "active",
      "uuid"             => Fog::UUID.uuid,
      "links"            => []
    }]
  }
  response
end
list_nodes_detailed(parameters=nil) click to toggle source
# File lib/fog/openstack/requests/baremetal/list_nodes_detailed.rb, line 22
def list_nodes_detailed(parameters=nil)
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = { "nodes" => self.data[:nodes] }
  response
end
list_ports(parameters=nil) click to toggle source
# File lib/fog/openstack/requests/baremetal/list_ports.rb, line 22
def list_ports(parameters=nil)
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = {
    "ports" => [
      {
        "address" => "fe:54:00:77:07:d9",
        "links" => [
          {
            "href" => "http://localhost:6385/v1/ports/27e3153e-d5bf-4b7e-b517-fb518e17f34c",
            "rel" => "self"
          },
          {
            "href" => "http://localhost:6385/ports/27e3153e-d5bf-4b7e-b517-fb518e17f34c",
            "rel" => "bookmark"
          }
        ],
        "uuid" => Fog::UUID.uuid
      }
    ]
  }
  response
end
list_ports_detailed(parameters=nil) click to toggle source
# File lib/fog/openstack/requests/baremetal/list_ports_detailed.rb, line 22
def list_ports_detailed(parameters=nil)
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = { "ports" => self.data[:ports] }
  response
end
patch_chassis(chassis_uuid, patch) click to toggle source
# File lib/fog/openstack/requests/baremetal/patch_chassis.rb, line 26
def patch_chassis(chassis_uuid, patch)
  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 =  self.data[:chassis_collection].first
  response
end
patch_node(node_uuid, patch) click to toggle source
# File lib/fog/openstack/requests/baremetal/patch_node.rb, line 26
def patch_node(node_uuid, patch)
  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 =  self.data[:nodes].first
  response
end
patch_port(port_uuid, patch) click to toggle source
# File lib/fog/openstack/requests/baremetal/patch_port.rb, line 26
def patch_port(port_uuid, patch)
  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 =  self.data[:ports].first
  response
end
reset_data() click to toggle source
# File lib/fog/openstack/baremetal.rb, line 230
def reset_data
  self.class.data.delete(@openstack_username)
end