MCPcopy Create free account
hub / github.com/apache/cloudstack / CsIP

Class CsIP

systemvm/debian/opt/cloud/bin/cs/CsAddress.py:315–1000  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

313
314
315class CsIP:
316 DEFAULT_MTU = '1500'
317
318 def __init__(self, dev, config):
319 self.dev = dev
320 self.dnum = hex(100 + int(dev[3:]))
321 self.iplist = {}
322 self.address = {}
323 self.list()
324 self.fw = config.get_fw()
325 self.cl = config.cmdline()
326 self.config = config
327 self.nft_ipv4_fw = config.get_nft_ipv4_fw()
328 self.nft_ipv4_acl = config.get_nft_ipv4_acl()
329
330 def setAddress(self, address):
331 self.address = address
332
333 def getAddress(self):
334 return self.address
335
336 def configure(self, address):
337 # When "add" is false, it means that the IP has to be removed.
338 if address["add"]:
339 try:
340 logging.info("Configuring address %s on device %s", self.ip(), self.dev)
341 cmd = "ip addr add dev %s %s brd +" % (self.dev, self.ip())
342 CsHelper.execute(cmd)
343 cmd = "ifconfig %s mtu %s" % (self.dev, self.mtu())
344 CsHelper.execute(cmd)
345 except Exception as e:
346 logging.info("Exception occurred ==> %s" % e)
347
348 self.post_configure(address)
349 else:
350 # delete method performs post_configure, so no need to call post_configure here
351 self.delete(self.ip())
352
353 def post_configure(self, address):
354 """ The steps that must be done after a device is configured """
355 route = CsRoute()
356 if not self.get_type() in ["control"]:
357 route.add_table(self.dev)
358
359 CsRule(self.dev).addMark()
360
361 interfaces = [CsInterface(address, self.config)]
362 CsHelper.reconfigure_interfaces(self.cl, interfaces)
363 if self.get_type() in ['public'] and not self.config.is_routed() and self.config.has_public_network():
364 self.set_mark()
365
366 if 'gateway' in self.address:
367 self.arpPing()
368
369 CsRpsrfs(self.dev).enable()
370 self.post_config_change("add")
371
372 '''For isolated/redundant and dhcpsrvr routers, call this method after the post_config is complete '''

Callers 3

test_initMethod · 0.90
compareMethod · 0.85
processMethod · 0.85

Calls

no outgoing calls

Tested by 1

test_initMethod · 0.72