kytoon 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -61,7 +61,7 @@ class ServerGroup
61
61
  @dns_nameserver = options[:dns_nameserver]
62
62
  @gateway_ip = options[:gateway_ip]
63
63
  @gateway_ip = ENV['GATEWAY_IP'] if @gateway_ip.nil?
64
- raise "Please specify a GATEWAY_IP" if @gateway_ip.nil?
64
+ raise ConfigException, "Please specify a GATEWAY_IP" if @gateway_ip.nil?
65
65
 
66
66
  @servers=[]
67
67
  end
@@ -195,12 +195,12 @@ fi
195
195
  id = options[:id]
196
196
  if id.nil? then
197
197
  group=ServerGroup.most_recent
198
- raise "No server group files exist." if group.nil?
198
+ raise NoServerGroupExists, "No server group files exist." if group.nil?
199
199
  id=group.id
200
200
  end
201
201
 
202
202
  out_file=File.join(@@data_dir, "#{id}.json")
203
- raise "No server group files exist." if not File.exists?(out_file)
203
+ raise NoServerGroupExists, "No server group files exist." if not File.exists?(out_file)
204
204
  ServerGroup.from_json(IO.read(out_file))
205
205
  end
206
206
 
@@ -287,7 +287,7 @@ echo 1 > /proc/sys/net/ipv4/ip_forward
287
287
  }, gw_ip) do |ok, out|
288
288
  if not ok
289
289
  puts out
290
- raise "Failed to create instance #{hostname}."
290
+ raise KytoonException, "Failed to create instance #{hostname}."
291
291
  end
292
292
  end
293
293
  end
@@ -1,52 +1,68 @@
1
+ module Kytoon
2
+
1
3
  class ServerGroup
2
4
 
3
5
  @@group_class = nil
4
6
 
5
7
  # called to init the configured group class we will use
6
- def self.init
8
+ def self.init(group_type=nil)
7
9
  return if not @@group_class.nil?
8
10
  configs = Util.load_configs
9
- group_type = ENV['GROUP_TYPE'] || configs['group_type']
10
- if group_type == "cloud_server_vpc" then
11
- require 'kytoon/providers/cloud_servers_vpc'
12
- @@group_class = Kytoon::Providers::CloudServersVPC::ServerGroup
11
+ group_type = configs['group_type'] if group_type.nil?
12
+ if group_type == "openstack" then
13
+ require 'kytoon/providers/openstack'
14
+ @@group_class = Kytoon::Providers::Openstack::ServerGroup
13
15
  elsif group_type == "xenserver" then
14
16
  require 'kytoon/providers/xenserver'
15
17
  @@group_class = Kytoon::Providers::Xenserver::ServerGroup
16
18
  elsif group_type == "libvirt" then
17
19
  require 'kytoon/providers/libvirt'
18
20
  @@group_class = Kytoon::Providers::Libvirt::ServerGroup
21
+ elsif group_type == "cloud_server_vpc" or group_type == "cloud_servers_vpc" then
22
+ require 'kytoon/providers/cloud_servers_vpc'
23
+ @@group_class = Kytoon::Providers::CloudServersVPC::ServerGroup
19
24
  else
20
- raise "Invalid 'group_type' specified in config file."
25
+ raise ConfigException, "Invalid 'group_type' specified."
21
26
  end
22
27
  end
23
28
 
24
- def self.index(options)
29
+ def self.index(options={})
25
30
  self.init
26
- @@group_class.index(options)
31
+ server_groups = @@group_class.index(options)
32
+ if server_groups.size > 0
33
+ puts "Server groups:"
34
+ server_groups.sort { |a,b| b.id <=> a.id }.each do |sg|
35
+ gw=sg.gateway_ip.nil? ? "" : " (#{sg.gateway_ip})"
36
+ puts "\t :id => #{sg.id}, :name => #{sg.name} #{gw}"
37
+ end
38
+ else
39
+ puts "No server groups."
40
+ end
27
41
  end
28
42
 
29
- def self.create
43
+ def self.create(config_file)
30
44
  self.init
