gogetit 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/gogetit/cli.rb +32 -2
- data/lib/gogetit/maas.rb +9 -0
- data/lib/gogetit/util.rb +4 -4
- data/lib/gogetit/version.rb +1 -1
- data/lib/providers/libvirt.rb +40 -11
- data/lib/providers/lxd.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01a616e34651706a336ec6a266e45b0ea5facbb1
|
4
|
+
data.tar.gz: 7a49f258a50d7b4d5f678daa02c9e67a9e5f19a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad0e68eaf277c1b05fb6fd1b9b0634f32b79bd30eee220db2b9ec4bfc3f9bfde500e6b326bf59c92d35055b07529846e6d243880a4c83643240ee1e21c3ccb23
|
7
|
+
data.tar.gz: fe1334ef49fe38c0b5cbb9a1095176a75d8735a48c8c0c16cec008380086cd04af9f4c39046036a7ce896f4de6f8d75aab286f09fc03a2f92bc737f0a179aef0
|
data/README.md
CHANGED
@@ -56,6 +56,13 @@ gogetit create lxd01 -p lxd -i 192.168.10.10 10.0.0.2
|
|
56
56
|
gogetit create kvm01 -p libvirt
|
57
57
|
gogetit create kvm01 -p libvirt -i 192.168.10.10 10.0.0.2
|
58
58
|
|
59
|
+
# When specifying alias for LXD provider
|
60
|
+
gogetit create kvm01 -a centos7
|
61
|
+
gogetit create kvm01 -p lxd -a centos7
|
62
|
+
|
63
|
+
# When specifying distro for Libvirt provider
|
64
|
+
gogetit create kvm01 -p libvirt -d centos
|
65
|
+
|
59
66
|
# to create a LXD container without MAAS awareness
|
60
67
|
gogetit create lxd01 --no-maas -f lxd_without_maas.yml
|
61
68
|
gogetit create lxd01 --no-maas -f lxd_without_maas_vlans.yml
|
@@ -78,6 +85,9 @@ CHEF=true gogetit create chef01
|
|
78
85
|
|
79
86
|
# to destroy a container deleting corresponding chef node and client
|
80
87
|
gogetit destroy chef01 --chef
|
88
|
+
|
89
|
+
# to release a machine(or instance created by libvirt) in MAAS
|
90
|
+
gogetit release node01
|
81
91
|
```
|
82
92
|
|
83
93
|
```ruby
|
data/lib/gogetit/cli.rb
CHANGED
@@ -20,7 +20,9 @@ module Gogetit
|
|
20
20
|
method_option :provider, :aliases => '-p', :type => :string, \
|
21
21
|
:default => 'lxd', :desc => 'A provider such as lxd and libvirt'
|
22
22
|
method_option :alias, :aliases => '-a', :type => :string, \
|
23
|
-
:
|
23
|
+
:desc => 'An alias name for a lxd image'
|
24
|
+
method_option :distro, :aliases => '-d', :type => :string, \
|
25
|
+
:desc => 'A distro name with its series for libvirt provider'
|
24
26
|
method_option :chef, :aliases => '-c', :type => :boolean, \
|
25
27
|
:default => false, :desc => 'Chef awareness'
|
26
28
|
method_option :vlans, :aliases => '-v', :type => :array, \
|
@@ -41,6 +43,12 @@ module Gogetit
|
|
41
43
|
abort("'no-maas' and 'file' have to be set together.") \
|
42
44
|
if options['no-maas'] ^ !!options['file']
|
43
45
|
|
46
|
+
abort("'distro' has to be set with libvirt provider.") \
|
47
|
+
if options['distro'] and options['provider'] == 'lxd'
|
48
|
+
|
49
|
+
abort("'alias' has to be set with lxd provider.") \
|
50
|
+
if options['alias'] and options['provider'] == 'libvirt'
|
51
|
+
|
44
52
|
case options['provider']
|
45
53
|
when 'lxd'
|
46
54
|
Gogetit.lxd.create(name, options.to_hash)
|
@@ -57,7 +65,7 @@ module Gogetit
|
|
57
65
|
end
|
58
66
|
end
|
59
67
|
|
60
|
-
desc 'destroy NAME', 'Destroy either a container or KVM
|
68
|
+
desc 'destroy NAME', 'Destroy either a container or KVM instance.'
|
61
69
|
method_option :chef, :type => :boolean, :desc => "Enable chef awareness."
|
62
70
|
def destroy(name)
|
63
71
|
# Let Gogetit recognize the provider.
|
@@ -79,6 +87,28 @@ module Gogetit
|
|
79
87
|
end
|
80
88
|
end
|
81
89
|
|
90
|
+
desc 'release NAME', 'Release a node in MAAS'
|
91
|
+
method_option :chef, :type => :boolean, :desc => "Enable chef awareness."
|
92
|
+
def release(name)
|
93
|
+
# Let Gogetit recognize the provider.
|
94
|
+
provider = Gogetit.get_provider_of(name)
|
95
|
+
if provider
|
96
|
+
case provider
|
97
|
+
when 'lxd'
|
98
|
+
abort('This method is not available for LXD container.')
|
99
|
+
when 'libvirt'
|
100
|
+
Gogetit.libvirt.release(name)
|
101
|
+
else
|
102
|
+
abort('Invalid argument entered.')
|
103
|
+
end
|
104
|
+
end
|
105
|
+
# post-tasks
|
106
|
+
if options['chef']
|
107
|
+
knife_remove(name, Gogetit.logger) if options[:chef]
|
108
|
+
update_databags(Gogetit.config, Gogetit.logger)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
82
112
|
# This feature is broken and might be deprecated in the future.
|
83
113
|
# desc 'rebuild NAME', 'Destroy and create either a container or KVM domain again.'
|
84
114
|
# def rebuild(type=nil, name)
|
data/lib/gogetit/maas.rb
CHANGED
@@ -28,6 +28,14 @@ module Gogetit
|
|
28
28
|
false
|
29
29
|
end
|
30
30
|
|
31
|
+
def get_distro_name(system_id)
|
32
|
+
logger.info("Calling <#{__method__.to_s}>")
|
33
|
+
conn.request(:get, ['machines']).each do |m|
|
34
|
+
return m['osystem'] if m['system_id'] == system_id
|
35
|
+
end
|
36
|
+
false
|
37
|
+
end
|
38
|
+
|
31
39
|
def dnsresource_exists?(name)
|
32
40
|
logger.info("Calling <#{__method__.to_s}>")
|
33
41
|
conn.request(:get, ['dnsresources']).each do |item|
|
@@ -201,6 +209,7 @@ module Gogetit
|
|
201
209
|
until conn.request(:get, ['machines', system_id])['status_name'] == state
|
202
210
|
sleep 3
|
203
211
|
end
|
212
|
+
logger.info("The status has become '#{state}'.")
|
204
213
|
end
|
205
214
|
|
206
215
|
def get_machine_state(system_id)
|
data/lib/gogetit/util.rb
CHANGED
@@ -141,7 +141,7 @@ module Gogetit
|
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
144
|
-
def wait_until_available(ip_or_fqdn, logger)
|
144
|
+
def wait_until_available(ip_or_fqdn, distro_name, logger)
|
145
145
|
logger.info("Calling <#{__method__.to_s}>")
|
146
146
|
until ping_available?(ip_or_fqdn, logger)
|
147
147
|
logger.info("Calling <#{__method__.to_s}> for ping to be ready..")
|
@@ -149,7 +149,7 @@ module Gogetit
|
|
149
149
|
end
|
150
150
|
logger.info("#{ip_or_fqdn} is now available to ping..")
|
151
151
|
|
152
|
-
until ssh_available?(ip_or_fqdn,
|
152
|
+
until ssh_available?(ip_or_fqdn, distro_name, logger)
|
153
153
|
logger.info("Calling <#{__method__.to_s}> for ssh to be ready..")
|
154
154
|
sleep 3
|
155
155
|
end
|
@@ -185,9 +185,9 @@ module Gogetit
|
|
185
185
|
return ifaces
|
186
186
|
end
|
187
187
|
|
188
|
-
def run_through_ssh(host, commands, logger)
|
188
|
+
def run_through_ssh(host, distro_name, commands, logger)
|
189
189
|
logger.info("Calling <#{__method__.to_s}>")
|
190
|
-
Net::SSH.start(host,
|
190
|
+
Net::SSH.start(host, distro_name) do |ssh|
|
191
191
|
commands.each do |cmd|
|
192
192
|
logger.info("'#{cmd}' is being executed..")
|
193
193
|
output = ssh.exec!(cmd)
|
data/lib/gogetit/version.rb
CHANGED
data/lib/providers/libvirt.rb
CHANGED
@@ -95,8 +95,8 @@ module Gogetit
|
|
95
95
|
if options['ipaddresses']
|
96
96
|
ifaces = check_ip_available(options['ipaddresses'], maas, logger)
|
97
97
|
domain = generate_nics(ifaces, domain)
|
98
|
-
elsif options[
|
99
|
-
#check_vlan_available(options[
|
98
|
+
elsif options['vlans']
|
99
|
+
#check_vlan_available(options['vlans'])
|
100
100
|
else
|
101
101
|
domain[:nic] = [
|
102
102
|
{
|
@@ -167,26 +167,39 @@ module Gogetit
|
|
167
167
|
|
168
168
|
end
|
169
169
|
|
170
|
-
elsif options[
|
171
|
-
#check_vlan_available(options[
|
170
|
+
elsif options['vlans']
|
171
|
+
#check_vlan_available(options['vlans'])
|
172
172
|
else
|
173
173
|
end
|
174
174
|
|
175
175
|
logger.info("Calling to deploy...")
|
176
|
-
|
176
|
+
|
177
|
+
distro = nil
|
178
|
+
if options['distro'].nil? or options['distro'].empty?
|
179
|
+
distro = 'xenial'
|
180
|
+
else
|
181
|
+
distro = options['distro']
|
182
|
+
end
|
183
|
+
|
184
|
+
maas.conn.request(:post, ['machines', system_id], \
|
185
|
+
{'op' => 'deploy', 'distro_series' => distro})
|
177
186
|
maas.wait_until_state(system_id, 'Deployed')
|
178
187
|
|
179
188
|
fqdn = name + '.' + maas.get_domain
|
180
|
-
|
189
|
+
distro_name = maas.get_distro_name(system_id)
|
190
|
+
wait_until_available(fqdn, distro_name, logger)
|
181
191
|
|
182
192
|
# To enable serial console to use 'virsh console'
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
193
|
+
if distro_name == 'ubuntu'
|
194
|
+
commands = [
|
195
|
+
'sudo systemctl enable serial-getty@ttyS0.service',
|
196
|
+
'sudo systemctl start serial-getty@ttyS0.service'
|
197
|
+
]
|
198
|
+
run_through_ssh(fqdn, commands, distro_name, logger)
|
199
|
+
end
|
188
200
|
|
189
201
|
logger.info("#{domain[:name]} has been created.")
|
202
|
+
puts "ssh #{distro_name}@#{name}"
|
190
203
|
true
|
191
204
|
end
|
192
205
|
|
@@ -225,6 +238,22 @@ module Gogetit
|
|
225
238
|
true
|
226
239
|
end
|
227
240
|
|
241
|
+
def release(name)
|
242
|
+
logger.info("Calling <#{__method__.to_s}>")
|
243
|
+
system_id = maas.get_system_id(name)
|
244
|
+
if maas.machine_exists?(name)
|
245
|
+
if maas.get_machine_state(system_id) == 'Deployed'
|
246
|
+
logger.info("Calling to release...")
|
247
|
+
maas.conn.request(:post, ['machines', system_id], {'op' => 'release'})
|
248
|
+
maas.wait_until_state(system_id, 'Ready')
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
maas.refresh_pods
|
253
|
+
logger.info("#{name} has been released.")
|
254
|
+
true
|
255
|
+
end
|
256
|
+
|
228
257
|
def define_domain(domain)
|
229
258
|
logger.info("Calling <#{__method__.to_s}>")
|
230
259
|
template = File.read(config[:lib_dir] + '/template/domain.xml')
|
data/lib/providers/lxd.rb
CHANGED
@@ -318,9 +318,6 @@ module Gogetit
|
|
318
318
|
ip_or_fqdn = name + '.' + maas.get_domain
|
319
319
|
end
|
320
320
|
|
321
|
-
wait_until_available(ip_or_fqdn, logger)
|
322
|
-
logger.info("#{name} has been created.")
|
323
|
-
|
324
321
|
if conn.execute_command(name, "ls /etc/lsb-release")[:metadata][:return] == 0
|
325
322
|
default_user = 'ubuntu'
|
326
323
|
elsif conn.execute_command(name, "ls /etc/redhat-release")[:metadata][:return] == 0
|
@@ -329,6 +326,9 @@ module Gogetit
|
|
329
326
|
default_user = config[:default][:user]
|
330
327
|
end
|
331
328
|
|
329
|
+
wait_until_available(ip_or_fqdn, default_user, logger)
|
330
|
+
logger.info("#{name} has been created.")
|
331
|
+
|
332
332
|
if options['no-maas']
|
333
333
|
puts "ssh #{default_user}@#{options['ip_to_access']}"
|
334
334
|
else
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gogetit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Don Draper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|