conoha 0.9.7 → 0.9.8

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
  SHA1:
3
- metadata.gz: 06a8df63a110b42396a551befb8348eac2d3e3e3
4
- data.tar.gz: fbbf1c900781ac7d25da9f12f0fcecd3c77f61b0
3
+ metadata.gz: bb6f56840fc4fb7f5c8bb07246ece0d140535a1c
4
+ data.tar.gz: d8f1388a6e1123a4832f5a12197c36963b712be5
5
5
  SHA512:
6
- metadata.gz: 50e4d0516082bd978370a6876c348dd672498ced9e66ac5d828fddabad320121753546b8777c74a2cd2e08f824a273c474579e2e58ff17ed79892568df41cefc
7
- data.tar.gz: 408c1eafa34e81b63ade6f71596763a6798e59917f3ed01c64ee053255f333d01a09157abf423a70ef54da8e0f62a80df6e0df49c11bac837128a11cc18cd0a9
6
+ metadata.gz: 2c8153d4f39099c5fdf778991e976712e9b06c7d1f5f02d6d3d409703f3ba2e84a1cf96ae18e21fb545ea028a5641e34cdf67645003ad33de00ca7367241d9c6
7
+ data.tar.gz: adee960756406fe4ed14585b32b33cfb55b56e59f4a85f385f72125760e2afd688fb216f4dcc99ad99e7b5efa50f9725e4436bc92ff2e6743434a4a2e9987d77
@@ -1,8 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3.0
4
- - 2.3.1
5
- - 2.3.2
6
3
  - 2.3.3
7
4
  - 2.4.0
8
- before_install: gem install bundler -v 1.13.6
5
+ before_install: gem install bundler -v 1.13.7
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015-2016 ka
1
+ Copyright (c) 2015-2017 ka
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/conoha.svg)](http://badge.fury.io/rb/conoha)
4
4
  [![Dependency Status](https://gemnasium.com/kaosf/conoha.svg)](https://gemnasium.com/kaosf/conoha)
5
5
  [![Build Status](https://travis-ci.org/kaosf/conoha.svg)](https://travis-ci.org/kaosf/conoha)
6
+ [![Coverage Status](https://coveralls.io/repos/github/kaosf/conoha/badge.svg?branch=master)](https://coveralls.io/github/kaosf/conoha?branch=master)
6
7
  [![Code Climate](https://codeclimate.com/github/kaosf/conoha/badges/gpa.svg)](https://codeclimate.com/github/kaosf/conoha)
7
8
 
8
9
  CLI tool for management ConoHa VPS.
@@ -134,12 +135,6 @@ conoha nametag 01234567-89ab-cdef-0123-456789abcdef
134
135
 
135
136
  ## Test
136
137
 
137
- ```sh
138
- ruby test/run_test.rb
139
- ```
140
-
141
- or
142
-
143
138
  ```sh
144
139
  rake
145
140
  ```
@@ -19,10 +19,11 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.11"
23
- spec.add_development_dependency "rake", "~> 11.3"
24
- spec.add_development_dependency "test-unit", "~> 3.1"
25
- spec.add_development_dependency "test-unit-notify", "~> 1.0"
22
+ spec.add_development_dependency "bundler", "~> 1.13"
23
+ spec.add_development_dependency "rake", "~> 12.0"
24
+ spec.add_development_dependency "test-unit", "~> 3.2"
25
+ spec.add_development_dependency "test-unit-rr", "~> 1.0"
26
+ spec.add_development_dependency "coveralls", "~> 0.8"
26
27
  spec.add_development_dependency "guard", "~> 2.13"
27
28
  spec.add_development_dependency "guard-minitest", "~> 2.4"
28
29
  end
@@ -2,6 +2,7 @@ require 'conoha/version'
2
2
  require 'conoha/util'
3
3
  require 'json'
4
4
 
5
+ # :nocov:
5
6
  class Conoha
6
7
  def self.init!
7
8
  load_config!
@@ -13,15 +14,7 @@ class Conoha
13
14
 
14
15
  def self.authenticate!
15
16
  uri = "https://identity.#{region}.conoha.io/v2.0/tokens"
16
- payload = {
17
- auth: {
18
- passwordCredentials: {
19
- username: @@username,
20
- password: @@password
21
- },
22
- tenantId: @@tenant_id
23
- }
24
- }
17
+ payload = payload_for_authentication @@username, @@password, @@tenant_id
25
18
  res = https_post uri, payload, nil
26
19
  if res.code == '401'
27
20
  raise StandardError.new 'Authentication failure'
@@ -38,25 +31,14 @@ class Conoha
38
31
  raise StandardError.new "User \"#{user_id}\" doesn't exist."
39
32
  end
40
33
 
41
- payload = {
42
- auth: {
43
- passwordCredentials: {
44
- username: credential['username'],
45
- password: credential['password']
46
- },
47
- tenantId: credential['tenant_id']
48
- }
49
- }
34
+ payload = payload_for_authentication credential['username'], credential['password'], credential['tenant_id']
50
35
  res = https_post uri, payload, nil
51
36
  if res.code == '401'
52
37
  raise StandardError.new 'Authentication failure'
53
38
  end
54
39
 
55
- @@username = credential['username']
56
- @@password = credential['password']
57
- @@tenant_id = credential['tenant_id']
58
- @@public_key = credential['public_key']
59
- @@authtoken = JSON.parse(res.body)["access"]["token"]["id"]
40
+ auth_token = JSON.parse(res.body)["access"]["token"]["id"]
41
+ set_class_variables_from_credential! credential, auth_token
60
42
  save_config!
61
43
  end
62
44
 
@@ -100,15 +82,7 @@ class Conoha
100
82
  def self.create(os, ram, name_tag = nil)
101
83
  image_ref = image_ref_from_image_tag(image_tag_dictionary(os))
102
84
  uri = "https://compute.#{region}.conoha.io/v2/#{tenant_id}/servers"
103
- payload = {
104
- server: {
105
- adminPass: randstr,
106
- imageRef: image_ref,
107
- flavorRef: flavor_ref(ram),
108
- key_name: public_key,
109
- security_groups: [{name: 'default'}, {name: 'gncs-ipv4-all'}],
110
- }
111
- }
85
+ payload = payload_for_create_vps image_ref, ram, public_key
112
86
  if name_tag
113
87
  payload[:server].merge!({metadata: {instance_name_tag: name_tag}})
114
88
  end
@@ -191,15 +165,7 @@ class Conoha
191
165
 
192
166
  def self.create_from_image(image_ref, ram)
193
167
  uri = "https://compute.#{region}.conoha.io/v2/#{tenant_id}/servers"
194
- payload = {
195
- server: {
196
- adminPass: randstr,
197
- imageRef: image_ref,
198
- flavorRef: flavor_ref(ram),
199
- key_name: public_key,
200
- security_groups: [{name: 'default'}, {name: 'gncs-ipv4-all'}],
201
- }
202
- }
168
+ payload = payload_for_create_vps image_ref, ram, public_key
203
169
  res = https_post uri, payload, authtoken
204
170
  JSON.parse(res.body)["server"]["id"]
205
171
  end
@@ -253,6 +219,14 @@ EOS
253
219
  end
254
220
  end
255
221
 
222
+ def self.set_class_variables_from_credential! credential, auth_token
223
+ @@username = credential['username']
224
+ @@password = credential['password']
225
+ @@tenant_id = credential['tenant_id']
226
+ @@public_key = credential['public_key']
227
+ @@authtoken = authtoken
228
+ end
229
+
256
230
  def self.save_config!
257
231
  s = JSON.generate({
258
232
  username: @@username,
@@ -287,7 +261,7 @@ EOS
287
261
  if image = images.find { |e| e[0] == image_tag }
288
262
  image[1]
289
263
  else
290
- raise StandardError.new "Tag \"#{tag}\" doesn't exist in image list."
264
+ raise StandardError.new "Tag \"#{image_tag}\" doesn't exist in image list."
291
265
  end
292
266
  end
293
267
 
@@ -317,4 +291,31 @@ EOS
317
291
  def self.randstr
318
292
  (1..60).map{['0'..'9','a'..'z','A'..'Z'].map(&:to_a).flatten.sample}.join
319
293
  end
294
+
295
+ def self.payload_for_authentication username, password, tenant_id
296
+ {
297
+ auth: {
298
+ passwordCredentials: {
299
+ username: username,
300
+ password: password
301
+ },
302
+ tenantId: tenant_id
303
+ }
304
+ }
305
+ end
306
+
307
+ # @param [String] image_ref
308
+ # @param [String] ram
309
+ # @param [String] public_key
310
+ def self.payload_for_create_vps image_ref, ram, public_key
311
+ {
312
+ server: {
313
+ adminPass: randstr,
314
+ imageRef: image_ref,
315
+ flavorRef: flavor_ref(ram),
316
+ key_name: public_key,
317
+ security_groups: [{name: 'default'}, {name: 'gncs-ipv4-all'}],
318
+ }
319
+ }
320
+ end
320
321
  end
@@ -2,9 +2,28 @@ require 'json'
2
2
 
3
3
  class Conoha
4
4
  class Config
5
- attr_reader :username, :password, :tenant_id, :public_key, :authtoken
5
+ attr_reader :username, :password, :tenant_id, :public_key, :authtoken, :accounts
6
6
 
7
- class Error < StandardError
7
+ class Error < StandardError; end
8
+
9
+ class Account
10
+ attr_reader :username, :password, :tenant_id, :public_key
11
+
12
+ def initialize(h)
13
+ @username = h['username']
14
+ @password = h['password']
15
+ @tenant_id = h['tenant_id']
16
+ @public_key = h['public_key']
17
+ end
18
+
19
+ def to_hash
20
+ {
21
+ 'username' => @username,
22
+ 'password' => @password,
23
+ 'tenant_id' => @tenant_id,
24
+ 'public_key' => @public_key,
25
+ }
26
+ end
8
27
  end
9
28
 
10
29
  def load_from_yaml!(yaml_str)
@@ -20,6 +39,7 @@ class Conoha
20
39
  @tenant_id = parsed["tenant_id"]
21
40
  @public_key = parsed["public_key"]
22
41
  @authtoken = parsed["authtoken"]
42
+ @accounts = parsed["accounts"]&.map { |e| Account.new e }
23
43
  end
24
44
 
25
45
  def authtoken=(authtoken)
@@ -78,7 +78,7 @@ def image_tag_dictionary(os)
78
78
  'openbsd' => 'vmi-openbsd-6.0-amd64', # OpenBSD
79
79
  'netbsd' => 'vmi-netbsd-7.0-amd64', # NetBSD
80
80
  'freebsd' => 'vmi-freebsd-10.3-x86_64', # FreeBSD
81
- 'docker' => 'vmi-docker-1.12-ubuntu-16.04', # Docker on Ubuntu 16.04
81
+ 'docker' => 'vmi-docker-17.03-ubuntu-16.04-unified', # Docker on Ubuntu 16.04
82
82
 
83
83
  # 20GB storage for 512MB RAM
84
84
  'ubuntu-20gb' => 'vmi-ubuntu-16.04-amd64-20gb',
@@ -93,7 +93,7 @@ def image_tag_dictionary(os)
93
93
  'openbsd-20gb' => 'vmi-openbsd-6.0-amd64-20gb',
94
94
  'netbsd-20gb' => 'vmi-netbsd-7.0-amd64-20gb',
95
95
  'freebsd-20gb' => 'vmi-freebsd-10.3-amd64-20gb',
96
- 'docker-20gb' => 'vmi-docker-1.12-ubuntu-16.04-20gb',
96
+ 'docker-20gb' => 'vmi-docker-17.03-ubuntu-16.04-unified-20gb',
97
97
  }
98
98
 
99
99
  if dictionary.keys.include? os
@@ -1,3 +1,3 @@
1
1
  module ConohaVersion
2
- ITSELF = "0.9.7"
2
+ ITSELF = "0.9.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conoha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.9.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - ka
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-25 00:00:00.000000000 Z
11
+ date: 2017-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,44 +16,44 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.11'
19
+ version: '1.13'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.11'
26
+ version: '1.13'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '11.3'
33
+ version: '12.0'
34
34
  type: :development
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: '11.3'
40
+ version: '12.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: test-unit
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.1'
47
+ version: '3.2'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.1'
54
+ version: '3.2'
55
55
  - !ruby/object:Gem::Dependency
56
- name: test-unit-notify
56
+ name: test-unit-rr
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.8'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: guard
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -139,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
153
  version: '0'
140
154
  requirements: []
141
155
  rubyforge_project:
142
- rubygems_version: 2.5.2
156
+ rubygems_version: 2.6.8
143
157
  signing_key:
144
158
  specification_version: 4
145
159
  summary: ConoHa VPS CLI Tool