31
- json_config_file=ENV['SERVER_GROUP_JSON']
32
- if json_config_file.nil? then
33
- json_config_file = @@group_class::CONFIG_FILE
45
+ if config_file.nil? then
46
+ config_file = @@group_class::CONFIG_FILE
47
+ end
48
+ if not File.exists?(config_file) then
49
+ raise ConfigException, "Please specify a valid GROUP_CONFIG."
34
50
  end
35
- sg = @@group_class.from_json(IO.read(json_config_file))
51
+ sg = @@group_class.from_json(IO.read(config_file))
36
52
  @@group_class.create(sg)
37
53
  end
38
54
 
39
- def self.get
55
+ def self.get(id=nil)
40
56
  self.init
41
- id = ENV['GROUP_ID']
42
57
  @@group_class.get(:id => id)
43
58
  end
44
59
 
45
- def self.delete
60
+ def self.delete(id=nil)
46
61
  self.init
47
- id = ENV['GROUP_ID']
48
62
  sg = @@group_class.get(:id => id)
49
63
  sg.delete
50
64
  end
51
65
 
52
66
  end
67
+
68
+ end
@@ -0,0 +1,92 @@
1
+ require 'thor'
2
+
3
+ module Kytoon
4
+
5
+ class ThorTasks < Thor
6
+
7
+ desc "create", "Create a new server group."
8
+ method_options :group_type => :string
9
+ method_options :group_config => :string
10
+ def create(options=(options or {}))
11
+ begin
12
+ ServerGroup.init(options[:group_type])
13
+ sg = ServerGroup.create(options[:group_config])
14
+ puts "Server group ID #{sg.id} created."
15
+ rescue KytoonException => ke
16
+ puts ke.message
17
+ end
18
+ end
19
+
20
+ desc "list", "List existing server groups."
21
+ method_options :group_type => :string
22
+ def list(options=(options or {}))
23
+ begin
24
+ ServerGroup.init(options[:group_type])
25
+ ServerGroup.index()
26
+ rescue KytoonException => ke
27
+ puts ke.message
28
+ end
29
+ end
30
+
31
+ desc "show", "Print information for a server group."
32
+ method_options :group_id => :string
33
+ method_options :group_type => :string
34
+ def show(options=(options or {}))
35
+ begin
36
+ ServerGroup.init(options[:group_type])
37
+ sg = ServerGroup.get(options[:group_id])
38
+ sg.pretty_print
39
+ rescue KytoonException => ke
40
+ puts ke.message
41
+ end
42
+ end
43
+
44
+ desc "delete", "Delete a server group."
45
+ method_options :group_id => :string
46
+ method_options :group_type => :string
47
+ def delete(options=(options or {}))
48
+ begin
49
+ ServerGroup.init(options[:group_type])
50
+ sg = ServerGroup.get(options[:group_id])
51
+ sg.delete
52
+ SshUtil.remove_known_hosts_ip(sg.gateway_ip)
53
+ rescue KytoonException => ke
54
+ puts ke.message
55
+ end
56
+ end
57
+
58
+ desc "ip", "Print the IP address of the gateway server"
59
+ method_options :group_id => :string
60
+ method_options :group_type => :string
61
+ def ip(options=(options or {}))
62
+ begin
63
+ ServerGroup.init(options[:group_type])
64
+ sg = ServerGroup.get(options[:group_id])
65
+ puts sg.gateway_ip
66
+ rescue KytoonException => ke
67
+ puts ke.message
68
+ end
69
+ end
70
+
71
+ desc "ssh", "SSH into a group."
72
+ method_options :group_id => :string
73
+ method_options :group_type => :string
74
+ def ssh(options=(options or {}))
75
+ begin
76
+ ServerGroup.init(options[:group_type])
77
+ args=ARGV[1, ARGV.length].join(" ")
78
+ sg = ServerGroup.get(options[:group_id])
79
+ if (ARGV[1] and ARGV[1] =~ /^--group_id.*/) and (ARGV[2] and ARGV[2] =~ /^--group_id.*/)
80
+ args=ARGV[3, ARGV.length].join(" ")
81
+ elsif ARGV[1] and ARGV[1] =~ /^--group_id.*/
82
+ args=ARGV[2, ARGV.length].join(" ")
83
+ end
84
+ exec("ssh -o \"StrictHostKeyChecking no\" root@#{sg.gateway_ip} #{args}")
85
+ rescue KytoonException => ke
86
+ puts ke.message
87
+ end
88
+ end
89
+
90
+ end
91
+
92
+ end
data/lib/kytoon/util.rb CHANGED
@@ -32,32 +32,37 @@ module Util
32
32
  configs=YAML.load_file(config_file)
33
33
  @@configs=configs
34
34
  else
35
- raise "Failed to load kytoon config file. Please configure /etc/kytoon.conf or create a .kytoon.conf config file in your HOME directory."
35
+ raise ConfigException, "Failed to load kytoon config file. Please configure /etc/kytoon.conf or create a .kytoon.conf config file in your HOME directory."
36
36
  end
37
37
 
38
38
  @@configs
39
39
 
40
40
  end
41
41
 
42
- def self.load_public_key
42
+ def self.public_key_path
43
43
 
44
- ssh_dir=ENV['HOME']+File::SEPARATOR+".ssh"+File::SEPARATOR
45
- if File.exists?(ssh_dir+"id_rsa.pub")
46
- pubkey=IO.read(ssh_dir+"id_rsa.pub")
47
- elsif File.exists?(ssh_dir+"id_dsa.pub")
48
- pubkey=IO.read(ssh_dir+"id_dsa.pub")
44
+ ssh_dir=File.join(ENV['HOME'], ".ssh")
45
+ if File.exists?(File.join(ssh_dir, "id_rsa.pub"))
46
+ File.join(ssh_dir, "id_rsa.pub")
47
+ elsif File.exists?(File.join(ssh_dir, "id_dsa.pub"))
48
+ File.join(ssh_dir, "id_dsa.pub")
49
49
  else
50
- raise "Failed to load SSH key. Please create a SSH public key pair in your HOME directory."
50
+ raise ConfigException, "Failed to load SSH key. Please create a SSH public key pair in your HOME directory."
51
51
  end
52
52
 
53
+ end
54
+
55
+ def self.load_public_key
56
+
57
+ pubkey=IO.read(self.public_key_path)
53
58
  pubkey.chomp
54
59
 
55
60
  end
56
61
 
57
62
  def self.check_config_param(key)
58
63
  configs = load_configs
59
- if not configs or configs[key].nil? or configs[key].empty? then
60
- raise "Please specify '#{key.to_s}' in your kytoon config file."
64
+ if not configs or configs[key].nil? or configs[key].to_s.empty? then
65
+ raise ConfigException, "Please specify '#{key.to_s}' in your kytoon config file."
61
66
  end
62
67
  end
63
68
 
data/rake/kytoon.rake CHANGED
@@ -1,72 +1,60 @@
1
1
  include Kytoon
2
2
 
3
- namespace :group do
3
+ namespace :kytoon do
4
4
  TMP_SG=File.join(KYTOON_PROJECT, 'tmp', 'server_groups')
5
5
 
6
6
  directory TMP_SG
7
7
 
8
8
  task :init => [TMP_SG] do
9
- ServerGroup.init
10
- end
9
+ ServerGroup.init(ENV['GROUP_TYPE'])
10
+ end
11
11
 
12
- desc "Create a new group of cloud servers"
13
- task :create => [ "init" ] do
14
- sg = ServerGroup.create
12
+ desc "Create a new group of servers"
13
+ task :create do
14
+ sg = ServerGroup.create(ENV['GROUP_CONFIG'])
15
15
  puts "Server group ID #{sg.id} created."
16
16
  end
17
17
 
18
- desc "List existing cloud server groups."
19
- task :list => "init" do
20
-
21
- server_groups=nil
22
- server_groups=ServerGroup.index(:source => "cache")
23
- if server_groups.size > 0
24
- puts "Server groups:"
25
- server_groups.sort { |a,b| b.id <=> a.id }.each do |sg|
26
- gw=sg.gateway_ip.nil? ? "" : " (#{sg.gateway_ip})"
27
- puts "\t :id => #{sg.id}, :name => #{sg.name} #{gw}"
28
- end
29
- else
30
- puts "No server groups."
31
- end
32
-
18
+ desc "List existing server groups."
19
+ task :list do
20
+ ServerGroup.index(:source => "cache")
33
21
  end
34
22
 
35
- desc "Print information for a cloud server group"
36
- task :show => [ "init" ] do
37
- sg = ServerGroup.get
23
+ desc "Print information for a server group"
24
+ task :show do
25
+ sg = ServerGroup.get(ENV['GROUP_ID'])
38
26
  sg.pretty_print
39
27
  end
40
28
 
41
- desc "Delete a cloud server group"
42
- task :delete => ["init"] do
29
+ desc "Delete a server group"
30
+ task :delete do
43
31
 
44
- sg = ServerGroup.get
45
- puts "Deleting cloud server group ID: #{sg.id}."
32
+ sg = ServerGroup.get(ENV['GROUP_ID'])
33
+ puts "Deleting server group ID: #{sg.id}."
46
34
  sg.delete
47
35
  SshUtil.remove_known_hosts_ip(sg.gateway_ip)
48
36
 
49
37
  end
50
38
 
51
- desc "Print the VPN gateway IP address"
52
- task :gateway_ip do
53
- group = ServerGroup.get
39
+ desc "Print the gateway IP address"
40
+ task :ip do
41
+ group = ServerGroup.get(ENV['GROUP_ID'])
54
42
  puts group.gateway_ip
55
43
  end
56
44
 
57
- end
58
-
59
- desc "SSH into the most recently created VPN gateway server."
60
- task :ssh => 'group:init' do
45
+ desc "SSH into the most recently created server group."
46
+ task :ssh => 'kytoon:init' do
61
47
 
62
- sg=ServerGroup.get
63
- args=ARGV[1, ARGV.length].join(" ")
64
- if (ARGV[1] and ARGV[1] =~ /^GROUP_.*/) and (ARGV[2] and ARGV[2] =~ /^GROUP_.*/)
65
- args=ARGV[3, ARGV.length].join(" ")
66
- elsif ARGV[1] and ARGV[1] =~ /^GROUP_.*/
67
- args=ARGV[2, ARGV.length].join(" ")
48
+ sg=ServerGroup.get(ENV['GROUP_ID'])
49
+ args=ARGV[1, ARGV.length].join(" ")
50
+ if (ARGV[1] and ARGV[1] =~ /^GROUP_.*/) and (ARGV[2] and ARGV[2] =~ /^GROUP_.*/)
51
+ args=ARGV[3, ARGV.length].join(" ")
52
+ elsif ARGV[1] and ARGV[1] =~ /^GROUP_.*/
53
+ args=ARGV[2, ARGV.length].join(" ")
54
+ end
55
+ exec("ssh -o \"StrictHostKeyChecking no\" root@#{sg.gateway_ip} #{args}")
68
56
  end
69
- exec("ssh -o \"StrictHostKeyChecking no\" root@#{sg.gateway_ip} #{args}")
57
+
70
58
  end
71
59
 
72
60
  desc "Print help and usage information"
@@ -81,34 +69,30 @@ task :usage do
81
69
  puts "----"
82
70
  puts "Example commands:"
83
71
  puts ""
84
- puts "\t- Create a new server group."
72
+ puts "\t- Create a new server group with default config file"
73
+ puts "\t (config/server_group.json)."
85
74
  puts ""
86
- puts "\t\t$ rake group:create"
75
+ puts "\t$ rake kytoon:create"
87
76
 
88
77
  puts ""
89
78
  puts "\t- List your currently running server groups."
90
79
  puts ""
91
- puts "\t\t$ rake group:list"
92
-
93
- puts ""
94
- puts "\t- List all remote groups using a common Cloud Servers VPC account."
95
- puts ""
96
- puts "\t\t$ rake group:list"
80
+ puts "\t$ rake kytoon:list"
97
81
 
98
82
  puts ""
99
83
  puts "\t- SSH into the current (most recently created) server group."
100
84
  puts ""
101
- puts "\t\t$ rake ssh"
85
+ puts "\t$ rake ssh"
102
86
 
103
87
  puts ""
104
88
  puts "\t- SSH into a server group with an ID of 3."
105
89
  puts ""
106
- puts "\t\t$ rake ssh GROUP_ID=3"
90
+ puts "\t$ rake ssh GROUP_ID=3"
107
91
 
108
92
  puts ""
109
93
  puts "\t- Delete the server group with an ID of 3."
110
94
  puts ""
111
- puts "\t\t$ rake group:delete GROUP_ID=3"
95
+ puts "\t$ rake kytoon:delete GROUP_ID=3"
112
96
 
113
97
  end
114
98
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kytoon
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-24 00:00:00.000000000 Z
12
+ date: 2012-09-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
@@ -75,6 +75,22 @@ dependencies:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
77
  version: 1.8.3
78
+ - !ruby/object:Gem::Dependency
79
+ name: thor
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '0.14'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '0.14'
78
94
  - !ruby/object:Gem::Dependency
79
95
  name: uuidtools
80
96
  requirement: !ruby/object:Gem::Requirement
@@ -155,6 +171,38 @@ dependencies:
155
171
  - - ! '>='
156
172
  - !ruby/object:Gem::Version
157
173
  version: '0'
174
+ - !ruby/object:Gem::Dependency
175
+ name: openstack-compute
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ type: :runtime
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ - !ruby/object:Gem::Dependency
191
+ name: thor
192
+ requirement: !ruby/object:Gem::Requirement
193
+ none: false
194
+ requirements:
195
+ - - ! '>='
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ type: :runtime
199
+ prerelease: false
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
158
206
  - !ruby/object:Gem::Dependency
159
207
  name: uuidtools
160
208
  requirement: !ruby/object:Gem::Requirement
@@ -174,24 +222,28 @@ dependencies:
174
222
  description: A set of Rake tasks that provide a framework to help automate the creation
175
223
  and configuration of VPC server groups.
176
224
  email: dprince@redhat.com
177
- executables: []
225
+ executables:
226
+ - kytoon
178
227
  extensions: []
179
228
  extra_rdoc_files:
180
229
  - LICENSE.txt
181
- - README.rdoc
230
+ - README.md
182
231
  files:
183
232
  - .document
184
233
  - CHANGELOG
185
234
  - Gemfile
186
235
  - Gemfile.lock
187
236
  - LICENSE.txt
188
- - README.rdoc
237
+ - README.md
189
238
  - Rakefile
190
239
  - VERSION
240
+ - bin/kytoon
191
241
  - config/server_group_libvirt.json
242
+ - config/server_group_openstack.json
192
243
  - config/server_group_vpc.json
193
244
  - config/server_group_xen.json
194
245
  - lib/kytoon.rb
246
+ - lib/kytoon/exception.rb
195
247
  - lib/kytoon/providers/cloud_servers_vpc.rb
196
248
  - lib/kytoon/providers/cloud_servers_vpc/client.rb
197
249
  - lib/kytoon/providers/cloud_servers_vpc/connection.rb
@@ -201,10 +253,13 @@ files:
201
253
  - lib/kytoon/providers/cloud_servers_vpc/vpn_network_interface.rb
202
254
  - lib/kytoon/providers/libvirt.rb
203
255
  - lib/kytoon/providers/libvirt/server_group.rb
256
+ - lib/kytoon/providers/openstack.rb
257
+ - lib/kytoon/providers/openstack/server_group.rb
204
258
  - lib/kytoon/providers/xenserver.rb
205
259
  - lib/kytoon/providers/xenserver/server_group.rb
206
260
  - lib/kytoon/server_group.rb
207
261
  - lib/kytoon/ssh_util.rb
262
+ - lib/kytoon/thor_tasks.rb
208
263
  - lib/kytoon/util.rb
209
264
  - lib/kytoon/version.rb
210
265
  - lib/kytoon/vpn/vpn_connection.rb
@@ -220,7 +275,6 @@ files:
220
275
  - test/test_helper.rb
221
276
  - test/test_kytoon.rb
222
277
  - test/util_test.rb
223
- - test/vpn_network_manager_test.rb
224
278
  homepage: http://github.com/dprince/kytoon
225
279
  licenses: []
226
280
  post_install_message:
@@ -235,7 +289,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
235
289
  version: '0'
236
290
  segments:
237
291
  - 0
238
- hash: -1959876688659758005
292
+ hash: -603401049467997741
239
293
  required_rubygems_version: !ruby/object:Gem::Requirement
240
294
  none: false
241
295
  requirements: