yao 0.19.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4995f4848c6b4d4fe74b39999648c0d1fe4cb473d086ea35017ad5d7611b07e3
4
- data.tar.gz: 6fddaff2cd5e2118f7652559e7f3d3f36cceb03961c39c4e54d9cd940f6f733e
3
+ metadata.gz: 390b05f4ca044196755551231ee7f297900816c3742318bcc502b0376e70512a
4
+ data.tar.gz: 0a6bb49a598bb7667d488ce316280ed3504b5ab2c3e0f97da0019783a5f6a939
5
5
  SHA512:
6
- metadata.gz: d3d72831ab303bac1453d3cfeda3e98f73554ebc3960d324cb4d701d4f15e59c0d90279c249e64bfc5b598e805b8f1b2647c21dbcf798845a38c8d7c9822ba76
7
- data.tar.gz: 9c5b6ab144c089554c0c245ec93ecce895d14121447c7f70058cfa8e6e8682e71190a0c1d8776b89d6f0994183f40c8fd6df9de24e05a96ba162e88eac291c52
6
+ metadata.gz: 731688676c2b1b9d120ef76f67131de2b060a25b8e3c9cb0b1cbf138c6a58fe632220c7f02c87c58972ee51c40f0d902bca2e69d254cd9eecd427d3960a1740b
7
+ data.tar.gz: 63b4adfd5b841b0c4b99c262b8cc2235a980165c574db4b60dab8b39ba39b4b659b0d4761286e81a48e61f33a57821ba1167b1bd53ba35387fb6f1c0b37dc2cc
@@ -21,6 +21,11 @@ module Yao::Resources
21
21
  status == 'disabled'
22
22
  end
23
23
 
24
+ # @return []
25
+ def delete
26
+ self.class.delete(id)
27
+ end
28
+
24
29
  class << self
25
30
  # @param host [String]
26
31
  # @param binary [String]
@@ -2,7 +2,7 @@ module Yao::Resources
2
2
  class Network < Base
3
3
  include ProjectAssociationable
4
4
 
5
- friendly_attributes :name, :status, :shared, :subnets, :admin_state_up
5
+ friendly_attributes :name, :status, :shared, :admin_state_up
6
6
  map_attribute_to_attribute "provider:physical_network" => :physical_network
7
7
  map_attribute_to_attribute "provider:network_type" => :type
8
8
  map_attribute_to_attribute "provider:segmentation_id" => :segmentation_id
@@ -17,5 +17,10 @@ module Yao::Resources
17
17
  def ports
18
18
  @ports ||= Yao::Port.list(network_id: id)
19
19
  end
20
+
21
+ # @return [Array<Yao::Resources::Subnet>]
22
+ def subnets
23
+ @subnets ||= self['subnets'].map {|id| Yao::Subnet.new("id" => id)}
24
+ end
20
25
  end
21
26
  end
@@ -25,6 +25,11 @@ module Yao::Resources
25
25
  Time.parse(self["heartbeat_timestamp"])
26
26
  end
27
27
 
28
+ # @return []
29
+ def delete
30
+ self.class.delete(id)
31
+ end
32
+
28
33
  alias :state :admin_state_up
29
34
  end
30
35
  end
@@ -106,9 +106,8 @@ module Yao::Resources
106
106
  r = GET(url, query).body
107
107
  if r.is_a?(Hash)
108
108
  res.deep_merge!(r)
109
- links = r.find {|k,_| k =~ /links/ }
110
- if links && links.last.is_a?(Array) && next_link = links.last.find{|s| s["rel"] == "next" }
111
- uri = URI.parse(next_link["href"])
109
+ if next_link = find_next_link(r)
110
+ uri = URI.parse(next_link)
112
111
  query = Hash[URI::decode_www_form(uri.query)] if uri.query
113
112
  next
114
113
  end
@@ -127,6 +126,16 @@ module Yao::Resources
127
126
  # @note .list is defined to keep backward compatibility and will be deprecated
128
127
  alias :list_detail :list
129
128
 
129
+ # @param response [Hash]
130
+ # @return [String]
131
+ def find_next_link(response)
132
+ if links = response.find {|k, v| k =~ /links/ && v.is_a?(Array) }&.last
133
+ links.find{|s| s["rel"] == "next" }&.fetch("href")
134
+ else
135
+ response["next"]
136
+ end
137
+ end
138
+
130
139
  # @param id_or_name_or_permalink [Stirng]
131
140
  # @param query [Hash]
132
141
  # @return [Yao::Resources::*]
@@ -0,0 +1,15 @@
1
+ module Yao::Resources
2
+ class ServerMigrate < Base
3
+ friendly_attributes :dest_compute, :dest_host, :dest_node, :instance_uuid, :new_instance_type_id, :old_instance_type_id,
4
+ :source_compute, :source_node, :status, :migration_type, :uuid, :user_id, :project_id
5
+ map_attributes_to_time :created_at, :updated_at
6
+
7
+ self.service = "compute"
8
+ self.resource_name = "migrations"
9
+ self.resources_name = "os-migrations"
10
+
11
+ def server
12
+ @server ||= Yao::Server.get(self["instance_uuid"])
13
+ end
14
+ end
15
+ end
@@ -10,6 +10,10 @@ module Yao::Resources
10
10
  map_attribute_to_attribute 'os-vol-host-attr:host' => :host
11
11
  map_attribute_to_attribute 'os-vol-tenant-attr:tenant_id' => :tenant_id
12
12
 
13
+ map_attributes_to_time :created_at, :updated_at
14
+ alias :created :created_at
15
+ alias :updated :updated_at
16
+
13
17
  self.service = "volumev3"
14
18
  self.resource_name = "volume"
15
19
  self.resources_name = "volumes"
@@ -0,0 +1,76 @@
1
+ module Yao::Resources
2
+ class VolumeServices < Base
3
+
4
+ friendly_attributes :binary, :disabled_reason, :host, :state, :status,
5
+ :frozen, :zone, :cluster, :replication_status,
6
+ :active_backend_id, :backed_state
7
+ map_attributes_to_time :updated_at
8
+
9
+ self.service = "volumev3"
10
+ self.resource_name = "os-service"
11
+ self.resources_name = "os-services"
12
+
13
+ # return true if ComputeServices is enabled
14
+ # @return [Bool]
15
+ def enabled?
16
+ status == 'enabled'
17
+ end
18
+
19
+ # return true if ComputeServices is disabled
20
+ # @return [Bool]
21
+ def disabled?
22
+ status == 'disabled'
23
+ end
24
+
25
+ def enable
26
+ self.class.enable(host, binary)
27
+ end
28
+
29
+ def disable(reason = nil)
30
+ self.class.disable(host, binary, reason)
31
+ end
32
+
33
+ class << self
34
+ # @param host [String]
35
+ # @param binary [String]
36
+ # @return [Hash]
37
+ def enable(host, binary)
38
+ params = {
39
+ "host" => host,
40
+ "binary" => binary,
41
+ }
42
+ put("enable", params)
43
+ end
44
+
45
+ # @param host [String]
46
+ # @param binary [String]
47
+ # @param resason [String]
48
+ # @return [Hash]
49
+ def disable(host, binary, reason = nil)
50
+ params = {
51
+ "host" => host,
52
+ "binary" => binary,
53
+ }
54
+ if reason
55
+ params["disabled_reason"] = reason
56
+ put("disable-log-reason", params)
57
+ else
58
+ put("disable", params)
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ # @param path [String]
65
+ # @param params [Hash]
66
+ # @return [Hash]
67
+ def put(path, params)
68
+ res = PUT(create_url(path), params) do |req|
69
+ req.body = params.to_json
70
+ req.headers['Content-Type'] = 'application/json'
71
+ end
72
+ res.body
73
+ end
74
+ end
75
+ end
76
+ end
data/lib/yao/resources.rb CHANGED
@@ -8,6 +8,7 @@ module Yao
8
8
 
9
9
  autoload :Server, "yao/resources/server"
10
10
  autoload :ServerGroup, "yao/resources/server_group"
11
+ autoload :ServerMigrate, "yao/resources/server_migrate"
11
12
  autoload :Flavor, "yao/resources/flavor"
12
13
  autoload :Image, "yao/resources/image"
13
14
  autoload :SecurityGroup, "yao/resources/security_group"
@@ -33,6 +34,7 @@ module Yao
33
34
  autoload :Role, "yao/resources/role"
34
35
  autoload :RoleAssignment, "yao/resources/role_assignment"
35
36
  autoload :Volume, "yao/resources/volume"
37
+ autoload :VolumeServices, "yao/resources/volume_services"
36
38
  autoload :VolumeType, "yao/resources/volume_type"
37
39
  autoload :ComputeServices, "yao/resources/compute_services"
38
40
  autoload :Project, "yao/resources/project"
data/lib/yao/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yao
2
- VERSION = "0.19.0"
2
+ VERSION = "0.20.0"
3
3
  end
@@ -51,6 +51,29 @@ module RestfullyAccessibleStub
51
51
  )
52
52
  end
53
53
 
54
+ def stub_put_request(url, body, response = {})
55
+ stub_request(:put,url)
56
+ .with(
57
+ headers: request_headers.merge({'Content-Type' => 'application/json'}),
58
+ body: body.to_json,
59
+ ).to_return(
60
+ status: 200,
61
+ headers: {'Content-Type' => 'application/json'},
62
+ body: response.to_json
63
+ )
64
+ end
65
+
66
+ def stub_delete_request(url, response = {})
67
+ stub_request(:delete,url)
68
+ .with(
69
+ headers: request_headers
70
+ ).to_return(
71
+ status: 200,
72
+ headers: {'Content-Type' => 'application/json'},
73
+ body: response.to_json
74
+ )
75
+ end
76
+
54
77
  def request_headers
55
78
  {'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}"}
56
79
  end
@@ -1,4 +1,5 @@
1
1
  class TestComputeServices < TestYaoResource
2
+ include RestfullyAccessibleStub
2
3
 
3
4
  def test_compute_services
4
5
 
@@ -127,4 +128,11 @@ class TestComputeServices < TestYaoResource
127
128
 
128
129
  assert_requested stub
129
130
  end
131
+
132
+ def test_delete
133
+ stub = stub_delete_request("https://example.com:12345/os-services/test-id")
134
+ compute_service = Yao::ComputeServices.new({"id" => "test-id"})
135
+ assert_equal({}, compute_service.delete)
136
+ assert_requested(stub)
137
+ end
130
138
  end
@@ -14,7 +14,7 @@ class TestNetwork < TestYaoResource
14
14
  "router:external" => false,
15
15
  "shared" => false,
16
16
  "status" => "ACTIVE",
17
- "subnets" => [],
17
+ "subnets" => ["52822b63-eb89-496d-9509-f91473b9d85d"],
18
18
  "tenant_id" => "c05140b3dc7c4555afff9fab6b58edc2",
19
19
  "project_id" => "c05140b3dc7c4555afff9fab6b58edc2",
20
20
  }
@@ -28,13 +28,15 @@ class TestNetwork < TestYaoResource
28
28
  assert_equal(false, network.shared)
29
29
  assert_equal(false, network.shared?)
30
30
  assert_equal("c05140b3dc7c4555afff9fab6b58edc2", network.tenant_id)
31
- assert_equal([], network.subnets)
32
31
  assert_equal(true, network.admin_state_up)
33
32
 
34
33
  #map_attribute_to_attribute
35
34
  assert_equal("physnet1", network.physical_network)
36
35
  assert_equal("vlan", network.type)
37
36
  assert_equal(1000, network.segmentation_id)
37
+
38
+ assert_equal(Yao::Subnet, network.subnets.first.class)
39
+ assert_equal("52822b63-eb89-496d-9509-f91473b9d85d", network.subnets.first.id)
38
40
  end
39
41
 
40
42
  def test_project
@@ -1,4 +1,5 @@
1
1
  class TestNetworkingAgents < TestYaoResource
2
+ include RestfullyAccessibleStub
2
3
 
3
4
  def test_networking_agents
4
5
 
@@ -81,4 +82,11 @@ class TestNetworkingAgents < TestYaoResource
81
82
  assert_equal(Time.parse("2017-09-12 19:35:38"), agent.created_at)
82
83
  assert_equal(Time.parse("2017-09-12 19:35:38"), agent.started_at)
83
84
  end
85
+
86
+ def test_delete
87
+ stub = stub_delete_request("https://example.com:12345/agents/test-id")
88
+ agents = Yao::NetworkingAgents.new({"id" => "test-id"})
89
+ assert_equal({}, agents.delete)
90
+ assert_requested(stub)
91
+ end
84
92
  end
@@ -0,0 +1,33 @@
1
+ class TestServerGroup < TestYaoResource
2
+ def test_server_group
3
+ # https://docs.openstack.org/api-ref/compute/?expanded=list-migrations-detail#list-migrations
4
+ params = {
5
+ "created_at" => "2012-10-29T13:42:02.000000",
6
+ "dest_compute" => "compute2",
7
+ "dest_host" => "1.2.3.4",
8
+ "dest_node" => "node2",
9
+ "id" => 1234,
10
+ "instance_uuid" => "8600d31b-d1a1-4632-b2ff-45c2be1a70ff",
11
+ "new_instance_type_id" => 2,
12
+ "old_instance_type_id" => 1,
13
+ "source_compute" => "compute1",
14
+ "source_node" => "node1",
15
+ "status" => "done",
16
+ "updated_at" => "2012-10-29T13:42:02.000000"
17
+ }
18
+
19
+ migrate = Yao::ServerMigrate.new(params)
20
+ assert_equal(Time.parse("2012-10-29T13:42:02.000000"), migrate.created_at)
21
+ assert_equal("compute2", migrate.dest_compute)
22
+ assert_equal("1.2.3.4", migrate.dest_host)
23
+ assert_equal("node2", migrate.dest_node)
24
+ assert_equal(1234, migrate.id)
25
+ assert_equal("8600d31b-d1a1-4632-b2ff-45c2be1a70ff", migrate.instance_uuid)
26
+ assert_equal(2, migrate.new_instance_type_id)
27
+ assert_equal(1, migrate.old_instance_type_id)
28
+ assert_equal("compute1", migrate.source_compute)
29
+ assert_equal("node1", migrate.source_node)
30
+ assert_equal("done", migrate.status)
31
+ assert_equal(Time.parse("2012-10-29T13:42:02.000000"), migrate.updated_at)
32
+ end
33
+ end
@@ -13,7 +13,9 @@ class TestVolume < TestYaoResource
13
13
  'snapshot_id' => nil,
14
14
  'status' => 'available',
15
15
  'user_id' => 'aaaa166533fd49f3b11b1cdce2430000',
16
- 'volume_type' => 'test'
16
+ 'volume_type' => 'test',
17
+ 'created_at' => '2018-11-28T06:25:15.288987',
18
+ 'updated_at' => '2019-11-28T06:25:15.288987'
17
19
  }
18
20
 
19
21
  volume = Yao::Volume.new(params)
@@ -30,6 +32,10 @@ class TestVolume < TestYaoResource
30
32
  assert_equal(volume.user_id, 'aaaa166533fd49f3b11b1cdce2430000')
31
33
  assert_equal(volume.volume_type, 'test')
32
34
  assert_equal(volume.type, 'test')
35
+ assert_equal(Time.parse('2018-11-28T06:25:15.288987'), volume.created_at)
36
+ assert_equal(Time.parse('2018-11-28T06:25:15.288987'), volume.created)
37
+ assert_equal(Time.parse('2019-11-28T06:25:15.288987'), volume.updated_at)
38
+ assert_equal(Time.parse('2019-11-28T06:25:15.288987'), volume.updated)
33
39
  end
34
40
 
35
41
  def test_list
@@ -0,0 +1,116 @@
1
+ class TestVolumeServices < TestYaoResource
2
+ include RestfullyAccessibleStub
3
+
4
+ def test_volume_services
5
+ # https://docs.openstack.org/api-ref/block-storage/v3/index.html?expanded=list-all-cinder-services-detail#list-all-cinder-services
6
+ params = JSON.parse(<<~JSON)
7
+ {
8
+ "status": "enabled",
9
+ "binary": "cinder-scheduler",
10
+ "zone": "nova",
11
+ "state": "up",
12
+ "updated_at": "2017-06-29T05:50:35.000000",
13
+ "host": "devstack",
14
+ "disabled_reason": null
15
+ }
16
+ JSON
17
+
18
+ service = Yao::VolumeServices.new(params)
19
+ assert_equal('enabled', service.status)
20
+ assert_equal('cinder-scheduler', service.binary)
21
+ assert_equal('nova', service.zone)
22
+ assert_equal('up', service.state)
23
+ assert_equal(Time.parse('2017-06-29T05:50:35.000000'), service.updated_at)
24
+ assert_equal('devstack', service.host)
25
+ assert_equal(nil, service.disabled_reason)
26
+ end
27
+
28
+ def test_enabled
29
+ service = Yao::VolumeServices.new({'status' => 'enabled'})
30
+ assert_equal(true, service.enabled?)
31
+ end
32
+
33
+ def test_disabled
34
+ service = Yao::VolumeServices.new({'status' => 'enabled'})
35
+ assert_equal(false, service.disabled?)
36
+ end
37
+
38
+ def stub_enable_request
39
+ body = {
40
+ "host" => "test-host",
41
+ "binary" => "test-binary",
42
+ }
43
+ response = { "disabled" => false }
44
+ stub_put_request('https://example.com:12345/os-services/enable', body, response)
45
+ end
46
+
47
+ def test_enable
48
+ stub = stub_enable_request
49
+ service = Yao::VolumeServices.new({
50
+ "host" => "test-host",
51
+ "binary" => "test-binary",
52
+ })
53
+ response = service.enable
54
+ assert_equal(false, response['disabled'])
55
+ assert_requested(stub)
56
+ end
57
+
58
+ def test_self_enable
59
+ stub = stub_enable_request
60
+ response = Yao::VolumeServices.enable('test-host', 'test-binary')
61
+ assert_equal(false, response['disabled'])
62
+ assert_requested(stub)
63
+ end
64
+
65
+ def stub_disable_request(reason = nil)
66
+ body = {
67
+ "host" => "test-host",
68
+ "binary" => "test-binary",
69
+ }
70
+ response = { "disabled" => true }
71
+ if reason
72
+ body["disabled_reason"] = reason
73
+ response["disabled_reason"] = reason
74
+ stub_put_request('https://example.com:12345/os-services/disable-log-reason', body, response)
75
+ else
76
+ stub_put_request('https://example.com:12345/os-services/disable', body, response)
77
+ end
78
+ end
79
+
80
+ def test_disable
81
+ stub = stub_disable_request
82
+ service = Yao::VolumeServices.new({
83
+ "host" => "test-host",
84
+ "binary" => "test-binary",
85
+ })
86
+ response = service.disable
87
+ assert_equal(true, response['disabled'])
88
+ assert_requested(stub)
89
+ end
90
+
91
+ def test_disable_reason
92
+ stub = stub_disable_request('test-reason')
93
+ service = Yao::VolumeServices.new({
94
+ "host" => "test-host",
95
+ "binary" => "test-binary",
96
+ })
97
+ response = service.disable('test-reason')
98
+ assert_equal(true, response['disabled'])
99
+ assert_equal('test-reason', response['disabled_reason'])
100
+ assert_requested(stub)
101
+ end
102
+
103
+ def test_self_disable
104
+ stub = stub_disable_request
105
+ response = Yao::VolumeServices.disable('test-host', 'test-binary')
106
+ assert_equal(true, response['disabled'])
107
+ assert_requested(stub)
108
+ end
109
+
110
+ def test_self_disable_reason
111
+ stub = stub_disable_request('test-reason')
112
+ response = Yao::VolumeServices.disable('test-host', 'test-binary', 'test-reason')
113
+ assert_equal(true, response['disabled'])
114
+ assert_requested(stub)
115
+ end
116
+ 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.19.0
4
+ version: 0.20.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: 2022-05-12 00:00:00.000000000 Z
11
+ date: 2023-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -133,12 +133,14 @@ files:
133
133
  - lib/yao/resources/security_group_rule.rb
134
134
  - lib/yao/resources/server.rb
135
135
  - lib/yao/resources/server_group.rb
136
+ - lib/yao/resources/server_migrate.rb
136
137
  - lib/yao/resources/server_usage_associationable.rb
137
138
  - lib/yao/resources/subnet.rb
138
139
  - lib/yao/resources/tenant.rb
139
140
  - lib/yao/resources/user.rb
140
141
  - lib/yao/resources/volume.rb
141
142
  - lib/yao/resources/volume_action.rb
143
+ - lib/yao/resources/volume_services.rb
142
144
  - lib/yao/resources/volume_type.rb
143
145
  - lib/yao/setup.rb
144
146
  - lib/yao/token.rb
@@ -182,9 +184,11 @@ files:
182
184
  - test/yao/resources/test_security_group_rule.rb
183
185
  - test/yao/resources/test_server.rb
184
186
  - test/yao/resources/test_server_group.rb
187
+ - test/yao/resources/test_server_migrate.rb
185
188
  - test/yao/resources/test_subnet.rb
186
189
  - test/yao/resources/test_user.rb
187
190
  - test/yao/resources/test_volume.rb
191
+ - test/yao/resources/test_volume_services.rb
188
192
  - test/yao/resources/test_volume_type.rb
189
193
  - test/yao/test_auth.rb
190
194
  - test/yao/test_authv3.rb
@@ -216,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
220
  - !ruby/object:Gem::Version
217
221
  version: '0'
218
222
  requirements: []
219
- rubygems_version: 3.3.7
223
+ rubygems_version: 3.4.6
220
224
  signing_key:
221
225
  specification_version: 4
222
226
  summary: Yet Another OpenStack API Wrapper that rocks!!
@@ -259,9 +263,11 @@ test_files:
259
263
  - test/yao/resources/test_security_group_rule.rb
260
264
  - test/yao/resources/test_server.rb
261
265
  - test/yao/resources/test_server_group.rb
266
+ - test/yao/resources/test_server_migrate.rb
262
267
  - test/yao/resources/test_subnet.rb
263
268
  - test/yao/resources/test_user.rb
264
269
  - test/yao/resources/test_volume.rb
270
+ - test/yao/resources/test_volume_services.rb
265
271
  - test/yao/resources/test_volume_type.rb
266
272
  - test/yao/test_auth.rb
267
273
  - test/yao/test_authv3.rb