nub 0.0.136 → 0.0.138

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nub/net.rb +9 -5
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc637d2de51ea4c4473d8659baae4e93f479e210825735eac4810ac504a802a6
4
- data.tar.gz: 244953131f4c7bf9e89f9f6f5320d18691f1fb6db134c40de79388cb1a86800e
3
+ metadata.gz: 89f02089be4f4ce91020479f5812fa4089143e32e73eced4c65ce5f2f1cf0b54
4
+ data.tar.gz: 245d02777cfe330471fa7b50d801f1c0044ed8a5df9dabf6eb1bdf8db82bde7a
5
5
  SHA512:
6
- metadata.gz: f6f526accb8fdfad3a18c5ac1b1f4a709f468d620560fcfa2ac545f2057fc4b93ad1c8b88f406f85381846b4cba1ae91f48092945d4054cbac0fb044c2842c41
7
- data.tar.gz: 6d64c6c44ff233cc4dd781837eef8bad11ce2944804ee27623c914778d2d851630d82fa22231064182a065b2fc6bab39dc9b39a4d85eb49226f6233d1896ad6d
6
+ metadata.gz: 6e43f5866c1d15d10020403671a88d02ec0d46ba99ff20d91ad1f910e6583bda24304550f6b1b2c5d3157b8fe0fae4df10a4d34a7f3667f0516699edd7a98d4a
7
+ data.tar.gz: 628b315e03a6a25752903d4638501889f957e14095a69825722cf97b1bfc3b9d233ad67c31d2dcb2e89885efa4d7709f1b580d05bdc99ebd524ced3935deaeb3
data/lib/nub/net.rb CHANGED
@@ -146,7 +146,7 @@ module Net
146
146
  # Network object
147
147
  # @param subnet [String] of the network e.g. 192.168.100.0
148
148
  # @param cidr [String] of the network
149
- # @param nic [String] to use for NAT etc...
149
+ # @param nic [String] to use for NAT, true pics primary
150
150
  # @param nameservers [Array[String]] to optionally use for new network else uses hosts
151
151
  Network = Struct.new(:subnet, :cidr, :nic, :nameservers)
152
152
 
@@ -161,6 +161,7 @@ module Net
161
161
  # @returns [Array] of name server ips
162
162
  def nameservers(*args)
163
163
  filename = args.any? ? args.first.to_s : '/etc/resolv.conf'
164
+ filename = '/etc/resolv.conf' if !File.file?(filename)
164
165
 
165
166
  result = []
166
167
  if File.file?(filename)
@@ -239,6 +240,7 @@ module Net
239
240
 
240
241
  # Pull from existing namespace first
241
242
  if self.namespaces.include?(namespace)
243
+ network.nameservers = self.nameservers("/etc/netns/#{namespace}/resolv.conf")
242
244
  host_veth, guest_veth = self.namespace_veths(namespace)
243
245
 
244
246
  # Handle args as either as positional or named
@@ -247,7 +249,7 @@ module Net
247
249
  network = args.first[:network] if args.first.key?(:network)
248
250
  host_veth = args.first[:host_veth] if args.first.key?(:host_veth)
249
251
  guest_veth = args.first[:guest_veth] if args.first.key?(:guest_veth)
250
- elsif args.size > 1
252
+ elsif args.any?
251
253
  host_veth = args.shift
252
254
  guest_veth = args.shift if args.any?
253
255
  network = args.shift if args.any?
@@ -257,7 +259,9 @@ module Net
257
259
  # Populate missing information
258
260
  host_veth.name = "#{namespace}_host" if !host_veth.name
259
261
  guest_veth.name = "#{namespace}_guest" if !guest_veth.name
260
- network.nic = self.primary_nic if network.nic == true
262
+ network.subnet = @@namespace_subnet if !network.subnet
263
+ network.cidr = @@namespace_cidr if !network.cidr
264
+ network.nic = self.primary_nic if network.nic.nil? || network.nic == true
261
265
  network.nameservers = self.nameservers if !network.nameservers
262
266
  if !host_veth.ip or !guest_veth.ip
263
267
  host_ip, guest_ip = self.namespace_next_veth_ips
@@ -278,7 +282,7 @@ module Net
278
282
  # If the nic param is nil NAT is not enabled. If nic is true then the primary nic is dynamically
279
283
  # looked up else use user given If nameservers are not given the host nameservers will be used
280
284
  def create_namespace(namespace, *args)
281
- host_veth, guest_veth, network = self.namespace_details(namespace, args)
285
+ host_veth, guest_veth, network = self.namespace_details(namespace, *args)
282
286
 
283
287
  # Ensure namespace i.e. /var/run/netns/<namespace> exists
284
288
  if !self.namespaces.include?(namespace)
@@ -360,7 +364,7 @@ module Net
360
364
  # If the nic param is nil NAT is not enabled. If nic is true then the primary nic is dynamically
361
365
  # looked up else use user given If nameservers are not given the host nameservers will be used
362
366
  def delete_namespace(namespace, *args)
363
- host_veth, guest_veth, network = self.namespace_details(namespace, args)
367
+ host_veth, guest_veth, network = self.namespace_details(namespace, *args)
364
368
 
365
369
  # Remove nameserver config for network namespace
366
370
  namespace_conf = File.join("/etc/netns", namespace)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.136
4
+ version: 0.0.138
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Crummett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-28 00:00:00.000000000 Z
11
+ date: 2018-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize