|
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 |
|
@@ -1050,6 +1052,9 @@ def pifs(self, device: str | None = None) -> list[PIF]: |
1050 | 1052 |
|
1051 | 1053 | return [PIF(uuid, self) for uuid in safe_split(self.xe("pif-list", args, minimal=True))] |
1052 | 1054 |
|
| 1055 | + def tunnels(self) -> list[Tunnel]: |
| 1056 | + return [Tunnel(self, uuid) for uuid in safe_split(self.xe("tunnel-list", {}, minimal=True))] |
| 1057 | + |
1053 | 1058 | def create_bond(self, network: Network, pifs: list[PIF], mode: str | None = None) -> Bond: |
1054 | 1059 | args: dict[str, str | bool | dict[str, str]] = { |
1055 | 1060 | 'network-uuid': network.uuid, |
@@ -1077,3 +1082,35 @@ def create_network(self, label: str, description: str | None = None) -> Network: |
1077 | 1082 | logging.info(f"[{self}] New Network: {uuid}") |
1078 | 1083 |
|
1079 | 1084 | return Network(self, uuid) |
| 1085 | + |
| 1086 | + def create_vlan(self, network: Network, pif: PIF, vlan: int) -> VLAN: |
| 1087 | + args: dict[str, str | bool | dict[str, str]] = { |
| 1088 | + 'network-uuid': network.uuid, |
| 1089 | + 'pif-uuid': pif.uuid, |
| 1090 | + 'vlan': str(vlan), |
| 1091 | + } |
| 1092 | + |
| 1093 | + untagged_pif_uuid = self.xe("vlan-create", args, minimal=True) |
| 1094 | + uuid = self.xe("pif-param-get", { |
| 1095 | + "uuid": untagged_pif_uuid, |
| 1096 | + "param-name": "vlan-master-of", |
| 1097 | + }) |
| 1098 | + logging.info(f"New VLAN: {uuid} (untagged-pif: {untagged_pif_uuid})") |
| 1099 | + |
| 1100 | + return VLAN(self, uuid) |
| 1101 | + |
| 1102 | + def create_tunnel(self, network: Network, pif: PIF, protocol: str) -> Tunnel: |
| 1103 | + args: dict[str, str | bool | dict[str, str]] = { |
| 1104 | + 'network-uuid': network.uuid, |
| 1105 | + 'pif-uuid': pif.uuid, |
| 1106 | + 'protocol': protocol, |
| 1107 | + } |
| 1108 | + |
| 1109 | + access_pif_uuid = self.xe("tunnel-create", args, minimal=True) |
| 1110 | + uuid = self.xe("pif-param-get", { |
| 1111 | + "uuid": access_pif_uuid, |
| 1112 | + "param-name": "tunnel-access-PIF-of", |
| 1113 | + }) |
| 1114 | + logging.info(f"New Tunnel: {uuid} (access-pif: {access_pif_uuid})") |
| 1115 | + |
| 1116 | + return Tunnel(self, uuid) |
0 commit comments