|
31 | 31 | from lib.network import Network |
32 | 32 | from lib.pif import PIF |
33 | 33 | from lib.sr import SR |
| 34 | +from lib.tunnel import Tunnel |
| 35 | +from lib.vlan import VLAN |
34 | 36 | from lib.vm import VM |
35 | 37 | from lib.xo import xo_cli, xo_object_exists |
36 | 38 |
|
@@ -1037,6 +1039,9 @@ def pifs(self, device: str | None = None) -> list[PIF]: |
1037 | 1039 |
|
1038 | 1040 | return [PIF(uuid, self) for uuid in safe_split(self.xe("pif-list", args, minimal=True))] |
1039 | 1041 |
|
| 1042 | + def tunnels(self) -> list[Tunnel]: |
| 1043 | + return [Tunnel(self, uuid) for uuid in safe_split(self.xe("tunnel-list", {}, minimal=True))] |
| 1044 | + |
1040 | 1045 | def create_bond(self, network: Network, pifs: list[PIF], mode: str | None = None) -> Bond: |
1041 | 1046 | args: dict[str, str | bool | dict[str, str]] = { |
1042 | 1047 | 'network-uuid': network.uuid, |
@@ -1064,3 +1069,35 @@ def create_network(self, label: str, description: str | None = None) -> Network: |
1064 | 1069 | logging.info(f"[{self}] New Network: {uuid}") |
1065 | 1070 |
|
1066 | 1071 | return Network(self, uuid) |
| 1072 | + |
| 1073 | + def create_vlan(self, network: Network, pif: PIF, vlan: int) -> VLAN: |
| 1074 | + args: dict[str, str | bool | dict[str, str]] = { |
| 1075 | + 'network-uuid': network.uuid, |
| 1076 | + 'pif-uuid': pif.uuid, |
| 1077 | + 'vlan': str(vlan), |
| 1078 | + } |
| 1079 | + |
| 1080 | + untagged_pif_uuid = self.xe("vlan-create", args, minimal=True) |
| 1081 | + uuid = self.xe("pif-param-get", { |
| 1082 | + "uuid": untagged_pif_uuid, |
| 1083 | + "param-name": "vlan-master-of", |
| 1084 | + }) |
| 1085 | + logging.info(f"New VLAN: {uuid} (untagged-pif: {untagged_pif_uuid})") |
| 1086 | + |
| 1087 | + return VLAN(self, uuid) |
| 1088 | + |
| 1089 | + def create_tunnel(self, network: Network, pif: PIF, protocol: str) -> Tunnel: |
| 1090 | + args: dict[str, str | bool | dict[str, str]] = { |
| 1091 | + 'network-uuid': network.uuid, |
| 1092 | + 'pif-uuid': pif.uuid, |
| 1093 | + 'protocol': protocol, |
| 1094 | + } |
| 1095 | + |
| 1096 | + access_pif_uuid = self.xe("tunnel-create", args, minimal=True) |
| 1097 | + uuid = self.xe("pif-param-get", { |
| 1098 | + "uuid": access_pif_uuid, |
| 1099 | + "param-name": "tunnel-access-PIF-of", |
| 1100 | + }) |
| 1101 | + logging.info(f"New Tunnel: {uuid} (access-pif: {access_pif_uuid})") |
| 1102 | + |
| 1103 | + return Tunnel(self, uuid) |
0 commit comments