| 30 | VRRP_TYPES = ['guest'] |
| 31 | |
| 32 | class CsAddress(CsDataBag): |
| 33 | |
| 34 | def compare(self): |
| 35 | for dev in CsDevice('', self.config).list(): |
| 36 | ip = CsIP(dev, self.config) |
| 37 | ip.compare(self.dbag) |
| 38 | |
| 39 | def get_interfaces(self): |
| 40 | interfaces = [] |
| 41 | for dev in self.dbag: |
| 42 | if dev == "id": |
| 43 | continue |
| 44 | for ip in self.dbag[dev]: |
| 45 | interfaces.append(CsInterface(ip, self.config)) |
| 46 | return interfaces |
| 47 | |
| 48 | def get_guest_if_by_network_id(self): |
| 49 | guest_interface = None |
| 50 | lowest_network_id = 1000 |
| 51 | for interface in self.get_interfaces(): |
| 52 | if interface.is_guest() and interface.is_added(): |
| 53 | if not self.config.is_vpc(): |
| 54 | return interface |
| 55 | network_id = self.config.guestnetwork().get_network_id(interface.get_device()) |
| 56 | if network_id and network_id < lowest_network_id: |
| 57 | lowest_network_id = network_id |
| 58 | guest_interface = interface |
| 59 | return guest_interface |
| 60 | |
| 61 | def get_guest_if(self): |
| 62 | """ |
| 63 | Return CsInterface object for the lowest in use guest interface |
| 64 | """ |
| 65 | guest_interface = None |
| 66 | lowest_device = 1000 |
| 67 | for interface in self.get_interfaces(): |
| 68 | if interface.is_guest() and interface.is_added(): |
| 69 | device = interface.get_device() |
| 70 | device_suffix = int(''.join([digit for digit in device if digit.isdigit()])) |
| 71 | if device_suffix < lowest_device: |
| 72 | lowest_device = device_suffix |
| 73 | guest_interface = interface |
| 74 | logging.debug("Guest interface will be set on device '%s' and IP '%s'" % (guest_interface.get_device(), guest_interface.get_ip())) |
| 75 | return guest_interface |
| 76 | |
| 77 | def get_guest_ip(self): |
| 78 | """ |
| 79 | Return the ip of the first guest interface |
| 80 | For use with routers not vpcrouters |
| 81 | """ |
| 82 | ip = self.get_guest_if() |
| 83 | if ip: |
| 84 | return ip.get_ip() |
| 85 | return None |
| 86 | |
| 87 | def get_guest_netmask(self): |
| 88 | """ |
| 89 | Return the netmask of the first guest interface |
no outgoing calls