Class: Fog::Metric::OpenStack::Mock
- Inherits:
-
Object
- Object
- Fog::Metric::OpenStack::Mock
- Defined in:
- lib/fog/metric/openstack.rb,
lib/fog/metric/openstack/requests/get_metric.rb,
lib/fog/metric/openstack/requests/get_resource.rb,
lib/fog/metric/openstack/requests/list_metrics.rb,
lib/fog/metric/openstack/requests/list_resources.rb,
lib/fog/metric/openstack/requests/get_metric_measures.rb,
lib/fog/metric/openstack/requests/get_resource_metric_measures.rb
Class Method Summary collapse
Instance Method Summary collapse
- #credentials ⇒ Object
- #data ⇒ Object
- #get_metric(_metric_id) ⇒ Object
- #get_metric_measures(_metric_id, _options = {}) ⇒ Object
- #get_resource(_resource_id) ⇒ Object
- #get_resource_metric_measures(_resource_id, _metric_name, _options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #list_metrics(_options = {}) ⇒ Object
- #list_resources(_type = "generic", _options = {}) ⇒ Object
- #reset_data ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
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 |
# File 'lib/fog/metric/openstack.rb', line 48 def initialize( = {}) @openstack_username = [:openstack_username] @openstack_tenant = [:openstack_tenant] @openstack_auth_uri = URI.parse([:openstack_auth_url]) @auth_token = Fog::Mock.random_base64(64) @auth_token_expiration = (Time.now.utc + 86400).iso8601 management_url = URI.parse([:openstack_auth_url]) management_url.port = 8041 management_url.path = '/v1' @openstack_management_url = management_url.to_s @data ||= {:users => {}} unless @data[:users].find { |u| u['name'] == [:openstack_username] } id = Fog::Mock.random_numbers(6).to_s @data[:users][id] = { 'id' => id, 'name' => [:openstack_username], 'email' => "#{[:openstack_username]}@mock.com", 'tenantId' => Fog::Mock.random_numbers(6).to_s, 'enabled' => true } end end |
Class Method Details
.data ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/fog/metric/openstack.rb', line 35 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :users => {}, :tenants => {} } end end |
.reset ⇒ Object
44 45 46 |
# File 'lib/fog/metric/openstack.rb', line 44 def self.reset @data = nil end |
Instance Method Details
#credentials ⇒ Object
82 83 84 85 86 87 |
# File 'lib/fog/metric/openstack.rb', line 82 def credentials {:provider => 'openstack', :openstack_auth_url => @openstack_auth_uri.to_s, :openstack_auth_token => @auth_token, :openstack_management_url => @openstack_management_url} end |
#data ⇒ Object
74 75 76 |
# File 'lib/fog/metric/openstack.rb', line 74 def data self.class.data[@openstack_username] end |
#get_metric(_metric_id) ⇒ 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 55 56 57 58 |
# File 'lib/fog/metric/openstack/requests/get_metric.rb', line 15 def get_metric(_metric_id) response = Excon::Response.new response.status = 200 response.body = { "archive_policy" => { "aggregation_methods" => [ "95pct", "median", "max", "count", "std", "sum", "min", "mean" ], "back_window" => 0, "definition" => [ { "granularity" => "0:00:01", "points" => 3600, "timespan" => "1:00:00" }, { "granularity" => "0:01:00", "points" => 10080, "timespan" => "7 days, 0:00:00" }, { "granularity" => "1:00:00", "points" => 8760, "timespan" => "365 days, 0:00:00" } ], "name" => "high" }, "created_by_project_id" => "384a902b-6856-424c-9d30-6b5325ac20a5", "created_by_user_id" => "d040def9-fd68-45f0-a19f-253014f397c3", "id" => "8bbb5f02-b654-4861-b19e-d372fcdca124", "name" => nil, "resource" => nil, "unit" => nil } response end |
#get_metric_measures(_metric_id, _options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/fog/metric/openstack/requests/get_metric_measures.rb', line 16 def get_metric_measures(_metric_id, = {}) response = Excon::Response.new response.status = 200 response.body = [ { "timestamp" => "2014-10-06T14:33:57", "value" => 43.1 }, { "timestamp" => "2014-10-06T14:34:12", "value" => 12 }, { "timestamp" => "2014-10-06T14:34:20", "value" => 2 } ] response end |
#get_resource(_resource_id) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/fog/metric/openstack/requests/get_resource.rb', line 15 def get_resource(_resource_id) response = Excon::Response.new response.status = 200 response.body = { "created_by_project_id" => "384a902b-6856-424c-9d30-6b5325ac20a5", "created_by_user_id" => "d040def9-fd68-45f0-a19f-253014f397c3", "ended_at" => nil, "id" => "75c44741-cc60-4033-804e-2d3098c7d2e9", "metrics" => {}, "original_resource_id" => "75C44741-CC60-4033-804E-2D3098C7D2E9", "project_id" => "BD3A1E52-1C62-44CB-BF04-660BD88CD74D", "revision_end" => nil, "revision_start" => "2016-11-08T11:23:45.989977+00:00", "started_at" => "2016-11-08T11:23:45.989960+00:00", "type" => "generic", "user_id" => "BD3A1E52-1C62-44CB-BF04-660BD88CD74D" } response end |
#get_resource_metric_measures(_resource_id, _metric_name, _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 |
# File 'lib/fog/metric/openstack/requests/get_resource_metric_measures.rb', line 16 def get_resource_metric_measures(_resource_id, _metric_name, = {}) response = Excon::Response.new response.status = 200 response.body = [ [ "2014-10-06T14:00:00+00:00", 3600.0, 24.7 ], [ "2014-10-06T14:34:00+00:00", 60.0, 15.5 ], [ "2014-10-06T14:34:12+00:00", 1.0, 6.0 ], [ "2014-10-06T14:34:20+00:00", 1.0, 25.0 ] ] response end |
#list_metrics(_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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/fog/metric/openstack/requests/list_metrics.rb', line 16 def list_metrics( = {}) response = Excon::Response.new response.status = 200 response.body = [ { "archive_policy" => { "aggregation_methods" => [ "95pct", "median", "max", "count", "std", "sum", "min", "mean" ], "back_window" => 0, "definition" => [ { "granularity" => "0:00:01", "points" => 3600, "timespan" => "1:00:00" }, { "granularity" => "0:01:00", "points" => 10080, "timespan" => "7 days, 0:00:00" }, { "granularity" => "1:00:00", "points" => 8760, "timespan" => "365 days, 0:00:00" } ], "name" => "high" }, "created_by_project_id" => "384a902b-6856-424c-9d30-6b5325ac20a5", "created_by_user_id" => "d040def9-fd68-45f0-a19f-253014f397c3", "id" => "8bbb5f02-b654-4861-b19e-d372fcdca124", "name" => nil, "resource_id" => nil, "unit" => nil }, { "archive_policy" => { "aggregation_methods" => [ "95pct", "median", "max", "count", "std", "sum", "min", "mean" ], "back_window" => 0, "definition" => [ { "granularity" => "0:05:00", "points" => 12, "timespan" => "1:00:00" }, { "granularity" => "1:00:00", "points" => 24, "timespan" => "1 day, 0:00:00" }, { "granularity" => "1 day, 0:00:00", "points" => 30, "timespan" => "30 days, 0:00:00" } ], "name" => "low" }, "created_by_project_id" => "384a902b-6856-424c-9d30-6b5325ac20a5", "created_by_user_id" => "d040def9-fd68-45f0-a19f-253014f397c3", "id" => "af3446dc-e20f-4ecf-aaaa-1240c05ff19b", "name" => nil, "resource_id" => nil, "unit" => nil } ] response end |
#list_resources(_type = "generic", _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 58 59 60 61 62 63 64 65 66 |
# File 'lib/fog/metric/openstack/requests/list_resources.rb', line 16 def list_resources(_type = "generic", = {}) response = Excon::Response.new response.status = 200 response.body = [ { "created_by_project_id" => "384a902b-6856-424c-9d30-6b5325ac20a5", "created_by_user_id" => "d040def9-fd68-45f0-a19f-253014f397c3", "ended_at" => nil, "id" => "75c44741-cc60-4033-804e-2d3098c7d2e9", "metrics" => {}, "original_resource_id" => "75C44741-CC60-4033-804E-2D3098C7D2E9", "project_id" => "BD3A1E52-1C62-44CB-BF04-660BD88CD74D", "revision_end" => nil, "revision_start" => "2016-11-08T11:23:45.989977+00:00", "started_at" => "2016-11-08T11:23:45.989960+00:00", "type" => "generic", "user_id" => "BD3A1E52-1C62-44CB-BF04-660BD88CD74D" }, { "created_by_project_id" => "384a902b-6856-424c-9d30-6b5325ac20a5", "created_by_user_id" => "d040def9-fd68-45f0-a19f-253014f397c3", "ended_at" => nil, "id" => "ab68da77-fa82-4e67-aba9-270c5a98cbcb", "metrics" => { "temperature" => "ed51c966-8890-4f4e-96c4-f0a753dbad42" }, "original_resource_id" => "AB68DA77-FA82-4E67-ABA9-270C5A98CBCB", "project_id" => "BD3A1E52-1C62-44CB-BF04-660BD88CD74D", "revision_end" => nil, "revision_start" => "2016-11-08T11:23:46.177259+00:00", "started_at" => "2016-11-08T11:23:46.177236+00:00", "type" => "generic", "user_id" => "BD3A1E52-1C62-44CB-BF04-660BD88CD74D" }, { "created_by_project_id" => "384a902b-6856-424c-9d30-6b5325ac20a5", "created_by_user_id" => "d040def9-fd68-45f0-a19f-253014f397c3", "ended_at" => "2014-01-04T10:00:12+00:00", "id" => "6868da77-fa82-4e67-aba9-270c5ae8cbca", "metrics" => {}, "original_resource_id" => "6868DA77-FA82-4E67-ABA9-270C5AE8CBCA", "project_id" => "BD3A1E52-1C62-44CB-BF04-660BD88CD74D", "revision_end" => nil, "revision_start" => "2016-11-08T11:23:46.781604+00:00", "started_at" => "2014-01-02T23:23:34+00:00", "type" => "instance", "user_id" => "BD3A1E52-1C62-44CB-BF04-660BD88CD74D" } ] response end |
#reset_data ⇒ Object
78 79 80 |
# File 'lib/fog/metric/openstack.rb', line 78 def reset_data self.class.data.delete(@openstack_username) end |