Class: Fog::OpenStack::Planning::Mock

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



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

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



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

def self.data
  @data ||= {}
end

.resetObject



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

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

def add_role_to_plan(_plan_uuid, _role_uuid)
  response = Excon::Response.new
  response.status = 201
  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/planning/openstack/requests/create_plan.rb', line 16

def create_plan(_parameters)
  response = Excon::Response.new
  response.status = 201
  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



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

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



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

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

#delete_plan(_plan_uuid) ⇒ Object



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

def delete_plan(_plan_uuid)
  response = Excon::Response.new
  response.status = 204
  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/planning/openstack/requests/get_plan.rb', line 15

def get_plan(_parameters = nil)
  response = Excon::Response.new
  response.status = [200, 204][rand(2)]
  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/planning/openstack/requests/get_plan_templates.rb', line 15

def get_plan_templates(_plan_uuid)
  response = Excon::Response.new
  response.status = [200, 204][rand(2)]
  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/planning/openstack/requests/list_plans.rb', line 16

def list_plans(_options = {})
  response = Excon::Response.new
  response.status = [200, 204][rand(2)]
  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/planning/openstack/requests/list_roles.rb', line 16

def list_roles(_options = {})
  response = Excon::Response.new
  response.status = [200, 204][rand(2)]
  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/planning/openstack/requests/patch_plan.rb', line 16

def patch_plan(_plan_uuid, _parameters)
  response = Excon::Response.new
  response.status = 201
  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/planning/openstack/requests/remove_role_from_plan.rb', line 15

def remove_role_from_plan(_plan_uuid, _role_uuid)
  response = Excon::Response.new
  response.status = 200
  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



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

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