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
@@ -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
 
@@ -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 TenantAssociationable
5
+ include ProjectAssociationable
6
6
 
7
7
  friendly_attributes :addresses, :metadata, :name, :progress,
8
8
  :status, :user_id, :key_name
@@ -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
@@ -2,11 +2,12 @@ module Yao::Resources
2
2
  class Subnet < Base
3
3
 
4
4
  include NetworkAssociationable
5
- include TenantAssociationable
5
+ include ProjectAssociationable
6
6
 
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"]
@@ -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,22 +10,31 @@ 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
26
32
 
33
+ # @return [Yao::Resources::RoleAssignment]
34
+ def role_assignment
35
+ Yao::RoleAssignment.get(tenant: id)
36
+ end
37
+
27
38
  class << self
28
39
  def accessible
29
40
  as_member { self.list }
@@ -1,6 +1,6 @@
1
1
  module Yao::Resources
2
2
  class User < Base
3
- friendly_attributes :name, :email, :enabled, :id
3
+ friendly_attributes :name, :email, :enabled
4
4
 
5
5
  alias enabled? enabled
6
6
 
@@ -9,12 +9,19 @@ 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
18
+ # @return [Bool]
13
19
  def return_single_on_querying
14
20
  api_verion_v2?
15
21
  end
16
22
 
17
23
  private
24
+ # @return [Bool]
18
25
  def api_verion_v2?
19
26
  client.url_prefix.to_s.match?(/v2\.0/)
20
27
  end
@@ -1,12 +1,25 @@
1
+ require 'yao/resources/volume_action'
2
+
1
3
  module Yao::Resources
2
4
  class Volume < Base
3
- friendly_attributes :name, :size, :volume_type
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
@@ -0,0 +1,13 @@
1
+ require 'yao/resources/action'
2
+
3
+ module Yao::Resources
4
+ module VolumeAction
5
+ include Action
6
+
7
+ def set_status(id, status)
8
+ action(id, 'os-reset_status' => {
9
+ 'status' => status,
10
+ })
11
+ end
12
+ end
13
+ end
data/lib/yao/resources.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  module Yao
2
2
  module Resources
3
3
  require "yao/resources/base"
4
- require "yao/resources/tenant_associationable"
4
+ require "yao/resources/project_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
@@ -2,6 +2,7 @@ require 'yao/client'
2
2
 
3
3
  module Yao
4
4
  class Token
5
+
5
6
  def self.issue(cli, auth_info)
6
7
  t = new(auth_info)
7
8
  t.refresh(cli)
data/lib/yao/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yao
2
- VERSION = "0.13.4"
2
+ VERSION = "0.16.0"
3
3
  end
@@ -12,4 +12,36 @@ 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
+
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
+
15
47
  end
@@ -46,48 +46,64 @@ class TestFlavor < TestYaoResource
46
46
  assert_equal(512, flavor.memory)
47
47
  end
48
48
 
49
- def test_list
50
- stub = stub_request(:get, "https://example.com:12345/flavors/detail").
49
+ def flavor_detail
50
+ JSON.parse(<<~JSON)
51
+ {
52
+ "OS-FLV-DISABLED:disabled": false,
53
+ "disk": 20,
54
+ "OS-FLV-EXT-DATA:ephemeral": 0,
55
+ "os-flavor-access:is_public": true,
56
+ "id": "7",
57
+ "links": [
58
+ {
59
+ "href": "http://openstack.example.com/v2/6f70656e737461636b20342065766572/flavors/7",
60
+ "rel": "self"
61
+ },
62
+ {
63
+ "href": "http://openstack.example.com/6f70656e737461636b20342065766572/flavors/7",
64
+ "rel": "bookmark"
65
+ }
66
+ ],
67
+ "name": "m1.small.description",
68
+ "ram": 2048,
69
+ "swap": 0,
70
+ "vcpus": 1,
71
+ "rxtx_factor": 1.0,
72
+ "description": "test description",
73
+ "extra_specs": {
74
+ "hw:cpu_policy": "shared",
75
+ "hw:numa_nodes": "1"
76
+ }
77
+ }
78
+ JSON
79
+ end
80
+
81
+ def stub_flavors_detail(query=nil)
82
+ url = ['https://example.com:12345/flavors/detail',query].compact.join('?')
83
+ stub_request(:get, url).
51
84
  to_return(
52
85
  status: 200,
53
- body: <<-JSON,
54
- {
55
- "flavors": [
56
- {
57
- "OS-FLV-DISABLED:disabled": false,
58
- "disk": 1,
59
- "OS-FLV-EXT-DATA:ephemeral": 0,
60
- "os-flavor-access:is_public": true,
61
- "id": "1",
62
- "links": [
63
- {
64
- "href": "http://openstack.example.com/v2/6f70656e737461636b20342065766572/flavors/1",
65
- "rel": "self"
66
- },
67
- {
68
- "href": "http://openstack.example.com/6f70656e737461636b20342065766572/flavors/1",
69
- "rel": "bookmark"
70
- }
71
- ],
72
- "name": "m1.tiny",
73
- "ram": 512,
74
- "swap": "",
75
- "vcpus": 1,
76
- "rxtx_factor": 1.0,
77
- "description": null,
78
- "extra_specs": {}
79
- }
80
- ]
81
- }
82
- JSON
86
+ body: { flavors:[flavor_detail] }.to_json,
83
87
  headers: {'Content-Type' => 'application/json'}
84
88
  )
89
+ end
85
90
 
91
+ def stub_flavor(id)
92
+ stub_request(:get, "https://example.com:12345/flavors/#{id}").
93
+ to_return(
94
+ status: 200,
95
+ body: { 'flavor': flavor_detail }.to_json,
96
+ headers: {'Content-Type' => 'application/json'}
97
+ )
98
+ end
99
+
100
+ def test_list
101
+ stub = stub_flavors_detail
86
102
  assert(Yao::Flavor.resources_detail_available)
87
103
 
88
104
  flavors = Yao::Flavor.list
89
105
  assert_instance_of(Yao::Flavor, flavors.first)
90
- assert_equal("m1.tiny", flavors.first.name)
106
+ assert_equal("m1.small.description", flavors.first.name)
91
107
 
92
108
  assert_requested(stub)
93
109
  end
@@ -97,4 +113,22 @@ class TestFlavor < TestYaoResource
97
113
  # see also: https://stackoverflow.com/questions/25883618/how-to-test-method-alias-ruby
98
114
  assert_equal(Yao::Flavor.method(:list), Yao::Flavor.method(:list_detail))
99
115
  end
116
+
117
+ def test_get_by_id
118
+ stub = stub_flavor(7)
119
+ flavor = Yao::Flavor.get('7')
120
+ assert_equal('m1.small.description', flavor.name)
121
+ assert_requested(stub)
122
+ end
123
+
124
+ def test_get_by_name
125
+ stub = stub_request(:get, "https://example.com:12345/flavors/m1.small.description").to_return(status: 404)
126
+ stub2 = stub_flavors_detail
127
+ stub3 = stub_flavor(7)
128
+ flavor = Yao::Flavor.get('m1.small.description')
129
+ assert_equal('7', flavor.id)
130
+ assert_requested(stub)
131
+ assert_requested(stub2)
132
+ assert_requested(stub3)
133
+ end
100
134
  end
@@ -82,14 +82,14 @@ class TestFloatingIP < TestYaoResource
82
82
  assert_requested(stub)
83
83
  end
84
84
 
85
- def test_tenant
85
+ def test_project
86
86
 
87
- stub = stub_request(:get, "https://example.com:12345/tenants/0123456789abcdef0123456789abcdef")
87
+ stub = stub_request(:get, "https://example.com:12345/projects/0123456789abcdef0123456789abcdef")
88
88
  .to_return(
89
89
  status: 200,
90
90
  body: <<-JSON,
91
91
  {
92
- "tenant": {
92
+ "project": {
93
93
  "id": "0123456789abcdef0123456789abcdef"
94
94
  }
95
95
  }
@@ -102,8 +102,8 @@ class TestFloatingIP < TestYaoResource
102
102
  "tenant_id" => "0123456789abcdef0123456789abcdef",
103
103
  )
104
104
 
105
- assert_instance_of(Yao::Tenant, fip.tenant)
106
- assert_instance_of(Yao::Tenant, fip.project)
105
+ assert_instance_of(Yao::Project, fip.tenant)
106
+ assert_instance_of(Yao::Project, fip.project)
107
107
  assert_equal('0123456789abcdef0123456789abcdef', fip.tenant.id)
108
108
 
109
109
  assert_requested(stub)
@@ -41,6 +41,11 @@ class TestImage < TestYaoResource
41
41
 
42
42
  end
43
43
 
44
+ def test_empty_image
45
+ image = Yao::Server.new("image"=>"").image
46
+ assert_equal(image, nil)
47
+ end
48
+
44
49
  def test_to_hash
45
50
  server = Yao::Resources::Server.new(
46
51
  "OS-DCF:diskConfig" => "AUTO",
@@ -13,7 +13,14 @@ class TestLoadBalancerPool < TestYaoResource
13
13
  "type" => "SOURCE_IP"
14
14
  },
15
15
  "operating_status" => "ONLINE",
16
- "name" => "round_robin_pool"
16
+ "name" => "round_robin_pool",
17
+ "members" => [
18
+ {"id" => "957a1ace-1bd2-449b-8455-820b6e4b63f3"},
19
+ ],
20
+ "listeners" => [
21
+ {"id" => "023f2e34-7806-443b-bfae-16c324569a3d"}
22
+ ],
23
+ "healthmonitor_id" => "8ed3c5ac-6efa-420c-bedb-99ba14e58db5",
17
24
  }
18
25
 
19
26
  pool = Yao::Resources::LoadBalancerPool.new(params)
@@ -30,5 +37,143 @@ class TestLoadBalancerPool < TestYaoResource
30
37
  }, pool.session_persistence)
31
38
  assert_equal("ONLINE", pool.operating_status)
32
39
  assert_equal("round_robin_pool", pool.name)
40
+
41
+ # https://docs.openstack.org/api-ref/load-balancer/v2/?expanded=show-member-details-detail#show-member-details
42
+ stub = stub_request(:get, "http://endpoint.example.com:9876/v2.0/lbaas/pools//members/957a1ace-1bd2-449b-8455-820b6e4b63f3")
43
+ .to_return(
44
+ status: 200,
45
+ body: <<-JSON,
46
+ {
47
+ "member": {
48
+ "monitor_port": 8080,
49
+ "project_id": "e3cd678b11784734bc366148aa37580e",
50
+ "name": "web-server-1",
51
+ "weight": 20,
52
+ "backup": false,
53
+ "admin_state_up": true,
54
+ "subnet_id": "bbb35f84-35cc-4b2f-84c2-a6a29bba68aa",
55
+ "created_at": "2017-05-11T17:21:34",
56
+ "provisioning_status": "ACTIVE",
57
+ "monitor_address": null,
58
+ "updated_at": "2017-05-11T17:21:37",
59
+ "address": "192.0.2.16",
60
+ "protocol_port": 80,
61
+ "id": "957a1ace-1bd2-449b-8455-820b6e4b63f3",
62
+ "operating_status": "NO_MONITOR",
63
+ "tags": ["test_tag"]
64
+ }
65
+ }
66
+ JSON
67
+ headers: {'Content-Type' => 'application/json'}
68
+ )
69
+
70
+ assert_instance_of(Yao::LoadBalancerPoolMember, pool.members.first)
71
+ assert_equal("957a1ace-1bd2-449b-8455-820b6e4b63f3", pool.members.first.id)
72
+ assert_equal("web-server-1", pool.members.first.name)
73
+ assert_requested(stub)
74
+
75
+ # https://docs.openstack.org/api-ref/load-balancer/v2/?expanded=show-member-details-detail,show-listener-details-detail,show-pool-details-detail#show-listener-details
76
+ stub = stub_request(:get, "http://endpoint.example.com:9876/v2.0/lbaas/listeners/023f2e34-7806-443b-bfae-16c324569a3d")
77
+ .to_return(
78
+ status: 200,
79
+ body: <<-JSON,
80
+ {
81
+ "listener": {
82
+ "description": "A great TLS listener",
83
+ "admin_state_up": true,
84
+ "project_id": "e3cd678b11784734bc366148aa37580e",
85
+ "protocol": "TERMINATED_HTTPS",
86
+ "protocol_port": 443,
87
+ "provisioning_status": "ACTIVE",
88
+ "default_tls_container_ref": "http://198.51.100.10:9311/v1/containers/a570068c-d295-4780-91d4-3046a325db51",
89
+ "loadbalancers": [
90
+ {
91
+ "id": "607226db-27ef-4d41-ae89-f2a800e9c2db"
92
+ }
93
+ ],
94
+ "insert_headers": {
95
+ "X-Forwarded-Port": "true",
96
+ "X-Forwarded-For": "true"
97
+ },
98
+ "created_at": "2017-02-28T00:42:44",
99
+ "updated_at": "2017-02-28T00:44:30",
100
+ "id": "023f2e34-7806-443b-bfae-16c324569a3d",
101
+ "operating_status": "ONLINE",
102
+ "default_pool_id": "ddb2b28f-89e9-45d3-a329-a359c3e39e4a",
103
+ "sni_container_refs": [
104
+ "http://198.51.100.10:9311/v1/containers/a570068c-d295-4780-91d4-3046a325db51",
105
+ "http://198.51.100.10:9311/v1/containers/aaebb31e-7761-4826-8cb4-2b829caca3ee"
106
+ ],
107
+ "l7policies": [
108
+ {
109
+ "id": "5e618272-339d-4a80-8d14-dbc093091bb1"
110
+ }
111
+ ],
112
+ "name": "great_tls_listener",
113
+ "timeout_client_data": 50000,
114
+ "timeout_member_connect": 5000,
115
+ "timeout_member_data": 50000,
116
+ "timeout_tcp_inspect": 0,
117
+ "tags": ["test_tag"],
118
+ "client_ca_tls_container_ref": "http://198.51.100.10:9311/v1/containers/35649991-49f3-4625-81ce-2465fe8932e5",
119
+ "client_authentication": "MANDATORY",
120
+ "client_crl_container_ref": "http://198.51.100.10:9311/v1/containers/e222b065-b93b-4e2a-9a02-804b7a118c3c",
121
+ "allowed_cidrs": [
122
+ "192.0.2.0/24",
123
+ "198.51.100.0/24"
124
+ ],
125
+ "tls_ciphers": "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256",
126
+ "tls_versions": ["TLSv1.2", "TLSv1.3"],
127
+ "alpn_protocols": ["http/1.1", "http/1.0"]
128
+ }
129
+ }
130
+ JSON
131
+ headers: {'Content-Type' => 'application/json'}
132
+ )
133
+ assert_instance_of(Yao::LoadBalancerListener, pool.listeners.first)
134
+ assert_equal("023f2e34-7806-443b-bfae-16c324569a3d", pool.listeners.first.id)
135
+ assert_equal("great_tls_listener", pool.listeners.first.name)
136
+ assert_requested(stub)
137
+
138
+ # https://docs.openstack.org/api-ref/load-balancer/v2/?expanded=show-member-details-detail,show-listener-details-detail,show-pool-details-detail,show-health-monitor-details-detail#show-health-monitor-details
139
+ stub = stub_request(:get, "http://endpoint.example.com:9876/v2.0/lbaas/healthmonitors/8ed3c5ac-6efa-420c-bedb-99ba14e58db5")
140
+ .to_return(
141
+ status: 200,
142
+ body: <<-JSON,
143
+ {
144
+ "healthmonitor": {
145
+ "project_id": "e3cd678b11784734bc366148aa37580e",
146
+ "name": "super-pool-health-monitor",
147
+ "admin_state_up": true,
148
+ "pools": [
149
+ {
150
+ "id": "4029d267-3983-4224-a3d0-afb3fe16a2cd"
151
+ }
152
+ ],
153
+ "created_at": "2017-05-11T23:53:47",
154
+ "provisioning_status": "ACTIVE",
155
+ "updated_at": "2017-05-11T23:53:47",
156
+ "delay": 10,
157
+ "expected_codes": "200",
158
+ "max_retries": 1,
159
+ "http_method": "GET",
160
+ "timeout": 5,
161
+ "max_retries_down": 3,
162
+ "url_path": "/",
163
+ "type": "HTTP",
164
+ "id": "8ed3c5ac-6efa-420c-bedb-99ba14e58db5",
165
+ "operating_status": "ONLINE",
166
+ "tags": ["test_tag"],
167
+ "http_version": 1.0,
168
+ "domain_name": null
169
+ }
170
+ }
171
+ JSON
172
+ headers: {'Content-Type' => 'application/json'}
173
+ )
174
+ assert_instance_of(Yao::LoadBalancerHealthMonitor, pool.healthmonitor)
175
+ assert_equal("8ed3c5ac-6efa-420c-bedb-99ba14e58db5", pool.healthmonitor.id)
176
+ assert_equal("super-pool-health-monitor", pool.healthmonitor.name)
177
+ assert_requested(stub)
33
178
  end
34
179
  end