Class: Fog::Joyent::Analytics::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/joyent/analytics.rb,
lib/fog/joyent/requests/analytics/describe_analytics.rb,
lib/fog/joyent/requests/analytics/get_instrumentation.rb,
lib/fog/joyent/requests/analytics/list_instrumentations.rb,
lib/fog/joyent/requests/analytics/create_instrumentation.rb,
lib/fog/joyent/requests/analytics/delete_instrumentation.rb,
lib/fog/joyent/requests/analytics/get_instrumentation_value.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



134
135
136
137
138
139
# File 'lib/fog/joyent/analytics.rb', line 134

def initialize(options = {})
  @joyent_username = options[:joyent_username] || Fog.credentials[:joyent_username]
  @joyent_password = options[:joyent_password] || Fog.credentials[:joyent_password]
  @joyent_url = 'https://us-sw-1.api.joyentcloud.com'
  @joyent_version = '~7'
end

Class Method Details

.dataObject



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
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
# File 'lib/fog/joyent/analytics.rb', line 51

def self.data
  @data ||= Hash.new do |hash, key|
    hash[key] =case key
               when :instrumentation
                 { 'module' => "cpu",
                   'stat' => "usage",
                   'predicate' => {},
                   'decomposition' => ["zonename"],
                   'value-dimension' => 2,
                   'value-arity' => "discrete-decomposition",
                   'enabled' => true,
                   'retention-time' => 86400,
                   'idle-max' => 86400,
                   'transformations' => [],
                   'nsources' => 3,
                   'granularity' => 30,
                   'persist-data' => false,
                   'crtime' => 1388690982000,
                   'value-scope' => "point",
                   'id' => "63",
                   'uris' =>
                       [{ "uri" => "/#{@joyent_username}/analytics/instrumentations/63/value/raw",
                          "name" => "value_raw" }] }
               when :values
                 {
                     'value' => { 'zoneid' => 0 },
                     'transformations' => {},
                     'start_time' => Time.now.utc - 600,
                     'duration' => 30,
                     'end_time' => Time.now.utc - 570,
                     'nsources' => 1,
                     'minreporting' => 1,
                     'requested_start_time' => Time.now.utc - 600,
                     'requested_duration' => 30,
                     'requested_end_time' => Time.now.utc - 570
                 }
               when :describe_analytics
                 {
                     'fields' => {
                         'zonename' => {
                             'label' => 'zone name',
                             'type' => 'string'
                         },
                         'pid' => {
                             'label' => 'process identifier',
                             'type' => 'string'
                         }
                     },
                     'modules' => {
                         'cpu' => {
                             'label' => 'CPU'
                         }
                     },
                     'transformations' => {
                         'geolocate' => {
                             'label' => 'geolocate IP addresses',
                             'fields' => ['raddr'] }
                     },
                     'metrics' => [{
                                       "module" => "cpu",
                                       "stat" => "thread_executions",
                                       "label" => "thread executions",
                                       "interval" => "interval",
                                       "fields" => ["hostname", "zonename", "runtime"],
                                       "unit" => "operations"
                                   }],
                     'types' => {
                         'string' => {
                             'arity' => "discrete",
                             'unit' => ""
                         }
                     }
                 }
               else
                 {}
               end
  end
end

Instance Method Details

#create_instrumentation(values = {}) ⇒ Object



16
17
18
19
20
21
# File 'lib/fog/joyent/requests/analytics/create_instrumentation.rb', line 16

def create_instrumentation(values = {})
  response = Excon::Response.new
  response.status = 201
  response.body = self.data[:instrumentation]
  response
end

#dataObject



130
131
132
# File 'lib/fog/joyent/analytics.rb', line 130

def data
  self.class.data
end

#delete_instrumentation(id) ⇒ Object



15
16
17
18
19
# File 'lib/fog/joyent/requests/analytics/delete_instrumentation.rb', line 15

def delete_instrumentation(id)
  response = Excon::Response.new
  response.status = 204
  response
end

#describe_analytics(force = false) ⇒ Object



17
18
19
20
21
22
# File 'lib/fog/joyent/requests/analytics/describe_analytics.rb', line 17

def describe_analytics(force = false)
  response = Excon::Response.new
  response.status = 200
  response.body = self.data[:describe_analytics]
  response
end

#get_instrumentation(id) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/fog/joyent/requests/analytics/get_instrumentation.rb', line 16

def get_instrumentation(id)
  raise Fog::Compute::Joyent::Errors::NotFound.new('not found') unless id == self.data[:instrumentation]['id']
  response = Excon::Response.new
  response.status = 200
  response.body = self.data[:instrumentation]
  response
end

#get_instrumentation_value(url, requested_start_time, ndatapoints, duration) ⇒ Object



21
22
23
24
25
26
# File 'lib/fog/joyent/requests/analytics/get_instrumentation_value.rb', line 21

def get_instrumentation_value(url, requested_start_time, ndatapoints, duration)
  response = Excon::Response.new
  response.status = 200
  response.body = [self.data[:values]]
  response
end

#list_instrumentationsObject



16
17
18
19
20
21
# File 'lib/fog/joyent/requests/analytics/list_instrumentations.rb', line 16

def list_instrumentations
  response = Excon::Response.new
  response.status = 200
  response.body = [self.data[:instrumentation]]
  response
end

#request(opts) ⇒ Object



141
142
143
# File 'lib/fog/joyent/analytics.rb', line 141

def request(opts)
  raise "Not Implemented"
end