| 50 | |
| 51 | |
| 52 | class wvmInterface(wvmConnect): |
| 53 | def __init__(self, host, login, passwd, conn, iface): |
| 54 | wvmConnect.__init__(self, host, login, passwd, conn) |
| 55 | self.iface = self.get_iface(iface) |
| 56 | |
| 57 | def _XMLDesc(self, flags=0): |
| 58 | return self.iface.XMLDesc(flags) |
| 59 | |
| 60 | def get_start_mode(self): |
| 61 | try: |
| 62 | xml = self._XMLDesc(VIR_INTERFACE_XML_INACTIVE) |
| 63 | return util.get_xml_path(xml, "/interface/start/@mode") |
| 64 | except: |
| 65 | return None |
| 66 | |
| 67 | def is_active(self): |
| 68 | return self.iface.isActive() |
| 69 | |
| 70 | def get_mac(self): |
| 71 | mac = self.iface.MACString() |
| 72 | if mac: |
| 73 | return mac |
| 74 | else: |
| 75 | return None |
| 76 | |
| 77 | def get_type(self): |
| 78 | xml = self._XMLDesc() |
| 79 | return util.get_xml_path(xml, "/interface/@type") |
| 80 | |
| 81 | def get_ipv4_type(self): |
| 82 | try: |
| 83 | xml = self._XMLDesc(VIR_INTERFACE_XML_INACTIVE) |
| 84 | ipaddr = util.get_xml_path(xml, "/interface/protocol/ip/@address") |
| 85 | if ipaddr: |
| 86 | return 'static' |
| 87 | else: |
| 88 | return 'dhcp' |
| 89 | except: |
| 90 | return None |
| 91 | |
| 92 | def get_ipv4(self): |
| 93 | xml = self._XMLDesc() |
| 94 | int_ipv4_ip = util.get_xml_path(xml, "/interface/protocol/ip/@address") |
| 95 | int_ipv4_mask = util.get_xml_path(xml, "/interface/protocol/ip/@prefix") |
| 96 | if not int_ipv4_ip or not int_ipv4_mask: |
| 97 | return None |
| 98 | else: |
| 99 | return int_ipv4_ip + '/' + int_ipv4_mask |
| 100 | |
| 101 | def get_ipv6_type(self): |
| 102 | try: |
| 103 | xml = self._XMLDesc(VIR_INTERFACE_XML_INACTIVE) |
| 104 | ipaddr = util.get_xml_path(xml, "/interface/protocol[2]/ip/@address") |
| 105 | if ipaddr: |
| 106 | return 'static' |
| 107 | else: |
| 108 | return 'dhcp' |
| 109 | except: |