gogetit 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2893781eb0a3fc67d8515b13aaaab0f25fb9f0f6
4
- data.tar.gz: e2d9bcbfdbb819011e07c3c3143b187743fb4711
3
+ metadata.gz: 90850298a6e02e953b7f0ebb6ed8e7cd7a4d47bd
4
+ data.tar.gz: 2f5fca754895bcf3f5342b952c08b81a7819d64f
5
5
  SHA512:
6
- metadata.gz: 3be3cc5ecabcf20b5ea652b2d58e8afdf96afb5c63c2ad76746da7e286b91d5f55f0b073583c7655124f5c2ccbdd07e53434980cd8938785df824e4fb7f8bb6f
7
- data.tar.gz: f35c97aa197aeb6e7afe4e36f61017511fc4e90b4bf3369d12ce61dd7a8fe8c8b2449819d3a24c1ced7179e6162610358f947920a786b131d2566b9e7c0e311f
6
+ metadata.gz: ee71a4680053f4b696bdebeceb9e366a97484f0ba1a2f2ea1a64aa3d121e24e9364a2536fb6c9848990ab5c097d29af5edb451b9677391669b57221dcd01ec14
7
+ data.tar.gz: 83b2a138facc3e1b9616a737f7277baf204a6b763ff329a91f9aa23f7372657f1fcddd3923250968e49cce66cec8f3a13a59cbdecc50d4d4f13d0f55b8f6ded4
data/README.md CHANGED
@@ -97,13 +97,6 @@ gogetit release node01
97
97
  ```ruby
98
98
  require 'gogetit'
99
99
  ```
100
- ## To make Gogetit recognize data bag that needs to be encrypted by Vault
101
- - Fill this out!
102
-
103
- ## To develop
104
- - Deploying bare metal machine from machine pool
105
- - Static IP auto-assignment with VLAN info
106
- - Working with Multiple LXD and Libvirt hosts
107
100
 
108
101
  ## To document
109
102
  - How to make Gogetit recognize vault data bag items
@@ -117,6 +110,9 @@ Clone and then execute followings:
117
110
 
118
111
  Questions, pull requests, advices and suggestions are always welcome!
119
112
 
113
+ ## rubygems
114
+ [https://rubygems.org/gems/gogetit](https://rubygems.org/gems/gogetit)
115
+
120
116
  ## License
121
117
 
122
118
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/lib/gogetit/cli.rb CHANGED
@@ -3,10 +3,28 @@ require 'gogetit'
3
3
  require 'gogetit/util'
4
4
 
5
5
  module Gogetit
6
+
7
+ @@result = nil
8
+
9
+ def self.set_result(x)
10
+ @@result = x
11
+ end
12
+
13
+ def self.get_result
14
+ @@result
15
+ end
16
+
6
17
  class CLI < Thor
7
18
  include Gogetit::Util
8
19
  package_name 'Gogetit'
9
20
 
21
+ # attr_accessor :result
22
+
23
+ # def initialize(*args)
24
+ # super
25
+ # @result = nil
26
+ # end
27
+
10
28
  desc 'list', 'List containers and instances, running currently.'
11
29
  def list
12
30
  puts "Listing LXD containers on #{Gogetit.config[:lxd][:nodes][0][:url]}.."
@@ -51,9 +69,11 @@ module Gogetit
51
69
 
52
70
  case options['provider']
53
71
  when 'lxd'
54
- Gogetit.lxd.create(name, options.to_hash)
72
+ result = Gogetit.lxd.create(name, options.to_hash)
73
+ Gogetit.set_result(result)
55
74
  when 'libvirt'
56
- Gogetit.libvirt.create(name, options.to_hash)
75
+ result = Gogetit.libvirt.create(name, options.to_hash)
76
+ Gogetit.set_result(result)
57
77
  else
58
78
  abort('Invalid argument entered.')
59
79
  end
@@ -73,9 +93,11 @@ module Gogetit
73
93
  if provider
74
94
  case provider
75
95
  when 'lxd'
76
- Gogetit.lxd.destroy(name)
96
+ result = Gogetit.lxd.destroy(name)
97
+ Gogetit.set_result(result)
77
98
  when 'libvirt'
78
- Gogetit.libvirt.destroy(name)
99
+ result = Gogetit.libvirt.destroy(name)
100
+ Gogetit.set_result(result)
79
101
  else
80
102
  abort('Invalid argument entered.')
81
103
  end
@@ -93,7 +115,7 @@ module Gogetit
93
115
  method_option :chef, :aliases => '-c', :type => :boolean, \
94
116
  :default => false, :desc => 'Chef awareness'
95
117
  def deploy(name)
96
- Gogetit.libvirt.deploy(name, options.to_hash)
118
+ Gogetit.set_result(Gogetit.libvirt.deploy(name, options.to_hash))
97
119
 
98
120
  # post-tasks
99
121
  if options['chef']
@@ -105,14 +127,35 @@ module Gogetit
105
127
  desc 'release NAME', 'Release a node in MAAS'
106
128
  method_option :chef, :type => :boolean, :desc => "Enable chef awareness."
107
129
  def release(name)
130
+ result = Gogetit.libvirt.release(name)
131
+ Gogetit.set_result(result)
132
+
133
+ # post-tasks
134
+ if options['chef']
135
+ knife_remove(name, Gogetit.logger) if options[:chef]
136
+ update_databags(Gogetit.config, Gogetit.logger)
137
+ end
138
+ end
139
+
140
+ desc 'rebuild NAME', 'Destroy(or release) and create(or deploy)'\
141
+ ' either a container or a node(machine) in MAAS again.'
142
+ method_option :chef, :aliases => '-c', :type => :boolean, \
143
+ :default => false, :desc => 'Chef awareness'
144
+ def rebuild(name)
108
145
  # Let Gogetit recognize the provider.
109
146
  provider = Gogetit.get_provider_of(name)
110
147
  if provider
111
148
  case provider
112
149
  when 'lxd'
113
- abort('This method is not available for LXD container.')
150
+ invoke :destroy, [name]
151
+ alias_name = YAML.load(
152
+ Gogetit.get_result[:info][:config][:"user.user-data"]
153
+ )['source_image_alias']
154
+ invoke :create, [name], :alias => alias_name
114
155
  when 'libvirt'
115
- Gogetit.libvirt.release(name)
156
+ invoke :release, [name]
157
+ distro_name = Gogetit.get_result[:info][:machine]['distro_series']
158
+ invoke :deploy, [name], :distro => distro_name
116
159
  else
117
160
  abort('Invalid argument entered.')
118
161
  end
@@ -123,12 +166,5 @@ module Gogetit
123
166
  update_databags(Gogetit.config, Gogetit.logger)
124
167
  end
125
168
  end
126
-
127
- # This feature is broken and might be deprecated in the future.
128
- # desc 'rebuild NAME', 'Destroy and create either a container or KVM domain again.'
129
- # def rebuild(type=nil, name)
130
- # invoke :destroy, [name]
131
- # invoke :create, [type, name]
132
- # end
133
169
  end
134
170
  end
data/lib/gogetit/util.rb CHANGED
@@ -72,12 +72,14 @@ module Gogetit
72
72
  if JSON.parse(File.read(item_file))['vault']
73
73
  if items_as_is.include? item
74
74
  run_command(
75
- "knife vault update #{bag} #{item} --json #{item_file} --search '*:*' -M client",
75
+ "knife vault update #{bag} #{item} --json #{item_file}"\
76
+ " --search '*:*' -M client",
76
77
  logger
77
78
  )
78
79
  else
79
80
  run_command(
80
- "knife vault create #{bag} #{item} --json #{item_file} --search '*:*' -M client",
81
+ "knife vault create #{bag} #{item} --json #{item_file}"\
82
+ " --search '*:*' -M client",
81
83
  logger
82
84
  )
83
85
  end
@@ -1,3 +1,3 @@
1
1
  module Gogetit
2
- VERSION = "0.9.0"
2
+ VERSION = "0.10.0"
3
3
  end
@@ -54,7 +54,8 @@ module Gogetit
54
54
  unless ifaces[0]['gateway_ip']
55
55
 
56
56
  # It seems the first IP has to belong to the untagged VLAN in the Fabric.
57
- abort("The first IP you entered does not belong to the untagged VLAN in the Fabric.") \
57
+ abort("The first IP you entered does not belong to the untagged"\
58
+ " VLAN in the Fabric.") \
58
59
  unless ifaces[0]['vlan']['name'] == 'untagged'
59
60
 
60
61
  domain[:ifaces] = ifaces
@@ -70,7 +71,8 @@ module Gogetit
70
71
  elsif iface['vlan']['name'] != 'untagged'
71
72
  nic = {
72
73
  network: config[:default][:root_bridge],
73
- portgroup: config[:default][:root_bridge] + '-' + iface['vlan']['vid'].to_s
74
+ portgroup: config[:default][:root_bridge] + '-' + \
75
+ iface['vlan']['vid'].to_s
74
76
  }
75
77
  end
76
78
  domain[:nic].push(nic)
@@ -81,7 +83,8 @@ module Gogetit
81
83
  if ifaces[0]['vlan']['name'] != 'untagged'
82
84
  nic = {
83
85
  network: config[:default][:root_bridge],
84
- portgroup: config[:default][:root_bridge] + '-' + iface['vlan']['vid'].to_s
86
+ portgroup: config[:default][:root_bridge] + '-' + \
87
+ iface['vlan']['vid'].to_s
85
88
  }
86
89
  domain[:nic].push(nic)
87
90
  end
@@ -142,7 +145,8 @@ module Gogetit
142
145
 
143
146
  def create(name, options = nil)
144
147
  logger.info("Calling <#{__method__.to_s}>")
145
- abort("Domain #{name} already exists! Please check both on MAAS and libvirt.") \
148
+ abort("Domain #{name} already exists!"\
149
+ " Please check both on MAAS and libvirt.") \
146
150
  if maas.domain_name_exists?(name) or domain_exists?(name)
147
151
 
148
152
  domain = config[:libvirt][:specs][:default]
@@ -206,12 +210,19 @@ module Gogetit
206
210
 
207
211
  logger.info("#{domain[:name]} has been created.")
208
212
  puts "ssh #{distro_name}@#{name}"
209
- true
213
+
214
+ { result: true, info: domain }
210
215
  end
211
216
 
212
217
  def destroy(name)
213
218
  logger.info("Calling <#{__method__.to_s}>")
219
+
214
220
  system_id = maas.get_system_id(name)
221
+
222
+ info = {}
223
+ info[:machine] = \
224
+ maas.conn.request(:get, ['machines', system_id])
225
+
215
226
  if maas.machine_exists?(name)
216
227
  if maas.get_machine_state(system_id) == 'Deployed'
217
228
  logger.info("Calling to release...")
@@ -227,11 +238,14 @@ module Gogetit
227
238
  end
228
239
 
229
240
  dom = conn.lookup_domain_by_name(name)
241
+ info[:domain_xml] = dom.xml_desc
242
+
230
243
  dom.destroy if dom.active?
231
244
  Oga.parse_xml(dom.xml_desc).xpath('domain/devices/disk/source').each do |d|
232
245
  pool_path = d.attribute('file').value.split('/')[0..2].join('/')
233
246
  pools.each do |p|
234
- if Oga.parse_xml(p.xml_desc).at_xpath('pool/target/path').inner_text == pool_path
247
+ if Oga.parse_xml(p.xml_desc).at_xpath('pool/target/path')\
248
+ .inner_text == pool_path
235
249
  logger.info("Deleting volume in #{p.name} pool.")
236
250
  p.lookup_volume_by_name(d.attribute('file').value.split('/')[3]).delete
237
251
  end
@@ -239,9 +253,9 @@ module Gogetit
239
253
  end
240
254
  dom.undefine
241
255
 
242
- maas.refresh_pods
243
256
  logger.info("#{name} has been destroyed.")
244
- true
257
+
258
+ { result: true, info: info }
245
259
  end
246
260
 
247
261
  def deploy(name, options = nil)
@@ -280,12 +294,18 @@ module Gogetit
280
294
 
281
295
  logger.info("#{name} has been created.")
282
296
  puts "ssh #{distro_name}@#{name}"
283
- true
297
+ { result: true, info: distro }
284
298
  end
285
299
 
286
300
  def release(name)
287
301
  logger.info("Calling <#{__method__.to_s}>")
302
+
288
303
  system_id = maas.get_system_id(name)
304
+
305
+ info = {}
306
+ info[:machine] = \
307
+ maas.conn.request(:get, ['machines', system_id])
308
+
289
309
  if maas.machine_exists?(name)
290
310
  if maas.get_machine_state(system_id) == 'Deployed'
291
311
  logger.info("Calling to release...")
@@ -294,9 +314,9 @@ module Gogetit
294
314
  end
295
315
  end
296
316
 
297
- maas.refresh_pods
298
317
  logger.info("#{name} has been released.")
299
- true
318
+
319
+ { result: true, info: info }
300
320
  end
301
321
 
302
322
  def define_domain(domain)
@@ -368,9 +388,11 @@ module Gogetit
368
388
 
369
389
  volume_doc.at_xpath('volume/name').inner_text = volume_name
370
390
  volume_doc.at_xpath('volume/target/path').inner_text = volume_file
371
- volume_doc.at_xpath('volume/capacity').inner_text = domain[:disk][:root][:capacity].to_s
391
+ volume_doc.at_xpath('volume/capacity').inner_text = \
392
+ domain[:disk][:root][:capacity].to_s
372
393
 
373
- create_volume(domain[:disk][:root][:pool], Oga::XML::Generator.new(volume_doc).to_xml)
394
+ create_volume(domain[:disk][:root][:pool], \
395
+ Oga::XML::Generator.new(volume_doc).to_xml)
374
396
  defined_volumes << volume_doc
375
397
 
376
398
  # For data(secondary) volumes
data/lib/providers/lxd.rb CHANGED
@@ -46,7 +46,6 @@ module Gogetit
46
46
  def generate_user_data(args, options)
47
47
  logger.info("Calling <#{__method__.to_s}>")
48
48
 
49
- args = {}
50
49
  args[:config] = {}
51
50
 
52
51
  if options['no-maas']
@@ -69,6 +68,7 @@ module Gogetit
69
68
  end
70
69
 
71
70
  args[:config][:"user.user-data"]['maas'] = true
71
+ args[:config][:"user.user-data"]['source_image_alias'] = args[:alias]
72
72
  end
73
73
 
74
74
  # To disable to update apt database on first boot
@@ -223,7 +223,8 @@ module Gogetit
223
223
  default_fabric = 'fabric-0'
224
224
 
225
225
  maas.get_subnets.each do |subnet|
226
- if subnet['vlan']['name'] == 'untagged' and subnet['vlan']['fabric'] == default_fabric
226
+ if subnet['vlan']['name'] == 'untagged' and \
227
+ subnet['vlan']['fabric'] == default_fabric
227
228
  root_bridge_mtu = subnet['vlan']['mtu']
228
229
  break
229
230
  end
@@ -286,9 +287,7 @@ module Gogetit
286
287
  abort("Domain #{name}.#{maas.get_domain} already exists!") \
287
288
  if maas.domain_name_exists?(name) unless options['no-maas']
288
289
 
289
- args = generate_user_data(args, options)
290
- args = generate_network_config(args, options)
291
- args = generate_devices(args, options)
290
+ args = {}
292
291
 
293
292
  if options['alias'].nil? or options['alias'].empty?
294
293
  args[:alias] = config[:lxd][:default_alias]
@@ -296,6 +295,10 @@ module Gogetit
296
295
  args[:alias] = options['alias']
297
296
  end
298
297
 
298
+ args = generate_user_data(args, options)
299
+ args = generate_network_config(args, options)
300
+ args = generate_devices(args, options)
301
+
299
302
  args[:sync] ||= true
300
303
 
301
304
  conn.create_container(name, args)
@@ -335,7 +338,7 @@ module Gogetit
335
338
  puts "ssh #{default_user}@#{name}"
336
339
  end
337
340
 
338
- true
341
+ { result: true, info: args }
339
342
  end
340
343
 
341
344
  def destroy(name, args = {})
@@ -344,6 +347,8 @@ module Gogetit
344
347
  container = conn.container(name)
345
348
  args[:sync] ||= true
346
349
 
350
+ info = container.to_hash
351
+
347
352
  if get_state(name) == 'Running'
348
353
  conn.stop_container(name, args)
349
354
  end
@@ -380,7 +385,8 @@ module Gogetit
380
385
  # When multiple static IPs were reserved, it will not delete anything
381
386
  # since they are deleted when releasing the IPs above.
382
387
  logger.info("#{name} has been destroyed.")
383
- true
388
+
389
+ { result: true, info: info }
384
390
  end
385
391
  end
386
392
  end
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.9.0
4
+ version: 0.10.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-12 00:00:00.000000000 Z
11
+ date: 2017-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler