yao 0.13.4 → 0.16.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 +2 -2
- 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 +39 -6
- data/lib/yao/resources/compute_services.rb +8 -1
- data/lib/yao/resources/flavor.rb +12 -0
- data/lib/yao/resources/floating_ip.rb +2 -6
- 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 +13 -17
- 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 +9 -2
- data/lib/yao/resources/network.rb +2 -1
- data/lib/yao/resources/network_associationable.rb +1 -0
- data/lib/yao/resources/old_sample.rb +5 -1
- data/lib/yao/resources/port.rb +3 -1
- data/lib/yao/resources/port_associationable.rb +1 -0
- data/lib/yao/resources/project.rb +11 -0
- data/lib/yao/resources/{tenant_associationable.rb → project_associationable.rb} +5 -4
- data/lib/yao/resources/resource.rb +9 -3
- data/lib/yao/resources/restfully_accessible.rb +18 -2
- data/lib/yao/resources/role.rb +6 -4
- data/lib/yao/resources/role_assignment.rb +37 -4
- data/lib/yao/resources/router.rb +26 -8
- data/lib/yao/resources/sample.rb +4 -0
- data/lib/yao/resources/security_group.rb +2 -1
- data/lib/yao/resources/security_group_rule.rb +10 -0
- data/lib/yao/resources/server.rb +21 -1
- 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 +2 -1
- data/lib/yao/resources/tenant.rb +11 -0
- data/lib/yao/resources/user.rb +8 -1
- data/lib/yao/resources/volume.rb +14 -1
- data/lib/yao/resources/volume_action.rb +13 -0
- data/lib/yao/resources.rb +4 -1
- data/lib/yao/token.rb +1 -0
- data/lib/yao/version.rb +1 -1
- data/test/yao/resources/test_base.rb +32 -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_image.rb +5 -0
- 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 +45 -6
- 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 +6 -6
- data/test/yao/resources/test_server_group.rb +1 -1
- 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/test/yao/test_client.rb +0 -1
- data/yao.gemspec +1 -1
- metadata +11 -8
@@ -5,6 +5,7 @@ module Yao::Resources
|
|
5
5
|
:monitor_address, :address,
|
6
6
|
:protocol_port, :operating_status
|
7
7
|
|
8
|
+
# @return [Yao::Resources::Tenant]
|
8
9
|
def project
|
9
10
|
if project_id = self["project_id"]
|
10
11
|
Yao::Tenant.find project_id
|
@@ -12,6 +13,7 @@ module Yao::Resources
|
|
12
13
|
end
|
13
14
|
alias :tenant :project
|
14
15
|
|
16
|
+
# @return [Yao::Resources::Subnet]
|
15
17
|
def subnet
|
16
18
|
if subnet_id = self["subnet_id"]
|
17
19
|
Yao::Subnet.find subnet_id
|
@@ -25,33 +27,52 @@ module Yao::Resources
|
|
25
27
|
|
26
28
|
class << self
|
27
29
|
|
30
|
+
# @param pool [Yao::Resources::LoadBalancerPool]
|
31
|
+
# @param query [Hash]
|
32
|
+
# @return [Array<Yao::Resources::LoadBalancerPoolMember>]
|
28
33
|
def list(pool, query={})
|
29
34
|
self.resources_path = member_resources_path(pool)
|
30
35
|
super(query)
|
31
36
|
end
|
32
37
|
|
38
|
+
# @param pool [Yao::Resources::LoadBalancerPool]
|
39
|
+
# @param id_or_permalink [String]
|
40
|
+
# @param query [Hash]
|
41
|
+
# @return [Yao::Resources::LoadBalancerPoolMember]
|
33
42
|
def get(pool, id_or_permalink, query={})
|
34
43
|
self.resources_path = member_resources_path(pool)
|
35
44
|
super(id_or_permalink, query)
|
36
45
|
end
|
37
46
|
alias find get
|
38
47
|
|
48
|
+
# @param pool [Yao::Resources::LoadBalancerPool]
|
49
|
+
# @param resource_params [Hash]
|
50
|
+
# @return [Yao::Resources::LoadBalancerPoolMember]
|
39
51
|
def create(pool, resource_params)
|
40
52
|
self.resources_path = member_resources_path(pool)
|
41
53
|
super(resource_params)
|
42
54
|
end
|
43
55
|
|
56
|
+
# @param pool [Yao::Resources::LoadBalancerPool]
|
57
|
+
# @param id [String]
|
58
|
+
# @param resource_params [Hash]
|
59
|
+
# @return [Yao::Resources::LoadBalancerPoolMember]
|
44
60
|
def update(pool, id, resource_params)
|
45
61
|
self.resources_path = member_resources_path(pool)
|
46
62
|
super(id, resource_params)
|
47
63
|
end
|
48
64
|
|
65
|
+
# @param pool [Yao::Resources::LoadBalancerPool]
|
66
|
+
# @param id [String]
|
67
|
+
# @return [String]
|
49
68
|
def destroy(pool, id)
|
50
69
|
self.resources_path = member_resources_path(pool)
|
51
70
|
super(id)
|
52
71
|
end
|
53
72
|
|
54
73
|
private
|
74
|
+
# @param pool [Yao::Resources::LoadBalancerPool]
|
75
|
+
# @return [String]
|
55
76
|
def member_resources_path(pool)
|
56
77
|
"lbaas/pools/#{pool.id}/#{self.resources_name}"
|
57
78
|
end
|
@@ -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
@@ -1,18 +1,21 @@
|
|
1
1
|
module Yao::Resources
|
2
2
|
class Meter < Base
|
3
3
|
|
4
|
-
include
|
4
|
+
include ProjectAssociationable
|
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)}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Yao::Resources
|
2
2
|
class Network < Base
|
3
|
-
include
|
3
|
+
include ProjectAssociationable
|
4
4
|
|
5
5
|
friendly_attributes :name, :status, :shared, :subnets, :admin_state_up
|
6
6
|
map_attribute_to_attribute "provider:physical_network" => :physical_network
|
@@ -13,6 +13,7 @@ module Yao::Resources
|
|
13
13
|
self.resource_name = "network"
|
14
14
|
self.resources_name = "networks"
|
15
15
|
|
16
|
+
# @return [Array<Yao::Resources::Port>]
|
16
17
|
def ports
|
17
18
|
@ports ||= Yao::Port.list(network_id: id)
|
18
19
|
end
|
@@ -1,24 +1,28 @@
|
|
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,
|
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
@@ -2,17 +2,19 @@ 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,
|
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,28 @@ 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
|
|
28
|
+
# @return [Yao::Resources::RoleAssignment]
|
29
|
+
def role_assignment
|
30
|
+
Yao::RoleAssignment.get(project: id)
|
31
|
+
end
|
32
|
+
|
23
33
|
class << self
|
34
|
+
|
24
35
|
def accessible
|
25
36
|
as_member { self.list }
|
26
37
|
end
|
@@ -1,17 +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
|
-
|
11
|
-
|
10
|
+
# @return [Yao::Resources::Project]
|
11
|
+
def project
|
12
|
+
@project ||= Yao::Project.find(project_id || tenant_id)
|
12
13
|
end
|
13
14
|
|
14
|
-
alias :
|
15
|
+
alias :tenant :project
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
@@ -1,35 +1,41 @@
|
|
1
1
|
require 'time'
|
2
2
|
module Yao::Resources
|
3
3
|
class Resource < Base
|
4
|
-
include
|
4
|
+
include ProjectAssociationable
|
5
5
|
|
6
6
|
friendly_attributes :user_id, :resource_id,
|
7
7
|
:last_sample_timestamp, :first_sample_timestamp,
|
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
|
@@ -133,7 +148,7 @@ module Yao::Resources
|
|
133
148
|
# @return [Yao::Resources::*]
|
134
149
|
def get!(id_or_name_or_permalink, query={})
|
135
150
|
get(id_or_name_or_permalink, query)
|
136
|
-
rescue Yao::ItemNotFound, Yao::NotFound
|
151
|
+
rescue Yao::ItemNotFound, Yao::NotFound, Yao::InvalidResponse
|
137
152
|
nil
|
138
153
|
end
|
139
154
|
|
@@ -173,6 +188,7 @@ module Yao::Resources
|
|
173
188
|
res = DELETE(create_url(id))
|
174
189
|
res.body
|
175
190
|
end
|
191
|
+
alias delete destroy
|
176
192
|
|
177
193
|
private
|
178
194
|
|
@@ -223,7 +239,7 @@ module Yao::Resources
|
|
223
239
|
GET(create_url(name), query)
|
224
240
|
rescue => e
|
225
241
|
raise e unless e.class == Yao::ItemNotFound || e.class == Yao::NotFound
|
226
|
-
item = find_by_name(name)
|
242
|
+
item = find_by_name(name).select { |r| r.name == name }
|
227
243
|
if item.size > 1
|
228
244
|
raise Yao::TooManyItemFonud.new("More than one resource exists with the name '#{name}'")
|
229
245
|
elsif item.size.zero?
|
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"]
|
@@ -1,18 +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
|
|
14
|
+
# @return [Yao::Resources::Project]
|
11
15
|
def project
|
12
|
-
@project ||= Yao::
|
16
|
+
@project ||= Yao::Project.get(scope["project"]["id"])
|
13
17
|
end
|
14
18
|
|
15
|
-
|
16
|
-
|
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
|
17
50
|
end
|
18
51
|
end
|
data/lib/yao/resources/router.rb
CHANGED
@@ -1,32 +1,50 @@
|
|
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
|
+
|
29
|
+
# @return [Array<Yao::Resources::Port>]
|
13
30
|
def interfaces
|
14
31
|
Yao::Port.list(device_id: id)
|
15
32
|
end
|
16
33
|
|
17
34
|
class << self
|
35
|
+
# @param id [String]
|
36
|
+
# @param param [Hash]
|
37
|
+
# @return [Hash]
|
18
38
|
def add_interface(id, param)
|
19
39
|
PUT(['routers', id, 'add_router_interface.json'].join('/'), param.to_json)
|
20
40
|
end
|
21
41
|
|
42
|
+
# @param id [String]
|
43
|
+
# @param param [Hash]
|
44
|
+
# @return [Hash]
|
22
45
|
def remove_interface(id, param)
|
23
46
|
PUT(['routers', id, 'remove_router_interface.json'].join('/'), param.to_json)
|
24
47
|
end
|
25
|
-
|
26
|
-
def get_by_name(name)
|
27
|
-
self.list(name: name)
|
28
|
-
end
|
29
|
-
alias find_by_name get_by_name
|
30
48
|
end
|
31
49
|
end
|
32
50
|
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
|
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'yao/resources/security_group_rule'
|
2
2
|
module Yao::Resources
|
3
3
|
class SecurityGroup < Base
|
4
|
-
include
|
4
|
+
include ProjectAssociationable
|
5
5
|
|
6
6
|
friendly_attributes :name, :description
|
7
7
|
|
8
|
+
# @return [Array<Yao::Resources::SecurityGroupRule>]
|
8
9
|
def rules
|
9
10
|
self[["rules", SecurityGroupRule].join("__")] ||= (case self.class.service
|
10
11
|
when "compute"
|