gogetit 0.8.0 → 0.9.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01a616e34651706a336ec6a266e45b0ea5facbb1
4
- data.tar.gz: 7a49f258a50d7b4d5f678daa02c9e67a9e5f19a9
3
+ metadata.gz: 2893781eb0a3fc67d8515b13aaaab0f25fb9f0f6
4
+ data.tar.gz: e2d9bcbfdbb819011e07c3c3143b187743fb4711
5
5
  SHA512:
6
- metadata.gz: ad0e68eaf277c1b05fb6fd1b9b0634f32b79bd30eee220db2b9ec4bfc3f9bfde500e6b326bf59c92d35055b07529846e6d243880a4c83643240ee1e21c3ccb23
7
- data.tar.gz: fe1334ef49fe38c0b5cbb9a1095176a75d8735a48c8c0c16cec008380086cd04af9f4c39046036a7ce896f4de6f8d75aab286f09fc03a2f92bc737f0a179aef0
6
+ metadata.gz: 3be3cc5ecabcf20b5ea652b2d58e8afdf96afb5c63c2ad76746da7e286b91d5f55f0b073583c7655124f5c2ccbdd07e53434980cd8938785df824e4fb7f8bb6f
7
+ data.tar.gz: f35c97aa197aeb6e7afe4e36f61017511fc4e90b4bf3369d12ce61dd7a8fe8c8b2449819d3a24c1ced7179e6162610358f947920a786b131d2566b9e7c0e311f
data/README.md CHANGED
@@ -63,6 +63,10 @@ gogetit create kvm01 -p lxd -a centos7
63
63
  # When specifying distro for Libvirt provider
64
64
  gogetit create kvm01 -p libvirt -d centos
65
65
 
66
+ # When deploying on an existing machine(only for libvirt provider)
67
+ gogetit deploy kvm01
68
+ gogetit deploy kvm01 -d centos
69
+
66
70
  # to create a LXD container without MAAS awareness
67
71
  gogetit create lxd01 --no-maas -f lxd_without_maas.yml
68
72
  gogetit create lxd01 --no-maas -f lxd_without_maas_vlans.yml
@@ -30,9 +30,9 @@ module Gogetit
30
30
  method_option :ipaddresses, :aliases => '-i', :type => :array, \
31
31
  :desc => 'A list of static IPs to assign'
32
32
  method_option :"no-maas", :type => :boolean, \
33
- :desc => 'Without MAAS awareness'
33
+ :desc => 'Without MAAS awareness(only for LXD provider)'
34
34
  method_option :"file", :aliases => '-f', :type => :string, \
35
- :desc => 'File location'
35
+ :desc => 'File location(only for LXD provider)'
36
36
  def create(name)
37
37
  abort("'vlans' and 'ipaddresses' can not be set together.") \
38
38
  if options['vlans'] and options['ipaddresses']
@@ -87,6 +87,21 @@ module Gogetit
87
87
  end
88
88
  end
89
89
 
90
+ desc 'deploy NAME', 'Deploy a node existing in MAAS.'
91
+ method_option :distro, :aliases => '-d', :type => :string, \
92
+ :desc => 'A distro name with its series for libvirt provider'
93
+ method_option :chef, :aliases => '-c', :type => :boolean, \
94
+ :default => false, :desc => 'Chef awareness'
95
+ def deploy(name)
96
+ Gogetit.libvirt.deploy(name, options.to_hash)
97
+
98
+ # post-tasks
99
+ if options['chef']
100
+ knife_bootstrap(name, options[:provider], Gogetit.config, Gogetit.logger)
101
+ update_databags(Gogetit.config, Gogetit.logger)
102
+ end
103
+ end
104
+
90
105
  desc 'release NAME', 'Release a node in MAAS'
91
106
  method_option :chef, :type => :boolean, :desc => "Enable chef awareness."
92
107
  def release(name)
@@ -1,3 +1,3 @@
1
1
  module Gogetit
2
- VERSION = "0.8.0"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -42,6 +42,11 @@ module Gogetit
42
42
  .value
43
43
  end
44
44
 
45
+ def get_domain_xml(domain_name)
46
+ logger.info("Calling <#{__method__.to_s}>")
47
+ Oga.parse_xml(conn.lookup_domain_by_name(domain_name).xml_desc)
48
+ end
49
+
45
50
  def generate_nics(ifaces, domain)
46
51
  abort("There is no dns server specified for the gateway network.") \
47
52
  unless ifaces[0]['dns_servers'][0]
@@ -85,13 +90,64 @@ module Gogetit
85
90
  return domain
86
91
  end
87
92
 
88
- # subject.create(name: 'test01')
93
+ def configure_interfaces(ifaces, system_id)
94
+
95
+ # It assumes you only have a physical interfaces.
96
+ interfaces = maas.interfaces([system_id])
97
+
98
+ maas.interfaces(
99
+ [system_id, interfaces[0]['id']],
100
+ {
101
+ 'op' => 'unlink_subnet',
102
+ 'id' => interfaces[0]['links'][0]['id']
103
+ }
104
+ )
105
+
106
+ # VLAN configuration
107
+ ifaces.each_with_index do |iface,index|
108
+ if index == 0
109
+ params = {
110
+ 'op' => 'link_subnet',
111
+ 'mode' => 'STATIC',
112
+ 'subnet' => ifaces[0]['id'],
113
+ 'ip_address' => ifaces[0]['ip'],
114
+ 'default_gateway' => 'True',
115
+ 'force' => 'False'
116
+ }
117
+ maas.interfaces([system_id, interfaces[0]['id']], params)
118
+
119
+ elsif index > 0
120
+ params = {
121
+ 'op' => 'create_vlan',
122
+ 'vlan' => iface['vlan']['id'],
123
+ 'parent' => interfaces[0]['id']
124
+ }
125
+ maas.interfaces([system_id], params)
126
+
127
+ interfaces = maas.interfaces([system_id])
128
+
129
+ params = {
130
+ 'op' => 'link_subnet',
131
+ 'mode' => 'STATIC',
132
+ 'subnet' => ifaces[index]['id'],
133
+ 'ip_address' => ifaces[index]['ip'],
134
+ 'default_gateway' => 'False',
135
+ 'force' => 'False'
136
+ }
137
+
138
+ maas.interfaces([system_id, interfaces[index]['id']], params)
139
+ end
140
+ end
141
+ end
142
+
89
143
  def create(name, options = nil)
90
144
  logger.info("Calling <#{__method__.to_s}>")
91
145
  abort("Domain #{name} already exists! Please check both on MAAS and libvirt.") \
92
146
  if maas.domain_name_exists?(name) or domain_exists?(name)
93
147
 
94
148
  domain = config[:libvirt][:specs][:default]
149
+ ifaces = nil
150
+
95
151
  if options['ipaddresses']
96
152
  ifaces = check_ip_available(options['ipaddresses'], maas, logger)
97
153
  domain = generate_nics(ifaces, domain)
@@ -115,58 +171,8 @@ module Gogetit
115
171
  system_id = maas.get_system_id(domain[:name])
116
172
  maas.wait_until_state(system_id, 'Ready')
117
173
 
118
- # To configure interfaces
119
174
  if options['ipaddresses']
120
-
121
- # It assumes you only have a physical interfaces.
122
- interfaces = maas.interfaces([system_id])
123
-
124
- maas.interfaces(
125
- [system_id, interfaces[0]['id']],
126
- {
127
- 'op' => 'unlink_subnet',
128
- 'id' => interfaces[0]['links'][0]['id']
129
- }
130
- )
131
-
132
- # VLAN configuration
133
- ifaces.each_with_index do |iface,index|
134
-
135
- if index == 0
136
- params = {
137
- 'op' => 'link_subnet',
138
- 'mode' => 'STATIC',
139
- 'subnet' => ifaces[0]['id'],
140
- 'ip_address' => ifaces[0]['ip'],
141
- 'default_gateway' => 'True',
142
- 'force' => 'False'
143
- }
144
- maas.interfaces([system_id, interfaces[0]['id']], params)
145
-
146
- elsif index > 0
147
- params = {
148
- 'op' => 'create_vlan',
149
- 'vlan' => iface['vlan']['id'],
150
- 'parent' => interfaces[0]['id']
151
- }
152
- maas.interfaces([system_id], params)
153
-
154
- interfaces = maas.interfaces([system_id])
155
-
156
- params = {
157
- 'op' => 'link_subnet',
158
- 'mode' => 'STATIC',
159
- 'subnet' => ifaces[index]['id'],
160
- 'ip_address' => ifaces[index]['ip'],
161
- 'default_gateway' => 'False',
162
- 'force' => 'False'
163
- }
164
-
165
- maas.interfaces([system_id, interfaces[index]['id']], params)
166
- end
167
-
168
- end
169
-
175
+ configure_interfaces(ifaces, system_id)
170
176
  elsif options['vlans']
171
177
  #check_vlan_available(options['vlans'])
172
178
  else
@@ -195,7 +201,7 @@ module Gogetit
195
201
  'sudo systemctl enable serial-getty@ttyS0.service',
196
202
  'sudo systemctl start serial-getty@ttyS0.service'
197
203
  ]
198
- run_through_ssh(fqdn, commands, distro_name, logger)
204
+ run_through_ssh(fqdn, distro_name, commands, logger)
199
205
  end
200
206
 
201
207
  logger.info("#{domain[:name]} has been created.")
@@ -238,6 +244,45 @@ module Gogetit
238
244
  true
239
245
  end
240
246
 
247
+ def deploy(name, options = nil)
248
+ logger.info("Calling <#{__method__.to_s}>")
249
+ abort("The machine, '#{name}', doesn't exist.") \
250
+ unless maas.machine_exists?(name)
251
+
252
+ system_id = maas.get_system_id(name)
253
+ maas.wait_until_state(system_id, 'Ready')
254
+
255
+ logger.info("Calling to deploy...")
256
+
257
+ distro = nil
258
+ if options['distro'].nil? or options['distro'].empty?
259
+ distro = 'xenial'
260
+ else
261
+ distro = options['distro']
262
+ end
263
+
264
+ maas.conn.request(:post, ['machines', system_id], \
265
+ {'op' => 'deploy', 'distro_series' => distro})
266
+ maas.wait_until_state(system_id, 'Deployed')
267
+
268
+ fqdn = name + '.' + maas.get_domain
269
+ distro_name = maas.get_distro_name(system_id)
270
+ wait_until_available(fqdn, distro_name, logger)
271
+
272
+ # To enable serial console to use 'virsh console'
273
+ if distro_name == 'ubuntu'
274
+ commands = [
275
+ 'sudo systemctl enable serial-getty@ttyS0.service',
276
+ 'sudo systemctl start serial-getty@ttyS0.service'
277
+ ]
278
+ run_through_ssh(fqdn, distro_name, commands, logger)
279
+ end
280
+
281
+ logger.info("#{name} has been created.")
282
+ puts "ssh #{distro_name}@#{name}"
283
+ true
284
+ end
285
+
241
286
  def release(name)
242
287
  logger.info("Calling <#{__method__.to_s}>")
243
288
  system_id = maas.get_system_id(name)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gogetit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Don Draper