yao 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6963885aed966be115cf500f834989d2f6255ef9aa349824d5a522d1c6721f6b
4
- data.tar.gz: f110ac903b2df56537c8a4a8ece422f36150568258c9a1d1e60de23846c99d8e
3
+ metadata.gz: 71b6f194cb567ae535fd1ec6ce25cd5fc5e55d755d4d082d1686f05d150620d2
4
+ data.tar.gz: aa758db06762998da0772177cba9c8da944d64644b76b5ea881bfd2a57cb836d
5
5
  SHA512:
6
- metadata.gz: 6bef23cbc43e2f274a11b87eafc5c3fc8e7e549bf2624a63bf27158a5f1cef633fb8f911bbfcdb2e2003dd1c0031d750259b8e6e95178c3b614cecc57ae0e91f
7
- data.tar.gz: 202374e5a06cee6eb569f0b7d87f1164fd38bcfbf4fef7165c958798e3ea4534341901b6fd11f31b84c0efc58cdef4a35bfec9a91c14fda23ebb715c59ec6c58
6
+ metadata.gz: 909ab5b74b8c5a50752a1a13c9861784f09f299d21f3bbe086d424ec9fad424c9c52597677f08c578f181471f0005e9420959482b69a77c0a7c79a4e33d49f11
7
+ data.tar.gz: 33a1c6ba2f7a9b5ce09f3d337a201b97b70186ca72f84c7f43e14d5361af1bbb4d1c077d5fde969d4c085baa44e3cf5d22e717527bc8247a8208ed6cb94df950
@@ -27,8 +27,11 @@ module Yao::Resources
27
27
  new(json)
28
28
  end
29
29
 
30
+ # override Yao::Resources::RestfullyAccessible.resources_from_json
31
+ # @param [Array]
32
+ # @return [Array<Yao::Resources::Meter>]
30
33
  def resources_from_json(json)
31
- new(json)
34
+ json.map{|d| new(d)}
32
35
  end
33
36
  end
34
37
  end
@@ -30,7 +30,7 @@ module Yao::Resources
30
30
  def self.list(meter_name, query={})
31
31
  cache_key = [meter_name, *query].join
32
32
  cache[cache_key] = GET("#{self.api_version}/meters/#{meter_name}", query).body unless cache[cache_key]
33
- new(cache[cache_key])
33
+ cache[cache_key].map{|d| new(d) }
34
34
  end
35
35
 
36
36
  def self.cache
@@ -12,5 +12,18 @@ module Yao::Resources
12
12
  @data["is_domain"]
13
13
  end
14
14
 
15
+ def servers
16
+ @servers ||= Yao::Server.list(project_id: id)
17
+ end
18
+
19
+ def ports
20
+ @ports ||= Yao::Port.list(tenant_id: id)
21
+ end
22
+
23
+ class << self
24
+ def accessible
25
+ as_member { self.list }
26
+ end
27
+ end
15
28
  end
16
29
  end
@@ -9,7 +9,7 @@ module Yao::Resources
9
9
  self.return_single_on_querying = true
10
10
 
11
11
  def servers
12
- @servers ||= Yao::Server.list(all_tenants: 1).select{|s| s.tenant_id == id }
12
+ @servers ||= Yao::Server.list(project_id: id)
13
13
  end
14
14
 
15
15
  def meters
@@ -1,3 +1,3 @@
1
1
  module Yao
2
- VERSION = "0.9.1"
2
+ VERSION = "0.10.0"
3
3
  end
@@ -27,6 +27,42 @@ class TestMeter < TestYaoResource
27
27
  assert_equal("efd87807-12d2-4b38-9c70-5f5c2ac427ff", meter.user_id)
28
28
  end
29
29
 
30
+ def test_list
31
+ stub = stub_request(:get, "https://example.com:12345/v2/meters")
32
+ .to_return(
33
+ status: 200,
34
+ # https://docs.openstack.org/ceilometer/pike/webapi/v2.html#meters
35
+ body: <<-JSON,
36
+ [
37
+ {
38
+ "meter_id": "YmQ5NDMxYzEtOGQ2OS00YWQzLTgwM2EtOGQ0YTZiODlmZDM2K2luc3RhbmNl",
39
+ "name": "instance",
40
+ "project_id": "35b17138-b364-4e6a-a131-8f3099c5be68",
41
+ "resource_id": "bd9431c1-8d69-4ad3-803a-8d4a6b89fd36",
42
+ "source": "openstack",
43
+ "type": "gauge",
44
+ "unit": "instance",
45
+ "user_id": "efd87807-12d2-4b38-9c70-5f5c2ac427ff"
46
+ },
47
+ {
48
+ "meter_id": "YmQ5NDMxYzEtOGQ2OS00YWQzLTgwM2EtOGQ0YTZiODlmZDM2K2luc3RhbmNl",
49
+ "name": "instance",
50
+ "project_id": "35b17138-b364-4e6a-a131-8f3099c5be68",
51
+ "resource_id": "bd9431c1-8d69-4ad3-803a-8d4a6b89fd36",
52
+ "source": "openstack",
53
+ "type": "gauge",
54
+ "unit": "instance",
55
+ "user_id": "efd87807-12d2-4b38-9c70-5f5c2ac427ff"
56
+ }
57
+ ]
58
+ JSON
59
+ headers: {'Content-Type' => 'application/json'}
60
+ )
61
+ meters = Yao::Meter.list
62
+ assert_instance_of(Array, meters)
63
+ assert_requested(stub)
64
+ end
65
+
30
66
  def test_resource
31
67
  # https://docs.openstack.org/ceilometer/pike/webapi/v2.html
32
68
  stub = stub_request(:get, "https://example.com:12345/v2/resources/00000000-0000-0000-0000-000000000000")
@@ -83,4 +83,54 @@ class TestOldSample < TestYaoResource
83
83
 
84
84
  assert_requested(stub)
85
85
  end
86
+
87
+ def test_list
88
+ stub = stub_request(:get, "https://example.com:12345/v2/meters/?q.field=timestamp&q.op=gt&q.value=2015-01-01T00:00:00%2B00:00")
89
+ .to_return(
90
+ status: 200,
91
+ body: <<-JSON,
92
+ [
93
+ {
94
+ "counter_name": "instance",
95
+ "counter_type": "gauge",
96
+ "counter_unit": "instance",
97
+ "counter_volume": 1.0,
98
+ "message_id": "5460acce-4fd6-480d-ab18-9735ec7b1996",
99
+ "project_id": "35b17138-b364-4e6a-a131-8f3099c5be68",
100
+ "recorded_at": "2015-01-01T12:00:00",
101
+ "resource_id": "bd9431c1-8d69-4ad3-803a-8d4a6b89fd36",
102
+ "resource_metadata": {
103
+ "name1": "value1",
104
+ "name2": "value2"
105
+ },
106
+ "source": "openstack",
107
+ "timestamp": "2015-01-01T12:00:00",
108
+ "user_id": "efd87807-12d2-4b38-9c70-5f5c2ac427ff"
109
+ },
110
+ {
111
+ "counter_name": "instance",
112
+ "counter_type": "gauge",
113
+ "counter_unit": "instance",
114
+ "counter_volume": 1.0,
115
+ "message_id": "5460acce-4fd6-480d-ab18-9735ec7b1996",
116
+ "project_id": "35b17138-b364-4e6a-a131-8f3099c5be68",
117
+ "recorded_at": "2015-01-01T12:00:00",
118
+ "resource_id": "bd9431c1-8d69-4ad3-803a-8d4a6b89fd36",
119
+ "resource_metadata": {
120
+ "name1": "value1",
121
+ "name2": "value2"
122
+ },
123
+ "source": "openstack",
124
+ "timestamp": "2015-01-01T12:00:00",
125
+ "user_id": "efd87807-12d2-4b38-9c70-5f5c2ac427ff"
126
+ }
127
+ ]
128
+ JSON
129
+ headers: {'Content-Type' => 'application/json'}
130
+ )
131
+
132
+ oldsamples = Yao::OldSample.list("", {'q.field': 'timestamp', 'q.op': 'gt', 'q.value': "2015-01-01T00:00:00+00:00"})
133
+ assert_instance_of(Array, oldsamples)
134
+ assert_requested(stub)
135
+ end
86
136
  end
@@ -29,4 +29,229 @@ class TestProject < TestYaoResource
29
29
  assert_equal("admin", project.name)
30
30
  assert_equal(nil, project.parent_id)
31
31
  end
32
+
33
+ def test_ports
34
+ stub = stub_request(:get, "https://example.com:12345/ports?tenant_id=d397de8a63f341818f198abb0966f6f3")
35
+ .to_return(
36
+ status: 200,
37
+ # https://docs.openstack.org/api-ref/network/v2/?expanded=list-floating-ips-detail,list-ports-detail#list-ports
38
+ body: <<-JSON,
39
+ {
40
+ "ports": [
41
+ {
42
+ "admin_state_up": true,
43
+ "allowed_address_pairs": [],
44
+ "binding:host_id": "devstack",
45
+ "binding:profile": {},
46
+ "binding:vif_details": {
47
+ "ovs_hybrid_plug": true,
48
+ "port_filter": true
49
+ },
50
+ "binding:vif_type": "ovs",
51
+ "binding:vnic_type": "normal",
52
+ "created_at": "2016-03-08T20:19:41",
53
+ "data_plane_status": null,
54
+ "description": "",
55
+ "device_id": "9ae135f4-b6e0-4dad-9e91-3c223e385824",
56
+ "device_owner": "network:router_gateway",
57
+ "dns_assignment": {
58
+ "hostname": "myport",
59
+ "ip_address": "172.24.4.2",
60
+ "fqdn": "myport.my-domain.org"
61
+ },
62
+ "dns_domain": "my-domain.org.",
63
+ "dns_name": "myport",
64
+ "extra_dhcp_opts": [],
65
+ "fixed_ips": [
66
+ {
67
+ "ip_address": "172.24.4.2",
68
+ "subnet_id": "008ba151-0b8c-4a67-98b5-0d2b87666062"
69
+ }
70
+ ],
71
+ "id": "d80b1a3b-4fc1-49f3-952e-1e2ab7081d8b",
72
+ "ip_allocation": "immediate",
73
+ "mac_address": "fa:16:3e:58:42:ed",
74
+ "name": "",
75
+ "network_id": "70c1db1f-b701-45bd-96e0-a313ee3430b3",
76
+ "port_security_enabled": true,
77
+ "project_id": "",
78
+ "revision_number": 1,
79
+ "security_groups": [],
80
+ "status": "ACTIVE",
81
+ "tenant_id": "",
82
+ "updated_at": "2016-03-08T20:19:41",
83
+ "qos_policy_id": "29d5e02e-d5ab-4929-bee4-4a9fc12e22ae",
84
+ "resource_request": {
85
+ "required": ["CUSTOM_PHYSNET_PUBLIC", "CUSTOM_VNIC_TYPE_NORMAL"],
86
+ "resources": {"NET_BW_EGR_KILOBIT_PER_SEC": 1000}
87
+ },
88
+ "tags": ["tag1,tag2"],
89
+ "tenant_id": "",
90
+ "uplink_status_propagation": false
91
+ },
92
+ {
93
+ "admin_state_up": true,
94
+ "allowed_address_pairs": [],
95
+ "binding:host_id": "devstack",
96
+ "binding:profile": {},
97
+ "binding:vif_details": {
98
+ "ovs_hybrid_plug": true,
99
+ "port_filter": true
100
+ },
101
+ "binding:vif_type": "ovs",
102
+ "binding:vnic_type": "normal",
103
+ "created_at": "2016-03-08T20:19:41",
104
+ "data_plane_status": null,
105
+ "description": "",
106
+ "device_id": "9ae135f4-b6e0-4dad-9e91-3c223e385824",
107
+ "device_owner": "network:router_interface",
108
+ "dns_assignment": {
109
+ "hostname": "myport2",
110
+ "ip_address": "10.0.0.1",
111
+ "fqdn": "myport2.my-domain.org"
112
+ },
113
+ "dns_domain": "my-domain.org.",
114
+ "dns_name": "myport2",
115
+ "extra_dhcp_opts": [],
116
+ "fixed_ips": [
117
+ {
118
+ "ip_address": "10.0.0.1",
119
+ "subnet_id": "288bf4a1-51ba-43b6-9d0a-520e9005db17"
120
+ }
121
+ ],
122
+ "id": "f71a6703-d6de-4be1-a91a-a570ede1d159",
123
+ "ip_allocation": "immediate",
124
+ "mac_address": "fa:16:3e:bb:3c:e4",
125
+ "name": "",
126
+ "network_id": "f27aa545-cbdd-4907-b0c6-c9e8b039dcc2",
127
+ "port_security_enabled": true,
128
+ "project_id": "d397de8a63f341818f198abb0966f6f3",
129
+ "revision_number": 2,
130
+ "security_groups": [],
131
+ "status": "ACTIVE",
132
+ "tenant_id": "d397de8a63f341818f198abb0966f6f3",
133
+ "updated_at": "2016-03-08T20:19:41",
134
+ "qos_policy_id": null,
135
+ "tags": ["tag1,tag2"],
136
+ "tenant_id": "d397de8a63f341818f198abb0966f6f3",
137
+ "uplink_status_propagation": false
138
+ }
139
+ ]
140
+ }
141
+ JSON
142
+ headers: {'Content-Type' => 'application/json'}
143
+ )
144
+ params = {
145
+ "id" => "d397de8a63f341818f198abb0966f6f3",
146
+ }
147
+ project = Yao::Project.new(params)
148
+ assert_instance_of(Array, project.ports)
149
+ assert_requested(stub)
150
+ end
151
+
152
+ def test_servers
153
+ stub = stub_request(:get, "https://example.com:12345/servers/detail?project_id=6f70656e737461636b20342065766572")
154
+ .to_return(
155
+ status: 200,
156
+ # https://docs.openstack.org/api-ref/compute/?expanded=list-servers-detailed-detail#list-servers-detailed
157
+ body: <<-JSON,
158
+ {
159
+ "servers": [
160
+ {
161
+ "OS-DCF:diskConfig": "AUTO",
162
+ "OS-EXT-AZ:availability_zone": "nova",
163
+ "OS-EXT-SRV-ATTR:host": "compute",
164
+ "OS-EXT-SRV-ATTR:hostname": "new-server-test",
165
+ "OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
166
+ "OS-EXT-SRV-ATTR:instance_name": "instance-00000001",
167
+ "OS-EXT-SRV-ATTR:kernel_id": "",
168
+ "OS-EXT-SRV-ATTR:launch_index": 0,
169
+ "OS-EXT-SRV-ATTR:ramdisk_id": "",
170
+ "OS-EXT-SRV-ATTR:reservation_id": "r-l0i0clt2",
171
+ "OS-EXT-SRV-ATTR:root_device_name": "/dev/sda",
172
+ "OS-EXT-SRV-ATTR:user_data": "IyEvYmluL2Jhc2gKL2Jpbi9zdQplY2hvICJJIGFtIGluIHlvdSEiCg==",
173
+ "OS-EXT-STS:power_state": 1,
174
+ "OS-EXT-STS:task_state": null,
175
+ "OS-EXT-STS:vm_state": "active",
176
+ "OS-SRV-USG:launched_at": "2019-04-23T15:19:15.317839",
177
+ "OS-SRV-USG:terminated_at": null,
178
+ "accessIPv4": "1.2.3.4",
179
+ "accessIPv6": "80fe::",
180
+ "addresses": {
181
+ "private": [
182
+ {
183
+ "OS-EXT-IPS-MAC:mac_addr": "00:0c:29:0d:11:74",
184
+ "OS-EXT-IPS:type": "fixed",
185
+ "addr": "192.168.1.30",
186
+ "version": 4
187
+ }
188
+ ]
189
+ },
190
+ "config_drive": "",
191
+ "created": "2019-04-23T15:19:14Z",
192
+ "description": null,
193
+ "flavor": {
194
+ "disk": 1,
195
+ "ephemeral": 0,
196
+ "extra_specs": {},
197
+ "original_name": "m1.tiny",
198
+ "ram": 512,
199
+ "swap": 0,
200
+ "vcpus": 1
201
+ },
202
+ "hostId": "2091634baaccdc4c5a1d57069c833e402921df696b7f970791b12ec6",
203
+ "host_status": "UP",
204
+ "id": "2ce4c5b3-2866-4972-93ce-77a2ea46a7f9",
205
+ "image": {
206
+ "id": "70a599e0-31e7-49b7-b260-868f441e862b",
207
+ "links": [
208
+ {
209
+ "href": "http://openstack.example.com/6f70656e737461636b20342065766572/images/70a599e0-31e7-49b7-b260-868f441e862b",
210
+ "rel": "bookmark"
211
+ }
212
+ ]
213
+ },
214
+ "key_name": null,
215
+ "links": [
216
+ {
217
+ "href": "http://openstack.example.com/v2.1/6f70656e737461636b20342065766572/servers/2ce4c5b3-2866-4972-93ce-77a2ea46a7f9",
218
+ "rel": "self"
219
+ },
220
+ {
221
+ "href": "http://openstack.example.com/6f70656e737461636b20342065766572/servers/2ce4c5b3-2866-4972-93ce-77a2ea46a7f9",
222
+ "rel": "bookmark"
223
+ }
224
+ ],
225
+ "locked": true,
226
+ "locked_reason": "I don't want to work",
227
+ "metadata": {
228
+ "My Server Name": "Apache1"
229
+ },
230
+ "name": "new-server-test",
231
+ "os-extended-volumes:volumes_attached": [],
232
+ "progress": 0,
233
+ "security_groups": [
234
+ {
235
+ "name": "default"
236
+ }
237
+ ],
238
+ "status": "ACTIVE",
239
+ "tags": [],
240
+ "tenant_id": "6f70656e737461636b20342065766572",
241
+ "trusted_image_certificates": null,
242
+ "updated": "2019-04-23T15:19:15Z",
243
+ "user_id": "fake"
244
+ }
245
+ ]
246
+ }
247
+ JSON
248
+ headers: {'Content-Type' => 'application/json'}
249
+ )
250
+ params = {
251
+ "id" => "6f70656e737461636b20342065766572",
252
+ }
253
+ project = Yao::Project.new(params)
254
+ assert_instance_of(Array, project.servers)
255
+ assert_requested(stub)
256
+ end
32
257
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yao
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uchio, KONDO
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-25 00:00:00.000000000 Z
11
+ date: 2019-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json