Class: Fog::NFV::OpenStack::Mock

Inherits:
Object
  • Object
show all
Includes:
OpenStack::Core
Defined in:
lib/fog/nfv/openstack.rb,
lib/fog/nfv/openstack/requests/get_vnf.rb,
lib/fog/nfv/openstack/requests/get_vnfd.rb,
lib/fog/nfv/openstack/requests/list_vnfs.rb,
lib/fog/nfv/openstack/requests/update_vnf.rb,
lib/fog/nfv/openstack/requests/create_vnf.rb,
lib/fog/nfv/openstack/requests/delete_vnf.rb,
lib/fog/nfv/openstack/requests/list_vnfds.rb,
lib/fog/nfv/openstack/requests/create_vnfd.rb,
lib/fog/nfv/openstack/requests/delete_vnfd.rb

Instance Attribute Summary

Attributes included from OpenStack::Core

#auth_token, #auth_token_expiration, #current_tenant, #current_user, #current_user_id, #openstack_cache_ttl, #openstack_domain_id, #openstack_domain_name, #openstack_identity_prefix, #openstack_project_domain, #openstack_project_domain_id, #openstack_project_id, #openstack_user_domain, #openstack_user_domain_id, #unscoped_token

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OpenStack::Core

#credentials, #initialize_identity, not_found_class, #reload

Constructor Details

#initialize(options = {}) ⇒ Mock


82
83
84
85
86
87
# File 'lib/fog/nfv/openstack.rb', line 82

def initialize(options = {})
  @auth_token = Fog::Mock.random_base64(64)
  @auth_token_expiration = (Time.now.utc + 86_400).iso8601

  initialize_identity options
end

Class Method Details

.dataObject


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/fog/nfv/openstack.rb', line 45

def self.data
  @data ||= Hash.new do |hash, key|
    hash[key] = {
      :vnfs  => [
        {
          "status"      => "ACTIVE",
          "description" => "demo-example",
          "tenant_id"   => "943b6ff8229a4ec2bed0a306f869a0ea",
          "instance_id" => "5a9a7d3b-24f5-4226-8d43-262972a1776e",
          "mgmt_url"    => "{\"vdu1\": \"192.168.0.8\"}",
          "attributes"  => {"monitoring_policy" => "{\"vdus\": {}}"},
          "id"          => "cb4cdbd8-cf1a-4758-8d36-40db788a37a1",
          "name"        => "LadasTest"
        }
      ],
      :vnfds => [
        {
          "service_types" => [{"service_type" => "vnfd", "id" => "f9211d81-b58a-4849-8d38-e25376c421bd"}],
          "description"   => "demo-example",
          "tenant_id"     => "943b6ff8229a4ec2bed0a306f869a0ea",
          "mgmt_driver"   => "noop",
          "infra_driver"  => "heat",
          "attributes"    => {"vnfd" => "template_name: sample-vnfd"},
          "id"            => "1f8f33cf-8c94-427e-a040-f3e393b773b7",
          "name"          => "sample-vnfd"
        }
      ]
    }
  end
end

.resetObject


76
77
78
# File 'lib/fog/nfv/openstack.rb', line 76

def self.reset
  @data = nil
end

Instance Method Details

#create_vnf(_) ⇒ Object


26
27
28
29
30
31
32
33
# File 'lib/fog/nfv/openstack/requests/create_vnf.rb', line 26

def create_vnf(_)
  response = Excon::Response.new
  response.status = 201

  create_data = data[:vnfs].first.merge("vnfd_id" => "id")
  response.body = {"vnf" => create_data}
  response
end

#create_vnfd(_) ⇒ Object


26
27
28
29
30
31
# File 'lib/fog/nfv/openstack/requests/create_vnfd.rb', line 26

def create_vnfd(_)
  response = Excon::Response.new
  response.status = 201
  response.body = {"vnfd" => data[:vnfds].first}
  response
end

#dataObject


89
90
91
# File 'lib/fog/nfv/openstack.rb', line 89

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

#delete_vnf(_vnf_id) ⇒ Object


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

def delete_vnf(_vnf_id)
  response = Excon::Response.new
  response.status = 204
  response
end

#delete_vnfd(_vnfd_id) ⇒ Object


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

def delete_vnfd(_vnfd_id)
  response = Excon::Response.new
  response.status = 204
  response
end

#get_vnf(_vnf_id) ⇒ Object


15
16
17
18
19
20
# File 'lib/fog/nfv/openstack/requests/get_vnf.rb', line 15

def get_vnf(_vnf_id)
  response = Excon::Response.new
  response.status = 200
  response.body = {"vnf" => data[:vnfs].first}
  response
end

#get_vnfd(_vnfd_id) ⇒ Object


15
16
17
18
19
20
# File 'lib/fog/nfv/openstack/requests/get_vnfd.rb', line 15

def get_vnfd(_vnfd_id)
  response = Excon::Response.new
  response.status = 200
  response.body = {"vnfd" => data[:vnfds].first}
  response
end

#list_vnfds(_options = {}) ⇒ Object


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

def list_vnfds(_options = {})
  response = Excon::Response.new
  response.status = 200
  response.body = {"vnfds" => data[:vnfds]}
  response
end

#list_vnfs(_options = {}) ⇒ Object


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

def list_vnfs(_options = {})
  response = Excon::Response.new
  response.status = 200
  response.body = {"vnfs" => data[:vnfs]}
  response
end

#reset_dataObject


93
94
95
# File 'lib/fog/nfv/openstack.rb', line 93

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

#update_vnf(_, _) ⇒ Object


26
27
28
29
30
31
# File 'lib/fog/nfv/openstack/requests/update_vnf.rb', line 26

def update_vnf(_, _)
  response = Excon::Response.new
  response.status = 200
  response.body = {"vnf" => data[:vnfs].first}
  response
end