yao 0.13.4 → 0.16.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.
Files changed (74) 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 +2 -2
  5. data/.rubocop.yml +3 -6
  6. data/lib/yao/auth.rb +18 -0
  7. data/lib/yao/client.rb +1 -1
  8. data/lib/yao/config.rb +19 -0
  9. data/lib/yao/faraday_middlewares.rb +37 -3
  10. data/lib/yao/mode.rb +4 -0
  11. data/lib/yao/plugins/default_client_generator.rb +0 -1
  12. data/lib/yao/plugins/registry.rb +2 -1
  13. data/lib/yao/resources/action.rb +7 -0
  14. data/lib/yao/resources/aggregates.rb +1 -0
  15. data/lib/yao/resources/base.rb +39 -6
  16. data/lib/yao/resources/compute_services.rb +8 -1
  17. data/lib/yao/resources/flavor.rb +12 -0
  18. data/lib/yao/resources/floating_ip.rb +2 -6
  19. data/lib/yao/resources/hypervisor.rb +1 -1
  20. data/lib/yao/resources/image.rb +2 -0
  21. data/lib/yao/resources/loadbalancer.rb +4 -0
  22. data/lib/yao/resources/loadbalancer_healthmonitor.rb +3 -0
  23. data/lib/yao/resources/loadbalancer_listener.rb +2 -0
  24. data/lib/yao/resources/loadbalancer_pool.rb +13 -17
  25. data/lib/yao/resources/loadbalancer_pool_member.rb +21 -0
  26. data/lib/yao/resources/metadata_available.rb +21 -0
  27. data/lib/yao/resources/meter.rb +9 -2
  28. data/lib/yao/resources/network.rb +2 -1
  29. data/lib/yao/resources/network_associationable.rb +1 -0
  30. data/lib/yao/resources/old_sample.rb +5 -1
  31. data/lib/yao/resources/port.rb +3 -1
  32. data/lib/yao/resources/port_associationable.rb +1 -0
  33. data/lib/yao/resources/project.rb +11 -0
  34. data/lib/yao/resources/{tenant_associationable.rb → project_associationable.rb} +5 -4
  35. data/lib/yao/resources/resource.rb +9 -3
  36. data/lib/yao/resources/restfully_accessible.rb +18 -2
  37. data/lib/yao/resources/role.rb +6 -4
  38. data/lib/yao/resources/role_assignment.rb +37 -4
  39. data/lib/yao/resources/router.rb +26 -8
  40. data/lib/yao/resources/sample.rb +4 -0
  41. data/lib/yao/resources/security_group.rb +2 -1
  42. data/lib/yao/resources/security_group_rule.rb +10 -0
  43. data/lib/yao/resources/server.rb +21 -1
  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 +2 -1
  47. data/lib/yao/resources/tenant.rb +11 -0
  48. data/lib/yao/resources/user.rb +8 -1
  49. data/lib/yao/resources/volume.rb +14 -1
  50. data/lib/yao/resources/volume_action.rb +13 -0
  51. data/lib/yao/resources.rb +4 -1
  52. data/lib/yao/token.rb +1 -0
  53. data/lib/yao/version.rb +1 -1
  54. data/test/yao/resources/test_base.rb +32 -0
  55. data/test/yao/resources/test_flavor.rb +67 -33
  56. data/test/yao/resources/test_floating_ip.rb +5 -5
  57. data/test/yao/resources/test_image.rb +5 -0
  58. data/test/yao/resources/test_loadbalancer_pool.rb +146 -1
  59. data/test/yao/resources/test_meter.rb +5 -5
  60. data/test/yao/resources/test_network.rb +6 -6
  61. data/test/yao/resources/test_port.rb +6 -6
  62. data/test/yao/resources/test_project.rb +45 -6
  63. data/test/yao/resources/test_restfully_accessible.rb +46 -4
  64. data/test/yao/resources/test_role_assignment.rb +100 -3
  65. data/test/yao/resources/test_router.rb +33 -12
  66. data/test/yao/resources/test_security_group.rb +5 -5
  67. data/test/yao/resources/test_server.rb +6 -6
  68. data/test/yao/resources/test_server_group.rb +1 -1
  69. data/test/yao/resources/test_subnet.rb +6 -6
  70. data/test/yao/resources/test_user.rb +28 -1
  71. data/test/yao/resources/test_volume.rb +81 -1
  72. data/test/yao/test_client.rb +0 -1
  73. data/yao.gemspec +1 -1
  74. metadata +11 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ee889ea30a4ed867e8f34bcb5fd185f194b317320fd8f5797f1a7b24b232e66
4
- data.tar.gz: 745bb13217eb75907e47732b457ac41cd90330f23becb0936e4c13beabdeb6e3
3
+ metadata.gz: edb91db2ac62cf431603c29ce61eaaf16f522827e455b563f0bcb2922af0fe18
4
+ data.tar.gz: 23b08a38cba8ac2d59fda37c33f9854ba0f88b8a3110e613439ba466014bbbc7
5
5
  SHA512:
6
- metadata.gz: bddf10dfefb8277e6ad2dda817ab08b54ede238586c1f4fd913b8648a257d4c8e79cb7301976cbf02f5991b4ffd8a0199d7a06db604d21a9f63438dea263801f
7
- data.tar.gz: 2e572a0ca854f98b118cb081daf3a862b3ad60ffcb7e8e0ba58d35d64cdaf40578a507cdd2b578c05b576be5d61c7d92161e251c03e0d6396fa73384599a2520
6
+ metadata.gz: 8d1e378004468dfaf40ea14866a8404c9936f3f2276f5492767cae69178bd323dd3f8bbb5cf82e45a87b72fd9d1b8b3f495ddd745562098abc44c2b25e41570b
7
+ data.tar.gz: 3bab6f8e27cad21a6bd704276fc26dcd2ec50e1e7d3af9cd22b9911ff4b10e0daea2022fd40fc480fe215665a466d8aeb86f2713850b868345b5144ba9a0fb35
@@ -0,0 +1,19 @@
1
+ name: rubocop
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@master
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.1
14
+ - name: Install dependencies
15
+ run: |
16
+ gem install bundler --no-document
17
+ bundle install
18
+ - name: Run rubocop
19
+ run: bundle exec rubocop
@@ -7,7 +7,7 @@ jobs:
7
7
  runs-on: ubuntu-latest
8
8
  strategy:
9
9
  matrix:
10
- ruby: [ 'ruby-2.7.0' ]
10
+ ruby: [ 'ruby-3.1.1' ]
11
11
  steps:
12
12
  - uses: actions/checkout@master
13
13
  - name: Set up RVM
@@ -7,11 +7,11 @@ jobs:
7
7
  runs-on: ubuntu-latest
8
8
  strategy:
9
9
  matrix:
10
- ruby: [ '2.6.x', '2.5.x', '2.4.x' ]
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: actions/setup-ruby@v1
14
+ uses: ruby/setup-ruby@v1
15
15
  with:
16
16
  ruby-version: ${{ matrix.ruby }}
17
17
  - name: Install dependencies
data/.rubocop.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.4
2
+ SuggestExtensions: false
3
+ TargetRubyVersion: 3.0
3
4
  DisplayCopNames: true
4
5
  DisabledByDefault: true
5
6
  Exclude:
@@ -11,7 +12,7 @@ Style/HashSyntax:
11
12
  Layout/EmptyLines:
12
13
  Enabled: true
13
14
 
14
- Layout/TrailingBlankLines:
15
+ Layout/TrailingEmptyLines:
15
16
  Enabled: true
16
17
 
17
18
  Layout/TrailingWhitespace:
@@ -52,7 +53,3 @@ Style/NumericLiteralPrefix:
52
53
  Style/StabbyLambdaParentheses:
53
54
  EnforcedStyle: require_parentheses
54
55
  Enabled: true
55
-
56
- Rails/ActionFilter:
57
- EnforcedStyle: action
58
- Enabled: true
data/lib/yao/auth.rb CHANGED
@@ -12,12 +12,22 @@ module Yao
12
12
 
13
13
  module Auth
14
14
  class << self
15
+ # @return [Yao::Auth]
15
16
  def try_new
16
17
  if Yao.config.tenant_name && Yao.config.username && Yao.config.password && Yao.default_client
17
18
  Yao::Auth.new
18
19
  end
19
20
  end
20
21
 
22
+ # @param tenant_name [String]
23
+ # @param username [String]
24
+ # @param password [String]
25
+ # @param default_domain [String]
26
+ # @param user_domain_id [String]
27
+ # @param user_domain_name [String]
28
+ # @param project_domain_id [String]
29
+ # @param project_domain_name [String]
30
+ # @return [Hash]
21
31
  def build_authv3_info(tenant_name, username, password,
22
32
  default_domain,
23
33
  user_domain_id, user_domain_name,
@@ -55,6 +65,10 @@ module Yao
55
65
  }
56
66
  end
57
67
 
68
+ # @param tenant_name [String]
69
+ # @param username [String]
70
+ # @param password [String]
71
+ # @return [Hash]
58
72
  def build_auth_info(tenant_name, username, password)
59
73
  auth_info = {
60
74
  auth: {
@@ -68,6 +82,10 @@ module Yao
68
82
  auth_info
69
83
  end
70
84
 
85
+ # if identity_api_version == "3"
86
+ # @return [TokenV3]
87
+ # else
88
+ # @return [Token]
71
89
  def new(
72
90
  tenant_name: Yao.config.tenant_name,
73
91
  username: Yao.config.username,
data/lib/yao/client.rb CHANGED
@@ -104,7 +104,7 @@ module Yao
104
104
  end
105
105
  end
106
106
 
107
- # @param [String]
107
+ # @param new_endpoint [String]
108
108
  def reset_client(new_endpoint=nil)
109
109
  set = ClientSet.new
110
110
  endpoint = {
data/lib/yao/config.rb CHANGED
@@ -1,22 +1,30 @@
1
1
  module Yao
2
2
  class Config
3
+
4
+ # @return [Hash]
3
5
  def _configuration_defaults
4
6
  @_configuration_defaults ||= {}
5
7
  end
6
8
 
9
+ # @return [Hash]
7
10
  def _configuration_hooks
8
11
  @_configuration_hooks ||= {}
9
12
  end
10
13
 
14
+ # @return [Array]
11
15
  def _configuration_hooks_queue
12
16
  @_configuration_hooks_queue ||= []
13
17
  end
14
18
 
19
+ # @return [Hash]
15
20
  def configuration
16
21
  @configuration ||= {}
17
22
  end
18
23
 
19
24
  HOOK_RENEW_CLIENT_KEYS = %i(tenant_name username password auth_url debug debug_record_response)
25
+
26
+ # @param v [Boolean]
27
+ # @return [Array]
20
28
  def delay_hook=(v)
21
29
  @delay_hook = v
22
30
  if !v and !_configuration_hooks_queue.empty?
@@ -33,10 +41,14 @@ module Yao
33
41
  end
34
42
  end
35
43
 
44
+ # @return [Boolean]
36
45
  def delay_hook?
37
46
  @delay_hook
38
47
  end
39
48
 
49
+ # @param name [String]
50
+ # @param default [String]
51
+ # @param hook [Proc]
40
52
  def param(name, default, &hook)
41
53
  raise("Duplicate definition of #{name}") if self.respond_to?(name)
42
54
 
@@ -55,6 +67,9 @@ module Yao
55
67
  end
56
68
  end
57
69
 
70
+ # @param name [String]
71
+ # @param value [String]
72
+ # @return [String]
58
73
  def set(name, value)
59
74
  raise("Undefined config key #{name}") unless self.respond_to?(name)
60
75
  configuration[name.to_sym] = value
@@ -67,6 +82,8 @@ module Yao
67
82
  end
68
83
  end
69
84
 
85
+ # @param blk [Proc]
86
+ # @return [Yao::Config]
70
87
  def self.config(&blk)
71
88
  @__config ||= Config.new
72
89
  if blk
@@ -77,6 +94,8 @@ module Yao
77
94
  @__config
78
95
  end
79
96
 
97
+ # @param blk [Proc]
98
+ # @return [Yao::Config]
80
99
  def self.configure(&blk)
81
100
  config(&blk)
82
101
  end
@@ -81,17 +81,21 @@ class Faraday::Response::OSDumper < Faraday::Response::Middleware
81
81
  def on_complete(env)
82
82
  require 'pp'
83
83
 
84
- body = if env.response_headers["content-type"] == "application/json"
84
+ body = if env.response_headers["content-type"].start_with?("application/json")
85
85
  JSON.parse(env.body)
86
86
  else
87
87
  env.body
88
88
  end
89
+ body = conseal_token_in_body(body)
90
+
91
+ request_headers = conseal_token_in_request_headers(env.request_headers.dup)
92
+ response_headers= conseal_token_in_response_headers(env.response_headers.dup)
89
93
 
90
94
  params = [
91
95
  env.url.to_s,
92
96
  body,
93
- env.request_headers,
94
- env.response_headers,
97
+ request_headers,
98
+ response_headers,
95
99
  env.method,
96
100
  env.status
97
101
  ].map(&:pretty_inspect)
@@ -114,6 +118,36 @@ Status Code: %s
114
118
 
115
119
  FMT
116
120
  end
121
+
122
+ private
123
+ def conseal_token_in_body(body)
124
+ # for keystone v2.0
125
+ if body.is_a?(Hash) && token = body.dig("access", "token", "id")
126
+ body["access"]["token"]["id"] = hashed_token(token)
127
+ end
128
+ body
129
+ end
130
+
131
+ def conseal_token_in_request_headers(headers)
132
+ if token = headers["X-Auth-Token"]
133
+ headers["X-Auth-Token"] = hashed_token(token)
134
+ end
135
+ headers
136
+ end
137
+
138
+ def conseal_token_in_response_headers(headers)
139
+ if token = headers["x-subject-token"]
140
+ headers["x-subject-token"] = hashed_token(token)
141
+ end
142
+ headers
143
+ end
144
+
145
+ def hashed_token(token)
146
+ require 'openssl'
147
+
148
+ # This format was based on openstack client.
149
+ "{SHA256}" + OpenSSL::Digest::SHA256.hexdigest(token)
150
+ end
117
151
  end
118
152
  Faraday::Response.register_middleware os_dumper: -> { Faraday::Response::OSDumper }
119
153
 
data/lib/yao/mode.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module Yao
2
2
  module Mode
3
+ # @param blk [Proc]
4
+ # @return [String]
3
5
  def read_only!(&blk)
4
6
  raise unless block_given?
5
7
 
@@ -16,6 +18,8 @@ module Yao
16
18
  end
17
19
  end
18
20
 
21
+ # @param blk [Proc]
22
+ # @return [String]
19
23
  def read_only(&blk)
20
24
  raise unless block_given?
21
25
 
@@ -20,7 +20,6 @@ module Yao::Plugins
20
20
  f.response :json, content_type: /\bjson$/
21
21
 
22
22
  if Yao.config.debug
23
- f.response :logger
24
23
  f.response :os_dumper
25
24
  end
26
25
 
@@ -6,11 +6,12 @@ module Yao::Plugins
6
6
  class Registry
7
7
  include Singleton
8
8
 
9
+ # @return [Hash]
9
10
  def initialize
10
11
  @types = {}
11
12
  end
12
13
 
13
- # @type type [Symbol]
14
+ # @param type [Symbol]
14
15
  # @return [Object]
15
16
  def [](type)
16
17
  @types[type]
@@ -1,5 +1,9 @@
1
1
  module Yao::Resources
2
2
  module Action
3
+
4
+ # @param id [String]
5
+ # @param query [Hash]
6
+ # @return [Hash]
3
7
  def action(id, query)
4
8
  res = POST(action_path(id)) do |req|
5
9
  req.body = query.to_json
@@ -9,6 +13,9 @@ module Yao::Resources
9
13
  end
10
14
 
11
15
  private
16
+
17
+ # @param id [String]
18
+ # @return [String]
12
19
  def action_path(id)
13
20
  [resources_name, id, "action"].join("/")
14
21
  end
@@ -4,6 +4,7 @@ module Yao::Resources
4
4
  class Aggregates < Base
5
5
  friendly_attributes :availability_zone, :deleted, :hosts, :metadata, :name
6
6
 
7
+ # @return [Date]
7
8
  def deleted_at
8
9
  Date.parse(self["deleted_at"]) if self["deleted_at"]
9
10
  end
@@ -3,17 +3,18 @@ require 'time'
3
3
 
4
4
  module Yao::Resources
5
5
  class Base
6
+
7
+ # @param name [Array]
6
8
  def self.friendly_attributes(*names)
7
9
  names.map(&:to_s).each do |name|
8
10
  define_method(name) do
9
- if !@data.key?(name) && id
10
- @data = self.class.get(id).to_hash
11
- end
12
11
  self[name]
13
12
  end
14
13
  end
15
14
  end
16
15
 
16
+ # @param k_and_v [Hash]
17
+ # @return [Symbol]
17
18
  def self.map_attribute_to_attribute(k_and_v)
18
19
  as_json, as_method = *k_and_v.to_a.first.map(&:to_s)
19
20
  define_method(as_method) do
@@ -21,14 +22,20 @@ module Yao::Resources
21
22
  end
22
23
  end
23
24
 
25
+ # @param k_and_v [Hash]
26
+ # @return [Symbol]
24
27
  def self.map_attribute_to_resource(k_and_v)
25
28
  _name, klass = *k_and_v.to_a.first
26
29
  name = _name.to_s
27
30
  define_method(name) do
28
- self[[name, klass].join("__")] ||= klass.new(self[name])
31
+ unless self[name].empty?
32
+ self[[name, klass].join("__")] ||= klass.new(self[name])
33
+ end
29
34
  end
30
35
  end
31
36
 
37
+ # @param k_and_v [Hash]
38
+ # @return [Symbol]
32
39
  def self.map_attribute_to_resources(k_and_v)
33
40
  _name, klass = *k_and_v.to_a.first
34
41
  name = _name.to_s
@@ -39,38 +46,64 @@ module Yao::Resources
39
46
  end
40
47
  end
41
48
 
49
+ # @param data_via_json [Hash]
50
+ # @return [Hash]
42
51
  def initialize(data_via_json)
43
52
  @data = data_via_json
44
53
  end
45
54
 
55
+ # @param name [String]
56
+ # @return [String]
46
57
  def [](name)
58
+ unless @data["id"].nil? || @data.key?(name) || name.include?("__")
59
+ @data = self.class.get(@data["id"]).to_hash
60
+ end
47
61
  @data[name]
48
62
  end
49
63
 
64
+ # @param name [String]
65
+ # @param value [String]
66
+ # @return [String]
50
67
  def []=(name, value)
51
68
  @data[name] = value
52
69
  end
53
70
 
71
+ # @return [Hash]
54
72
  def to_hash
55
73
  @data
56
74
  end
57
75
 
76
+ # @return [String]
58
77
  def id
59
78
  self["id"]
60
79
  end
61
80
 
81
+ # @return [Date]
62
82
  def created
63
- if date = self["created"] || self["created_at"]
83
+ if date = self["created_at"] || self["created"]
64
84
  Time.parse(date)
65
85
  end
66
86
  end
67
87
 
88
+ # @return [Date]
68
89
  def updated
69
- if date = self["updated"] || self["updated_at"]
90
+ if date = self["updated_at"] || self["updated"]
70
91
  Time.parse(date)
71
92
  end
72
93
  end
73
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
+
74
107
  extend RestfullyAccessible
75
108
  end
76
109
  end
@@ -19,6 +19,9 @@ module Yao::Resources
19
19
  end
20
20
 
21
21
  class << self
22
+ # @param host [String]
23
+ # @param binary [String]
24
+ # @return [Yao::Resources::ComputeServices]
22
25
  def enable(host, binary)
23
26
  params = {
24
27
  "host" => host,
@@ -27,6 +30,10 @@ module Yao::Resources
27
30
  put("enable", params)
28
31
  end
29
32
 
33
+ # @param host [String]
34
+ # @param binary [String]
35
+ # @param resason [String]
36
+ # @return [Yao::Resources::ComputeServices]
30
37
  def disable(host, binary, reason = nil)
31
38
  params = {
32
39
  "host" => host,
@@ -55,4 +62,4 @@ module Yao::Resources
55
62
  end
56
63
 
57
64
  end
58
- end
65
+ end
@@ -4,6 +4,8 @@ module Yao::Resources
4
4
  map_attribute_to_attribute "os-flavor-access:is_public" => :public?
5
5
  map_attribute_to_attribute "OS-FLV-DISABLED:disabled" => :disabled?
6
6
 
7
+ # @param unit [String]
8
+ # @return [Integer]
7
9
  def ram(unit='M')
8
10
  case unit
9
11
  when 'M'
@@ -18,5 +20,15 @@ module Yao::Resources
18
20
  self.resource_name = "flavor"
19
21
  self.resources_name = "flavors"
20
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
21
33
  end
22
34
  end
@@ -2,7 +2,7 @@ module Yao::Resources
2
2
  class FloatingIP < Base
3
3
 
4
4
  include PortAssociationable
5
- include TenantAssociationable
5
+ include ProjectAssociationable
6
6
 
7
7
  friendly_attributes :router_id, :description, :dns_domain, :dns_name,
8
8
  :revision_number,
@@ -14,13 +14,9 @@ module Yao::Resources
14
14
  self.resource_name = "floatingip"
15
15
  self.resources_name = "floatingips"
16
16
 
17
+ # @return [Yao::Resources::Router]
17
18
  def router
18
19
  @router ||= Yao::Router.get(router_id)
19
20
  end
20
-
21
- def project
22
- @project ||= Yao::Tenant.get(project_id)
23
- end
24
- alias :tenant :project
25
21
  end
26
22
  end
@@ -22,7 +22,7 @@ module Yao::Resources
22
22
  self['status'] == 'disabled'
23
23
  end
24
24
 
25
- # @return [Yao::ComputeServices]
25
+ # @return [Yao::Resources::ComputeServices]
26
26
  def service
27
27
  Yao::ComputeServices.new(self['service'])
28
28
  end
@@ -5,6 +5,8 @@ module Yao::Resources
5
5
  map_attribute_to_attribute minDisk: :min_disk
6
6
  map_attribute_to_attribute minRam: :min_ram
7
7
 
8
+ # @param unit [String]
9
+ # @return [Integer]
8
10
  def size(unit=nil)
9
11
  size = self["OS-EXT-IMG-SIZE:size"]
10
12
  case unit
@@ -6,6 +6,7 @@ module Yao::Resources
6
6
  map_attribute_to_resources listeners: LoadBalancerListener
7
7
  map_attribute_to_resources pools: LoadBalancerPool
8
8
 
9
+ # @return [Yao::Resources::Tenant]
9
10
  def project
10
11
  if project_id = self["project_id"]
11
12
  Yao::Tenant.find project_id
@@ -13,18 +14,21 @@ module Yao::Resources
13
14
  end
14
15
  alias :tenant :project
15
16
 
17
+ # @return [Yao::Resources::Network]
16
18
  def vip_network
17
19
  if vip_network_id = self["vip_network_id"]
18
20
  Yao::Network.find vip_network_id
19
21
  end
20
22
  end
21
23
 
24
+ # @return [Yao::Resources::Port]
22
25
  def vip_port
23
26
  if vip_port_id = self["vip_port_id"]
24
27
  Yao::Port.find vip_port_id
25
28
  end
26
29
  end
27
30
 
31
+ # @return [Yao::Resources::Subnet]
28
32
  def vip_subnet
29
33
  if vip_subnet_id = self["vip_subnet_id"]
30
34
  Yao::Subnet.find vip_subnet_id
@@ -7,14 +7,17 @@ module Yao::Resources
7
7
 
8
8
  map_attribute_to_resources pools: LoadBalancerListener
9
9
 
10
+ # @return [Date]
10
11
  def created_at
11
12
  Date.parse(self["created_at"])
12
13
  end
13
14
 
15
+ # @return [Date]
14
16
  def updated_at
15
17
  Date.parse(self["updated_at"])
16
18
  end
17
19
 
20
+ # @return [Date]
18
21
  def project
19
22
  if project_id = self["project_id"]
20
23
  Yao::Tenant.find project_id
@@ -8,6 +8,7 @@ module Yao::Resources
8
8
 
9
9
  map_attribute_to_resources loadbalancers: LoadBalancer
10
10
 
11
+ # @return [Yao::Resources::Tenant]
11
12
  def project
12
13
  if project_id = self["project_id"]
13
14
  Yao::Tenant.find project_id
@@ -15,6 +16,7 @@ module Yao::Resources
15
16
  end
16
17
  alias :tenant :project
17
18
 
19
+ # @return [Yao::Resources::LoadBalancerPool]
18
20
  def default_pool
19
21
  if default_pool_id = self["default_pool_id"]
20
22
  Yao::LoadBalancerPool.find default_pool_id
@@ -7,20 +7,14 @@ module Yao::Resources
7
7
  map_attribute_to_resources loadbalancers: LoadBalancer
8
8
  map_attribute_to_resources listeners: LoadBalancerListener
9
9
 
10
- def created_at
11
- Date.parse(self["created_at"])
12
- end
13
-
14
- def updated_at
15
- Date.parse(self["updated_at"])
16
- end
17
-
10
+ # @return [Yao::Resources::LoadBalancerListener]
18
11
  def listeners
19
- self["listeners"].map do |listener|
20
- Yao::LoadBalancerListener.find listener["id"]
21
- end
12
+ @listeners ||= self["listeners"].map do |listener|
13
+ Yao::LoadBalancerListener.get(listener["id"])
14
+ end
22
15
  end
23
16
 
17
+ # @return [Yao::Resources::Tenant]
24
18
  def project
25
19
  if project_id = self["project_id"]
26
20
  Yao::Tenant.find project_id
@@ -28,16 +22,18 @@ module Yao::Resources
28
22
  end
29
23
  alias :tenant :project
30
24
 
25
+ # @return [Yao::Resources::LoadBalancerPoolMember]
31
26
  def members
32
- self["members"].map do |member|
33
- Yao::LoadBalancerPoolMember.find(self,member["id"])
34
- end
27
+ @members ||= self["members"].map do |member|
28
+ Yao::LoadBalancerPoolMember.get(self, member["id"])
29
+ end
35
30
  end
36
31
 
32
+ # @return [Yao::Resources::LoadBalancerHealthMonitor]
37
33
  def healthmonitor
38
- if healthmonitor_id = self["healthmonitor_id"]
39
- Yao::LoadBalancerHealthMonitor.find healthmonitor_id
40
- end
34
+ @healthmonitor ||= if healthmonitor_id = self["healthmonitor_id"]
35
+ Yao::LoadBalancerHealthMonitor.get(healthmonitor_id)
36
+ end
41
37
  end
42
38
 
43
39
  self.service = "load-balancer"