Class: Fog::Baremetal::OpenStack::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/openstack/baremetal.rb,
lib/fog/openstack/requests/baremetal/get_node.rb,
lib/fog/openstack/requests/baremetal/get_port.rb,
lib/fog/openstack/requests/baremetal/list_ports.rb,
lib/fog/openstack/requests/baremetal/patch_node.rb,
lib/fog/openstack/requests/baremetal/list_nodes.rb,
lib/fog/openstack/requests/baremetal/patch_port.rb,
lib/fog/openstack/requests/baremetal/get_driver.rb,
lib/fog/openstack/requests/baremetal/create_port.rb,
lib/fog/openstack/requests/baremetal/delete_port.rb,
lib/fog/openstack/requests/baremetal/get_chassis.rb,
lib/fog/openstack/requests/baremetal/create_node.rb,
lib/fog/openstack/requests/baremetal/delete_node.rb,
lib/fog/openstack/requests/baremetal/list_chassis.rb,
lib/fog/openstack/requests/baremetal/list_drivers.rb,
lib/fog/openstack/requests/baremetal/patch_chassis.rb,
lib/fog/openstack/requests/baremetal/create_chassis.rb,
lib/fog/openstack/requests/baremetal/delete_chassis.rb,
lib/fog/openstack/requests/baremetal/list_ports_detailed.rb,
lib/fog/openstack/requests/baremetal/list_nodes_detailed.rb,
lib/fog/openstack/requests/baremetal/set_node_maintenance.rb,
lib/fog/openstack/requests/baremetal/set_node_power_state.rb,
lib/fog/openstack/requests/baremetal/list_chassis_detailed.rb,
lib/fog/openstack/requests/baremetal/get_driver_properties.rb,
lib/fog/openstack/requests/baremetal/unset_node_maintenance.rb,
lib/fog/openstack/requests/baremetal/set_node_provision_state.rb

Overview

class Real

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock


205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/fog/openstack/baremetal.rb', line 205

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

Class Method Details

.dataObject


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/fog/openstack/baremetal.rb', line 87

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

.resetObject


201
202
203
# File 'lib/fog/openstack/baremetal.rb', line 201

def self.reset
  @data = nil
end

Instance Method Details

#create_chassis(attributes) ⇒ Object


29
30
31
32
33
34
35
36
37
38
39
40
# 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) ⇒ Object


39
40
41
42
43
44
45
46
47
48
49
50
# 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) ⇒ Object


31
32
33
34
35
36
37
38
39
40
41
42
# 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

#credentialsObject


239
240
241
242
243
244
245
# File 'lib/fog/openstack/baremetal.rb', line 239

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

#dataObject


231
232
233
# File 'lib/fog/openstack/baremetal.rb', line 231

def data
  self.class.data[@openstack_username]
end

#delete_chassis(chassis_uuid) ⇒ Object


17
18
19
20
21
# 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) ⇒ Object


17
18
19
20
21
# 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) ⇒ Object


17
18
19
20
21
# 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) ⇒ Object


15
16
17
18
19
20
# 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) ⇒ Object


15
16
17
18
19
20
# 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) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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) ⇒ Object


15
16
17
18
19
20
# 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) ⇒ Object


15
16
17
18
19
20
# 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) ⇒ Object


16
17
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/baremetal/list_chassis.rb', line 16

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(options = {}) ⇒ Object


16
17
18
19
20
21
# File 'lib/fog/openstack/requests/baremetal/list_chassis_detailed.rb', line 16

def list_chassis_detailed(options = {})
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = { "chassis" => self.data[:chassis_collection] }
  response
end

#list_drivers(options = {}) ⇒ Object


16
17
18
19
20
21
# File 'lib/fog/openstack/requests/baremetal/list_drivers.rb', line 16

def list_drivers(options = {})
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = { "drivers" => self.data[:drivers] }
  response
end

#list_nodes(options = {}) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fog/openstack/requests/baremetal/list_nodes.rb', line 16

def list_nodes(options = {})
  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(options = {}) ⇒ Object


16
17
18
19
20
21
# File 'lib/fog/openstack/requests/baremetal/list_nodes_detailed.rb', line 16

def list_nodes_detailed(options = {})
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = { "nodes" => self.data[:nodes] }
  response
end

#list_ports(options = {}) ⇒ Object


16
17
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/baremetal/list_ports.rb', line 16

def list_ports(options = {})
  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(options = {}) ⇒ Object


16
17
18
19
20
21
# File 'lib/fog/openstack/requests/baremetal/list_ports_detailed.rb', line 16

def list_ports_detailed(options = {})
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = { "ports" => self.data[:ports] }
  response
end

#patch_chassis(chassis_uuid, patch) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
# 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) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
# 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) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
# 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_dataObject


235
236
237
# File 'lib/fog/openstack/baremetal.rb', line 235

def reset_data
  self.class.data.delete(@openstack_username)
end

#set_node_maintenance(node_uuid, parameters = nil) ⇒ Object


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

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) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fog/openstack/requests/baremetal/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 =  self.data[:nodes].first
  response
end

#set_node_provision_state(node_id, provision_state) ⇒ Object


23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fog/openstack/requests/baremetal/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 =  self.data[:nodes].first
  response
end

#unset_node_maintenance(node_uuid, parameters = nil) ⇒ Object


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

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