yao 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2ea8c98f6fdefadcfeca2782ed5dde20a91423afc3cc44b925a64fdee3b552a
4
- data.tar.gz: a0993ca6bd8ddb9a222d632e98c77031682b492756be20c164632410da64bed4
3
+ metadata.gz: 30ea2f00c9ac02892a86b95ffd29c6dac6323d430fcc9656e053f7ceb0c55987
4
+ data.tar.gz: 174922729484e225f2d362f15a19fe5fad949c2e91ab7f301a858cd21eaf4073
5
5
  SHA512:
6
- metadata.gz: aa2d0252174bc0e69a7697d6fb8e90aba053105fa416219bb5c7b0800a861fcffee6d1e48d0fdc3d84a38f20cb4790d8030dbafbae65f1548c221ae79dbd7e52
7
- data.tar.gz: ccef8bca36eda0c7191017929f466a9b424ca8ac697e2e0f104519394ccdc022bd7159391ad1cfebbf9590635ca4b74c5a5705823b2fc54a27027877e252bcb5
6
+ metadata.gz: 97ef036c9655f766fa79475aaaa634067adc4f8f78c1521e5958de2a77f1360cfc504026e5b7321268f392062ea2b7f42c7ef84235696807945f5b766101a46b
7
+ data.tar.gz: 3e83cbce18a6e9a59d7fa23641e6309274a1f085082cfb9819c91a445dd45fb86333be02ba302685fed5428bd346d1bde1a1a3d7dc0d55094b703b8ec59ae6ef
@@ -5,7 +5,7 @@ module Yao::Resources
5
5
  req.body = query.to_json
6
6
  req.headers['Content-Type'] = 'application/json'
7
7
  end
8
- res.body ? resource_from_json(res.body) : nil
8
+ res.body
9
9
  end
10
10
 
11
11
  private
@@ -25,5 +25,16 @@ module Yao::Resources
25
25
  self.resources_name = "images"
26
26
 
27
27
  extend MetadataAvailable
28
+
29
+ class << self
30
+ private
31
+
32
+ # override Yao::Resources::RestfullyAccessible.resource_from_json
33
+ # @param json [Hash]
34
+ # @return [Yao::Resources::*]
35
+ def resource_from_json(json)
36
+ new(json)
37
+ end
38
+ end
28
39
  end
29
40
  end
@@ -53,6 +53,11 @@ module Yao::Resources
53
53
  action(id, {"removeSecurityGroup": {"name": sg_name}})
54
54
  end
55
55
 
56
+ def self.get_vnc_console(id)
57
+ response = action(id, {"os-getVNCConsole": {"type": "novnc"}})
58
+ response.dig("console", "url")
59
+ end
60
+
56
61
  class << self
57
62
  alias :stop :shutoff
58
63
  end
@@ -1,3 +1,3 @@
1
1
  module Yao
2
- VERSION = "0.12.0"
2
+ VERSION = "0.13.0"
3
3
  end
@@ -1,44 +1,56 @@
1
1
  class TestImage < TestYaoResource
2
+ # https://docs.openstack.org/api-ref/compute/?expanded=list-flavors-detail,list-flavors-with-details-detail,list-hosts-detail,show-host-details-detail,list-images-detail,list-images-with-details-detail#list-images-with-details
3
+ @@params = {
4
+ "OS-DCF:diskConfig" => "AUTO",
5
+ "OS-EXT-IMG-SIZE:size" => 74185822,
6
+ "created" => "2011-01-01T01:02:03Z",
7
+ "id" => "70a599e0-31e7-49b7-b260-868f441e862b",
8
+ "links" => [
9
+ {
10
+ "href" => "http://openstack.example.com/v2/6f70656e737461636b20342065766572/images/70a599e0-31e7-49b7-b260-868f441e862b",
11
+ "rel" => "self"
12
+ },
13
+ {
14
+ "href" => "http://openstack.example.com/6f70656e737461636b20342065766572/images/70a599e0-31e7-49b7-b260-868f441e862b",
15
+ "rel" => "bookmark"
16
+ },
17
+ {
18
+ "href" => "http://glance.openstack.example.com/images/70a599e0-31e7-49b7-b260-868f441e862b",
19
+ "rel" => "alternate",
20
+ "type" => "application/vnd.openstack.image"
21
+ }
22
+ ],
23
+ "metadata" => {
24
+ "architecture" => "x86_64",
25
+ "auto_disk_config" => "True",
26
+ "kernel_id" => "nokernel",
27
+ "ramdisk_id" => "nokernel"
28
+ },
29
+ "minDisk" => 0,
30
+ "minRam" => 0,
31
+ "name" => "fakeimage7",
32
+ "progress" => 100,
33
+ "status" => "ACTIVE",
34
+ "updated" => "2011-01-01T01:02:03Z"
35
+ }
2
36
 
3
37
  def test_image
4
38
 
5
- # https://docs.openstack.org/api-ref/compute/?expanded=list-flavors-detail,list-flavors-with-details-detail,list-hosts-detail,show-host-details-detail,list-images-detail,list-images-with-details-detail#list-images-with-details
6
- params = {
7
- "OS-DCF:diskConfig" => "AUTO",
8
- "OS-EXT-IMG-SIZE:size" => 74185822,
9
- "created" => "2011-01-01T01:02:03Z",
10
- "id" => "70a599e0-31e7-49b7-b260-868f441e862b",
11
- "links" => [
12
- {
13
- "href" => "http://openstack.example.com/v2/6f70656e737461636b20342065766572/images/70a599e0-31e7-49b7-b260-868f441e862b",
14
- "rel" => "self"
15
- },
16
- {
17
- "href" => "http://openstack.example.com/6f70656e737461636b20342065766572/images/70a599e0-31e7-49b7-b260-868f441e862b",
18
- "rel" => "bookmark"
19
- },
20
- {
21
- "href" => "http://glance.openstack.example.com/images/70a599e0-31e7-49b7-b260-868f441e862b",
22
- "rel" => "alternate",
23
- "type" => "application/vnd.openstack.image"
24
- }
25
- ],
26
- "metadata" => {
27
- "architecture" => "x86_64",
28
- "auto_disk_config" => "True",
29
- "kernel_id" => "nokernel",
30
- "ramdisk_id" => "nokernel"
31
- },
32
- "minDisk" => 0,
33
- "minRam" => 0,
34
- "name" => "fakeimage7",
35
- "progress" => 100,
36
- "status" => "ACTIVE",
37
- "updated" => "2011-01-01T01:02:03Z"
38
- }
39
+ image = Yao::Resources::Image.new(@@params)
40
+ check_image(image)
39
41
 
40
- image = Yao::Image.new(params)
42
+ end
41
43
 
44
+ def test_resource_from_json
45
+
46
+ image = Yao::Resources::Image.send(:resource_from_json, @@params)
47
+ check_image(image)
48
+
49
+ end
50
+
51
+ private
52
+
53
+ def check_image(image)
42
54
  # friendly_attributes
43
55
  assert_equal("fakeimage7", image.name)
44
56
  assert_equal("ACTIVE", image.status)
@@ -60,4 +72,5 @@ class TestImage < TestYaoResource
60
72
  assert_equal(70.74911308288574, image.size('M')) #
61
73
  assert_equal(0.06909093074500561, image.size('G')) #
62
74
  end
75
+
63
76
  end
@@ -8,27 +8,30 @@ class TestClient < Test::Unit::TestCase
8
8
  cli = Yao::Client.gen_client("http://cool-api.example.com:12345/v3.0")
9
9
  assert { cli.url_prefix.to_s == "http://cool-api.example.com:12345/v3.0" }
10
10
 
11
+ adapter = Faraday::Adapter::NetHttp
12
+ assert { cli.builder.adapter == adapter }
13
+
11
14
  handlers = [
12
15
  Faraday::Request::Accept,
13
16
  Faraday::Request::UrlEncoded,
14
17
  Faraday::Request::ReadOnly,
15
18
  Faraday::Response::OSErrorDetector,
16
- FaradayMiddleware::ParseJson,
17
- Faraday::Adapter::NetHttp
19
+ FaradayMiddleware::ParseJson
18
20
  ]
19
21
  assert { cli.builder.handlers == handlers }
20
22
  end
21
23
 
22
24
  def test_gen_with_token
23
25
  cli = Yao::Client.gen_client("http://cool-api.example.com:12345/v3.0", token: "deadbeaf")
26
+ adapter = Faraday::Adapter::NetHttp
27
+ assert { cli.builder.adapter == adapter }
24
28
  handlers = [
25
29
  Faraday::Request::Accept,
26
30
  Faraday::Request::UrlEncoded,
27
31
  Faraday::Request::OSToken,
28
32
  Faraday::Request::ReadOnly,
29
33
  Faraday::Response::OSErrorDetector,
30
- FaradayMiddleware::ParseJson,
31
- Faraday::Adapter::NetHttp
34
+ FaradayMiddleware::ParseJson
32
35
  ]
33
36
  assert { cli.builder.handlers == handlers }
34
37
  end
@@ -37,6 +40,8 @@ class TestClient < Test::Unit::TestCase
37
40
  stub(Yao.config).debug { true }
38
41
 
39
42
  cli = Yao::Client.gen_client("http://cool-api.example.com:12345/v3.0")
43
+ adapter = Faraday::Adapter::NetHttp
44
+ assert { cli.builder.adapter == adapter }
40
45
  handlers = [
41
46
  Faraday::Request::Accept,
42
47
  Faraday::Request::UrlEncoded,
@@ -44,8 +49,7 @@ class TestClient < Test::Unit::TestCase
44
49
  Faraday::Response::OSErrorDetector,
45
50
  FaradayMiddleware::ParseJson,
46
51
  Faraday::Response::Logger,
47
- Faraday::Response::OSDumper,
48
- Faraday::Adapter::NetHttp
52
+ Faraday::Response::OSDumper
49
53
  ]
50
54
  assert { cli.builder.handlers == handlers }
51
55
  end
@@ -1,8 +1,8 @@
1
1
  class TestServerError < Test::Unit::TestCase
2
2
  def test_detects_error_with_env
3
3
  env = Faraday::Env.new
4
- env.body = {"itemNotFound"=>{"message"=>"Image not found.", "code"=>404}}
5
4
  env.status = 404
5
+ env.body = {"itemNotFound"=>{"message"=>"Image not found.", "code"=>404}}
6
6
 
7
7
  error = Yao::ServerError.detect(env)
8
8
  assert { error.is_a? Yao::ItemNotFound }
@@ -13,8 +13,8 @@ class TestServerError < Test::Unit::TestCase
13
13
 
14
14
  def test_anyway_returns_error
15
15
  env = Faraday::Env.new
16
- env.body = "<html>Not found.</html>"
17
16
  env.status = 599
17
+ env.body = "<html>Not found.</html>"
18
18
 
19
19
  error = Yao::ServerError.detect(env)
20
20
  assert { error.is_a? Yao::ServerError }
@@ -18,6 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_dependency "json"
21
- spec.add_dependency "faraday"
21
+ spec.add_dependency "faraday", "~> 1.0.1"
22
22
  spec.add_dependency "faraday_middleware"
23
23
  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.12.0
4
+ version: 0.13.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: 2020-02-28 00:00:00.000000000 Z
11
+ date: 2020-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: faraday
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 1.0.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 1.0.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: faraday_middleware
43
43
  requirement: !ruby/object:Gem::Requirement