conoha 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -0
- data/exe/conoharant +137 -0
- data/lib/conoha/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e74e785f4bb9c620e31f0eaa64dc2ce4aed8755
|
4
|
+
data.tar.gz: d72ed86c473189df9841b9570e462d04ab9fd9fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41567c6082d53fdc1e8f13313acdc409462043bed0b7e04c9237481a622b8f414f87dc9213c973cd86ae85296b8c870525763847c620456863839096cb033cdd
|
7
|
+
data.tar.gz: 41582098947f4f5a39c9b80e9d36eb2fbb574fb8cf07c49bef020d532a32fa31714ee886d20898df57ac40f99bb5691870d7847b4c0a401f54b2bcc19700b30a
|
data/README.md
CHANGED
@@ -126,6 +126,30 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/kaosf/
|
|
126
126
|
- [ ] subcommand help messages
|
127
127
|
- [ ] CLI support library (e.g. thor)
|
128
128
|
|
129
|
+
## WIP feature
|
130
|
+
|
131
|
+
`Conoharantfile`
|
132
|
+
|
133
|
+
```yml
|
134
|
+
# vim: ft=yaml
|
135
|
+
---
|
136
|
+
os: centos67
|
137
|
+
ram: g-1gb
|
138
|
+
tagprefix: tagnameprefixasyoulike
|
139
|
+
```
|
140
|
+
|
141
|
+
```sh
|
142
|
+
# conoharant up
|
143
|
+
conoharant ssh
|
144
|
+
conoharant ssh root
|
145
|
+
conoharant mosh
|
146
|
+
conoharant dump
|
147
|
+
conoharant restore
|
148
|
+
conoharant clean
|
149
|
+
conoharant browse
|
150
|
+
conoharant browse 3000
|
151
|
+
```
|
152
|
+
|
129
153
|
## License
|
130
154
|
|
131
155
|
[MIT](http://opensource.org/licenses/MIT)
|
data/exe/conoharant
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
unless File.exist? 'Conoharantfile'
|
4
|
+
STDERR.puts "\"Conoharantfile\" doesn't exist."
|
5
|
+
exit 1
|
6
|
+
end
|
7
|
+
unless Dir.exist? '.conoharant'
|
8
|
+
Dir.mkdir '.conoharant'
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'yaml'
|
12
|
+
config = YAML.load(File.open('Conoharantfile').read)
|
13
|
+
if File.exist? '.conoharant/status.yml'
|
14
|
+
status = YAML.load(File.open('.conoharant/status.yml').read)
|
15
|
+
else
|
16
|
+
status = {
|
17
|
+
'status' => 'no',
|
18
|
+
'id' => nil,
|
19
|
+
'images' => [],
|
20
|
+
'latestnumber' => 0,
|
21
|
+
'image-tags' => [],
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'conoha/util'
|
26
|
+
# Dump current status to ".conoharant/status.yml"
|
27
|
+
# @params [Hash] status
|
28
|
+
def dump_conoharant_status(status)
|
29
|
+
File.open('.conoharant/status.yml', 'w').print(YAML.dump(status))
|
30
|
+
end
|
31
|
+
|
32
|
+
require 'conoha'
|
33
|
+
Conoha.init!
|
34
|
+
begin
|
35
|
+
Conoha.vps_list
|
36
|
+
rescue => e
|
37
|
+
puts "Auth token is invalid."
|
38
|
+
puts "Reauthenticating..."
|
39
|
+
begin
|
40
|
+
Conoha.authenticate!
|
41
|
+
rescue => e
|
42
|
+
STDERR.puts "Failed to authenticate again."
|
43
|
+
STDERR.puts "Retry after modifying \"~/.conoha-config.json\"."
|
44
|
+
exit 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
puts "Authentication OK."
|
48
|
+
|
49
|
+
arg = ARGV.first
|
50
|
+
case arg
|
51
|
+
when 'ssh', 'mosh'
|
52
|
+
connection = arg # 'ssh' or 'mosh'
|
53
|
+
if status['status'] != 'running'
|
54
|
+
STDERR.puts "VPS is not running."
|
55
|
+
exit 1
|
56
|
+
end
|
57
|
+
server_id = status['id']
|
58
|
+
ipaddress = ipv4(Conoha.ip_address_of(server_id))
|
59
|
+
user = ARGV[1].nil? ? '' : "#{ARGV[1]}@"
|
60
|
+
case connection
|
61
|
+
when 'ssh'
|
62
|
+
command = "ssh -oStrictHostKeyChecking=no #{user}#{ipaddress}"
|
63
|
+
when 'mosh'
|
64
|
+
command = "mosh #{ipaddress}"
|
65
|
+
end
|
66
|
+
puts command
|
67
|
+
system command
|
68
|
+
when 'dump'
|
69
|
+
if status['status'] != 'running'
|
70
|
+
STDERR.puts "A running VPS doesn't exist."
|
71
|
+
exit 1
|
72
|
+
end
|
73
|
+
latest_number = status['latestnumber']
|
74
|
+
server_id = status['id']
|
75
|
+
name = "#{config['tagprefix']}#{latest_number + 1}"
|
76
|
+
latest_number += 1
|
77
|
+
puts "conoha shutdown #{server_id}"
|
78
|
+
Conoha.shutdown server_id
|
79
|
+
loop do
|
80
|
+
sleep 60
|
81
|
+
puts "conoha imagecreate #{server_id} #{name}"
|
82
|
+
result = Conoha.create_image server_id, name
|
83
|
+
break if result == 'OK'
|
84
|
+
puts '# Error! Retry after 60 seconds...'
|
85
|
+
end
|
86
|
+
puts '# OK!'
|
87
|
+
image_id = Conoha.images.find { |e| e[0] == name }[1]
|
88
|
+
loop do
|
89
|
+
sleep 60
|
90
|
+
puts "conoha delete #{server_id}"
|
91
|
+
result = Conoha.delete server_id
|
92
|
+
break if result == 'OK'
|
93
|
+
puts '# Error! Retry after 60 seconds...'
|
94
|
+
end
|
95
|
+
puts '# OK!'
|
96
|
+
status['status'] = 'no'
|
97
|
+
status['id'] = nil
|
98
|
+
status['images'] << image_id
|
99
|
+
status['latestnumber'] = latest_number
|
100
|
+
status['image-tags'] << name
|
101
|
+
dump_conoharant_status status
|
102
|
+
when 'restore'
|
103
|
+
if status['status'] != 'no'
|
104
|
+
STDERR.puts "A VPS already exists."
|
105
|
+
exit 1
|
106
|
+
end
|
107
|
+
image_id = status['images'][-1]
|
108
|
+
ram = config['ram']
|
109
|
+
puts "conoha restore #{image_id} #{ram}"
|
110
|
+
server_id = Conoha.create_from_image image_id, ram
|
111
|
+
status['status'] = 'running'
|
112
|
+
status['id'] = server_id
|
113
|
+
dump_conoharant_status status
|
114
|
+
when 'clean'
|
115
|
+
images = status['images']
|
116
|
+
if images.length > 2
|
117
|
+
images[0...-2].each do |e|
|
118
|
+
puts "conoha delete #{e}"
|
119
|
+
Conoha.delete_image e
|
120
|
+
end
|
121
|
+
status['images'] = status['images'][-2..-1]
|
122
|
+
status['image-tags'] = status['image-tags'][-2..-1]
|
123
|
+
dump_conoharant_status status
|
124
|
+
else
|
125
|
+
puts "Nothing to do."
|
126
|
+
end
|
127
|
+
when 'browse'
|
128
|
+
server_id = status['id']
|
129
|
+
ipaddress = ipv4(Conoha.ip_address_of(server_id))
|
130
|
+
port = ARGV[1].nil? ? '' : ":#{ARGV[1]}"
|
131
|
+
command = "xdg-open http://#{ipaddress}#{port}"
|
132
|
+
puts command
|
133
|
+
system command
|
134
|
+
else
|
135
|
+
STDERR.puts 'Invalid argument.'
|
136
|
+
exit 1
|
137
|
+
end
|
data/lib/conoha/version.rb
CHANGED
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.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ka
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -99,6 +99,7 @@ email:
|
|
99
99
|
- ka.kaosf@gmail.com
|
100
100
|
executables:
|
101
101
|
- conoha
|
102
|
+
- conoharant
|
102
103
|
extensions: []
|
103
104
|
extra_rdoc_files: []
|
104
105
|
files:
|
@@ -113,6 +114,7 @@ files:
|
|
113
114
|
- bin/setup
|
114
115
|
- conoha.gemspec
|
115
116
|
- exe/conoha
|
117
|
+
- exe/conoharant
|
116
118
|
- lib/conoha.rb
|
117
119
|
- lib/conoha/config.rb
|
118
120
|
- lib/conoha/util.rb
|