yao 0.18.0 → 0.20.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.
- checksums.yaml +4 -4
- data/lib/yao/resources/aggregates.rb +3 -4
- data/lib/yao/resources/base.rb +28 -15
- data/lib/yao/resources/compute_services.rb +8 -0
- data/lib/yao/resources/floating_ip.rb +4 -0
- data/lib/yao/resources/loadbalancer.rb +4 -0
- data/lib/yao/resources/loadbalancer_healthmonitor.rb +4 -0
- data/lib/yao/resources/loadbalancer_listener.rb +4 -0
- data/lib/yao/resources/loadbalancer_pool.rb +4 -0
- data/lib/yao/resources/loadbalancer_pool_member.rb +4 -0
- data/lib/yao/resources/network.rb +6 -1
- data/lib/yao/resources/networking_agents.rb +5 -0
- data/lib/yao/resources/restfully_accessible.rb +12 -3
- data/lib/yao/resources/server.rb +66 -1
- data/lib/yao/resources/server_migrate.rb +15 -0
- data/lib/yao/resources/volume.rb +4 -0
- data/lib/yao/resources/volume_services.rb +76 -0
- data/lib/yao/resources.rb +2 -0
- data/lib/yao/version.rb +1 -1
- data/test/support/restfully_accesible_stub.rb +34 -0
- data/test/yao/resources/test_aggregates.rb +1 -1
- data/test/yao/resources/test_compute_services.rb +8 -0
- data/test/yao/resources/test_network.rb +4 -2
- data/test/yao/resources/test_networking_agents.rb +8 -0
- data/test/yao/resources/test_server.rb +95 -0
- data/test/yao/resources/test_server_migrate.rb +33 -0
- data/test/yao/resources/test_volume.rb +7 -1
- data/test/yao/resources/test_volume_services.rb +116 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 390b05f4ca044196755551231ee7f297900816c3742318bcc502b0376e70512a
|
4
|
+
data.tar.gz: 0a6bb49a598bb7667d488ce316280ed3504b5ab2c3e0f97da0019783a5f6a939
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 731688676c2b1b9d120ef76f67131de2b060a25b8e3c9cb0b1cbf138c6a58fe632220c7f02c87c58972ee51c40f0d902bca2e69d254cd9eecd427d3960a1740b
|
7
|
+
data.tar.gz: 63b4adfd5b841b0c4b99c262b8cc2235a980165c574db4b60dab8b39ba39b4b659b0d4761286e81a48e61f33a57821ba1167b1bd53ba35387fb6f1c0b37dc2cc
|
@@ -4,10 +4,9 @@ module Yao::Resources
|
|
4
4
|
class Aggregates < Base
|
5
5
|
friendly_attributes :availability_zone, :deleted, :hosts, :metadata, :name
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
7
|
+
map_attributes_to_time :created_at, :updated_at, :deleted_at
|
8
|
+
alias :created :created_at
|
9
|
+
alias :updated :updated_at
|
11
10
|
|
12
11
|
self.service = "compute"
|
13
12
|
self.resources_name = "aggregates"
|
data/lib/yao/resources/base.rb
CHANGED
@@ -4,9 +4,22 @@ require 'time'
|
|
4
4
|
module Yao::Resources
|
5
5
|
class Base
|
6
6
|
|
7
|
+
# @param name [String]
|
8
|
+
def self.add_instantiation_name_list(name)
|
9
|
+
@instantiation_list ||= []
|
10
|
+
@instantiation_list << name
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param name [String]
|
14
|
+
# @return [bool]
|
15
|
+
def self.instantiation?(name)
|
16
|
+
@instantiation_list.include?(name)
|
17
|
+
end
|
18
|
+
|
7
19
|
# @param name [Array]
|
8
20
|
def self.friendly_attributes(*names)
|
9
21
|
names.map(&:to_s).each do |name|
|
22
|
+
add_instantiation_name_list(name)
|
10
23
|
define_method(name) do
|
11
24
|
self[name]
|
12
25
|
end
|
@@ -17,6 +30,7 @@ module Yao::Resources
|
|
17
30
|
# @return [Symbol]
|
18
31
|
def self.map_attribute_to_attribute(k_and_v)
|
19
32
|
as_json, as_method = *k_and_v.to_a.first.map(&:to_s)
|
33
|
+
add_instantiation_name_list(as_method)
|
20
34
|
define_method(as_method) do
|
21
35
|
self[as_json]
|
22
36
|
end
|
@@ -27,6 +41,7 @@ module Yao::Resources
|
|
27
41
|
def self.map_attribute_to_resource(k_and_v)
|
28
42
|
_name, klass = *k_and_v.to_a.first
|
29
43
|
name = _name.to_s
|
44
|
+
add_instantiation_name_list(name)
|
30
45
|
define_method(name) do
|
31
46
|
unless self[name].empty?
|
32
47
|
self[[name, klass].join("__")] ||= klass.new(self[name])
|
@@ -39,6 +54,7 @@ module Yao::Resources
|
|
39
54
|
def self.map_attribute_to_resources(k_and_v)
|
40
55
|
_name, klass = *k_and_v.to_a.first
|
41
56
|
name = _name.to_s
|
57
|
+
add_instantiation_name_list(name)
|
42
58
|
define_method(name) do
|
43
59
|
self[[name, klass].join("__")] ||= self[name].map {|d|
|
44
60
|
klass.new(d)
|
@@ -46,6 +62,17 @@ module Yao::Resources
|
|
46
62
|
end
|
47
63
|
end
|
48
64
|
|
65
|
+
# @param names [Array<Symbol>]
|
66
|
+
# @return [Symbol]
|
67
|
+
def self.map_attributes_to_time(*names)
|
68
|
+
names.map(&:to_s).each do |name|
|
69
|
+
add_instantiation_name_list(name)
|
70
|
+
define_method(name) do
|
71
|
+
Time.parse(self[name])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
49
76
|
# @param data_via_json [Hash]
|
50
77
|
# @return [Hash]
|
51
78
|
def initialize(data_via_json)
|
@@ -55,7 +82,7 @@ module Yao::Resources
|
|
55
82
|
# @param name [String]
|
56
83
|
# @return [String]
|
57
84
|
def [](name)
|
58
|
-
|
85
|
+
if @data["id"] && !@data.key?(name) && self.class.instantiation?(name)
|
59
86
|
@data = self.class.get(@data["id"]).to_hash
|
60
87
|
end
|
61
88
|
@data[name]
|
@@ -78,20 +105,6 @@ module Yao::Resources
|
|
78
105
|
self["id"]
|
79
106
|
end
|
80
107
|
|
81
|
-
# @return [Date]
|
82
|
-
def created
|
83
|
-
if date = self["created_at"] || self["created"]
|
84
|
-
Time.parse(date)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
# @return [Date]
|
89
|
-
def updated
|
90
|
-
if date = self["updated_at"] || self["updated"]
|
91
|
-
Time.parse(date)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
108
|
# @param resource_params [Hash]
|
96
109
|
# @return [Yao::Resources::*]
|
97
110
|
def update(resource_params)
|
@@ -2,6 +2,9 @@ module Yao::Resources
|
|
2
2
|
class ComputeServices < Base
|
3
3
|
friendly_attributes :status, :binary, :host, :zone, :state, :disabled_reason, :forced_down
|
4
4
|
|
5
|
+
map_attributes_to_time :updated_at
|
6
|
+
alias :updated :updated_at
|
7
|
+
|
5
8
|
self.service = "compute"
|
6
9
|
self.resource_name = "service"
|
7
10
|
self.resources_name = "os-services"
|
@@ -18,6 +21,11 @@ module Yao::Resources
|
|
18
21
|
status == 'disabled'
|
19
22
|
end
|
20
23
|
|
24
|
+
# @return []
|
25
|
+
def delete
|
26
|
+
self.class.delete(id)
|
27
|
+
end
|
28
|
+
|
21
29
|
class << self
|
22
30
|
# @param host [String]
|
23
31
|
# @param binary [String]
|
@@ -10,6 +10,10 @@ module Yao::Resources
|
|
10
10
|
:floating_ip_address,
|
11
11
|
:status, :port_details, :tags, :port_forwardings
|
12
12
|
|
13
|
+
map_attributes_to_time :created_at, :updated_at
|
14
|
+
alias :created :created_at
|
15
|
+
alias :updated :updated_at
|
16
|
+
|
13
17
|
self.service = "network"
|
14
18
|
self.resource_name = "floatingip"
|
15
19
|
self.resources_name = "floatingips"
|
@@ -6,6 +6,10 @@ module Yao::Resources
|
|
6
6
|
map_attribute_to_resources listeners: LoadBalancerListener
|
7
7
|
map_attribute_to_resources pools: LoadBalancerPool
|
8
8
|
|
9
|
+
map_attributes_to_time :created_at, :updated_at
|
10
|
+
alias :created :created_at
|
11
|
+
alias :updated :updated_at
|
12
|
+
|
9
13
|
# @return [Yao::Resources::Tenant]
|
10
14
|
def project
|
11
15
|
if project_id = self["project_id"]
|
@@ -7,6 +7,10 @@ module Yao::Resources
|
|
7
7
|
|
8
8
|
map_attribute_to_resources pools: LoadBalancerListener
|
9
9
|
|
10
|
+
map_attributes_to_time :created_at, :updated_at
|
11
|
+
alias :created :created_at
|
12
|
+
alias :updated :updated_at
|
13
|
+
|
10
14
|
# @return [Date]
|
11
15
|
def created_at
|
12
16
|
Date.parse(self["created_at"])
|
@@ -8,6 +8,10 @@ module Yao::Resources
|
|
8
8
|
|
9
9
|
map_attribute_to_resources loadbalancers: LoadBalancer
|
10
10
|
|
11
|
+
map_attributes_to_time :created_at, :updated_at
|
12
|
+
alias :created :created_at
|
13
|
+
alias :updated :updated_at
|
14
|
+
|
11
15
|
# @return [Yao::Resources::Tenant]
|
12
16
|
def project
|
13
17
|
if project_id = self["project_id"]
|
@@ -7,6 +7,10 @@ module Yao::Resources
|
|
7
7
|
map_attribute_to_resources loadbalancers: LoadBalancer
|
8
8
|
map_attribute_to_resources listeners: LoadBalancerListener
|
9
9
|
|
10
|
+
map_attributes_to_time :created_at, :updated_at
|
11
|
+
alias :created :created_at
|
12
|
+
alias :updated :updated_at
|
13
|
+
|
10
14
|
# @return [Yao::Resources::LoadBalancerListener]
|
11
15
|
def listeners
|
12
16
|
@listeners ||= self["listeners"].map do |listener|
|
@@ -5,6 +5,10 @@ module Yao::Resources
|
|
5
5
|
:monitor_address, :address,
|
6
6
|
:protocol_port, :operating_status
|
7
7
|
|
8
|
+
map_attributes_to_time :created_at, :updated_at
|
9
|
+
alias :created :created_at
|
10
|
+
alias :updated :updated_at
|
11
|
+
|
8
12
|
# @return [Yao::Resources::Tenant]
|
9
13
|
def project
|
10
14
|
if project_id = self["project_id"]
|
@@ -2,7 +2,7 @@ module Yao::Resources
|
|
2
2
|
class Network < Base
|
3
3
|
include ProjectAssociationable
|
4
4
|
|
5
|
-
friendly_attributes :name, :status, :shared, :
|
5
|
+
friendly_attributes :name, :status, :shared, :admin_state_up
|
6
6
|
map_attribute_to_attribute "provider:physical_network" => :physical_network
|
7
7
|
map_attribute_to_attribute "provider:network_type" => :type
|
8
8
|
map_attribute_to_attribute "provider:segmentation_id" => :segmentation_id
|
@@ -17,5 +17,10 @@ module Yao::Resources
|
|
17
17
|
def ports
|
18
18
|
@ports ||= Yao::Port.list(network_id: id)
|
19
19
|
end
|
20
|
+
|
21
|
+
# @return [Array<Yao::Resources::Subnet>]
|
22
|
+
def subnets
|
23
|
+
@subnets ||= self['subnets'].map {|id| Yao::Subnet.new("id" => id)}
|
24
|
+
end
|
20
25
|
end
|
21
26
|
end
|
@@ -106,9 +106,8 @@ module Yao::Resources
|
|
106
106
|
r = GET(url, query).body
|
107
107
|
if r.is_a?(Hash)
|
108
108
|
res.deep_merge!(r)
|
109
|
-
|
110
|
-
|
111
|
-
uri = URI.parse(next_link["href"])
|
109
|
+
if next_link = find_next_link(r)
|
110
|
+
uri = URI.parse(next_link)
|
112
111
|
query = Hash[URI::decode_www_form(uri.query)] if uri.query
|
113
112
|
next
|
114
113
|
end
|
@@ -127,6 +126,16 @@ module Yao::Resources
|
|
127
126
|
# @note .list is defined to keep backward compatibility and will be deprecated
|
128
127
|
alias :list_detail :list
|
129
128
|
|
129
|
+
# @param response [Hash]
|
130
|
+
# @return [String]
|
131
|
+
def find_next_link(response)
|
132
|
+
if links = response.find {|k, v| k =~ /links/ && v.is_a?(Array) }&.last
|
133
|
+
links.find{|s| s["rel"] == "next" }&.fetch("href")
|
134
|
+
else
|
135
|
+
response["next"]
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
130
139
|
# @param id_or_name_or_permalink [Stirng]
|
131
140
|
# @param query [Hash]
|
132
141
|
# @return [Yao::Resources::*]
|
data/lib/yao/resources/server.rb
CHANGED
@@ -20,6 +20,10 @@ module Yao::Resources
|
|
20
20
|
map_attribute_to_attribute 'OS-EXT-STS:task_state' => :ext_sts_task_state
|
21
21
|
map_attribute_to_attribute 'OS-EXT-STS:vm_state' => :ext_sts_vm_state
|
22
22
|
|
23
|
+
map_attributes_to_time :created, :updated
|
24
|
+
alias :created_at :created
|
25
|
+
alias :updated_at :updated
|
26
|
+
|
23
27
|
self.service = "compute"
|
24
28
|
self.resource_name = "server"
|
25
29
|
self.resources_name = "servers"
|
@@ -43,6 +47,52 @@ module Yao::Resources
|
|
43
47
|
action(id, "os-start" => nil)
|
44
48
|
end
|
45
49
|
|
50
|
+
# @return [Hash]
|
51
|
+
def start
|
52
|
+
self.class.start(id)
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [Hash]
|
56
|
+
def shutoff
|
57
|
+
self.class.shutoff(id)
|
58
|
+
end
|
59
|
+
alias :stop :shutoff
|
60
|
+
|
61
|
+
# @return [Hash]
|
62
|
+
def reboot
|
63
|
+
self.class.reboot(id)
|
64
|
+
end
|
65
|
+
|
66
|
+
# @return [Hash]
|
67
|
+
def resize(flavor_id)
|
68
|
+
self.class.resize(id, flavor_id)
|
69
|
+
end
|
70
|
+
|
71
|
+
# @param id [String]
|
72
|
+
# @param host [String]
|
73
|
+
# @param block_migration [Boolean]
|
74
|
+
# @param disk_over_commit [Boolean]
|
75
|
+
# @param opts [Hash]
|
76
|
+
# @return [Hash]
|
77
|
+
def live_migrate(host = nil, block_migration = false, disk_over_commit = false, opts = {})
|
78
|
+
self.class.live_migrate(id, host, block_migration, disk_over_commit, opts)
|
79
|
+
end
|
80
|
+
|
81
|
+
# @return [Hash]
|
82
|
+
def add_security_group(sg_name)
|
83
|
+
self.class.add_security_group(id, sg_name)
|
84
|
+
end
|
85
|
+
|
86
|
+
# @return [Hash]
|
87
|
+
def remove_security_group(sg_name)
|
88
|
+
self.class.remove_security_group(id, sg_name)
|
89
|
+
end
|
90
|
+
|
91
|
+
# @return [Hash]
|
92
|
+
def get_vnc_console
|
93
|
+
self.class.get_vnc_console(id)
|
94
|
+
end
|
95
|
+
|
46
96
|
# @param id [String]
|
47
97
|
# @return [Hash]
|
48
98
|
def self.shutoff(id)
|
@@ -62,6 +112,21 @@ module Yao::Resources
|
|
62
112
|
action(id,"resize" => { "flavorRef" => flavor_id })
|
63
113
|
end
|
64
114
|
|
115
|
+
# @param id [String]
|
116
|
+
# @param host [String]
|
117
|
+
# @param block_migration [Boolean]
|
118
|
+
# @param disk_over_commit [Boolean]
|
119
|
+
# @param opts [Hash]
|
120
|
+
# @return [Hash]
|
121
|
+
def self.live_migrate(id, host = nil, block_migration = false, disk_over_commit = false, opts ={})
|
122
|
+
query = {
|
123
|
+
"host" => host,
|
124
|
+
"block_migration" => block_migration,
|
125
|
+
"disk_over_commit" => disk_over_commit,
|
126
|
+
}.merge(opts)
|
127
|
+
action(id, "os-migrateLive" => query)
|
128
|
+
end
|
129
|
+
|
65
130
|
# @param id [String]
|
66
131
|
# @param sg_name [String]
|
67
132
|
# @return [Hash]
|
@@ -77,7 +142,7 @@ module Yao::Resources
|
|
77
142
|
end
|
78
143
|
|
79
144
|
# @param id [String]
|
80
|
-
# @return [
|
145
|
+
# @return [String]
|
81
146
|
def self.get_vnc_console(id)
|
82
147
|
response = action(id, {"os-getVNCConsole": {"type": "novnc"}})
|
83
148
|
response.dig("console", "url")
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Yao::Resources
|
2
|
+
class ServerMigrate < Base
|
3
|
+
friendly_attributes :dest_compute, :dest_host, :dest_node, :instance_uuid, :new_instance_type_id, :old_instance_type_id,
|
4
|
+
:source_compute, :source_node, :status, :migration_type, :uuid, :user_id, :project_id
|
5
|
+
map_attributes_to_time :created_at, :updated_at
|
6
|
+
|
7
|
+
self.service = "compute"
|
8
|
+
self.resource_name = "migrations"
|
9
|
+
self.resources_name = "os-migrations"
|
10
|
+
|
11
|
+
def server
|
12
|
+
@server ||= Yao::Server.get(self["instance_uuid"])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/yao/resources/volume.rb
CHANGED
@@ -10,6 +10,10 @@ module Yao::Resources
|
|
10
10
|
map_attribute_to_attribute 'os-vol-host-attr:host' => :host
|
11
11
|
map_attribute_to_attribute 'os-vol-tenant-attr:tenant_id' => :tenant_id
|
12
12
|
|
13
|
+
map_attributes_to_time :created_at, :updated_at
|
14
|
+
alias :created :created_at
|
15
|
+
alias :updated :updated_at
|
16
|
+
|
13
17
|
self.service = "volumev3"
|
14
18
|
self.resource_name = "volume"
|
15
19
|
self.resources_name = "volumes"
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Yao::Resources
|
2
|
+
class VolumeServices < Base
|
3
|
+
|
4
|
+
friendly_attributes :binary, :disabled_reason, :host, :state, :status,
|
5
|
+
:frozen, :zone, :cluster, :replication_status,
|
6
|
+
:active_backend_id, :backed_state
|
7
|
+
map_attributes_to_time :updated_at
|
8
|
+
|
9
|
+
self.service = "volumev3"
|
10
|
+
self.resource_name = "os-service"
|
11
|
+
self.resources_name = "os-services"
|
12
|
+
|
13
|
+
# return true if ComputeServices is enabled
|
14
|
+
# @return [Bool]
|
15
|
+
def enabled?
|
16
|
+
status == 'enabled'
|
17
|
+
end
|
18
|
+
|
19
|
+
# return true if ComputeServices is disabled
|
20
|
+
# @return [Bool]
|
21
|
+
def disabled?
|
22
|
+
status == 'disabled'
|
23
|
+
end
|
24
|
+
|
25
|
+
def enable
|
26
|
+
self.class.enable(host, binary)
|
27
|
+
end
|
28
|
+
|
29
|
+
def disable(reason = nil)
|
30
|
+
self.class.disable(host, binary, reason)
|
31
|
+
end
|
32
|
+
|
33
|
+
class << self
|
34
|
+
# @param host [String]
|
35
|
+
# @param binary [String]
|
36
|
+
# @return [Hash]
|
37
|
+
def enable(host, binary)
|
38
|
+
params = {
|
39
|
+
"host" => host,
|
40
|
+
"binary" => binary,
|
41
|
+
}
|
42
|
+
put("enable", params)
|
43
|
+
end
|
44
|
+
|
45
|
+
# @param host [String]
|
46
|
+
# @param binary [String]
|
47
|
+
# @param resason [String]
|
48
|
+
# @return [Hash]
|
49
|
+
def disable(host, binary, reason = nil)
|
50
|
+
params = {
|
51
|
+
"host" => host,
|
52
|
+
"binary" => binary,
|
53
|
+
}
|
54
|
+
if reason
|
55
|
+
params["disabled_reason"] = reason
|
56
|
+
put("disable-log-reason", params)
|
57
|
+
else
|
58
|
+
put("disable", params)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
# @param path [String]
|
65
|
+
# @param params [Hash]
|
66
|
+
# @return [Hash]
|
67
|
+
def put(path, params)
|
68
|
+
res = PUT(create_url(path), params) do |req|
|
69
|
+
req.body = params.to_json
|
70
|
+
req.headers['Content-Type'] = 'application/json'
|
71
|
+
end
|
72
|
+
res.body
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/yao/resources.rb
CHANGED
@@ -8,6 +8,7 @@ module Yao
|
|
8
8
|
|
9
9
|
autoload :Server, "yao/resources/server"
|
10
10
|
autoload :ServerGroup, "yao/resources/server_group"
|
11
|
+
autoload :ServerMigrate, "yao/resources/server_migrate"
|
11
12
|
autoload :Flavor, "yao/resources/flavor"
|
12
13
|
autoload :Image, "yao/resources/image"
|
13
14
|
autoload :SecurityGroup, "yao/resources/security_group"
|
@@ -33,6 +34,7 @@ module Yao
|
|
33
34
|
autoload :Role, "yao/resources/role"
|
34
35
|
autoload :RoleAssignment, "yao/resources/role_assignment"
|
35
36
|
autoload :Volume, "yao/resources/volume"
|
37
|
+
autoload :VolumeServices, "yao/resources/volume_services"
|
36
38
|
autoload :VolumeType, "yao/resources/volume_type"
|
37
39
|
autoload :ComputeServices, "yao/resources/compute_services"
|
38
40
|
autoload :Project, "yao/resources/project"
|
data/lib/yao/version.rb
CHANGED
@@ -40,6 +40,40 @@ module RestfullyAccessibleStub
|
|
40
40
|
)
|
41
41
|
end
|
42
42
|
|
43
|
+
def stub_post_request(url, body, response = {})
|
44
|
+
stub_request(:post,url)
|
45
|
+
.with(
|
46
|
+
headers: request_headers
|
47
|
+
).to_return(
|
48
|
+
status: 202,
|
49
|
+
headers: {'Content-Type' => 'application/json'},
|
50
|
+
body: response.to_json
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
def stub_put_request(url, body, response = {})
|
55
|
+
stub_request(:put,url)
|
56
|
+
.with(
|
57
|
+
headers: request_headers.merge({'Content-Type' => 'application/json'}),
|
58
|
+
body: body.to_json,
|
59
|
+
).to_return(
|
60
|
+
status: 200,
|
61
|
+
headers: {'Content-Type' => 'application/json'},
|
62
|
+
body: response.to_json
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
def stub_delete_request(url, response = {})
|
67
|
+
stub_request(:delete,url)
|
68
|
+
.with(
|
69
|
+
headers: request_headers
|
70
|
+
).to_return(
|
71
|
+
status: 200,
|
72
|
+
headers: {'Content-Type' => 'application/json'},
|
73
|
+
body: response.to_json
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
43
77
|
def request_headers
|
44
78
|
{'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Yao/#{Yao::VERSION} Faraday/#{Faraday::VERSION}"}
|
45
79
|
end
|
@@ -19,6 +19,6 @@ class TestAggregates < TestYaoResource
|
|
19
19
|
assert_equal("nova", aggregates.name)
|
20
20
|
assert_equal(Time.parse("2015-08-27T09:49:58-05:00"), aggregates.created)
|
21
21
|
assert_equal(Time.parse("2015-08-27T09:49:58-05:00"), aggregates.updated)
|
22
|
-
assert_equal(
|
22
|
+
assert_equal(Time.parse("2015-08-27T09:49:58-05:00"), aggregates.deleted_at)
|
23
23
|
end
|
24
24
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
class TestComputeServices < TestYaoResource
|
2
|
+
include RestfullyAccessibleStub
|
2
3
|
|
3
4
|
def test_compute_services
|
4
5
|
|
@@ -127,4 +128,11 @@ class TestComputeServices < TestYaoResource
|
|
127
128
|
|
128
129
|
assert_requested stub
|
129
130
|
end
|
131
|
+
|
132
|
+
def test_delete
|
133
|
+
stub = stub_delete_request("https://example.com:12345/os-services/test-id")
|
134
|
+
compute_service = Yao::ComputeServices.new({"id" => "test-id"})
|
135
|
+
assert_equal({}, compute_service.delete)
|
136
|
+
assert_requested(stub)
|
137
|
+
end
|
130
138
|
end
|
@@ -14,7 +14,7 @@ class TestNetwork < TestYaoResource
|
|
14
14
|
"router:external" => false,
|
15
15
|
"shared" => false,
|
16
16
|
"status" => "ACTIVE",
|
17
|
-
"subnets" => [],
|
17
|
+
"subnets" => ["52822b63-eb89-496d-9509-f91473b9d85d"],
|
18
18
|
"tenant_id" => "c05140b3dc7c4555afff9fab6b58edc2",
|
19
19
|
"project_id" => "c05140b3dc7c4555afff9fab6b58edc2",
|
20
20
|
}
|
@@ -28,13 +28,15 @@ class TestNetwork < TestYaoResource
|
|
28
28
|
assert_equal(false, network.shared)
|
29
29
|
assert_equal(false, network.shared?)
|
30
30
|
assert_equal("c05140b3dc7c4555afff9fab6b58edc2", network.tenant_id)
|
31
|
-
assert_equal([], network.subnets)
|
32
31
|
assert_equal(true, network.admin_state_up)
|
33
32
|
|
34
33
|
#map_attribute_to_attribute
|
35
34
|
assert_equal("physnet1", network.physical_network)
|
36
35
|
assert_equal("vlan", network.type)
|
37
36
|
assert_equal(1000, network.segmentation_id)
|
37
|
+
|
38
|
+
assert_equal(Yao::Subnet, network.subnets.first.class)
|
39
|
+
assert_equal("52822b63-eb89-496d-9509-f91473b9d85d", network.subnets.first.id)
|
38
40
|
end
|
39
41
|
|
40
42
|
def test_project
|
@@ -1,4 +1,5 @@
|
|
1
1
|
class TestNetworkingAgents < TestYaoResource
|
2
|
+
include RestfullyAccessibleStub
|
2
3
|
|
3
4
|
def test_networking_agents
|
4
5
|
|
@@ -81,4 +82,11 @@ class TestNetworkingAgents < TestYaoResource
|
|
81
82
|
assert_equal(Time.parse("2017-09-12 19:35:38"), agent.created_at)
|
82
83
|
assert_equal(Time.parse("2017-09-12 19:35:38"), agent.started_at)
|
83
84
|
end
|
85
|
+
|
86
|
+
def test_delete
|
87
|
+
stub = stub_delete_request("https://example.com:12345/agents/test-id")
|
88
|
+
agents = Yao::NetworkingAgents.new({"id" => "test-id"})
|
89
|
+
assert_equal({}, agents.delete)
|
90
|
+
assert_requested(stub)
|
91
|
+
end
|
84
92
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
class TestServer < TestYaoResource
|
2
|
+
include RestfullyAccessibleStub
|
2
3
|
|
3
4
|
def test_server
|
4
5
|
|
@@ -273,4 +274,98 @@ class TestServer < TestYaoResource
|
|
273
274
|
assert_equal(0, ports.size)
|
274
275
|
assert_requested(stub)
|
275
276
|
end
|
277
|
+
|
278
|
+
def test_start
|
279
|
+
server_id = '2ce4c5b3-2866-4972-93ce-77a2ea46a7f9'
|
280
|
+
stub = stub_post_request(
|
281
|
+
"https://example.com:12345/servers/#{server_id}/action",
|
282
|
+
[{"os-start": nil}]
|
283
|
+
)
|
284
|
+
|
285
|
+
Yao::Server.new('id' => server_id).start
|
286
|
+
assert_requested(stub)
|
287
|
+
end
|
288
|
+
|
289
|
+
def test_shutoff
|
290
|
+
server_id = '2ce4c5b3-2866-4972-93ce-77a2ea46a7f9'
|
291
|
+
stub = stub_post_request(
|
292
|
+
"https://example.com:12345/servers/#{server_id}/action",
|
293
|
+
[{"os-stop": nil}]
|
294
|
+
)
|
295
|
+
|
296
|
+
Yao::Server.new('id' => server_id).stop
|
297
|
+
assert_requested(stub)
|
298
|
+
assert_equal(Yao::Server.method(:stop), Yao::Server.method(:shutoff))
|
299
|
+
end
|
300
|
+
|
301
|
+
def test_reboot
|
302
|
+
server_id = '2ce4c5b3-2866-4972-93ce-77a2ea46a7f9'
|
303
|
+
stub = stub_post_request(
|
304
|
+
"https://example.com:12345/servers/#{server_id}/action",
|
305
|
+
[{"reboot": { "type" => "HARD" }}]
|
306
|
+
)
|
307
|
+
|
308
|
+
Yao::Server.new('id' => server_id).reboot
|
309
|
+
assert_requested(stub)
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_resize
|
313
|
+
server_id = '2ce4c5b3-2866-4972-93ce-77a2ea46a7f9'
|
314
|
+
stub = stub_post_request(
|
315
|
+
"https://example.com:12345/servers/#{server_id}/action",
|
316
|
+
[{"resize": { "flavorRef": "test-flavor" }}]
|
317
|
+
)
|
318
|
+
|
319
|
+
Yao::Server.new('id' => server_id).resize("test-flavor")
|
320
|
+
assert_requested(stub)
|
321
|
+
end
|
322
|
+
|
323
|
+
def test_live_migrate
|
324
|
+
server_id = '2ce4c5b3-2866-4972-93ce-77a2ea46a7f9'
|
325
|
+
stub = stub_post_request(
|
326
|
+
"https://example.com:12345/servers/#{server_id}/action",
|
327
|
+
[{"os-migrateLive": {
|
328
|
+
"host": "test-node-1",
|
329
|
+
"block_migration": false,
|
330
|
+
"disk_over_commit": false
|
331
|
+
}}]
|
332
|
+
)
|
333
|
+
|
334
|
+
Yao::Server.new('id' => server_id).live_migrate("test-node-1", false, false)
|
335
|
+
assert_requested(stub)
|
336
|
+
end
|
337
|
+
|
338
|
+
def test_add_security_group
|
339
|
+
server_id = '2ce4c5b3-2866-4972-93ce-77a2ea46a7f9'
|
340
|
+
stub = stub_post_request(
|
341
|
+
"https://example.com:12345/servers/#{server_id}/action",
|
342
|
+
[{"addSecurityGroup": { "name": "test-sg" }}]
|
343
|
+
)
|
344
|
+
|
345
|
+
Yao::Server.new('id' => server_id).add_security_group("test-sg")
|
346
|
+
assert_requested(stub)
|
347
|
+
end
|
348
|
+
|
349
|
+
def test_remove_security_group
|
350
|
+
server_id = '2ce4c5b3-2866-4972-93ce-77a2ea46a7f9'
|
351
|
+
stub = stub_post_request(
|
352
|
+
"https://example.com:12345/servers/#{server_id}/action",
|
353
|
+
[{"removeSecurityGroup": { "name": "test-sg" }}]
|
354
|
+
)
|
355
|
+
|
356
|
+
Yao::Server.new('id' => server_id).remove_security_group("test-sg")
|
357
|
+
assert_requested(stub)
|
358
|
+
end
|
359
|
+
|
360
|
+
def test_get_vnc_concolse
|
361
|
+
server_id = '2ce4c5b3-2866-4972-93ce-77a2ea46a7f9'
|
362
|
+
stub = stub_post_request(
|
363
|
+
"https://example.com:12345/servers/#{server_id}/action",
|
364
|
+
[{"os-getVNCConsole": { "type": "novnc" }}],
|
365
|
+
{"console": { "url": "https://example.com/vnc" }}
|
366
|
+
)
|
367
|
+
|
368
|
+
Yao::Server.new('id' => server_id).get_vnc_console
|
369
|
+
assert_requested(stub)
|
370
|
+
end
|
276
371
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class TestServerGroup < TestYaoResource
|
2
|
+
def test_server_group
|
3
|
+
# https://docs.openstack.org/api-ref/compute/?expanded=list-migrations-detail#list-migrations
|
4
|
+
params = {
|
5
|
+
"created_at" => "2012-10-29T13:42:02.000000",
|
6
|
+
"dest_compute" => "compute2",
|
7
|
+
"dest_host" => "1.2.3.4",
|
8
|
+
"dest_node" => "node2",
|
9
|
+
"id" => 1234,
|
10
|
+
"instance_uuid" => "8600d31b-d1a1-4632-b2ff-45c2be1a70ff",
|
11
|
+
"new_instance_type_id" => 2,
|
12
|
+
"old_instance_type_id" => 1,
|
13
|
+
"source_compute" => "compute1",
|
14
|
+
"source_node" => "node1",
|
15
|
+
"status" => "done",
|
16
|
+
"updated_at" => "2012-10-29T13:42:02.000000"
|
17
|
+
}
|
18
|
+
|
19
|
+
migrate = Yao::ServerMigrate.new(params)
|
20
|
+
assert_equal(Time.parse("2012-10-29T13:42:02.000000"), migrate.created_at)
|
21
|
+
assert_equal("compute2", migrate.dest_compute)
|
22
|
+
assert_equal("1.2.3.4", migrate.dest_host)
|
23
|
+
assert_equal("node2", migrate.dest_node)
|
24
|
+
assert_equal(1234, migrate.id)
|
25
|
+
assert_equal("8600d31b-d1a1-4632-b2ff-45c2be1a70ff", migrate.instance_uuid)
|
26
|
+
assert_equal(2, migrate.new_instance_type_id)
|
27
|
+
assert_equal(1, migrate.old_instance_type_id)
|
28
|
+
assert_equal("compute1", migrate.source_compute)
|
29
|
+
assert_equal("node1", migrate.source_node)
|
30
|
+
assert_equal("done", migrate.status)
|
31
|
+
assert_equal(Time.parse("2012-10-29T13:42:02.000000"), migrate.updated_at)
|
32
|
+
end
|
33
|
+
end
|
@@ -13,7 +13,9 @@ class TestVolume < TestYaoResource
|
|
13
13
|
'snapshot_id' => nil,
|
14
14
|
'status' => 'available',
|
15
15
|
'user_id' => 'aaaa166533fd49f3b11b1cdce2430000',
|
16
|
-
'volume_type' => 'test'
|
16
|
+
'volume_type' => 'test',
|
17
|
+
'created_at' => '2018-11-28T06:25:15.288987',
|
18
|
+
'updated_at' => '2019-11-28T06:25:15.288987'
|
17
19
|
}
|
18
20
|
|
19
21
|
volume = Yao::Volume.new(params)
|
@@ -30,6 +32,10 @@ class TestVolume < TestYaoResource
|
|
30
32
|
assert_equal(volume.user_id, 'aaaa166533fd49f3b11b1cdce2430000')
|
31
33
|
assert_equal(volume.volume_type, 'test')
|
32
34
|
assert_equal(volume.type, 'test')
|
35
|
+
assert_equal(Time.parse('2018-11-28T06:25:15.288987'), volume.created_at)
|
36
|
+
assert_equal(Time.parse('2018-11-28T06:25:15.288987'), volume.created)
|
37
|
+
assert_equal(Time.parse('2019-11-28T06:25:15.288987'), volume.updated_at)
|
38
|
+
assert_equal(Time.parse('2019-11-28T06:25:15.288987'), volume.updated)
|
33
39
|
end
|
34
40
|
|
35
41
|
def test_list
|
@@ -0,0 +1,116 @@
|
|
1
|
+
class TestVolumeServices < TestYaoResource
|
2
|
+
include RestfullyAccessibleStub
|
3
|
+
|
4
|
+
def test_volume_services
|
5
|
+
# https://docs.openstack.org/api-ref/block-storage/v3/index.html?expanded=list-all-cinder-services-detail#list-all-cinder-services
|
6
|
+
params = JSON.parse(<<~JSON)
|
7
|
+
{
|
8
|
+
"status": "enabled",
|
9
|
+
"binary": "cinder-scheduler",
|
10
|
+
"zone": "nova",
|
11
|
+
"state": "up",
|
12
|
+
"updated_at": "2017-06-29T05:50:35.000000",
|
13
|
+
"host": "devstack",
|
14
|
+
"disabled_reason": null
|
15
|
+
}
|
16
|
+
JSON
|
17
|
+
|
18
|
+
service = Yao::VolumeServices.new(params)
|
19
|
+
assert_equal('enabled', service.status)
|
20
|
+
assert_equal('cinder-scheduler', service.binary)
|
21
|
+
assert_equal('nova', service.zone)
|
22
|
+
assert_equal('up', service.state)
|
23
|
+
assert_equal(Time.parse('2017-06-29T05:50:35.000000'), service.updated_at)
|
24
|
+
assert_equal('devstack', service.host)
|
25
|
+
assert_equal(nil, service.disabled_reason)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_enabled
|
29
|
+
service = Yao::VolumeServices.new({'status' => 'enabled'})
|
30
|
+
assert_equal(true, service.enabled?)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_disabled
|
34
|
+
service = Yao::VolumeServices.new({'status' => 'enabled'})
|
35
|
+
assert_equal(false, service.disabled?)
|
36
|
+
end
|
37
|
+
|
38
|
+
def stub_enable_request
|
39
|
+
body = {
|
40
|
+
"host" => "test-host",
|
41
|
+
"binary" => "test-binary",
|
42
|
+
}
|
43
|
+
response = { "disabled" => false }
|
44
|
+
stub_put_request('https://example.com:12345/os-services/enable', body, response)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_enable
|
48
|
+
stub = stub_enable_request
|
49
|
+
service = Yao::VolumeServices.new({
|
50
|
+
"host" => "test-host",
|
51
|
+
"binary" => "test-binary",
|
52
|
+
})
|
53
|
+
response = service.enable
|
54
|
+
assert_equal(false, response['disabled'])
|
55
|
+
assert_requested(stub)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_self_enable
|
59
|
+
stub = stub_enable_request
|
60
|
+
response = Yao::VolumeServices.enable('test-host', 'test-binary')
|
61
|
+
assert_equal(false, response['disabled'])
|
62
|
+
assert_requested(stub)
|
63
|
+
end
|
64
|
+
|
65
|
+
def stub_disable_request(reason = nil)
|
66
|
+
body = {
|
67
|
+
"host" => "test-host",
|
68
|
+
"binary" => "test-binary",
|
69
|
+
}
|
70
|
+
response = { "disabled" => true }
|
71
|
+
if reason
|
72
|
+
body["disabled_reason"] = reason
|
73
|
+
response["disabled_reason"] = reason
|
74
|
+
stub_put_request('https://example.com:12345/os-services/disable-log-reason', body, response)
|
75
|
+
else
|
76
|
+
stub_put_request('https://example.com:12345/os-services/disable', body, response)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_disable
|
81
|
+
stub = stub_disable_request
|
82
|
+
service = Yao::VolumeServices.new({
|
83
|
+
"host" => "test-host",
|
84
|
+
"binary" => "test-binary",
|
85
|
+
})
|
86
|
+
response = service.disable
|
87
|
+
assert_equal(true, response['disabled'])
|
88
|
+
assert_requested(stub)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_disable_reason
|
92
|
+
stub = stub_disable_request('test-reason')
|
93
|
+
service = Yao::VolumeServices.new({
|
94
|
+
"host" => "test-host",
|
95
|
+
"binary" => "test-binary",
|
96
|
+
})
|
97
|
+
response = service.disable('test-reason')
|
98
|
+
assert_equal(true, response['disabled'])
|
99
|
+
assert_equal('test-reason', response['disabled_reason'])
|
100
|
+
assert_requested(stub)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_self_disable
|
104
|
+
stub = stub_disable_request
|
105
|
+
response = Yao::VolumeServices.disable('test-host', 'test-binary')
|
106
|
+
assert_equal(true, response['disabled'])
|
107
|
+
assert_requested(stub)
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_self_disable_reason
|
111
|
+
stub = stub_disable_request('test-reason')
|
112
|
+
response = Yao::VolumeServices.disable('test-host', 'test-binary', 'test-reason')
|
113
|
+
assert_equal(true, response['disabled'])
|
114
|
+
assert_requested(stub)
|
115
|
+
end
|
116
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yao
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uchio, KONDO
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -133,12 +133,14 @@ files:
|
|
133
133
|
- lib/yao/resources/security_group_rule.rb
|
134
134
|
- lib/yao/resources/server.rb
|
135
135
|
- lib/yao/resources/server_group.rb
|
136
|
+
- lib/yao/resources/server_migrate.rb
|
136
137
|
- lib/yao/resources/server_usage_associationable.rb
|
137
138
|
- lib/yao/resources/subnet.rb
|
138
139
|
- lib/yao/resources/tenant.rb
|
139
140
|
- lib/yao/resources/user.rb
|
140
141
|
- lib/yao/resources/volume.rb
|
141
142
|
- lib/yao/resources/volume_action.rb
|
143
|
+
- lib/yao/resources/volume_services.rb
|
142
144
|
- lib/yao/resources/volume_type.rb
|
143
145
|
- lib/yao/setup.rb
|
144
146
|
- lib/yao/token.rb
|
@@ -182,9 +184,11 @@ files:
|
|
182
184
|
- test/yao/resources/test_security_group_rule.rb
|
183
185
|
- test/yao/resources/test_server.rb
|
184
186
|
- test/yao/resources/test_server_group.rb
|
187
|
+
- test/yao/resources/test_server_migrate.rb
|
185
188
|
- test/yao/resources/test_subnet.rb
|
186
189
|
- test/yao/resources/test_user.rb
|
187
190
|
- test/yao/resources/test_volume.rb
|
191
|
+
- test/yao/resources/test_volume_services.rb
|
188
192
|
- test/yao/resources/test_volume_type.rb
|
189
193
|
- test/yao/test_auth.rb
|
190
194
|
- test/yao/test_authv3.rb
|
@@ -216,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
216
220
|
- !ruby/object:Gem::Version
|
217
221
|
version: '0'
|
218
222
|
requirements: []
|
219
|
-
rubygems_version: 3.
|
223
|
+
rubygems_version: 3.4.6
|
220
224
|
signing_key:
|
221
225
|
specification_version: 4
|
222
226
|
summary: Yet Another OpenStack API Wrapper that rocks!!
|
@@ -259,9 +263,11 @@ test_files:
|
|
259
263
|
- test/yao/resources/test_security_group_rule.rb
|
260
264
|
- test/yao/resources/test_server.rb
|
261
265
|
- test/yao/resources/test_server_group.rb
|
266
|
+
- test/yao/resources/test_server_migrate.rb
|
262
267
|
- test/yao/resources/test_subnet.rb
|
263
268
|
- test/yao/resources/test_user.rb
|
264
269
|
- test/yao/resources/test_volume.rb
|
270
|
+
- test/yao/resources/test_volume_services.rb
|
265
271
|
- test/yao/resources/test_volume_type.rb
|
266
272
|
- test/yao/test_auth.rb
|
267
273
|
- test/yao/test_authv3.rb
|