yao 0.13.4 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rubocop.yml +19 -0
- data/.github/workflows/ubuntu-rvm.yml +1 -1
- data/.github/workflows/ubuntu.yml +1 -1
- data/.rubocop.yml +3 -6
- data/lib/yao/auth.rb +18 -0
- data/lib/yao/client.rb +1 -1
- data/lib/yao/config.rb +19 -0
- data/lib/yao/faraday_middlewares.rb +37 -3
- data/lib/yao/mode.rb +4 -0
- data/lib/yao/plugins/default_client_generator.rb +0 -1
- data/lib/yao/plugins/registry.rb +2 -1
- data/lib/yao/resources/action.rb +7 -0
- data/lib/yao/resources/aggregates.rb +1 -0
- data/lib/yao/resources/base.rb +22 -1
- data/lib/yao/resources/compute_services.rb +8 -1
- data/lib/yao/resources/flavor.rb +2 -0
- data/lib/yao/resources/floating_ip.rb +2 -0
- data/lib/yao/resources/hypervisor.rb +1 -1
- data/lib/yao/resources/image.rb +2 -0
- data/lib/yao/resources/loadbalancer.rb +4 -0
- data/lib/yao/resources/loadbalancer_healthmonitor.rb +3 -0
- data/lib/yao/resources/loadbalancer_listener.rb +2 -0
- data/lib/yao/resources/loadbalancer_pool.rb +6 -0
- data/lib/yao/resources/loadbalancer_pool_member.rb +21 -0
- data/lib/yao/resources/metadata_available.rb +21 -0
- data/lib/yao/resources/meter.rb +8 -1
- data/lib/yao/resources/network.rb +1 -0
- data/lib/yao/resources/network_associationable.rb +1 -0
- data/lib/yao/resources/old_sample.rb +4 -0
- data/lib/yao/resources/port.rb +2 -0
- data/lib/yao/resources/port_associationable.rb +1 -0
- data/lib/yao/resources/project.rb +6 -0
- data/lib/yao/resources/resource.rb +8 -2
- data/lib/yao/resources/restfully_accessible.rb +15 -0
- data/lib/yao/resources/role.rb +6 -4
- data/lib/yao/resources/role_assignment.rb +1 -0
- data/lib/yao/resources/router.rb +9 -0
- data/lib/yao/resources/sample.rb +4 -0
- data/lib/yao/resources/security_group.rb +1 -0
- data/lib/yao/resources/security_group_rule.rb +10 -0
- data/lib/yao/resources/server.rb +20 -0
- data/lib/yao/resources/server_group.rb +1 -1
- data/lib/yao/resources/server_usage_associationable.rb +12 -0
- data/lib/yao/resources/subnet.rb +1 -0
- data/lib/yao/resources/tenant.rb +6 -0
- data/lib/yao/resources/tenant_associationable.rb +1 -0
- data/lib/yao/resources/user.rb +2 -0
- data/lib/yao/resources.rb +3 -0
- data/lib/yao/token.rb +1 -0
- data/lib/yao/version.rb +1 -1
- data/test/yao/resources/test_base.rb +11 -0
- data/test/yao/resources/test_image.rb +5 -0
- data/test/yao/resources/test_project.rb +20 -1
- data/test/yao/resources/test_server_group.rb +1 -1
- data/test/yao/test_client.rb +0 -1
- data/yao.gemspec +1 -1
- metadata +7 -5
@@ -1,9 +1,14 @@
|
|
1
1
|
module Yao::Resources
|
2
2
|
module MetadataAvailable
|
3
|
+
# @param id [String]
|
4
|
+
# @return [Hash]
|
3
5
|
def list_metadata(id)
|
4
6
|
GET(metadata_path(id)).body["metadata"]
|
5
7
|
end
|
6
8
|
|
9
|
+
# @param id [String]
|
10
|
+
# @param metadata [Hash]
|
11
|
+
# @return [Hash]
|
7
12
|
def create_metadata(id, metadata)
|
8
13
|
res = POST(metadata_path(id)) do |req|
|
9
14
|
req.body = {"metadata" => metadata}.to_json
|
@@ -13,6 +18,9 @@ module Yao::Resources
|
|
13
18
|
end
|
14
19
|
alias append_metadata create_metadata
|
15
20
|
|
21
|
+
# @param id [String]
|
22
|
+
# @param metadata [Hash]
|
23
|
+
# @return [Hash]
|
16
24
|
def update_metadata(id, metadata)
|
17
25
|
res = PUT(metadata_path(id)) do |req|
|
18
26
|
req.body = {"metadata" => metadata}.to_json
|
@@ -22,10 +30,17 @@ module Yao::Resources
|
|
22
30
|
end
|
23
31
|
alias replace_metadata update_metadata
|
24
32
|
|
33
|
+
# @param id [String]
|
34
|
+
# @param key [String]
|
35
|
+
# @return [Hash]
|
25
36
|
def get_metadata(id, key)
|
26
37
|
GET(metadata_key_path(id, key)).body["meta"]
|
27
38
|
end
|
28
39
|
|
40
|
+
# @param id [String]
|
41
|
+
# @param key [String]
|
42
|
+
# @param value [String]
|
43
|
+
# @return [Hash]
|
29
44
|
def set_metadata(id, key, value)
|
30
45
|
res = PUT(metadata_key_path(id, key)) do |req|
|
31
46
|
req.body = {"meta" => {key => value}}.to_json
|
@@ -34,15 +49,21 @@ module Yao::Resources
|
|
34
49
|
res.body["meta"]
|
35
50
|
end
|
36
51
|
|
52
|
+
# @param id [String]
|
53
|
+
# @param key [String]
|
37
54
|
def delete_metadata(id, key)
|
38
55
|
DELETE(metadata_key_path(id, key)).body
|
39
56
|
end
|
40
57
|
|
41
58
|
private
|
59
|
+
# @param id [String]
|
60
|
+
# @return [String]
|
42
61
|
def metadata_path(id)
|
43
62
|
["servers", id, "metadata"].join("/")
|
44
63
|
end
|
45
64
|
|
65
|
+
# @param id [String]
|
66
|
+
# @param key [String]
|
46
67
|
def metadata_key_path(id, key)
|
47
68
|
["servers", id, "metadata", key].join("/")
|
48
69
|
end
|
data/lib/yao/resources/meter.rb
CHANGED
@@ -5,14 +5,17 @@ module Yao::Resources
|
|
5
5
|
|
6
6
|
friendly_attributes :meter_id, :name, :user_id, :resource_id, :source, :type, :unit
|
7
7
|
|
8
|
+
# @return [String]
|
8
9
|
def id
|
9
10
|
meter_id
|
10
11
|
end
|
11
12
|
|
13
|
+
# @return [Yao::Resources::Resource]
|
12
14
|
def resource
|
13
15
|
@resource ||= Yao::Resource.get(resource_id)
|
14
16
|
end
|
15
17
|
|
18
|
+
# @return [Yao::Resources::User]
|
16
19
|
def user
|
17
20
|
@user ||= Yao::User.get(user_id)
|
18
21
|
end
|
@@ -23,12 +26,16 @@ module Yao::Resources
|
|
23
26
|
|
24
27
|
class << self
|
25
28
|
private
|
29
|
+
|
30
|
+
# override Yao::Resources::RestfullyAccessible.resource_from_json
|
31
|
+
# @param json [Hash]
|
32
|
+
# @return [Yao::Resources::Meter]
|
26
33
|
def resource_from_json(json)
|
27
34
|
new(json)
|
28
35
|
end
|
29
36
|
|
30
37
|
# override Yao::Resources::RestfullyAccessible.resources_from_json
|
31
|
-
# @param [Array]
|
38
|
+
# @param json [Array<Hash>]
|
32
39
|
# @return [Array<Yao::Resources::Meter>]
|
33
40
|
def resources_from_json(json)
|
34
41
|
json.map{|d| new(d)}
|
@@ -6,19 +6,23 @@ module Yao::Resources
|
|
6
6
|
:message_id, :resource_id, :timestamp, :resource_metadata, :user_id,
|
7
7
|
:source
|
8
8
|
|
9
|
+
# @return [Date]
|
9
10
|
def recorded_at
|
10
11
|
Time.parse(self["recorded_at"] || self["timestamp"])
|
11
12
|
end
|
12
13
|
alias timestamp recorded_at
|
13
14
|
|
15
|
+
# @return [String]
|
14
16
|
def id
|
15
17
|
message_id
|
16
18
|
end
|
17
19
|
|
20
|
+
# @return [Yao::Resources::Resource]
|
18
21
|
def resource
|
19
22
|
@resource ||= Yao::Resource.get(resource_id)
|
20
23
|
end
|
21
24
|
|
25
|
+
# @return [Yao::Resources::User]
|
22
26
|
def user
|
23
27
|
@user ||= Yao::User.get(user_id)
|
24
28
|
end
|
data/lib/yao/resources/port.rb
CHANGED
@@ -9,10 +9,12 @@ module Yao::Resources
|
|
9
9
|
:admin_state_up
|
10
10
|
map_attribute_to_attribute "binding:host_id" => :host_id
|
11
11
|
|
12
|
+
# @return [String]
|
12
13
|
def primary_ip
|
13
14
|
fixed_ips.first["ip_address"]
|
14
15
|
end
|
15
16
|
|
17
|
+
# @return [Yao::Resources::Subnet]
|
16
18
|
def primary_subnet
|
17
19
|
@subnet ||= Yao::Subnet.find fixed_ips.first["subnet_id"]
|
18
20
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module Yao::Resources
|
2
2
|
class Project < Base
|
3
|
+
include ServerUsageAssociationable
|
4
|
+
|
3
5
|
friendly_attributes :id, :name, :description, :enabled, :parent_id, :domain_id
|
4
6
|
alias :enabled? :enabled
|
5
7
|
|
@@ -8,19 +10,23 @@ module Yao::Resources
|
|
8
10
|
self.resources_name = "projects"
|
9
11
|
self.admin = true
|
10
12
|
|
13
|
+
# @return [Bool]
|
11
14
|
def domain?
|
12
15
|
@data["is_domain"]
|
13
16
|
end
|
14
17
|
|
18
|
+
# @return [Array<Yao::Resources::Server>]
|
15
19
|
def servers
|
16
20
|
@servers ||= Yao::Server.list(all_tenants: 1, project_id: id)
|
17
21
|
end
|
18
22
|
|
23
|
+
# @return [Yao::Resources::Port]
|
19
24
|
def ports
|
20
25
|
@ports ||= Yao::Port.list(tenant_id: id)
|
21
26
|
end
|
22
27
|
|
23
28
|
class << self
|
29
|
+
|
24
30
|
def accessible
|
25
31
|
as_member { self.list }
|
26
32
|
end
|
@@ -8,28 +8,34 @@ module Yao::Resources
|
|
8
8
|
:metadata,
|
9
9
|
:links
|
10
10
|
|
11
|
+
# @return [String]
|
11
12
|
def id
|
12
13
|
resource_id
|
13
14
|
end
|
14
15
|
|
16
|
+
# @return [Yao::User]
|
15
17
|
def user
|
16
18
|
@user ||= Yao::User.get(user_id)
|
17
19
|
end
|
18
20
|
|
21
|
+
# @return [Date]
|
19
22
|
def last_sampled_at
|
20
23
|
Time.parse last_sample_timestamp
|
21
24
|
end
|
22
25
|
|
26
|
+
# @return [Date]
|
23
27
|
def first_sampled_at
|
24
28
|
Time.parse first_sample_timestamp
|
25
29
|
end
|
26
30
|
|
31
|
+
# @return [Array<Yao::Sample>]
|
27
32
|
def get_meter(name)
|
28
33
|
if link = links.find{|l| l["rel"] == name }
|
29
34
|
Yao::Sample.list(link["href"])
|
30
35
|
end
|
31
36
|
end
|
32
37
|
|
38
|
+
# @return [Hash]
|
33
39
|
def meters
|
34
40
|
links.map{|l| l["rel"] }.delete_if{|n| n == 'self' }
|
35
41
|
end
|
@@ -42,14 +48,14 @@ module Yao::Resources
|
|
42
48
|
private
|
43
49
|
|
44
50
|
# override Yao::Resources::RestfullyAccessible.resource_from_json
|
45
|
-
# @param [Hash]
|
51
|
+
# @param json [Hash]
|
46
52
|
# @return [Yao::Resources::Resource]
|
47
53
|
def resource_from_json(json)
|
48
54
|
new(json)
|
49
55
|
end
|
50
56
|
|
51
57
|
# override Yao::Resources::RestfullyAccessible.resources_from_json
|
52
|
-
# @param [Hash]
|
58
|
+
# @param json [Hash]
|
53
59
|
# @return [Yao::Resources::Resource]
|
54
60
|
def resources_from_json(json)
|
55
61
|
new(json)
|
@@ -15,41 +15,55 @@ module Yao::Resources
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
# @param name [String]
|
19
|
+
# @return
|
18
20
|
def service=(name)
|
19
21
|
@service = name
|
20
22
|
end
|
21
23
|
attr_reader :service
|
22
24
|
|
25
|
+
# @return [String]
|
23
26
|
def api_version
|
24
27
|
@api_version || ''
|
25
28
|
end
|
26
29
|
|
30
|
+
# @param v [String]
|
31
|
+
# @return [String]
|
27
32
|
def api_version=(v)
|
28
33
|
raise("Set api_version after service is declared") unless service
|
29
34
|
@api_version = v
|
30
35
|
api_version
|
31
36
|
end
|
32
37
|
|
38
|
+
# @param bool [Boolean]
|
39
|
+
# @return [Boolean]
|
33
40
|
def admin=(bool)
|
34
41
|
@admin = bool
|
35
42
|
end
|
36
43
|
|
44
|
+
# @return [Boolean]
|
37
45
|
def return_single_on_querying
|
38
46
|
@return_single_on_querying
|
39
47
|
end
|
40
48
|
|
49
|
+
# @param bool [Boolean]
|
50
|
+
# @return [Boolean]
|
41
51
|
def return_single_on_querying=(bool)
|
42
52
|
@return_single_on_querying = bool
|
43
53
|
end
|
44
54
|
|
55
|
+
# @return [String]
|
45
56
|
def resources_path
|
46
57
|
@resources_path || resources_name
|
47
58
|
end
|
48
59
|
|
60
|
+
# @param path [String]
|
61
|
+
# @return [String]
|
49
62
|
def resources_path=(path)
|
50
63
|
@resources_path = path.sub(%r!^\/!, "")
|
51
64
|
end
|
52
65
|
|
66
|
+
# @return [Faraday::Connection]
|
53
67
|
def client
|
54
68
|
if @admin
|
55
69
|
Yao.default_client.admin_pool[service]
|
@@ -58,6 +72,7 @@ module Yao::Resources
|
|
58
72
|
end or raise "You do not have #{@admin ? 'admin' : 'public'} access to the #{service} service"
|
59
73
|
end
|
60
74
|
|
75
|
+
# @param blk [Proc]
|
61
76
|
def as_member(&blk)
|
62
77
|
if @admin
|
63
78
|
@admin = false
|
data/lib/yao/resources/role.rb
CHANGED
@@ -47,8 +47,8 @@ module Yao::Resources
|
|
47
47
|
end
|
48
48
|
|
49
49
|
# @param role_name [String]
|
50
|
-
# @param to
|
51
|
-
# @param on
|
50
|
+
# @param to [String]
|
51
|
+
# @param on [String]
|
52
52
|
# @return [Faraday::Response]
|
53
53
|
def grant(role_name, to:, on:)
|
54
54
|
role = Yao::Role.get(role_name)
|
@@ -64,8 +64,8 @@ module Yao::Resources
|
|
64
64
|
end
|
65
65
|
|
66
66
|
# @param role_name [String]
|
67
|
-
# @param from
|
68
|
-
# @param on
|
67
|
+
# @param from [String]
|
68
|
+
# @param on [String]
|
69
69
|
# @return [Faraday::Response]
|
70
70
|
def revoke(role_name, from:, on:)
|
71
71
|
role = Yao::Role.get(role_name)
|
@@ -88,6 +88,8 @@ module Yao::Resources
|
|
88
88
|
client.url_prefix.to_s =~ /v2\.0/
|
89
89
|
end
|
90
90
|
|
91
|
+
# @param tenant [String]
|
92
|
+
# @param user [String]
|
91
93
|
def path_for_role_resource(tenant, user, role = nil)
|
92
94
|
if api_version_v2?
|
93
95
|
paths = ["tenants", tenant.id, "users", user.id, "roles"]
|
data/lib/yao/resources/router.rb
CHANGED
@@ -10,19 +10,28 @@ module Yao::Resources
|
|
10
10
|
self.resource_name = 'router'
|
11
11
|
self.resources_name = 'routers'
|
12
12
|
|
13
|
+
# @return [Array<Yao::Resources::Port>]
|
13
14
|
def interfaces
|
14
15
|
Yao::Port.list(device_id: id)
|
15
16
|
end
|
16
17
|
|
17
18
|
class << self
|
19
|
+
# @param id [String]
|
20
|
+
# @param param [Hash]
|
21
|
+
# @return [Hash]
|
18
22
|
def add_interface(id, param)
|
19
23
|
PUT(['routers', id, 'add_router_interface.json'].join('/'), param.to_json)
|
20
24
|
end
|
21
25
|
|
26
|
+
# @param id [String]
|
27
|
+
# @param param [Hash]
|
28
|
+
# @return [Hash]
|
22
29
|
def remove_interface(id, param)
|
23
30
|
PUT(['routers', id, 'remove_router_interface.json'].join('/'), param.to_json)
|
24
31
|
end
|
25
32
|
|
33
|
+
# @param name [String]
|
34
|
+
# @return [Array<Yao::Resources::Router>]
|
26
35
|
def get_by_name(name)
|
27
36
|
self.list(name: name)
|
28
37
|
end
|
data/lib/yao/resources/sample.rb
CHANGED
@@ -4,18 +4,22 @@ module Yao::Resources
|
|
4
4
|
:source, :type, :unit, :volume,
|
5
5
|
:resource_id, :user_id
|
6
6
|
|
7
|
+
# @return [Date]
|
7
8
|
def recorded_at
|
8
9
|
Time.parse(self["recorded_at"])
|
9
10
|
end
|
10
11
|
|
12
|
+
# @return [Date]
|
11
13
|
def timestamp
|
12
14
|
Time.parse(self["timestamp"])
|
13
15
|
end
|
14
16
|
|
17
|
+
# @return [Yao::Resources::Resource]
|
15
18
|
def resource
|
16
19
|
@resource ||= Yao::Resource.get(resource_id)
|
17
20
|
end
|
18
21
|
|
22
|
+
# @return [Yao::Resources::User]
|
19
23
|
def user
|
20
24
|
@user ||= Yao::User.get(user_id)
|
21
25
|
end
|
@@ -3,6 +3,8 @@ module Yao::Resources
|
|
3
3
|
class SecurityGroupRule < Base
|
4
4
|
friendly_attributes :ethertype
|
5
5
|
|
6
|
+
# @param _name [Symbol]
|
7
|
+
# @param _guard_name [Symbol]
|
6
8
|
def self.define_attribute_with_guard(_name, _guard_name)
|
7
9
|
name = _name.to_s
|
8
10
|
guard_name = _guard_name.to_s
|
@@ -16,10 +18,15 @@ module Yao::Resources
|
|
16
18
|
define_attribute_with_guard :protocol, :ip_protocol
|
17
19
|
define_attribute_with_guard :security_group_id, :parent_group_id
|
18
20
|
|
21
|
+
# @return [Yao::Resources::SecurityGroup]
|
19
22
|
def security_group
|
20
23
|
SecurityGroup.find(security_group_id)
|
21
24
|
end
|
22
25
|
|
26
|
+
# if port_range_max == port_range_min
|
27
|
+
# @return [Integer]
|
28
|
+
# else
|
29
|
+
# @return [Range]
|
23
30
|
def port
|
24
31
|
if port_range_max == port_range_min
|
25
32
|
port_range_max
|
@@ -28,6 +35,7 @@ module Yao::Resources
|
|
28
35
|
end
|
29
36
|
end
|
30
37
|
|
38
|
+
# @return [String]
|
31
39
|
def remote_ip_cidr
|
32
40
|
if cidr = self["remote_ip_prefix"]
|
33
41
|
cidr
|
@@ -36,10 +44,12 @@ module Yao::Resources
|
|
36
44
|
end
|
37
45
|
end
|
38
46
|
|
47
|
+
# @return [Range]
|
39
48
|
def port_range
|
40
49
|
port_range_max..port_range_min
|
41
50
|
end
|
42
51
|
|
52
|
+
# @return [Yao::Resources::SecurityGroup]
|
43
53
|
def remote_group
|
44
54
|
return nil if self["remote_group_id"].nil? && (self["group"].nil? || self["group"].empty?)
|
45
55
|
|
data/lib/yao/resources/server.rb
CHANGED
@@ -25,34 +25,54 @@ module Yao::Resources
|
|
25
25
|
self.resources_name = "servers"
|
26
26
|
self.resources_detail_available = true
|
27
27
|
|
28
|
+
# @param counter_name [String]
|
29
|
+
# @param query [Hash]
|
30
|
+
# @return [Array<Yao::OldSample>]
|
28
31
|
def old_samples(counter_name: nil, query: {})
|
29
32
|
Yao::OldSample.list(counter_name, query).select{|os| os.resource_metadata["instance_id"] == id}
|
30
33
|
end
|
31
34
|
|
35
|
+
# @param id [String]
|
36
|
+
# @return [Hash]
|
32
37
|
def self.start(id)
|
33
38
|
action(id, "os-start" => nil)
|
34
39
|
end
|
35
40
|
|
41
|
+
# @param id [String]
|
42
|
+
# @return [Hash]
|
36
43
|
def self.shutoff(id)
|
37
44
|
action(id, "os-stop" => nil)
|
38
45
|
end
|
39
46
|
|
47
|
+
# @param id [String]
|
48
|
+
# @return [Hash]
|
40
49
|
def self.reboot(id)
|
41
50
|
action(id,"reboot" => { "type" => "HARD" })
|
42
51
|
end
|
43
52
|
|
53
|
+
# @param id [String]
|
54
|
+
# @param flavor_id [String]
|
55
|
+
# @return [Hash]
|
44
56
|
def self.resize(id, flavor_id)
|
45
57
|
action(id,"resize" => { "flavorRef" => flavor_id })
|
46
58
|
end
|
47
59
|
|
60
|
+
# @param id [String]
|
61
|
+
# @param sg_name [String]
|
62
|
+
# @return [Hash]
|
48
63
|
def self.add_security_group(id, sg_name)
|
49
64
|
action(id, {"addSecurityGroup": {"name": sg_name}})
|
50
65
|
end
|
51
66
|
|
67
|
+
# @param id [String]
|
68
|
+
# @param sg_name [String]
|
69
|
+
# @return [Hash]
|
52
70
|
def self.remove_security_group(id, sg_name)
|
53
71
|
action(id, {"removeSecurityGroup": {"name": sg_name}})
|
54
72
|
end
|
55
73
|
|
74
|
+
# @param id [String]
|
75
|
+
# @return [Hash]
|
56
76
|
def self.get_vnc_console(id)
|
57
77
|
response = action(id, {"os-getVNCConsole": {"type": "novnc"}})
|
58
78
|
response.dig("console", "url")
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Yao::Resources
|
2
|
+
module ServerUsageAssociationable
|
3
|
+
# @param opt [Hash]
|
4
|
+
# @return [Hash]
|
5
|
+
def server_usage(params = {})
|
6
|
+
path = "./os-simple-tenant-usage/#{id}"
|
7
|
+
client = Yao.default_client.pool['compute']
|
8
|
+
res = client.get(path, params, {"Accept" => "application/json"})
|
9
|
+
res.body["tenant_usage"]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/yao/resources/subnet.rb
CHANGED
@@ -7,6 +7,7 @@ module Yao::Resources
|
|
7
7
|
friendly_attributes :name, :cidr, :gateway_ip, :network_id, :ip_version,
|
8
8
|
:dns_nameservers, :host_routes, :enable_dhcp
|
9
9
|
|
10
|
+
# @return [Array<Range>]
|
10
11
|
def allocation_pools
|
11
12
|
self["allocation_pools"].map do |pool|
|
12
13
|
pool["start"]..pool["end"]
|
data/lib/yao/resources/tenant.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Yao::Resources
|
2
2
|
class Tenant < Base
|
3
|
+
include ServerUsageAssociationable
|
4
|
+
|
3
5
|
friendly_attributes :id, :name, :description, :enabled
|
4
6
|
|
5
7
|
self.service = "identity"
|
@@ -8,18 +10,22 @@ module Yao::Resources
|
|
8
10
|
self.admin = true
|
9
11
|
self.return_single_on_querying = true
|
10
12
|
|
13
|
+
# @return [Yao::Resources::Server]
|
11
14
|
def servers
|
12
15
|
@servers ||= Yao::Server.list(all_tenants: 1, project_id: id)
|
13
16
|
end
|
14
17
|
|
18
|
+
# @return [Yao::Resources::Meter]
|
15
19
|
def meters
|
16
20
|
@meters ||= Yao::Meter.list({'q.field' => 'project_id', 'q.op' => 'eq', 'q.value' => id})
|
17
21
|
end
|
18
22
|
|
23
|
+
# @return [Yao::Resources::Port]
|
19
24
|
def ports
|
20
25
|
@ports ||= Yao::Port.list(tenant_id: id)
|
21
26
|
end
|
22
27
|
|
28
|
+
# @return [Array<Yao::Resources::Meter>]
|
23
29
|
def meters_by_name(meter_name)
|
24
30
|
meters.select{|m| m.name == meter_name}
|
25
31
|
end
|
data/lib/yao/resources/user.rb
CHANGED
@@ -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
data/lib/yao/version.rb
CHANGED
@@ -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
|