yao 0.13.1 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +19 -0
  3. data/.github/workflows/ubuntu-rvm.yml +1 -1
  4. data/.github/workflows/ubuntu.yml +1 -1
  5. data/.rubocop.yml +3 -6
  6. data/README.md +2 -1
  7. data/lib/yao/auth.rb +19 -1
  8. data/lib/yao/client.rb +12 -8
  9. data/lib/yao/config.rb +19 -0
  10. data/lib/yao/faraday_middlewares.rb +50 -3
  11. data/lib/yao/mode.rb +4 -0
  12. data/lib/yao/plugins/default_client_generator.rb +1 -1
  13. data/lib/yao/plugins/registry.rb +2 -1
  14. data/lib/yao/resources/action.rb +7 -0
  15. data/lib/yao/resources/aggregates.rb +1 -0
  16. data/lib/yao/resources/base.rb +27 -2
  17. data/lib/yao/resources/compute_services.rb +8 -1
  18. data/lib/yao/resources/flavor.rb +2 -0
  19. data/lib/yao/resources/floating_ip.rb +2 -0
  20. data/lib/yao/resources/hypervisor.rb +1 -1
  21. data/lib/yao/resources/image.rb +2 -0
  22. data/lib/yao/resources/loadbalancer.rb +4 -0
  23. data/lib/yao/resources/loadbalancer_healthmonitor.rb +3 -0
  24. data/lib/yao/resources/loadbalancer_listener.rb +2 -0
  25. data/lib/yao/resources/loadbalancer_pool.rb +6 -0
  26. data/lib/yao/resources/loadbalancer_pool_member.rb +21 -0
  27. data/lib/yao/resources/metadata_available.rb +21 -0
  28. data/lib/yao/resources/meter.rb +8 -1
  29. data/lib/yao/resources/network.rb +1 -0
  30. data/lib/yao/resources/network_associationable.rb +1 -0
  31. data/lib/yao/resources/old_sample.rb +4 -0
  32. data/lib/yao/resources/port.rb +2 -0
  33. data/lib/yao/resources/port_associationable.rb +1 -0
  34. data/lib/yao/resources/project.rb +6 -0
  35. data/lib/yao/resources/resource.rb +8 -2
  36. data/lib/yao/resources/restfully_accessible.rb +35 -5
  37. data/lib/yao/resources/role.rb +6 -4
  38. data/lib/yao/resources/role_assignment.rb +1 -0
  39. data/lib/yao/resources/router.rb +9 -0
  40. data/lib/yao/resources/sample.rb +4 -0
  41. data/lib/yao/resources/security_group.rb +1 -0
  42. data/lib/yao/resources/security_group_rule.rb +10 -0
  43. data/lib/yao/resources/server.rb +20 -0
  44. data/lib/yao/resources/server_group.rb +1 -1
  45. data/lib/yao/resources/server_usage_associationable.rb +12 -0
  46. data/lib/yao/resources/subnet.rb +1 -0
  47. data/lib/yao/resources/tenant.rb +6 -0
  48. data/lib/yao/resources/tenant_associationable.rb +1 -0
  49. data/lib/yao/resources/user.rb +2 -0
  50. data/lib/yao/resources.rb +3 -0
  51. data/lib/yao/token.rb +1 -0
  52. data/lib/yao/version.rb +1 -1
  53. data/test/support/restfully_accesible_stub.rb +1 -1
  54. data/test/yao/resources/test_base.rb +11 -0
  55. data/test/yao/resources/test_hypervisor.rb +3 -3
  56. data/test/yao/resources/test_image.rb +95 -4
  57. data/test/yao/resources/test_project.rb +20 -1
  58. data/test/yao/resources/test_server.rb +40 -0
  59. data/test/yao/resources/test_server_group.rb +1 -1
  60. data/test/yao/test_client.rb +5 -1
  61. data/yao.gemspec +2 -1
  62. metadata +24 -8
@@ -7,6 +7,7 @@ module Yao
7
7
  base.friendly_attributes :tenant_id
8
8
  end
9
9
 
10
+ # @return [Yao::Resources::Tenant]
10
11
  def tenant
11
12
  @tenant ||= Yao::Tenant.find(project_id || tenant_id)
12
13
  end
@@ -10,11 +10,13 @@ module Yao::Resources
10
10
  self.admin = true
11
11
 
12
12
  class << self
13
+ # @return [Bool]
13
14
  def return_single_on_querying
14
15
  api_verion_v2?
15
16
  end
16
17
 
17
18
  private
19
+ # @return [Bool]
18
20
  def api_verion_v2?
19
21
  client.url_prefix.to_s.match?(/v2\.0/)
20
22
  end
data/lib/yao/resources.rb CHANGED
@@ -4,6 +4,7 @@ module Yao
4
4
  require "yao/resources/tenant_associationable"
5
5
  require "yao/resources/port_associationable"
6
6
  require "yao/resources/network_associationable"
7
+ require "yao/resources/server_usage_associationable"
7
8
 
8
9
  autoload :Server, "yao/resources/server"
9
10
  autoload :ServerGroup, "yao/resources/server_group"
@@ -42,6 +43,8 @@ module Yao
42
43
  autoload :Sample, "yao/resources/sample"
43
44
  end
44
45
 
46
+ # @param name [String]
47
+ # @return [object]
45
48
  def self.const_missing(name)
46
49
  new_klass = Yao::Resources.const_get(name)
47
50
  Yao.const_set(name, new_klass)
data/lib/yao/token.rb CHANGED
@@ -2,6 +2,7 @@ require 'yao/client'
2
2
 
3
3
  module Yao
4
4
  class Token
5
+
5
6
  def self.issue(cli, auth_info)
6
7
  t = new(auth_info)
7
8
  t.refresh(cli)
data/lib/yao/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yao
2
- VERSION = "0.13.1"
2
+ VERSION = "0.14.0"
3
3
  end
@@ -41,6 +41,6 @@ module RestfullyAccessibleStub
41
41
  end
42
42
 
43
43
  def request_headers
44
- {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Faraday v#{Faraday::VERSION}"}
44
+ {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Yao/#{Yao::VERSION} Faraday/#{Faraday::VERSION}"}
45
45
  end
46
46
  end
@@ -12,4 +12,15 @@ class TestResourceBase < TestYaoResource
12
12
  base.class.friendly_attributes(:name)
13
13
  assert_equal("bar", base.name)
14
14
  end
15
+
16
+ def test_map_attribute_to_resource
17
+ base = Yao::Resources::Base.new("string" => "hoge")
18
+ base.class.map_attribute_to_resource string: String
19
+ assert_equal("hoge", base.string)
20
+
21
+ base = Yao::Resources::Base.new({"empty" => ""})
22
+ base.class.map_attribute_to_resource empty: NilClass
23
+ assert_equal(nil, base.empty)
24
+ end
25
+
15
26
  end
@@ -80,7 +80,7 @@ class TestHypervisor < TestYaoResource
80
80
 
81
81
  def test_list
82
82
  stub = stub_request(:get, "https://example.com:12345/os-hypervisors/detail")
83
- .with(headers: {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Faraday v#{Faraday::VERSION}"})
83
+ .with(headers: {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Yao/#{Yao::VERSION} Faraday/#{Faraday::VERSION}"})
84
84
  .to_return(
85
85
  status: 200,
86
86
  body: <<-JSON,
@@ -105,7 +105,7 @@ class TestHypervisor < TestYaoResource
105
105
 
106
106
  def test_statistics
107
107
  stub = stub_request(:get, "https://example.com:12345/os-hypervisors/statistics")
108
- .with(headers: {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Faraday v#{Faraday::VERSION}"})
108
+ .with(headers: {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Yao/#{Yao::VERSION} Faraday/#{Faraday::VERSION}"})
109
109
  .to_return(
110
110
  status: 200,
111
111
  body: <<-JSON,
@@ -137,7 +137,7 @@ class TestHypervisor < TestYaoResource
137
137
 
138
138
  def test_uptime
139
139
  stub = stub_request(:get, "https://example.com:12345/os-hypervisors/1/uptime")
140
- .with(headers: {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Faraday v#{Faraday::VERSION}"})
140
+ .with(headers: {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Yao/#{Yao::VERSION} Faraday/#{Faraday::VERSION}"})
141
141
  .to_return(
142
142
  status: 200,
143
143
  body: <<-JSON,
@@ -41,11 +41,102 @@ class TestImage < TestYaoResource
41
41
 
42
42
  end
43
43
 
44
- def test_resource_from_json
44
+ def test_empty_image
45
+ image = Yao::Server.new("image"=>"").image
46
+ assert_equal(image, nil)
47
+ end
45
48
 
46
- image = Yao::Resources::Image.send(:resource_from_json, @@params)
47
- check_image(image)
48
-
49
+ def test_to_hash
50
+ server = Yao::Resources::Server.new(
51
+ "OS-DCF:diskConfig" => "AUTO",
52
+ "OS-EXT-AZ:availability_zone" => "nova",
53
+ "OS-EXT-SRV-ATTR:host" => "compute",
54
+ "OS-EXT-SRV-ATTR:hostname" => "new-server-test",
55
+ "OS-EXT-SRV-ATTR:hypervisor_hostname" => "fake-mini",
56
+ "OS-EXT-SRV-ATTR:instance_name" => "instance-00000001",
57
+ "OS-EXT-SRV-ATTR:kernel_id" => "",
58
+ "OS-EXT-SRV-ATTR:launch_index" => 0,
59
+ "OS-EXT-SRV-ATTR:ramdisk_id" => "",
60
+ "OS-EXT-SRV-ATTR:reservation_id" => "r-l0i0clt2",
61
+ "OS-EXT-SRV-ATTR:root_device_name" => "/dev/sda",
62
+ "OS-EXT-SRV-ATTR:user_data" => "IyEvYmluL2Jhc2gKL2Jpbi9zdQplY2hvICJJIGFtIGluIHlvdSEiCg==",
63
+ "OS-EXT-STS:power_state" => 1,
64
+ "OS-EXT-STS:task_state" => nil,
65
+ "OS-EXT-STS:vm_state" => "active",
66
+ "OS-SRV-USG:launched_at" => "2019-04-23T15:19:15.317839",
67
+ "OS-SRV-USG:terminated_at" => nil,
68
+ "accessIPv4" => "1.2.3.4",
69
+ "accessIPv6" => "80fe::",
70
+ "addresses" => {
71
+ "private" => [
72
+ {
73
+ "OS-EXT-IPS-MAC:mac_addr" => "aa:bb:cc:dd:ee:ff",
74
+ "OS-EXT-IPS:type" => "fixed",
75
+ "addr" => "192.168.0.3",
76
+ "version" => 4
77
+ }
78
+ ]
79
+ },
80
+ "config_drive" => "",
81
+ "created" => "2019-04-23T15:19:14Z",
82
+ "description" => nil,
83
+ "flavor" => {
84
+ "disk" => 1,
85
+ "ephemeral" => 0,
86
+ "extra_specs" => {},
87
+ "original_name" => "m1.tiny",
88
+ "ram" => 512,
89
+ "swap" => 0,
90
+ "vcpus" => 1
91
+ },
92
+ "hostId" => "2091634baaccdc4c5a1d57069c833e402921df696b7f970791b12ec6",
93
+ "host_status" => "UP",
94
+ "id" => "2ce4c5b3-2866-4972-93ce-77a2ea46a7f9",
95
+ "image" => {
96
+ "id" => "70a599e0-31e7-49b7-b260-868f441e862b",
97
+ "links" => [
98
+ {
99
+ "href" => "http://openstack.example.com/6f70656e737461636b20342065766572/images/70a599e0-31e7-49b7-b260-868f441e862b",
100
+ "rel" => "bookmark"
101
+ }
102
+ ]
103
+ },
104
+ "key_name" => nil,
105
+ "links" => [
106
+ {
107
+ "href" => "http://openstack.example.com/v2.1/6f70656e737461636b20342065766572/servers/2ce4c5b3-2866-4972-93ce-77a2ea46a7f9",
108
+ "rel" => "self"
109
+ },
110
+ {
111
+ "href" => "http://openstack.example.com/6f70656e737461636b20342065766572/servers/2ce4c5b3-2866-4972-93ce-77a2ea46a7f9",
112
+ "rel" => "bookmark"
113
+ }
114
+ ],
115
+ "locked" => true,
116
+ "locked_reason" => "I don't want to work",
117
+ "metadata" => {
118
+ "My Server Name" => "Apache1"
119
+ },
120
+ "name" => "new-server-test",
121
+ "os-extended-volumes:volumes_attached" => [],
122
+ "progress" => 0,
123
+ "security_groups" => [
124
+ {
125
+ "name" => "default"
126
+ }
127
+ ],
128
+ "status" => "ACTIVE",
129
+ "tags" => [],
130
+ "tenant_id" => "6f70656e737461636b20342065766572",
131
+ "trusted_image_certificates" => nil,
132
+ "updated" => "2019-04-23T15:19:15Z",
133
+ "user_id" => "fake"
134
+ )
135
+
136
+ assert_equal(server.image.to_hash, server['image__Yao::Resources::Image'].to_hash)
137
+
138
+ image = Yao::Resources::Image.new(@@params)
139
+ assert_equal(image.to_hash, @@params)
49
140
  end
50
141
 
51
142
  private
@@ -254,4 +254,23 @@ class TestProject < TestYaoResource
254
254
  assert_instance_of(Array, project.servers)
255
255
  assert_requested(stub)
256
256
  end
257
- end
257
+
258
+ def test_server_usage
259
+ stub = stub_request(:get, "https://example.com:12345/os-simple-tenant-usage/0123456789abcdef0123456789abcdef")
260
+ .to_return(
261
+ status: 200,
262
+ body: <<-JSON,
263
+ {
264
+ "tenant_usage": {
265
+ "total_memory_mb_usage": 1024
266
+ }
267
+ }
268
+ JSON
269
+ headers: {'Content-Type' => 'application/json'}
270
+ )
271
+
272
+ project = Yao::Project::new("id" => "0123456789abcdef0123456789abcdef")
273
+ usage = project.server_usage
274
+ assert_equal(1024, usage["total_memory_mb_usage"])
275
+ end
276
+ end
@@ -162,6 +162,46 @@ class TestServer < TestYaoResource
162
162
  assert_requested(stub)
163
163
  end
164
164
 
165
+ def test_paging
166
+ stub = stub_request(:get, "https://example.com:12345/servers/detail")
167
+ .to_return(
168
+ status: 200,
169
+ body: <<-JSON,
170
+ {
171
+ "servers_links":[
172
+ {
173
+ "href":"https://example.com:12345/servers/detail",
174
+ "rel":"next"
175
+ }
176
+ ],
177
+ "servers": [{
178
+ "id": "dummy1"
179
+ }]
180
+ }
181
+ JSON
182
+ headers: {'Content-Type' => 'application/json'}
183
+ ).times(1).then
184
+ .to_return(
185
+ status: 200,
186
+ body: <<-JSON,
187
+ {
188
+ "servers": [{
189
+ "id": "dummy2"
190
+ }]
191
+ }
192
+ JSON
193
+ headers: {'Content-Type' => 'application/json'}
194
+ ).times(1)
195
+
196
+ servers = Yao::Server.list
197
+ assert_instance_of(Array, servers)
198
+ assert_instance_of(Yao::Server, servers.first)
199
+ assert_equal('dummy1', servers.first.id)
200
+ assert_equal('dummy2', servers.last.id)
201
+
202
+ assert_requested(stub, times: 2)
203
+ end
204
+
165
205
  def test_list_detail
166
206
  assert_equal(Yao::Server.method(:list), Yao::Server.method(:list_detail))
167
207
  end
@@ -20,4 +20,4 @@ class TestServerGroup < TestYaoResource
20
20
  assert_equal("6f70656e737461636b20342065766572", sg.project_id)
21
21
  assert_equal("fake", sg.user_id)
22
22
  end
23
- end
23
+ end
@@ -14,6 +14,7 @@ class TestClient < Test::Unit::TestCase
14
14
  handlers = [
15
15
  Faraday::Request::Accept,
16
16
  Faraday::Request::UrlEncoded,
17
+ Faraday::Request::UserAgent,
17
18
  Faraday::Request::ReadOnly,
18
19
  Faraday::Response::OSErrorDetector,
19
20
  FaradayMiddleware::ParseJson
@@ -28,6 +29,7 @@ class TestClient < Test::Unit::TestCase
28
29
  handlers = [
29
30
  Faraday::Request::Accept,
30
31
  Faraday::Request::UrlEncoded,
32
+ Faraday::Request::UserAgent,
31
33
  Faraday::Request::OSToken,
32
34
  Faraday::Request::ReadOnly,
33
35
  Faraday::Response::OSErrorDetector,
@@ -45,10 +47,10 @@ class TestClient < Test::Unit::TestCase
45
47
  handlers = [
46
48
  Faraday::Request::Accept,
47
49
  Faraday::Request::UrlEncoded,
50
+ Faraday::Request::UserAgent,
48
51
  Faraday::Request::ReadOnly,
49
52
  Faraday::Response::OSErrorDetector,
50
53
  FaradayMiddleware::ParseJson,
51
- Faraday::Response::Logger,
52
54
  Faraday::Response::OSDumper
53
55
  ]
54
56
  assert { cli.builder.handlers == handlers }
@@ -61,6 +63,7 @@ class TestClient < Test::Unit::TestCase
61
63
  end
62
64
 
63
65
  def test_cert_key
66
+ stub(Yao.config).ca_cert { File.expand_path("../../fixtures/dummy.pem", __FILE__) }
64
67
  stub(Yao.config).client_cert { File.expand_path("../../fixtures/dummy.pem", __FILE__) }
65
68
  stub(Yao.config).client_key { File.expand_path("../../fixtures/dummy.key", __FILE__) }
66
69
  stub(OpenSSL::X509::Certificate).new { "DummyCert" }
@@ -68,6 +71,7 @@ class TestClient < Test::Unit::TestCase
68
71
 
69
72
  cli = Yao::Client.gen_client("http://cool-api.example.com:12345/v3.0")
70
73
  ssl = cli.ssl
74
+ assert { ssl[:ca_file] == File.expand_path("../../fixtures/dummy.pem", __FILE__) }
71
75
  assert { ssl[:client_cert] == "DummyCert" }
72
76
  assert { ssl[:client_key] == "DummyKey" }
73
77
  end
data/yao.gemspec CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_dependency "json"
21
- spec.add_dependency "faraday", "~> 1.0.1"
21
+ spec.add_dependency "deep_merge"
22
+ spec.add_dependency "faraday", "~> 1.8.0"
22
23
  spec.add_dependency "faraday_middleware"
23
24
  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.13.1
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uchio, KONDO
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-22 00:00:00.000000000 Z
11
+ date: 2021-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -24,20 +24,34 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: deep_merge
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: faraday
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: 1.0.1
47
+ version: 1.8.0
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: 1.0.1
54
+ version: 1.8.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: faraday_middleware
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -60,6 +74,7 @@ extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
62
76
  - ".github/workflows/macos.yml"
77
+ - ".github/workflows/rubocop.yml"
63
78
  - ".github/workflows/ubuntu-rvm.yml"
64
79
  - ".github/workflows/ubuntu.yml"
65
80
  - ".gitignore"
@@ -117,6 +132,7 @@ files:
117
132
  - lib/yao/resources/security_group_rule.rb
118
133
  - lib/yao/resources/server.rb
119
134
  - lib/yao/resources/server_group.rb
135
+ - lib/yao/resources/server_usage_associationable.rb
120
136
  - lib/yao/resources/subnet.rb
121
137
  - lib/yao/resources/tenant.rb
122
138
  - lib/yao/resources/tenant_associationable.rb
@@ -184,7 +200,7 @@ homepage: https://github.com/yaocloud/yao
184
200
  licenses:
185
201
  - MIT
186
202
  metadata: {}
187
- post_install_message:
203
+ post_install_message:
188
204
  rdoc_options: []
189
205
  require_paths:
190
206
  - lib
@@ -199,8 +215,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
215
  - !ruby/object:Gem::Version
200
216
  version: '0'
201
217
  requirements: []
202
- rubygems_version: 3.1.2
203
- signing_key:
218
+ rubygems_version: 3.2.32
219
+ signing_key:
204
220
  specification_version: 4
205
221
  summary: Yet Another OpenStack API Wrapper that rocks!!
206
222
  test_files: