knife-remotelxc 0.0.1

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.
data/CHANGELOG.md ADDED
File without changes
data/README.md ADDED
File without changes
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + '/lib/'
2
+ require 'knife-remotelxc/version'
3
+ Gem::Specification.new do |s|
4
+ s.name = 'knife-remotelxc'
5
+ s.version = KnifeRemoteLXC::VERSION.version
6
+ s.summary = 'Create LXC nodes'
7
+ s.author = 'Chris Roberts'
8
+ s.email = 'chrisroberts.code@gmail.com'
9
+ s.homepage = 'http://github.com/heavywater/knife-remotelxc'
10
+ s.description = "Remote LXC"
11
+ s.require_path = 'lib'
12
+ s.files = Dir.glob('**/*')
13
+ s.add_dependency 'chef'
14
+ end
@@ -0,0 +1,136 @@
1
+ require 'knife-remotelxc/helpers'
2
+
3
+ module RemoteLXC
4
+ class RemotelxcCreate < Chef::Knife
5
+
6
+ include RemoteLXC::Helpers
7
+
8
+ deps do
9
+ Chef::Knife::Bootstrap.load_deps
10
+ end
11
+
12
+ banner 'knife remotelxc create NODE_NAME'
13
+
14
+ option :lxc_node,
15
+ :short => '-l FQDN|IP',
16
+ :long => '--lxc-node FQDN|IP',
17
+ :description => 'LXC enabled node',
18
+ :required => true
19
+
20
+ option :lxc_ssh_user,
21
+ :short => '-X USERNAME',
22
+ :long => '--lxc-ssh-user USERNAME'
23
+
24
+ # TODO: Pass auth
25
+ #option :lxc_ssh_password,
26
+ # :short => '-S PASSWORD',
27
+ # :long => '--lxc-ssh-password PASSWORD'
28
+
29
+ # All the bootstrap options since we just proxy
30
+ option :ssh_user,
31
+ :short => "-x USERNAME",
32
+ :long => "--ssh-user USERNAME",
33
+ :description => "The ssh username",
34
+ :default => "ubuntu"
35
+
36
+ option :ssh_password,
37
+ :short => "-P PASSWORD",
38
+ :long => "--ssh-password PASSWORD",
39
+ :description => "The ssh password",
40
+ :default => "ubuntu"
41
+
42
+ option :ssh_port,
43
+ :short => "-p PORT",
44
+ :long => "--ssh-port PORT",
45
+ :description => "The ssh port",
46
+ :default => "22",
47
+ :proc => Proc.new { |key| Chef::Config[:knife][:ssh_port] = key }
48
+
49
+ option :ssh_gateway,
50
+ :short => "-G GATEWAY",
51
+ :long => "--ssh-gateway GATEWAY",
52
+ :description => "The ssh gateway",
53
+ :proc => Proc.new { |key| Chef::Config[:knife][:ssh_gateway] = key }
54
+
55
+ option :identity_file,
56
+ :short => "-i IDENTITY_FILE",
57
+ :long => "--identity-file IDENTITY_FILE",
58
+ :description => "The SSH identity file used for authentication"
59
+
60
+ option :prerelease,
61
+ :long => "--prerelease",
62
+ :description => "Install the pre-release chef gems"
63
+
64
+ option :bootstrap_version,
65
+ :long => "--bootstrap-version VERSION",
66
+ :description => "The version of Chef to install",
67
+ :proc => lambda { |v| Chef::Config[:knife][:bootstrap_version] = v }
68
+
69
+ option :bootstrap_proxy,
70
+ :long => "--bootstrap-proxy PROXY_URL",
71
+ :description => "The proxy server for the node being bootstrapped",
72
+ :proc => Proc.new { |p| Chef::Config[:knife][:bootstrap_proxy] = p }
73
+
74
+ option :use_sudo,
75
+ :long => "--sudo",
76
+ :description => "Execute the bootstrap via sudo",
77
+ :boolean => true
78
+
79
+ option :template_file,
80
+ :long => "--template-file TEMPLATE",
81
+ :description => "Full path to location of template to use",
82
+ :default => false
83
+
84
+ option :run_list,
85
+ :short => "-r RUN_LIST",
86
+ :long => "--run-list RUN_LIST",
87
+ :description => "Comma separated list of roles/recipes to apply",
88
+ :proc => lambda { |o| o.split(/[\s,]+/) },
89
+ :default => []
90
+
91
+ option :first_boot_attributes,
92
+ :short => "-j JSON_ATTRIBS",
93
+ :long => "--json-attributes",
94
+ :description => "A JSON string to be added to the first run of chef-client",
95
+ :proc => lambda { |o| JSON.parse(o) },
96
+ :default => {}
97
+
98
+ option :host_key_verify,
99
+ :long => "--[no-]host-key-verify",
100
+ :description => "Verify host key, enabled by default.",
101
+ :boolean => true,
102
+ :default => true
103
+
104
+
105
+ attr_reader :lxc_name
106
+
107
+ def initialize(*args)
108
+ super
109
+ config[:distro] = 'chef-full'
110
+ end
111
+
112
+ def run
113
+ @lxc_name = config[:chef_node_name] = name_args.first
114
+ ip_address = create_new_container
115
+ bootstrap_container(ip_address)
116
+ end
117
+
118
+ private
119
+
120
+ def lxc_base
121
+ config[:lxc_node]
122
+ end
123
+
124
+ def create_new_container
125
+ knife_ssh(lxc_base, "sudo /usr/local/bin/knife-lxc create #{lxc_name}").stdout.to_s.split(':').last.to_s.strip
126
+ end
127
+
128
+ def bootstrap_container(ip_address)
129
+ bootstrap = Chef::Knife::Bootstrap.new
130
+ bootstrap.config = config
131
+ bootstrap.name_args = [ip_address]
132
+ bootstrap.run
133
+ end
134
+
135
+ end
136
+ end
@@ -0,0 +1,26 @@
1
+ include 'knife-remotelxc/helpers'
2
+
3
+ module RemoteLXC
4
+ class RemotelxcDelete < Chef::Knife::Ssh
5
+
6
+ include RemoteLXC::Helpers
7
+
8
+ banner 'knife remotelxc delete NODE_NAME'
9
+
10
+ option :lxc_node,
11
+ :short => '-l FQDN|IP',
12
+ :long => '--lxc-node FQDN|IP',
13
+ :description => 'LXC enabled node',
14
+ :required => true
15
+
16
+ option :lxc_ssh_user,
17
+ :short => '-X USERNAME',
18
+ :long => '--lxc-ssh-user USERNAME'
19
+
20
+ def run
21
+ ui.confirm "Delete LXC node: #{name_args.first}"
22
+ knife_ssh(config[:lxc_node], "knife_lxc delete #{name_args.first}")
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ require 'knife-remotelxc/helpers'
2
+
3
+ module RemoteLXC
4
+ class RemotelxcInfo < Chef::Knife::Ssh
5
+
6
+ include RemoteLXC::Helpers
7
+
8
+ banner 'knife remotelxc info NODE_NAME'
9
+
10
+ option :lxc_node,
11
+ :short => '-l FQDN|IP',
12
+ :long => '--lxc-node FQDN|IP',
13
+ :description => 'LXC enabled node',
14
+ :required => true
15
+
16
+ option :lxc_ssh_user,
17
+ :short => '-X USERNAME',
18
+ :long => '--lxc-ssh-user USERNAME'
19
+
20
+ def run
21
+ knife_ssh(config[:lxc_node], "knife_lxc info #{name_args.first}")
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require 'knife-remotelxc/helpers'
2
+
3
+ module RemoteLXC
4
+ class RemotelxcList < Chef::Knife::Ssh
5
+
6
+ include RemoteLXC::Helpers
7
+
8
+ banner 'knife remotelxc list'
9
+
10
+ option :lxc_node,
11
+ :short => '-l FQDN|IP',
12
+ :long => '--lxc-node FQDN|IP',
13
+ :description => 'LXC enabled node',
14
+ :required => true
15
+
16
+ option :lxc_ssh_user,
17
+ :short => '-X USERNAME',
18
+ :long => '--lxc-ssh-user USERNAME'
19
+
20
+ def run
21
+ knife_ssh(config[:lxc_node], "sudo knife_lxc list")
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ module RemoteLXC
2
+ module Helpers
3
+ def knife_ssh(addr, command, args={})
4
+ cmd = "ssh -o StrictHostKeyChecking=no #{"{config[:lxc_ssh_user]}@" if config[:lxc_ssh_user]}#{addr} #{command}"
5
+ so = Mixlib::ShellOut.new(cmd,
6
+ :logger => Chef::Log.logger,
7
+ :live_stream => $stdout
8
+ ).run_command
9
+ so.error!
10
+ so
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module KnifeRemoteLXC
2
+ class Version < Gem::Version
3
+ end
4
+ VERSION = Version.new('0.0.1')
5
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-remotelxc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Roberts
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: chef
16
+ requirement: &8418360 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *8418360
25
+ description: Remote LXC
26
+ email: chrisroberts.code@gmail.com
27
+ executables: []
28
+ extensions: []
29
+ extra_rdoc_files: []
30
+ files:
31
+ - CHANGELOG.md
32
+ - knife-remotelxc.gemspec
33
+ - README.md
34
+ - lib/knife-remotelxc/version.rb
35
+ - lib/knife-remotelxc/helpers.rb
36
+ - lib/chef/knife/remotelxc_delete.rb
37
+ - lib/chef/knife/remotelxc_list.rb
38
+ - lib/chef/knife/remotelxc_info.rb
39
+ - lib/chef/knife/remotelxc_create.rb
40
+ homepage: http://github.com/heavywater/knife-remotelxc
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 1.8.17
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Create LXC nodes
64
+ test_files: []
65
+ has_rdoc: