conoha 0.8.1 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e557cb27ab1ae1f7532872ba763d257bfe27079
4
- data.tar.gz: d360ddd0ef2759aaaa9f7d95164e70c461560587
3
+ metadata.gz: ee13720321ef8d83cb1f53ef211175785b36f3ff
4
+ data.tar.gz: f46a2cdb58288e4e8c47fe25583a1d4368202c82
5
5
  SHA512:
6
- metadata.gz: 05a299e26608010374ee15900f3a167a16f5866ef5aa695107e6711ba39e8475328a8eac174a89dfce41589ff0f1214a0eb0f3ccc5e6881f362cbd732ef8382a
7
- data.tar.gz: 50ea78edf0182ec6a7e712f5727a613e4c2148dcabf848a5f98db43b2b67f034ecb0d397d98e9cc98b3c9455809643500eddae3b462a7f53690a1445f70eba01
6
+ metadata.gz: b6ce881814dd2633be87afbf7f462cbb1e3718f692ec85d00b522e0290835efe4d7229a8ebf9897a2af6f36e4713018346e0df6e7a77bf9d3a09d181234c5d86
7
+ data.tar.gz: 799de61271bdc30083a779154f847469346e7696599378745eb5e5760ad8b1160379a7bd86e26311cb4b36c8cf4667d83e02d7e58bad61219d32f445a26f16f6
data/README.md CHANGED
@@ -39,11 +39,14 @@ Create `~/.conoha-config.json` like following:
39
39
  {
40
40
  "username": "gncu123456789",
41
41
  "password": "your-password",
42
+ "region": "tyo1",
42
43
  "tenant_id": "0123456789abcdef",
43
44
  "public_key": "your-registered-public-key-name"
44
45
  }
45
46
  ```
46
47
 
48
+ You can select a region from `"tyo1"` (Tokyo), `"sin1"` (Singapore) and `"sjc1"` (USA).
49
+
47
50
  You should run `chmod 600 ~/.conoha-config.json`.
48
51
 
49
52
  ```
data/lib/conoha.rb CHANGED
@@ -7,8 +7,12 @@ class Conoha
7
7
  load_config!
8
8
  end
9
9
 
10
+ def self.region
11
+ @@region || 'tyo1'
12
+ end
13
+
10
14
  def self.authenticate!
11
- uri = 'https://identity.tyo1.conoha.io/v2.0/tokens'
15
+ uri = "https://identity.#{region}.conoha.io/v2.0/tokens"
12
16
  payload = {
13
17
  auth: {
14
18
  passwordCredentials: {
@@ -27,7 +31,7 @@ class Conoha
27
31
  end
28
32
 
29
33
  def self.authenticate_user!(user_id)
30
- uri = 'https://identity.tyo1.conoha.io/v2.0/tokens'
34
+ uri = "https://identity.#{region}.conoha.io/v2.0/tokens"
31
35
 
32
36
  credential = @@accounts[user_id]
33
37
  if credential.nil?
@@ -78,7 +82,7 @@ class Conoha
78
82
  end
79
83
 
80
84
  def self.servers
81
- uri = "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers"
85
+ uri = "https://compute.#{region}.conoha.io/v2/#{tenant_id}/servers"
82
86
  res = https_get uri, authtoken
83
87
  JSON.parse(res.body)["servers"]
84
88
  end
@@ -92,7 +96,7 @@ class Conoha
92
96
  # when "image_tag" doesn't exist in images
93
97
  def self.create(os, ram)
94
98
  image_ref = image_ref_from_image_tag(image_tag_dictionary(os))
95
- uri = "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers"
99
+ uri = "https://compute.#{region}.conoha.io/v2/#{tenant_id}/servers"
96
100
  payload = {
97
101
  server: {
98
102
  adminPass: randstr,
@@ -108,7 +112,7 @@ class Conoha
108
112
 
109
113
  def self.rebuild(server_id, os)
110
114
  image_ref = image_ref_from_image_tag(image_tag_dictionary(os))
111
- uri = "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers/#{server_id}/action"
115
+ uri = "https://compute.#{region}.conoha.io/v2/#{tenant_id}/servers/#{server_id}/action"
112
116
  payload = {
113
117
  rebuild: {
114
118
  imageRef: image_ref,
@@ -121,27 +125,27 @@ class Conoha
121
125
  end
122
126
 
123
127
  def self.delete(server_id)
124
- uri = "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers/#{server_id}"
128
+ uri = "https://compute.#{region}.conoha.io/v2/#{tenant_id}/servers/#{server_id}"
125
129
  res = https_delete uri, authtoken
126
130
  res.code == '204' ? 'OK' : 'Error'
127
131
  end
128
132
 
129
133
  def self.ip_address_of(server_id)
130
- uri = "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers/#{server_id}"
134
+ uri = "https://compute.#{region}.conoha.io/v2/#{tenant_id}/servers/#{server_id}"
131
135
  res = https_get uri, authtoken
132
136
  # NOTE: values[1] is needed if eth1 exists.
133
137
  JSON.parse(res.body)["server"]["addresses"].values[0].map{ |e| e["addr"] }
134
138
  end
135
139
 
136
140
  def self.status_of(server_id)
137
- uri = "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers/#{server_id}"
141
+ uri = "https://compute.#{region}.conoha.io/v2/#{tenant_id}/servers/#{server_id}"
138
142
  res = https_get uri, authtoken
139
143
  JSON.parse(res.body)["server"]["status"]
140
144
  end
141
145
 
142
146
  # @param [String] action "os-start" or "os-stop"
143
147
  def self.server_action(server_id, action)
144
- uri = "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers/#{server_id}/action"
148
+ uri = "https://compute.#{region}.conoha.io/v2/#{tenant_id}/servers/#{server_id}/action"
145
149
  res = https_post uri, {action => nil}, authtoken
146
150
  res.code == '202' ? 'OK' : 'Error'
147
151
  end
@@ -155,25 +159,25 @@ class Conoha
155
159
  end
156
160
 
157
161
  def self.images
158
- uri = "https://compute.tyo1.conoha.io/v2/#{tenant_id}/images"
162
+ uri = "https://compute.#{region}.conoha.io/v2/#{tenant_id}/images"
159
163
  res = https_get uri, authtoken
160
164
  JSON.parse(res.body)["images"].map { |e| [e["name"], e["id"]] }
161
165
  end
162
166
 
163
167
  def self.create_image(server_id, name)
164
- uri = "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers/#{server_id}/action"
168
+ uri = "https://compute.#{region}.conoha.io/v2/#{tenant_id}/servers/#{server_id}/action"
165
169
  res = https_post uri, {"createImage" => {"name" => name}}, authtoken
166
170
  res.code == '202' ? 'OK' : 'Error'
167
171
  end
168
172
 
169
173
  def self.delete_image(image_ref)
170
- uri = "https://image-service.tyo1.conoha.io/v2/images/#{image_ref}"
174
+ uri = "https://image-service.#{region}.conoha.io/v2/images/#{image_ref}"
171
175
  res = https_delete uri, authtoken
172
176
  res.code == '204' ? 'OK' : 'Error'
173
177
  end
174
178
 
175
179
  def self.create_from_image(image_ref, ram)
176
- uri = "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers"
180
+ uri = "https://compute.#{region}.conoha.io/v2/#{tenant_id}/servers"
177
181
  payload = {
178
182
  server: {
179
183
  adminPass: randstr,
@@ -221,6 +225,7 @@ EOS
221
225
  config = JSON.parse config_file_string
222
226
  @@username = config["username"]
223
227
  @@password = config["password"]
228
+ @@region = config["region"]
224
229
  @@tenant_id = config["tenant_id"]
225
230
  @@public_key = config["public_key"]
226
231
  @@authtoken = config["authtoken"]
@@ -233,6 +238,7 @@ EOS
233
238
  s = JSON.generate({
234
239
  username: @@username,
235
240
  password: @@password,
241
+ region: @@region,
236
242
  tenant_id: @@tenant_id,
237
243
  public_key: @@public_key,
238
244
  authtoken: @@authtoken,
@@ -1,3 +1,3 @@
1
1
  module ConohaVersion
2
- ITSELF = "0.8.1"
2
+ ITSELF = "0.9.0"
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.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ka
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-01 00:00:00.000000000 Z
11
+ date: 2016-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler