class Fog::OpenStack::Baremetal::Mock

Driver requests

request :get_vendor_passthru_methods

Public Class Methods

data() click to toggle source
# File lib/fog/openstack/baremetal.rb, line 86
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 204
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 200
def self.reset
  @data = nil
end

Public Instance Methods

create_chassis(_attributes) click to toggle source
# File lib/fog/openstack/baremetal/requests/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 = data[:chassis_collection].first
  response
end
create_node(_attributes) click to toggle source
# File lib/fog/openstack/baremetal/requests/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 = data[:nodes].first
  response
end
create_port(_attributes) click to toggle source
# File lib/fog/openstack/baremetal/requests/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 = data[:ports].first
  response
end
credentials() click to toggle source
# File lib/fog/openstack/baremetal.rb, line 238
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 230
def data
  self.class.data[@openstack_username]
end
delete_chassis(_chassis_uuid) click to toggle source
# File lib/fog/openstack/baremetal/requests/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/baremetal/requests/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/baremetal/requests/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/baremetal/requests/get_chassis.rb, line 15
def get_chassis(_chassis_uuid)
  response = Excon::Response.new
  response.status = [200, 204][rand(2)]
  response.body = data[:chassis_collection].first
  response
end
get_driver(_driver_name) click to toggle source
# File lib/fog/openstack/baremetal/requests/get_driver.rb, line 15
def get_driver(_driver_name)
  response = Excon::Response.new
  response.status = [200, 204][rand(2)]
  response.body = data[:drivers].first
  response
end
get_driver_properties(_driver_name) click to toggle source
# File lib/fog/openstack/baremetal/requests/get_driver_properties.rb, line 17
def get_driver_properties(_driver_name)
  response = Excon::Response.new
  response.status = [200, 204][rand(2)]
  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/baremetal/requests/get_node.rb, line 15
def get_node(_node_id)
  response = Excon::Response.new
  response.status = [200, 204][rand(2)]
  response.body = data[:nodes].first
  response
end
get_port(_port_id) click to toggle source
# File lib/fog/openstack/baremetal/requests/get_port.rb, line 15
def get_port(_port_id)
  response = Excon::Response.new
  response.status = [200, 204][rand(2)]
  response.body = data[:ports].first
  response
end
list_chassis(_parameters = nil) click to toggle source
# File lib/fog/openstack/baremetal/requests/list_chassis.rb, line 16
def list_chassis(_parameters = nil)
  response = Excon::Response.new
  response.status = [200, 204][rand(2)]
  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(_options = {}) click to toggle source
# File lib/fog/openstack/baremetal/requests/list_chassis_detailed.rb, line 16
def list_chassis_detailed(_options = {})
  response = Excon::Response.new
  response.status = [200, 204][rand(2)]
  response.body = {"chassis" => data[:chassis_collection]}
  response
end
list_drivers(_options = {}) click to toggle source
# File lib/fog/openstack/baremetal/requests/list_drivers.rb, line 16
def list_drivers(_options = {})
  response = Excon::Response.new
  response.status = [200, 204][rand(2)]
  response.body = {"drivers" => data[:drivers]}
  response
end
list_nodes(_options = {}) click to toggle source
# File lib/fog/openstack/baremetal/requests/list_nodes.rb, line 16
def list_nodes(_options = {})
  response = Excon::Response.new
  response.status = [200, 204][rand(2)]
  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(_options = {}) click to toggle source
# File lib/fog/openstack/baremetal/requests/list_nodes_detailed.rb, line 16
def list_nodes_detailed(_options = {})
  response = Excon::Response.new
  response.status = [200, 204][rand(2)]
  response.body = {"nodes" => data[:nodes]}
  response
end
list_ports(_options = {}) click to toggle source
# File lib/fog/openstack/baremetal/requests/list_ports.rb, line 16
def list_ports(_options = {})
  response = Excon::Response.new
  response.status = [200, 204][rand(2)]
  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(_options = {}) click to toggle source
# File lib/fog/openstack/baremetal/requests/list_ports_detailed.rb, line 16
def list_ports_detailed(_options = {})
  response = Excon::Response.new
  response.status = [200, 204][rand(2)]
  response.body = {"ports" => data[:ports]}
  response
end
patch_chassis(_chassis_uuid, _patch) click to toggle source
# File lib/fog/openstack/baremetal/requests/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 = data[:chassis_collection].first
  response
end
patch_node(_node_uuid, _patch) click to toggle source
# File lib/fog/openstack/baremetal/requests/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 = data[:nodes].first
  response
end
patch_port(_port_uuid, _patch) click to toggle source
# File lib/fog/openstack/baremetal/requests/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 = data[:ports].first
  response
end
reset_data() click to toggle source
# File lib/fog/openstack/baremetal.rb, line 234
def reset_data
  self.class.data.delete(@openstack_username)
end
set_node_maintenance(_node_uuid, _parameters = nil) click to toggle source
# File lib/fog/openstack/baremetal/requests/set_node_maintenance.rb, line 16
def set_node_maintenance(_node_uuid, _parameters = nil)
  response = Excon::Response.new
  response.status = 202
  response.headers = {
    "X-Compute-Request-Id" => "req-fdc6f99e-55a2-4ab1-8904-0892753828cf",
    "Content-Type"         => "application/json",
    "Content-Length"       => "356",
    "Date"                 => Date.new
  }
  response
end
set_node_power_state(_node_id, _power_state) click to toggle source
# File lib/fog/openstack/baremetal/requests/set_node_power_state.rb, line 20
def set_node_power_state(_node_id, _power_state)
  response = Excon::Response.new
  response.status = 202
  response.headers = {
    "X-Compute-Request-Id" => "req-fdc6f99e-55a2-4ab1-8904-0892753828cf",
    "Content-Type"         => "application/json",
    "Content-Length"       => "356",
    "Date"                 => Date.new
  }
  response.body = data[:nodes].first
  response
end
set_node_provision_state(_node_id, _provision_state) click to toggle source
# File lib/fog/openstack/baremetal/requests/set_node_provision_state.rb, line 23
def set_node_provision_state(_node_id, _provision_state)
  response = Excon::Response.new
  response.status = 202
  response.headers = {
    "X-Compute-Request-Id" => "req-fdc6f99e-55a2-4ab1-8904-0892753828cf",
    "Content-Type"         => "application/json",
    "Content-Length"       => "356",
    "Date"                 => Date.new
  }
  response.body = data[:nodes].first
  response
end
unset_node_maintenance(_node_uuid, _parameters = nil) click to toggle source
# File lib/fog/openstack/baremetal/requests/unset_node_maintenance.rb, line 16
def unset_node_maintenance(_node_uuid, _parameters = nil)
  response = Excon::Response.new
  response.status = 202
  response.headers = {
    "X-Compute-Request-Id" => "req-fdc6f99e-55a2-4ab1-8904-0892753828cf",
    "Content-Type"         => "application/json",
    "Content-Length"       => "356",
    "Date"                 => Date.new
  }
  response
end