yao 0.13.2 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) 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 +37 -3
  11. data/lib/yao/mode.rb +4 -0
  12. data/lib/yao/plugins/default_client_generator.rb +0 -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 +22 -1
  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 +11 -0
  35. data/lib/yao/resources/resource.rb +8 -2
  36. data/lib/yao/resources/restfully_accessible.rb +15 -0
  37. data/lib/yao/resources/role.rb +6 -4
  38. data/lib/yao/resources/role_assignment.rb +36 -3
  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 +11 -0
  48. data/lib/yao/resources/tenant_associationable.rb +1 -0
  49. data/lib/yao/resources/user.rb +8 -1
  50. data/lib/yao/resources/volume.rb +12 -1
  51. data/lib/yao/resources/volume_action.rb +13 -0
  52. data/lib/yao/resources.rb +3 -0
  53. data/lib/yao/token.rb +1 -0
  54. data/lib/yao/version.rb +1 -1
  55. data/test/yao/resources/test_base.rb +11 -0
  56. data/test/yao/resources/test_image.rb +5 -0
  57. data/test/yao/resources/test_project.rb +45 -6
  58. data/test/yao/resources/test_role_assignment.rb +98 -1
  59. data/test/yao/resources/test_server_group.rb +1 -1
  60. data/test/yao/resources/test_user.rb +28 -1
  61. data/test/yao/resources/test_volume.rb +60 -1
  62. data/test/yao/test_client.rb +2 -1
  63. data/yao.gemspec +1 -1
  64. metadata +8 -5
@@ -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
@@ -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)}
@@ -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
@@ -6,6 +6,7 @@ module Yao
6
6
  base.friendly_attributes :network_id
7
7
  end
8
8
 
9
+ # @return [Yao::Resources::Network]
9
10
  def network
10
11
  @tenant ||= Yao::Network.find(network_id)
11
12
  end
@@ -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
@@ -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
@@ -6,6 +6,7 @@ module Yao
6
6
  base.friendly_attributes :port_id
7
7
  end
8
8
 
9
+ # @return [Yao::Resources::Port]
9
10
  def port
10
11
  @port ||= Yao::Port.find(port_id)
11
12
  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
@@ -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
@@ -47,8 +47,8 @@ module Yao::Resources
47
47
  end
48
48
 
49
49
  # @param role_name [String]
50
- # @param to: [String]
51
- # @param on: [String]
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: [String]
68
- # @param on: [String]
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::Tenant]
11
15
  def project
12
16
  @project ||= Yao::Tenant.get(scope["project"]["id"])
13
17
  end
14
18
 
15
- map_attribute_to_resource role: Role
16
- map_attribute_to_resource user: User
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
@@ -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
@@ -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
@@ -5,6 +5,7 @@ module Yao::Resources
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"
@@ -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
 
@@ -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")
@@ -6,4 +6,4 @@ module Yao::Resources
6
6
  self.resource_name = "server_group"
7
7
  self.resources_name = "os-server-groups"
8
8
  end
9
- end
9
+ end
@@ -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
@@ -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"]