gogetit 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/gogetit/cli.rb +14 -7
- data/lib/gogetit/util.rb +8 -8
- data/lib/gogetit/version.rb +1 -1
- data/lib/providers/libvirt.rb +8 -8
- data/lib/providers/lxd.rb +237 -184
- data/lib/sample_conf/gogetit.yml +1 -1
- data/lib/sample_conf/lxd_without_maas.yml +56 -0
- data/lib/sample_conf/lxd_without_maas_vlans.yml +48 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 148adb0a4d5bf1227bba264f035bf222b6a3c5bf
|
4
|
+
data.tar.gz: f8d3d1a7f5762574f08acdc470f663c7d103ae9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab49648f3d9db3e552b523716ab85f1271952249fc392a970f812212d3511812256d246e2f2e2d9336b15a550d11ecccc7ed12d089e31def95fbc46ce2662b4e
|
7
|
+
data.tar.gz: 547011a4d9d806019e802eb6e890080354f521b2ca048c170288e36442b270d268c9f68a7852c03a5c2227c895986060e92e1c229d03bc799013a13f6960fee0
|
data/README.md
CHANGED
@@ -56,6 +56,10 @@ 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
|
+
# to create a LXD container without MAAS awareness
|
60
|
+
gogetit create lxd01 --no-maas -f lxd_without_maas.yml
|
61
|
+
gogetit create lxd01 --no-maas -f lxd_without_maas_vlans.yml
|
62
|
+
|
59
63
|
# to provision with a bare metal machine
|
60
64
|
# gogetit create kvm01 -p bare
|
61
65
|
|
data/lib/gogetit/cli.rb
CHANGED
@@ -21,16 +21,25 @@ module Gogetit
|
|
21
21
|
:default => 'lxd', :desc => 'A provider such as lxd and libvirt'
|
22
22
|
method_option :chef, :aliases => '-c', :type => :boolean, \
|
23
23
|
:default => false, :desc => 'Chef awareness'
|
24
|
-
|
25
24
|
method_option :vlans, :aliases => '-v', :type => :array, \
|
26
25
|
:desc => 'A list of VLAN IDs to connect to'
|
27
26
|
method_option :ipaddresses, :aliases => '-i', :type => :array, \
|
28
27
|
:desc => 'A list of static IPs to assign'
|
28
|
+
method_option :"no-maas", :type => :boolean, \
|
29
|
+
:desc => 'Without MAAS awareness'
|
30
|
+
method_option :"file", :aliases => '-f', :type => :string, \
|
31
|
+
:desc => 'File location'
|
29
32
|
def create(name)
|
30
|
-
abort("vlans and ipaddresses can not be
|
33
|
+
abort("'vlans' and 'ipaddresses' can not be set together.") \
|
31
34
|
if options['vlans'] and options['ipaddresses']
|
32
35
|
|
33
|
-
|
36
|
+
abort("when 'no-maas', the network configuration have to be set by 'file'.") \
|
37
|
+
if options['no-maas'] and (options['vlans'] or options['ipaddresses'])
|
38
|
+
|
39
|
+
abort("'no-maas' and 'file' have to be set together.") \
|
40
|
+
if options['no-maas'] ^ !!options['file']
|
41
|
+
|
42
|
+
case options['provider']
|
34
43
|
when 'lxd'
|
35
44
|
Gogetit.lxd.create(name, options.to_hash)
|
36
45
|
when 'libvirt'
|
@@ -40,12 +49,10 @@ module Gogetit
|
|
40
49
|
end
|
41
50
|
|
42
51
|
# post-tasks
|
43
|
-
if options[
|
52
|
+
if options['chef']
|
44
53
|
knife_bootstrap(name, options[:provider], Gogetit.config, Gogetit.logger)
|
45
54
|
update_databags(Gogetit.config, Gogetit.logger)
|
46
55
|
end
|
47
|
-
Gogetit.config[:default][:user] ||= ENV['USER']
|
48
|
-
puts "ssh #{Gogetit.config[:default][:user]}@#{name}"
|
49
56
|
end
|
50
57
|
|
51
58
|
desc 'destroy NAME', 'Destroy either a container or KVM domain.'
|
@@ -64,7 +71,7 @@ module Gogetit
|
|
64
71
|
end
|
65
72
|
end
|
66
73
|
# post-tasks
|
67
|
-
if options[
|
74
|
+
if options['chef']
|
68
75
|
knife_remove(name, Gogetit.logger) if options[:chef]
|
69
76
|
update_databags(Gogetit.config, Gogetit.logger)
|
70
77
|
end
|
data/lib/gogetit/util.rb
CHANGED
@@ -141,32 +141,32 @@ module Gogetit
|
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
144
|
-
def wait_until_available(
|
144
|
+
def wait_until_available(ip_or_fqdn, logger)
|
145
145
|
logger.info("Calling <#{__method__.to_s}>")
|
146
|
-
until ping_available?(
|
146
|
+
until ping_available?(ip_or_fqdn, logger)
|
147
147
|
logger.info("Calling <#{__method__.to_s}> for ping to be ready..")
|
148
148
|
sleep 3
|
149
149
|
end
|
150
|
-
logger.info("#{
|
150
|
+
logger.info("#{ip_or_fqdn} is now available to ping..")
|
151
151
|
|
152
|
-
until ssh_available?(
|
152
|
+
until ssh_available?(ip_or_fqdn, 'ubuntu', logger)
|
153
153
|
logger.info("Calling <#{__method__.to_s}> for ssh to be ready..")
|
154
154
|
sleep 3
|
155
155
|
end
|
156
|
-
logger.info("#{
|
156
|
+
logger.info("#{ip_or_fqdn} is now available to ssh..")
|
157
157
|
end
|
158
158
|
|
159
159
|
def ping_available?(host, logger)
|
160
|
-
# host can be both IP and
|
160
|
+
# host can be both IP and ip_or_fqdn.
|
161
161
|
logger.info("Calling <#{__method__.to_s}> for #{host}")
|
162
162
|
`ping -c 1 -W 1 #{host}`
|
163
163
|
$?.exitstatus == 0
|
164
164
|
end
|
165
165
|
|
166
|
-
def ssh_available?(
|
166
|
+
def ssh_available?(ip_or_fqdn, user, logger)
|
167
167
|
logger.info("Calling <#{__method__.to_s}>")
|
168
168
|
begin
|
169
|
-
Net::SSH.start(
|
169
|
+
Net::SSH.start(ip_or_fqdn, user).class
|
170
170
|
rescue Exception => e
|
171
171
|
puts e
|
172
172
|
end
|
data/lib/gogetit/version.rb
CHANGED
data/lib/providers/libvirt.rb
CHANGED
@@ -59,13 +59,13 @@ module Gogetit
|
|
59
59
|
if index == 0
|
60
60
|
if iface['vlan']['name'] == 'untagged'
|
61
61
|
nic = {
|
62
|
-
network: config[:default][:
|
63
|
-
portgroup: config[:default][:
|
62
|
+
network: config[:default][:root_bridge],
|
63
|
+
portgroup: config[:default][:root_bridge]
|
64
64
|
}
|
65
65
|
elsif iface['vlan']['name'] != 'untagged'
|
66
66
|
nic = {
|
67
|
-
network: config[:default][:
|
68
|
-
portgroup: config[:default][:
|
67
|
+
network: config[:default][:root_bridge],
|
68
|
+
portgroup: config[:default][:root_bridge] + '-' + iface['vlan']['vid'].to_s
|
69
69
|
}
|
70
70
|
end
|
71
71
|
domain[:nic].push(nic)
|
@@ -75,8 +75,8 @@ module Gogetit
|
|
75
75
|
# This will not be hit as of now and might be deprecated.
|
76
76
|
if ifaces[0]['vlan']['name'] != 'untagged'
|
77
77
|
nic = {
|
78
|
-
network: config[:default][:
|
79
|
-
portgroup: config[:default][:
|
78
|
+
network: config[:default][:root_bridge],
|
79
|
+
portgroup: config[:default][:root_bridge] + '-' + iface['vlan']['vid'].to_s
|
80
80
|
}
|
81
81
|
domain[:nic].push(nic)
|
82
82
|
end
|
@@ -100,8 +100,8 @@ module Gogetit
|
|
100
100
|
else
|
101
101
|
domain[:nic] = [
|
102
102
|
{
|
103
|
-
network: config[:default][:
|
104
|
-
portgroup: config[:default][:
|
103
|
+
network: config[:default][:root_bridge],
|
104
|
+
portgroup: config[:default][:root_bridge]
|
105
105
|
}
|
106
106
|
]
|
107
107
|
end
|
data/lib/providers/lxd.rb
CHANGED
@@ -42,44 +42,77 @@ module Gogetit
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
|
45
|
+
# to generate 'user.user-data'
|
46
|
+
def generate_user_data(args, options)
|
46
47
|
logger.info("Calling <#{__method__.to_s}>")
|
47
|
-
args[:devices] = {}
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
unless ifaces[0]['dns_servers'][0]
|
52
|
-
abort("There is no gateway specified for the gateway network.") \
|
53
|
-
unless ifaces[0]['gateway_ip']
|
54
|
-
args[:ifaces] = ifaces
|
55
|
-
args[:config][:'user.network-config'] = {
|
56
|
-
'version' => 1,
|
57
|
-
'config' => [
|
58
|
-
{
|
59
|
-
'type' => 'nameserver',
|
60
|
-
'address' => ifaces[0]['dns_servers'][0]
|
61
|
-
}
|
62
|
-
]
|
63
|
-
}
|
49
|
+
args = {}
|
50
|
+
args[:config] = {}
|
64
51
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
52
|
+
if options['no-maas']
|
53
|
+
args[:config][:'user.user-data'] = \
|
54
|
+
YAML.load_file(options['file'])[:config]['user.user-data']
|
55
|
+
else
|
56
|
+
sshkeys = maas.get_sshkeys
|
57
|
+
pkg_repos = maas.get_package_repos
|
58
|
+
|
59
|
+
args[:config][:'user.user-data'] = { 'ssh_authorized_keys' => [] }
|
60
|
+
|
61
|
+
sshkeys.each do |key|
|
62
|
+
args[:config][:'user.user-data']['ssh_authorized_keys'].push(key['key'])
|
63
|
+
end
|
64
|
+
|
65
|
+
pkg_repos.each do |repo|
|
66
|
+
if repo['name'] == 'main_archive'
|
67
|
+
args[:config][:'user.user-data']['apt_mirror'] = repo['url']
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
args[:config][:"user.user-data"]['maas'] = true
|
72
|
+
end
|
73
|
+
|
74
|
+
# To disable to update apt database on first boot
|
75
|
+
# so chef client can keep doing its job.
|
76
|
+
args[:config][:'user.user-data']['package_update'] = false
|
77
|
+
|
78
|
+
args[:config][:"user.user-data"] = \
|
79
|
+
"#cloud-config\n" + YAML.dump(args[:config][:"user.user-data"])[4..-1]
|
80
|
+
|
81
|
+
return args
|
82
|
+
end
|
83
|
+
|
84
|
+
def generate_network_config(args, options)
|
85
|
+
logger.info("Calling <#{__method__.to_s}>")
|
86
|
+
if options['no-maas']
|
87
|
+
args[:config][:'user.network-config'] = \
|
88
|
+
YAML.load_file(options['file'])[:config][:'user.network-config']
|
89
|
+
|
90
|
+
options['ip_to_access'] = \
|
91
|
+
args[:config][:"user.network-config"]['config'][1]['subnets'][0]['address']
|
92
|
+
.split('/')[0]
|
93
|
+
args[:config][:"user.network-config"] = \
|
94
|
+
YAML.dump(args[:config][:"user.network-config"])[4..-1]
|
95
|
+
|
96
|
+
elsif options['ipaddresses']
|
97
|
+
options[:ifaces] = check_ip_available(options['ipaddresses'], maas, logger)
|
98
|
+
abort("There is no dns server specified for the gateway network.") \
|
99
|
+
unless options[:ifaces][0]['dns_servers'][0]
|
100
|
+
abort("There is no gateway specified for the gateway network.") \
|
101
|
+
unless options[:ifaces][0]['gateway_ip']
|
102
|
+
|
103
|
+
args[:config][:'user.network-config'] = {
|
104
|
+
'version' => 1,
|
105
|
+
'config' => [
|
106
|
+
{
|
107
|
+
'type' => 'nameserver',
|
108
|
+
'address' => options[:ifaces][0]['dns_servers'][0]
|
109
|
+
}
|
110
|
+
]
|
111
|
+
}
|
112
|
+
|
113
|
+
# to generate configuration for [:config][:'user.network-config']['config']
|
114
|
+
options[:ifaces].each_with_index do |iface,index|
|
115
|
+
if index == 0
|
83
116
|
iface_conf = {
|
84
117
|
'type' => 'physical',
|
85
118
|
'name' => "eth#{index}",
|
@@ -88,120 +121,102 @@ module Gogetit
|
|
88
121
|
'type' => 'static',
|
89
122
|
'ipv4' => true,
|
90
123
|
'address' => iface['ip'] + '/' + iface['cidr'].split('/')[1],
|
124
|
+
'gateway' => iface['gateway_ip'],
|
91
125
|
'mtu' => iface['vlan']['mtu'],
|
92
126
|
'control' => 'auto'
|
93
127
|
}
|
94
128
|
]
|
95
129
|
}
|
96
|
-
elsif
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
130
|
+
elsif index > 0
|
131
|
+
if options[:ifaces][0]['vlan']['name'] != 'untagged'
|
132
|
+
iface_conf = {
|
133
|
+
'type' => 'physical',
|
134
|
+
'name' => "eth#{index}",
|
135
|
+
'subnets' => [
|
136
|
+
{
|
137
|
+
'type' => 'static',
|
138
|
+
'ipv4' => true,
|
139
|
+
'address' => iface['ip'] + '/' + iface['cidr'].split('/')[1],
|
140
|
+
'mtu' => iface['vlan']['mtu'],
|
141
|
+
'control' => 'auto'
|
142
|
+
}
|
143
|
+
]
|
144
|
+
}
|
145
|
+
elsif options[:ifaces][0]['vlan']['name'] == 'untagged'
|
146
|
+
iface_conf = {
|
147
|
+
'type' => 'vlan',
|
148
|
+
'name' => "eth0.#{iface['vlan']['vid'].to_s}",
|
149
|
+
'vlan_id' => iface['vlan']['vid'].to_s,
|
150
|
+
'vlan_link' => 'eth0',
|
151
|
+
'subnets' => [
|
152
|
+
{
|
153
|
+
'type' => 'static',
|
154
|
+
'ipv4' => true,
|
155
|
+
'address' => iface['ip'] + '/' + iface['cidr'].split('/')[1],
|
156
|
+
'mtu' => iface['vlan']['mtu'],
|
157
|
+
'control' => 'auto'
|
158
|
+
}
|
159
|
+
]
|
160
|
+
}
|
161
|
+
end
|
112
162
|
end
|
163
|
+
|
164
|
+
args[:config][:'user.network-config']['config'].push(iface_conf)
|
113
165
|
end
|
114
166
|
|
115
|
-
args[:config][:
|
167
|
+
args[:config][:"user.network-config"] = \
|
168
|
+
YAML.dump(args[:config][:"user.network-config"])[4..-1]
|
116
169
|
end
|
117
170
|
|
118
|
-
args
|
119
|
-
|
171
|
+
return args
|
172
|
+
end
|
120
173
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
174
|
+
# To configure devices
|
175
|
+
def generate_devices(args, options)
|
176
|
+
args[:devices] = {}
|
177
|
+
|
178
|
+
if options['no-maas']
|
179
|
+
args[:devices] = \
|
180
|
+
YAML.load_file(options['file'])[:devices]
|
181
|
+
|
182
|
+
elsif options['ipaddresses']
|
183
|
+
options[:ifaces].each_with_index do |iface,index|
|
184
|
+
if index == 0
|
185
|
+
if iface['vlan']['name'] == 'untagged' # or vid == 0
|
186
|
+
args[:devices][:"eth#{index}"] = {
|
187
|
+
mtu: iface['vlan']['mtu'].to_s, #This must be string
|
188
|
+
name: "eth#{index}",
|
189
|
+
nictype: 'bridged',
|
190
|
+
parent: config[:default][:root_bridge],
|
191
|
+
type: 'nic'
|
192
|
+
}
|
193
|
+
elsif iface['vlan']['name'] != 'untagged' # or vid != 0
|
194
|
+
args[:devices][:"eth#{index}"] = {
|
195
|
+
mtu: iface['vlan']['mtu'].to_s, #This must be string
|
196
|
+
name: "eth#{index}",
|
197
|
+
nictype: 'bridged',
|
198
|
+
parent: config[:default][:root_bridge] + "-" + iface['vlan']['vid'].to_s,
|
199
|
+
type: 'nic'
|
200
|
+
}
|
201
|
+
end
|
202
|
+
# When options[:ifaces][0]['vlan']['name'] == 'untagged' and index > 0,
|
203
|
+
# it does not need to generate more devices
|
204
|
+
# since it will configure the IPs with tagged VLANs.
|
205
|
+
elsif options[:ifaces][0]['vlan']['name'] != 'untagged'
|
133
206
|
args[:devices][:"eth#{index}"] = {
|
134
207
|
mtu: iface['vlan']['mtu'].to_s, #This must be string
|
135
208
|
name: "eth#{index}",
|
136
209
|
nictype: 'bridged',
|
137
|
-
parent: config[:default][:
|
210
|
+
parent: config[:default][:root_bridge] + "-" + iface['vlan']['vid'].to_s,
|
138
211
|
type: 'nic'
|
139
212
|
}
|
140
213
|
end
|
141
|
-
# When ifaces[0]['vlan']['name'] == 'untagged' and index > 0,
|
142
|
-
# it does not need to generate more devices
|
143
|
-
# since it will configure the IPs with tagged VLANs.
|
144
|
-
elsif ifaces[0]['vlan']['name'] != 'untagged'
|
145
|
-
args[:devices][:"eth#{index}"] = {
|
146
|
-
mtu: iface['vlan']['mtu'].to_s, #This must be string
|
147
|
-
name: "eth#{index}",
|
148
|
-
nictype: 'bridged',
|
149
|
-
parent: config[:default][:native_bridge] + "-" + iface['vlan']['vid'].to_s,
|
150
|
-
type: 'nic'
|
151
|
-
}
|
152
214
|
end
|
153
|
-
end
|
154
|
-
|
155
|
-
return args
|
156
|
-
end
|
157
|
-
|
158
|
-
def generate_common_args
|
159
|
-
logger.info("Calling <#{__method__.to_s}>")
|
160
|
-
args = {}
|
161
|
-
sshkeys = maas.get_sshkeys
|
162
|
-
pkg_repos = maas.get_package_repos
|
163
|
-
|
164
|
-
args[:config] = {
|
165
|
-
'user.user-data': { 'ssh_authorized_keys' => [] }
|
166
|
-
}
|
167
|
-
|
168
|
-
sshkeys.each do |key|
|
169
|
-
args[:config][:'user.user-data']['ssh_authorized_keys'].push(key['key'])
|
170
|
-
end
|
171
|
-
|
172
|
-
# To disable to update apt database on first boot
|
173
|
-
# so chef client can keep doing its job.
|
174
|
-
args[:config][:'user.user-data']['package_update'] = false
|
175
|
-
|
176
|
-
pkg_repos.each do |repo|
|
177
|
-
if repo['name'] == 'main_archive'
|
178
|
-
args[:config][:'user.user-data']['apt_mirror'] = repo['url']
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
args[:config][:"user.user-data"] = \
|
183
|
-
YAML.dump(args[:config][:"user.user-data"])[4..-1]
|
184
|
-
|
185
|
-
args[:config][:"user.user-data"] = "#cloud-config\n" + args[:config][:"user.user-data"]
|
186
|
-
return args
|
187
|
-
end
|
188
|
-
|
189
|
-
def create(name, options = {})
|
190
|
-
logger.info("Calling <#{__method__.to_s}>")
|
191
|
-
abort("Container or Hostname #{name} already exists!") \
|
192
|
-
if container_exists?(name) or maas.domain_name_exists?(name)
|
193
|
-
|
194
|
-
args = generate_common_args
|
195
|
-
|
196
|
-
if options['ipaddresses']
|
197
|
-
args = generate_args(args, options)
|
198
|
-
elsif options[:vlans]
|
199
|
-
#check_vlan_available(options[:vlans])
|
200
215
|
else
|
201
|
-
abort("
|
202
|
-
unless conn.networks.include? config[:default][:
|
216
|
+
abort("root_bridge #{config[:default][:root_bridge]} does not exist.") \
|
217
|
+
unless conn.networks.include? config[:default][:root_bridge]
|
203
218
|
|
204
|
-
|
219
|
+
root_bridge_mtu = nil
|
205
220
|
# It assumes you only use one fabric as of now,
|
206
221
|
# since there might be more fabrics with each untagged vlans on them,
|
207
222
|
# which might make finding exact mtu fail as following process.
|
@@ -209,21 +224,72 @@ module Gogetit
|
|
209
224
|
|
210
225
|
maas.get_subnets.each do |subnet|
|
211
226
|
if subnet['vlan']['name'] == 'untagged' and subnet['vlan']['fabric'] == default_fabric
|
212
|
-
|
227
|
+
root_bridge_mtu = subnet['vlan']['mtu']
|
213
228
|
break
|
214
229
|
end
|
215
230
|
end
|
216
231
|
|
217
232
|
args[:devices] = {}
|
218
233
|
args[:devices][:"eth0"] = {
|
219
|
-
mtu:
|
234
|
+
mtu: root_bridge_mtu.to_s, #This must be string
|
220
235
|
name: 'eth0',
|
221
236
|
nictype: 'bridged',
|
222
|
-
parent: config[:default][:
|
237
|
+
parent: config[:default][:root_bridge],
|
223
238
|
type: 'nic'
|
224
239
|
}
|
225
240
|
end
|
226
241
|
|
242
|
+
return args
|
243
|
+
end
|
244
|
+
|
245
|
+
def reserve_ips(name, options, container)
|
246
|
+
# Generate params to reserve IPs
|
247
|
+
options[:ifaces].each_with_index do |iface,index|
|
248
|
+
if index == 0
|
249
|
+
params = {
|
250
|
+
'subnet' => iface['cidr'],
|
251
|
+
'ip' => iface['ip'],
|
252
|
+
'hostname' => name,
|
253
|
+
'mac' => container[:expanded_config][:"volatile.eth#{index}.hwaddr"]
|
254
|
+
}
|
255
|
+
elsif index > 0
|
256
|
+
# if dot, '.', is used as a conjunction instead of '-',
|
257
|
+
# it fails ocuring '404 not found'.
|
258
|
+
# if under score, '_', is used as a conjunction instead of '-',
|
259
|
+
# it breaks MAAS DNS somehow..
|
260
|
+
if options[:ifaces][0]['vlan']['name'] == 'untagged'
|
261
|
+
params = {
|
262
|
+
'subnet' => iface['cidr'],
|
263
|
+
'ip' => iface['ip'],
|
264
|
+
'hostname' => 'eth0' + '-' + iface['vlan']['vid'].to_s + '-' + name,
|
265
|
+
'mac' => container[:expanded_config][:"volatile.eth0.hwaddr"]
|
266
|
+
}
|
267
|
+
elsif options[:ifaces][0]['vlan']['name'] != 'untagged'
|
268
|
+
params = {
|
269
|
+
'subnet' => iface['cidr'],
|
270
|
+
'ip' => iface['ip'],
|
271
|
+
'hostname' => "eth#{index}" + '-' + name,
|
272
|
+
'mac' => container[:expanded_config][:"volatile.eth#{index}.hwaddr"]
|
273
|
+
}
|
274
|
+
end
|
275
|
+
end
|
276
|
+
maas.ipaddresses('reserve', params)
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
def create(name, options = {})
|
281
|
+
logger.info("Calling <#{__method__.to_s}>")
|
282
|
+
|
283
|
+
abort("Container #{name} already exists!") \
|
284
|
+
if container_exists?(name)
|
285
|
+
|
286
|
+
abort("Domain #{name}.#{maas.get_domain} already exists!") \
|
287
|
+
if maas.domain_name_exists?(name) unless options['no-maas']
|
288
|
+
|
289
|
+
args = generate_user_data(args, options)
|
290
|
+
args = generate_network_config(args, options)
|
291
|
+
args = generate_devices(args, options)
|
292
|
+
|
227
293
|
args[:alias] ||= config[:lxd][:default_alias]
|
228
294
|
args[:sync] ||= true
|
229
295
|
|
@@ -235,46 +301,28 @@ module Gogetit
|
|
235
301
|
# Fetch container object again
|
236
302
|
container = conn.container(name)
|
237
303
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
if index == 0
|
242
|
-
params = {
|
243
|
-
'subnet' => iface['cidr'],
|
244
|
-
'ip' => iface['ip'],
|
245
|
-
'hostname' => name,
|
246
|
-
'mac' => container[:expanded_config][:"volatile.eth#{index}.hwaddr"]
|
247
|
-
}
|
248
|
-
elsif index > 0
|
249
|
-
# if dot, '.', is used as a conjunction instead of '-',
|
250
|
-
# it fails ocuring '404 not found'.
|
251
|
-
# if under score, '_', is used as a conjunction instead of '-',
|
252
|
-
# it breaks MAAS DNS somehow..
|
253
|
-
if args[:ifaces][0]['vlan']['name'] == 'untagged'
|
254
|
-
params = {
|
255
|
-
'subnet' => iface['cidr'],
|
256
|
-
'ip' => iface['ip'],
|
257
|
-
'hostname' => 'eth0' + '-' + iface['vlan']['vid'].to_s + '-' + name,
|
258
|
-
'mac' => container[:expanded_config][:"volatile.eth0.hwaddr"]
|
259
|
-
}
|
260
|
-
elsif args[:ifaces][0]['vlan']['name'] != 'untagged'
|
261
|
-
params = {
|
262
|
-
'subnet' => iface['cidr'],
|
263
|
-
'ip' => iface['ip'],
|
264
|
-
'hostname' => "eth#{index}" + '-' + name,
|
265
|
-
'mac' => container[:expanded_config][:"volatile.eth#{index}.hwaddr"]
|
266
|
-
}
|
267
|
-
end
|
268
|
-
end
|
269
|
-
maas.ipaddresses('reserve', params)
|
270
|
-
end
|
271
|
-
end
|
304
|
+
reserve_ips(name, options, container) \
|
305
|
+
if options['vlans'] or options['ipaddresses'] \
|
306
|
+
unless options['no-maas']
|
272
307
|
|
273
308
|
conn.start_container(name, :sync=>"true")
|
274
309
|
|
275
|
-
|
276
|
-
|
310
|
+
if options['no-maas']
|
311
|
+
ip_or_fqdn = options['ip_to_access']
|
312
|
+
else
|
313
|
+
ip_or_fqdn = name + '.' + maas.get_domain
|
314
|
+
end
|
315
|
+
|
316
|
+
wait_until_available(ip_or_fqdn, logger)
|
277
317
|
logger.info("#{name} has been created.")
|
318
|
+
|
319
|
+
config[:default][:user] ||= ENV['USER']
|
320
|
+
if options['no-maas']
|
321
|
+
puts "ssh #{config[:default][:user]}@#{options['ip_to_access']}"
|
322
|
+
else
|
323
|
+
puts "ssh #{config[:default][:user]}@#{name}"
|
324
|
+
end
|
325
|
+
|
278
326
|
true
|
279
327
|
end
|
280
328
|
|
@@ -289,31 +337,36 @@ module Gogetit
|
|
289
337
|
end
|
290
338
|
|
291
339
|
wait_until_state(name, 'Stopped')
|
292
|
-
conn.delete_container(name, args)
|
293
340
|
|
294
|
-
if container[:config][:"user.
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
341
|
+
if YAML.load(container[:config][:"user.user-data"])['maas']
|
342
|
+
logger.info("This is a MAAS enabled container.")
|
343
|
+
if container[:config][:"user.network-config"]
|
344
|
+
net_conf = YAML.load(
|
345
|
+
container[:config][:"user.network-config"]
|
346
|
+
)['config']
|
347
|
+
# To remove DNS configuration
|
348
|
+
net_conf.shift
|
349
|
+
|
350
|
+
net_conf.each do |nic|
|
351
|
+
if nic['subnets'][0]['type'] == 'static'
|
352
|
+
# It assumes we only assign a single subnet on a VLAN.
|
353
|
+
# Subnets in a VLAN, VLANs in a Fabric
|
354
|
+
ip = nic['subnets'][0]['address'].split('/')[0]
|
355
|
+
|
356
|
+
if maas.ipaddresses_reserved?(ip)
|
357
|
+
maas.ipaddresses('release', { 'ip' => ip })
|
358
|
+
end
|
309
359
|
end
|
310
360
|
end
|
311
361
|
end
|
362
|
+
|
363
|
+
maas.delete_dns_record(name)
|
312
364
|
end
|
313
365
|
|
366
|
+
conn.delete_container(name, args)
|
367
|
+
|
314
368
|
# When multiple static IPs were reserved, it will not delete anything
|
315
369
|
# since they are deleted when releasing the IPs above.
|
316
|
-
maas.delete_dns_record(name)
|
317
370
|
logger.info("#{name} has been destroyed.")
|
318
371
|
true
|
319
372
|
end
|
data/lib/sample_conf/gogetit.yml
CHANGED
@@ -0,0 +1,56 @@
|
|
1
|
+
---
|
2
|
+
:config:
|
3
|
+
:user.network-config:
|
4
|
+
version: 1
|
5
|
+
config:
|
6
|
+
- type: nameserver
|
7
|
+
address: $maas_ip
|
8
|
+
- type: physical
|
9
|
+
name: eth0
|
10
|
+
subnets:
|
11
|
+
- type: static
|
12
|
+
ipv4: true
|
13
|
+
address: 192.168.112.10/24
|
14
|
+
gateway: 192.168.112.1
|
15
|
+
mtu: 8954
|
16
|
+
control: auto
|
17
|
+
- type: physical
|
18
|
+
name: eth1
|
19
|
+
subnets:
|
20
|
+
- type: static
|
21
|
+
ipv4: true
|
22
|
+
address: 192.168.113.10/24
|
23
|
+
mtu: 8954
|
24
|
+
control: auto
|
25
|
+
- type: physical
|
26
|
+
name: eth2
|
27
|
+
subnets:
|
28
|
+
- type: static
|
29
|
+
ipv4: true
|
30
|
+
address: 192.168.114.10/24
|
31
|
+
mtu: 8954
|
32
|
+
control: auto
|
33
|
+
user.user-data:
|
34
|
+
ssh_authorized_keys:
|
35
|
+
- ssh-rsa blahblah someone1@somewhere1
|
36
|
+
- ssh-rsa blahblah someone2@somewhere2
|
37
|
+
apt_mirror: http://kr.archive.ubuntu.com/ubuntu
|
38
|
+
:devices:
|
39
|
+
eth0:
|
40
|
+
mtu: "8954"
|
41
|
+
name: eth0
|
42
|
+
nictype: bridged
|
43
|
+
parent: $root_bridge-112
|
44
|
+
type: nic
|
45
|
+
eth1:
|
46
|
+
mtu: "8954"
|
47
|
+
name: eth1
|
48
|
+
nictype: bridged
|
49
|
+
parent: $root_bridge-113
|
50
|
+
type: nic
|
51
|
+
eth2:
|
52
|
+
mtu: "8954"
|
53
|
+
name: eth2
|
54
|
+
nictype: bridged
|
55
|
+
parent: $root_bridge-114
|
56
|
+
type: nic
|
@@ -0,0 +1,48 @@
|
|
1
|
+
---
|
2
|
+
:config:
|
3
|
+
:user.network-config:
|
4
|
+
version: 1
|
5
|
+
config:
|
6
|
+
- type: nameserver
|
7
|
+
address: $maas_ip
|
8
|
+
- type: physical
|
9
|
+
name: eth0
|
10
|
+
subnets:
|
11
|
+
- type: static
|
12
|
+
ipv4: true
|
13
|
+
address: 192.168.111.10/24
|
14
|
+
gateway: 192.168.111.1
|
15
|
+
mtu: 8954
|
16
|
+
control: auto
|
17
|
+
- type: vlan
|
18
|
+
name: eth0.112
|
19
|
+
vlan_id: '112'
|
20
|
+
vlan_link: eth0
|
21
|
+
subnets:
|
22
|
+
- type: static
|
23
|
+
ipv4: true
|
24
|
+
address: 192.168.112.10/24
|
25
|
+
mtu: 8954
|
26
|
+
control: auto
|
27
|
+
- type: vlan
|
28
|
+
name: eth0.113
|
29
|
+
vlan_id: '113'
|
30
|
+
vlan_link: eth0
|
31
|
+
subnets:
|
32
|
+
- type: static
|
33
|
+
ipv4: true
|
34
|
+
address: 192.168.113.10/24
|
35
|
+
mtu: 8954
|
36
|
+
control: auto
|
37
|
+
user.user-data:
|
38
|
+
ssh_authorized_keys:
|
39
|
+
- ssh-rsa blahblahblah someone1@somewhere1
|
40
|
+
- ssh-rsa blahblahblah someone2@somewhere2
|
41
|
+
apt_mirror: http://kr.archive.ubuntu.com/ubuntu
|
42
|
+
:devices:
|
43
|
+
:eth0:
|
44
|
+
:mtu: '8954'
|
45
|
+
:name: eth0
|
46
|
+
:nictype: bridged
|
47
|
+
:parent: $root_bridge
|
48
|
+
:type: nic
|
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.5.
|
4
|
+
version: 0.5.3
|
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-10-
|
11
|
+
date: 2017-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -217,6 +217,8 @@ files:
|
|
217
217
|
- lib/providers/lxd.rb
|
218
218
|
- lib/sample_conf/gogetit.yml
|
219
219
|
- lib/sample_conf/lxd_profile.yml
|
220
|
+
- lib/sample_conf/lxd_without_maas.yml
|
221
|
+
- lib/sample_conf/lxd_without_maas_vlans.yml
|
220
222
|
- lib/template/disk.xml
|
221
223
|
- lib/template/domain.xml
|
222
224
|
- lib/template/nic.xml
|