Class: Fog::Openstack::Planning::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/openstack/requests/planning/get_plan.rb,
lib/fog/openstack/planning.rb,
lib/fog/openstack/requests/planning/list_plans.rb,
lib/fog/openstack/requests/planning/list_roles.rb,
lib/fog/openstack/requests/planning/patch_plan.rb,
lib/fog/openstack/requests/planning/create_plan.rb,
lib/fog/openstack/requests/planning/delete_plan.rb,
lib/fog/openstack/requests/planning/add_role_to_plan.rb,
lib/fog/openstack/requests/planning/get_plan_templates.rb,
lib/fog/openstack/requests/planning/remove_role_from_plan.rb

Overview

class Real

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/fog/openstack/planning.rb', line 53

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



45
46
47
# File 'lib/fog/openstack/planning.rb', line 45

def self.data
  @data ||= Hash.new
end

.resetObject



49
50
51
# File 'lib/fog/openstack/planning.rb', line 49

def self.reset
  @data = nil
end

Instance Method Details

#add_role_to_plan(plan_uuid, role_uuid) ⇒ Object



16
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/planning/add_role_to_plan.rb', line 16

def add_role_to_plan(plan_uuid, role_uuid)
  response = Excon::Response.new
  response.status = [201][rand(1)]
  response.body = {
    "created_at" => "2014-09-26T20:23:14.222815",
    "description" => "Development testing cloud",
    "name" => "dev-cloud",
    "parameters" => [],
    "roles" => [
      {
        "description" => "OpenStack hypervisor node. Can be wrapped in a ResourceGroup for scaling.\n",
        "name"        => "compute",
        "uuid"        => "f72c0656-5696-4c66-81a5-d6d88a48e385",
        "version"     => 1
      }
    ],
    "updated_at" => nil,
    "uuid" => "53268a27-afc8-4b21-839f-90227dd7a001"
  }
  response
end

#create_plan(parameters) ⇒ Object



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

def create_plan(parameters)
  response = Excon::Response.new
  response.status = [201][rand(1)]
  response.body = {
    "created_at" => "2014-09-26T20:23:14.222815",
    "description" => "Development testing cloud",
    "name" => "dev-cloud",
    "parameters" => [],
    "roles" => [],
    "updated_at" => nil,
    "uuid" => "53268a27-afc8-4b21-839f-90227dd7a001"
  }
  response
end

#credentialsObject



87
88
89
90
91
92
93
# File 'lib/fog/openstack/planning.rb', line 87

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



79
80
81
# File 'lib/fog/openstack/planning.rb', line 79

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

#delete_plan(plan_uuid) ⇒ Object



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

def delete_plan(plan_uuid)
  response = Excon::Response.new
  response.status = [204][rand(1)]
  response
end

#get_plan(parameters = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fog/openstack/requests/planning/get_plan.rb', line 15

def get_plan(parameters=nil)
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = {
    "created_at" => "2014-09-26T20:23:14.222815",
    "description" => "Development testing cloud",
    "name" => "dev-cloud",
    "parameters" =>
    [
      {
        "default" => "guest",
        "description" => "The password for RabbitMQ",
        "hidden" => true,
        "label" => nil,
        "name" => "compute-1 => =>RabbitPassword",
        "value" => "secret-password"
      },
      {
        "default" => "default",
        "description" => "description",
        "hidden" => true,
        "label" => nil,
        "name" => "name",
        "value" => "value"
      },
    ],
    "roles" =>
    [
      {
        "description" => "OpenStack hypervisor node. Can be wrapped in a ResourceGroup for scaling.\n",
        "name" => "compute",
        "uuid" => "b7b1583c-5c80-481f-a25b-708ed4a39734",
        "version" => 1
      }
    ],
    "updated_at" => nil,
    "uuid" => "53268a27-afc8-4b21-839f-90227dd7a001"
  }
  response
end

#get_plan_templates(plan_uuid) ⇒ Object



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

def get_plan_templates(plan_uuid)
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = {
    "environment.yaml" => "... content of template file ...",
    "plan.yaml" => "... content of template file ...",
    "provider-compute-1.yaml" => "... content of template file ..."
  }
  response
end

#list_plans(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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fog/openstack/requests/planning/list_plans.rb', line 16

def list_plans(options = {})
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = [
    {
      "created_at" => "2014-09-26T20:23:14.222815",
      "description" => "Development testing cloud",
      "name" => "dev-cloud",
      "parameters" =>
      [
        {
          "default" => "guest",
          "description" => "The password for RabbitMQ",
          "hidden" => true,
          "label" => nil,
          "name" => "compute-1 => =>RabbitPassword",
          "value" => "secret-password"
        },
        {
          "default" => "default",
          "description" => "description",
          "hidden" => true,
          "label" => nil,
          "name" => "name",
          "value" => "value"
        },
      ],
      "roles" =>
      [
        {
          "description" => "OpenStack hypervisor node. Can be wrapped in a ResourceGroup for scaling.\n",
          "name" => "compute",
          "uuid" => "b7b1583c-5c80-481f-a25b-708ed4a39734",
          "version" => 1
        }
      ],
      "updated_at" => nil,
      "uuid" => "53268a27-afc8-4b21-839f-90227dd7a001"
    }
  ]
  response
end

#list_roles(options = {}) ⇒ Object



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

def list_roles(options = {})
  response = Excon::Response.new
  response.status = [200, 204][rand(1)]
  response.body = [
    {
      "description" => "OpenStack hypervisor node. Can be wrapped in a ResourceGroup for scaling.\n",
      "name"        => "compute",
      "uuid"        => "f72c0656-5696-4c66-81a5-d6d88a48e385",
      "version"     => 1
    }
  ]
  response
end

#patch_plan(plan_uuid, parameters) ⇒ Object



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

def patch_plan(plan_uuid, parameters)
  response = Excon::Response.new
  response.status = [201][rand(1)]
  response.body = {
    "created_at" => "2014-09-26T20:23:14.222815",
    "description" => "Development testing cloud",
    "name" => "dev-cloud",
    "parameters" =>
    [
      {
        "default" => "guest",
        "description" => "The password for RabbitMQ",
        "hidden" => true,
        "label" => nil,
        "name" => "compute-1::RabbitPassword",
        "value" => "secret-password"
      }
    ],
    "roles" =>
    [
      {
        "description" => "OpenStack hypervisor node. Can be wrapped in a ResourceGroup for scaling.\n",
        "name" => "compute",
        "uuid" => "b7b1583c-5c80-481f-a25b-708ed4a39734",
        "version" => 1
      }
    ],
    "updated_at" => nil,
    "uuid" => "53268a27-afc8-4b21-839f-90227dd7a001"
  }
  response
end

#remove_role_from_plan(plan_uuid, role_uuid) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/openstack/requests/planning/remove_role_from_plan.rb', line 15

def remove_role_from_plan(plan_uuid, role_uuid)
  response = Excon::Response.new
  response.status = [200][rand(1)]
  response.body = {
    "created_at" => "2014-09-26T20:23:14.222815",
    "description" => "Development testing cloud",
    "name" => "dev-cloud",
    "parameters" => [],
    "roles" => [],
    "updated_at" => nil,
    "uuid" => "53268a27-afc8-4b21-839f-90227dd7a001"
  }
  response
end

#reset_dataObject



83
84
85
# File 'lib/fog/openstack/planning.rb', line 83

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