yao 0.14.0 → 0.17.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 +4 -4
- data/.github/workflows/rubocop.yml +2 -2
- data/.github/workflows/ubuntu-rvm.yml +1 -1
- data/.github/workflows/ubuntu.yml +2 -2
- data/lib/yao/resources/base.rb +17 -5
- data/lib/yao/resources/flavor.rb +10 -0
- data/lib/yao/resources/floating_ip.rb +1 -7
- data/lib/yao/resources/loadbalancer_pool.rb +10 -20
- data/lib/yao/resources/meter.rb +1 -1
- data/lib/yao/resources/network.rb +1 -1
- data/lib/yao/resources/old_sample.rb +1 -1
- data/lib/yao/resources/port.rb +1 -1
- data/lib/yao/resources/project.rb +5 -0
- data/lib/yao/resources/{tenant_associationable.rb → project_associationable.rb} +5 -5
- data/lib/yao/resources/resource.rb +1 -1
- data/lib/yao/resources/restfully_accessible.rb +3 -2
- data/lib/yao/resources/role_assignment.rb +37 -5
- data/lib/yao/resources/router.rb +19 -10
- data/lib/yao/resources/security_group.rb +1 -1
- data/lib/yao/resources/server.rb +6 -1
- data/lib/yao/resources/subnet.rb +1 -1
- data/lib/yao/resources/tenant.rb +5 -0
- data/lib/yao/resources/user.rb +6 -1
- data/lib/yao/resources/volume.rb +14 -1
- data/lib/yao/resources/volume_action.rb +13 -0
- data/lib/yao/resources.rb +1 -1
- data/lib/yao/version.rb +1 -1
- data/test/yao/resources/test_base.rb +21 -0
- data/test/yao/resources/test_flavor.rb +67 -33
- data/test/yao/resources/test_floating_ip.rb +5 -5
- data/test/yao/resources/test_loadbalancer_pool.rb +146 -1
- data/test/yao/resources/test_meter.rb +5 -5
- data/test/yao/resources/test_network.rb +6 -6
- data/test/yao/resources/test_port.rb +6 -6
- data/test/yao/resources/test_project.rb +25 -5
- data/test/yao/resources/test_restfully_accessible.rb +46 -4
- data/test/yao/resources/test_role_assignment.rb +100 -3
- data/test/yao/resources/test_router.rb +33 -12
- data/test/yao/resources/test_security_group.rb +5 -5
- data/test/yao/resources/test_server.rb +52 -6
- data/test/yao/resources/test_subnet.rb +6 -6
- data/test/yao/resources/test_user.rb +28 -1
- data/test/yao/resources/test_volume.rb +81 -1
- data/yao.gemspec +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22e30555da286a1d595d60c3278cb2d3b63d1353defa42ebfade5851341d486b
|
4
|
+
data.tar.gz: 27ed61a3d891a286a54c78af0f6b7eea591e461b7bca75e5e2da93e30f2e6741
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5610760a589bb5e0bbdd8bbfd6da917628865faa8b64f46f8cc9dbe94f6e9eb95929daf93d1831de5b2bc8a520b94da33455619bb1f412bbeda8dc51833cd5e
|
7
|
+
data.tar.gz: 8c2e8f48490af04d4f3a7cb9b42506f74f36fb99d39dc91a7036444de996838639443e3064a01616a9354078b98ca1092a9dfe9dd05feee96dd0cfb7198efadb
|
@@ -8,9 +8,9 @@ jobs:
|
|
8
8
|
steps:
|
9
9
|
- uses: actions/checkout@master
|
10
10
|
- name: Set up Ruby
|
11
|
-
uses:
|
11
|
+
uses: ruby/setup-ruby@v1
|
12
12
|
with:
|
13
|
-
ruby-version: 3.
|
13
|
+
ruby-version: 3.1
|
14
14
|
- name: Install dependencies
|
15
15
|
run: |
|
16
16
|
gem install bundler --no-document
|
@@ -7,11 +7,11 @@ jobs:
|
|
7
7
|
runs-on: ubuntu-latest
|
8
8
|
strategy:
|
9
9
|
matrix:
|
10
|
-
ruby: [3.
|
10
|
+
ruby: [3.1, 3.0, 2.7]
|
11
11
|
steps:
|
12
12
|
- uses: actions/checkout@master
|
13
13
|
- name: Set up Ruby
|
14
|
-
uses:
|
14
|
+
uses: ruby/setup-ruby@v1
|
15
15
|
with:
|
16
16
|
ruby-version: ${{ matrix.ruby }}
|
17
17
|
- name: Install dependencies
|
data/lib/yao/resources/base.rb
CHANGED
@@ -8,9 +8,6 @@ module Yao::Resources
|
|
8
8
|
def self.friendly_attributes(*names)
|
9
9
|
names.map(&:to_s).each do |name|
|
10
10
|
define_method(name) do
|
11
|
-
if !@data.key?(name) && id
|
12
|
-
@data = self.class.get(id).to_hash
|
13
|
-
end
|
14
11
|
self[name]
|
15
12
|
end
|
16
13
|
end
|
@@ -58,6 +55,9 @@ module Yao::Resources
|
|
58
55
|
# @param name [String]
|
59
56
|
# @return [String]
|
60
57
|
def [](name)
|
58
|
+
unless @data["id"].nil? || @data.key?(name) || name.include?("__")
|
59
|
+
@data = self.class.get(@data["id"]).to_hash
|
60
|
+
end
|
61
61
|
@data[name]
|
62
62
|
end
|
63
63
|
|
@@ -80,18 +80,30 @@ module Yao::Resources
|
|
80
80
|
|
81
81
|
# @return [Date]
|
82
82
|
def created
|
83
|
-
if date = self["
|
83
|
+
if date = self["created_at"] || self["created"]
|
84
84
|
Time.parse(date)
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
88
|
# @return [Date]
|
89
89
|
def updated
|
90
|
-
if date = self["
|
90
|
+
if date = self["updated_at"] || self["updated"]
|
91
91
|
Time.parse(date)
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
+
# @param resource_params [Hash]
|
96
|
+
# @return [Yao::Resources::*]
|
97
|
+
def update(resource_params)
|
98
|
+
self.class.update(id, resource_params)
|
99
|
+
end
|
100
|
+
|
101
|
+
# @return [String]
|
102
|
+
def destroy
|
103
|
+
self.class.destroy(id)
|
104
|
+
end
|
105
|
+
alias delete destroy
|
106
|
+
|
95
107
|
extend RestfullyAccessible
|
96
108
|
end
|
97
109
|
end
|
data/lib/yao/resources/flavor.rb
CHANGED
@@ -20,5 +20,15 @@ module Yao::Resources
|
|
20
20
|
self.resource_name = "flavor"
|
21
21
|
self.resources_name = "flavors"
|
22
22
|
self.resources_detail_available = true
|
23
|
+
|
24
|
+
class << self
|
25
|
+
# override Yao::Resources::RestfullyAccessible#find_by_name
|
26
|
+
# @return [Array<Yao::Resources::Role>]
|
27
|
+
def find_by_name(name, query={})
|
28
|
+
list(query).select do |flavor|
|
29
|
+
flavor.name == name
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
23
33
|
end
|
24
34
|
end
|
@@ -2,7 +2,7 @@ module Yao::Resources
|
|
2
2
|
class FloatingIP < Base
|
3
3
|
|
4
4
|
include PortAssociationable
|
5
|
-
include
|
5
|
+
include ProjectAssociationable
|
6
6
|
|
7
7
|
friendly_attributes :router_id, :description, :dns_domain, :dns_name,
|
8
8
|
:revision_number,
|
@@ -18,11 +18,5 @@ module Yao::Resources
|
|
18
18
|
def router
|
19
19
|
@router ||= Yao::Router.get(router_id)
|
20
20
|
end
|
21
|
-
|
22
|
-
# @return [Yao::Resources::Tenant]
|
23
|
-
def project
|
24
|
-
@project ||= Yao::Tenant.get(project_id)
|
25
|
-
end
|
26
|
-
alias :tenant :project
|
27
21
|
end
|
28
22
|
end
|
@@ -7,21 +7,11 @@ module Yao::Resources
|
|
7
7
|
map_attribute_to_resources loadbalancers: LoadBalancer
|
8
8
|
map_attribute_to_resources listeners: LoadBalancerListener
|
9
9
|
|
10
|
-
# @return [Date]
|
11
|
-
def created_at
|
12
|
-
Date.parse(self["created_at"])
|
13
|
-
end
|
14
|
-
|
15
|
-
# @return [Date]
|
16
|
-
def updated_at
|
17
|
-
Date.parse(self["updated_at"])
|
18
|
-
end
|
19
|
-
|
20
10
|
# @return [Yao::Resources::LoadBalancerListener]
|
21
11
|
def listeners
|
22
|
-
self["listeners"].map do |listener|
|
23
|
-
|
24
|
-
|
12
|
+
@listeners ||= self["listeners"].map do |listener|
|
13
|
+
Yao::LoadBalancerListener.get(listener["id"])
|
14
|
+
end
|
25
15
|
end
|
26
16
|
|
27
17
|
# @return [Yao::Resources::Tenant]
|
@@ -32,18 +22,18 @@ module Yao::Resources
|
|
32
22
|
end
|
33
23
|
alias :tenant :project
|
34
24
|
|
35
|
-
# @return [Yao::Resources::
|
25
|
+
# @return [Yao::Resources::LoadBalancerPoolMember]
|
36
26
|
def members
|
37
|
-
self["members"].map do |member|
|
38
|
-
|
39
|
-
|
27
|
+
@members ||= self["members"].map do |member|
|
28
|
+
Yao::LoadBalancerPoolMember.get(self, member["id"])
|
29
|
+
end
|
40
30
|
end
|
41
31
|
|
42
32
|
# @return [Yao::Resources::LoadBalancerHealthMonitor]
|
43
33
|
def healthmonitor
|
44
|
-
if healthmonitor_id = self["healthmonitor_id"]
|
45
|
-
|
46
|
-
|
34
|
+
@healthmonitor ||= if healthmonitor_id = self["healthmonitor_id"]
|
35
|
+
Yao::LoadBalancerHealthMonitor.get(healthmonitor_id)
|
36
|
+
end
|
47
37
|
end
|
48
38
|
|
49
39
|
self.service = "load-balancer"
|
data/lib/yao/resources/meter.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Yao::Resources
|
2
2
|
class OldSample < Base
|
3
|
-
include
|
3
|
+
include ProjectAssociationable
|
4
4
|
|
5
5
|
friendly_attributes :counter_name, :counter_type, :counter_unit, :counter_volume,
|
6
6
|
:message_id, :resource_id, :timestamp, :resource_metadata, :user_id,
|
data/lib/yao/resources/port.rb
CHANGED
@@ -2,7 +2,7 @@ module Yao::Resources
|
|
2
2
|
class Port < Base
|
3
3
|
|
4
4
|
include NetworkAssociationable
|
5
|
-
include
|
5
|
+
include ProjectAssociationable
|
6
6
|
|
7
7
|
friendly_attributes :name, :mac_address, :status, :allowed_address_pairs,
|
8
8
|
:device_owner, :fixed_ips, :security_groups, :device_id,
|
@@ -1,18 +1,18 @@
|
|
1
1
|
module Yao
|
2
2
|
module Resources
|
3
|
-
module
|
3
|
+
module ProjectAssociationable
|
4
4
|
|
5
5
|
def self.included(base)
|
6
6
|
base.friendly_attributes :project_id
|
7
7
|
base.friendly_attributes :tenant_id
|
8
8
|
end
|
9
9
|
|
10
|
-
# @return [Yao::Resources::
|
11
|
-
def
|
12
|
-
@
|
10
|
+
# @return [Yao::Resources::Project]
|
11
|
+
def project
|
12
|
+
@project ||= Yao::Project.find(project_id || tenant_id)
|
13
13
|
end
|
14
14
|
|
15
|
-
alias :
|
15
|
+
alias :tenant :project
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -148,7 +148,7 @@ module Yao::Resources
|
|
148
148
|
# @return [Yao::Resources::*]
|
149
149
|
def get!(id_or_name_or_permalink, query={})
|
150
150
|
get(id_or_name_or_permalink, query)
|
151
|
-
rescue Yao::ItemNotFound, Yao::NotFound
|
151
|
+
rescue Yao::ItemNotFound, Yao::NotFound, Yao::InvalidResponse
|
152
152
|
nil
|
153
153
|
end
|
154
154
|
|
@@ -188,6 +188,7 @@ module Yao::Resources
|
|
188
188
|
res = DELETE(create_url(id))
|
189
189
|
res.body
|
190
190
|
end
|
191
|
+
alias delete destroy
|
191
192
|
|
192
193
|
private
|
193
194
|
|
@@ -238,7 +239,7 @@ module Yao::Resources
|
|
238
239
|
GET(create_url(name), query)
|
239
240
|
rescue => e
|
240
241
|
raise e unless e.class == Yao::ItemNotFound || e.class == Yao::NotFound
|
241
|
-
item = find_by_name(name)
|
242
|
+
item = find_by_name(name).select { |r| r.name == name }
|
242
243
|
if item.size > 1
|
243
244
|
raise Yao::TooManyItemFonud.new("More than one resource exists with the name '#{name}'")
|
244
245
|
elsif item.size.zero?
|
@@ -1,19 +1,51 @@
|
|
1
1
|
module Yao::Resources
|
2
2
|
class RoleAssignment < Base
|
3
3
|
friendly_attributes :scope, :role, :user
|
4
|
+
|
5
|
+
map_attribute_to_resource role: Role
|
6
|
+
map_attribute_to_resource user: User
|
7
|
+
|
4
8
|
self.service = "identity"
|
5
9
|
self.resource_name = "role_assignment"
|
6
10
|
self.resources_name = "role_assignments"
|
7
11
|
self.admin = true
|
8
12
|
self.api_version = "v3"
|
9
|
-
self.client.url_prefix = Yao.config.auth_url.gsub(/v2.0|v3/, '')
|
10
13
|
|
11
|
-
# @return [Yao::Resources::
|
14
|
+
# @return [Yao::Resources::Project]
|
12
15
|
def project
|
13
|
-
@project ||= Yao::
|
16
|
+
@project ||= Yao::Project.get(scope["project"]["id"])
|
14
17
|
end
|
15
18
|
|
16
|
-
|
17
|
-
|
19
|
+
class << self
|
20
|
+
# @param _subpath [String]
|
21
|
+
# @return [String]
|
22
|
+
def create_url(_subpath='')
|
23
|
+
resources_name
|
24
|
+
end
|
25
|
+
|
26
|
+
# @param query [Hash]
|
27
|
+
def get(opt = {})
|
28
|
+
query = {}
|
29
|
+
|
30
|
+
if (user = opt[:user])
|
31
|
+
query['user.id'] = resource_id_or_string(user)
|
32
|
+
end
|
33
|
+
|
34
|
+
if (project = opt[:project] || opt[:tenant])
|
35
|
+
query['scope.project.id'] = resource_id_or_string(project)
|
36
|
+
end
|
37
|
+
|
38
|
+
list(query)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def resource_id_or_string(item)
|
43
|
+
if item.respond_to?(:id)
|
44
|
+
item.id
|
45
|
+
else
|
46
|
+
item
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
18
50
|
end
|
19
51
|
end
|
data/lib/yao/resources/router.rb
CHANGED
@@ -1,15 +1,31 @@
|
|
1
1
|
module Yao::Resources
|
2
2
|
class Router < Base
|
3
|
-
include
|
3
|
+
include ProjectAssociationable
|
4
4
|
|
5
5
|
friendly_attributes :name, :description, :admin_state_up, :status, :external_gateway_info,
|
6
|
-
:
|
7
|
-
:ha, :availability_zone_hints, :availability_zones
|
6
|
+
:routes, :distributed, :ha, :availability_zone_hints, :availability_zones
|
8
7
|
|
9
8
|
self.service = 'network'
|
10
9
|
self.resource_name = 'router'
|
11
10
|
self.resources_name = 'routers'
|
12
11
|
|
12
|
+
# @return [bool]
|
13
|
+
def enable_snat
|
14
|
+
external_gateway_info["enable_snat"]
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [Array<Hash>]
|
18
|
+
def external_fixed_ips
|
19
|
+
external_gateway_info["external_fixed_ips"]
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [Yao::Resource::Network]
|
23
|
+
def external_network
|
24
|
+
@external_network ||= if network_id = external_gateway_info["network_id"]
|
25
|
+
Yao::Network.get(network_id)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
13
29
|
# @return [Array<Yao::Resources::Port>]
|
14
30
|
def interfaces
|
15
31
|
Yao::Port.list(device_id: id)
|
@@ -29,13 +45,6 @@ module Yao::Resources
|
|
29
45
|
def remove_interface(id, param)
|
30
46
|
PUT(['routers', id, 'remove_router_interface.json'].join('/'), param.to_json)
|
31
47
|
end
|
32
|
-
|
33
|
-
# @param name [String]
|
34
|
-
# @return [Array<Yao::Resources::Router>]
|
35
|
-
def get_by_name(name)
|
36
|
-
self.list(name: name)
|
37
|
-
end
|
38
|
-
alias find_by_name get_by_name
|
39
48
|
end
|
40
49
|
end
|
41
50
|
end
|
data/lib/yao/resources/server.rb
CHANGED
@@ -2,7 +2,7 @@ require 'yao/resources/metadata_available'
|
|
2
2
|
require 'yao/resources/action'
|
3
3
|
module Yao::Resources
|
4
4
|
class Server < Base
|
5
|
-
include
|
5
|
+
include ProjectAssociationable
|
6
6
|
|
7
7
|
friendly_attributes :addresses, :metadata, :name, :progress,
|
8
8
|
:status, :user_id, :key_name
|
@@ -32,6 +32,11 @@ module Yao::Resources
|
|
32
32
|
Yao::OldSample.list(counter_name, query).select{|os| os.resource_metadata["instance_id"] == id}
|
33
33
|
end
|
34
34
|
|
35
|
+
# @return [Array<Yao::Resources::Port>]
|
36
|
+
def ports
|
37
|
+
@ports ||= Yao::Port.list(device_id: id)
|
38
|
+
end
|
39
|
+
|
35
40
|
# @param id [String]
|
36
41
|
# @return [Hash]
|
37
42
|
def self.start(id)
|
data/lib/yao/resources/subnet.rb
CHANGED
data/lib/yao/resources/tenant.rb
CHANGED
@@ -30,6 +30,11 @@ module Yao::Resources
|
|
30
30
|
meters.select{|m| m.name == meter_name}
|
31
31
|
end
|
32
32
|
|
33
|
+
# @return [Yao::Resources::RoleAssignment]
|
34
|
+
def role_assignment
|
35
|
+
Yao::RoleAssignment.get(tenant: id)
|
36
|
+
end
|
37
|
+
|
33
38
|
class << self
|
34
39
|
def accessible
|
35
40
|
as_member { self.list }
|
data/lib/yao/resources/user.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Yao::Resources
|
2
2
|
class User < Base
|
3
|
-
friendly_attributes :name, :email, :enabled
|
3
|
+
friendly_attributes :name, :email, :enabled
|
4
4
|
|
5
5
|
alias enabled? enabled
|
6
6
|
|
@@ -9,6 +9,11 @@ module Yao::Resources
|
|
9
9
|
self.resources_name = "users"
|
10
10
|
self.admin = true
|
11
11
|
|
12
|
+
# @return [Yao::Resources::RoleAssignment]
|
13
|
+
def role_assignment
|
14
|
+
Yao::RoleAssignment.get(user: self)
|
15
|
+
end
|
16
|
+
|
12
17
|
class << self
|
13
18
|
# @return [Bool]
|
14
19
|
def return_single_on_querying
|
data/lib/yao/resources/volume.rb
CHANGED
@@ -1,12 +1,25 @@
|
|
1
|
+
require 'yao/resources/volume_action'
|
2
|
+
|
1
3
|
module Yao::Resources
|
2
4
|
class Volume < Base
|
3
|
-
|
5
|
+
include ProjectAssociationable
|
6
|
+
|
7
|
+
friendly_attributes :attachments, :availability_zone, :bootable, :descriptions, :encrypted, :metadata, :multiattach, :name, :replication_status, :size, :snapshot_id, :status, :user_id, :volume_type
|
8
|
+
alias :type :volume_type
|
4
9
|
|
10
|
+
map_attribute_to_attribute 'os-vol-host-attr:host' => :host
|
5
11
|
map_attribute_to_attribute 'os-vol-tenant-attr:tenant_id' => :tenant_id
|
6
12
|
|
7
13
|
self.service = "volumev3"
|
8
14
|
self.resource_name = "volume"
|
9
15
|
self.resources_name = "volumes"
|
10
16
|
self.resources_detail_available = true
|
17
|
+
|
18
|
+
def status=(s)
|
19
|
+
self.class.set_status(self.id, s)
|
20
|
+
self['status'] = s
|
21
|
+
end
|
22
|
+
|
23
|
+
extend VolumeAction
|
11
24
|
end
|
12
25
|
end
|
data/lib/yao/resources.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Yao
|
2
2
|
module Resources
|
3
3
|
require "yao/resources/base"
|
4
|
-
require "yao/resources/
|
4
|
+
require "yao/resources/project_associationable"
|
5
5
|
require "yao/resources/port_associationable"
|
6
6
|
require "yao/resources/network_associationable"
|
7
7
|
require "yao/resources/server_usage_associationable"
|
data/lib/yao/version.rb
CHANGED
@@ -23,4 +23,25 @@ class TestResourceBase < TestYaoResource
|
|
23
23
|
assert_equal(nil, base.empty)
|
24
24
|
end
|
25
25
|
|
26
|
+
def test_update
|
27
|
+
stub(Yao::Resources::Base).update('foo', {name: 'BAR'}) { Yao::Resources::Base.new('id' => 'foo', 'name' => 'BAR')}
|
28
|
+
base = Yao::Resources::Base.new({'id' => 'foo', 'name' => 'bar'})
|
29
|
+
got = base.update(name: 'BAR')
|
30
|
+
assert_equal(got.name, 'BAR')
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_destroy
|
34
|
+
stub(Yao::Resources::Base).destroy('foo') { nil }
|
35
|
+
base = Yao::Resources::Base.new({'id' => 'foo'})
|
36
|
+
got = base.destroy
|
37
|
+
assert_equal(got, nil)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_delete
|
41
|
+
stub(Yao::Resources::Base).destroy('foo') { nil }
|
42
|
+
base = Yao::Resources::Base.new({'id' => 'foo'})
|
43
|
+
got = base.delete
|
44
|
+
assert_equal(got, nil)
|
45
|
+
end
|
46
|
+
|
26
47
|
end
|