|
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 |
|
@@ -716,6 +718,9 @@ def yum_restore_saved_state(self) -> None: |
716 | 718 | self.saved_packages_list = None |
717 | 719 | self.saved_rollback_id = None |
718 | 720 |
|
| 721 | + def service_started(self, name: str) -> bool: |
| 722 | + return self.ssh(f'systemctl is-active {name}', check=False) == 'active' |
| 723 | + |
719 | 724 | def reboot(self, verify: bool = False) -> None: |
720 | 725 | logging.info(f"[{self}] Reboot host") |
721 | 726 | # Running `reboot` directly immediately disconnects the ssh session and makes the ssh client return with an |
@@ -1051,6 +1056,9 @@ def pifs(self, device: str | None = None) -> list[PIF]: |
1051 | 1056 |
|
1052 | 1057 | return [PIF(uuid, self) for uuid in safe_split(self.xe("pif-list", args, minimal=True))] |
1053 | 1058 |
|
| 1059 | + def tunnels(self) -> list[Tunnel]: |
| 1060 | + return [Tunnel(self, uuid) for uuid in safe_split(self.xe("tunnel-list", {}, minimal=True))] |
| 1061 | + |
1054 | 1062 | def create_bond(self, network: Network, pifs: list[PIF], mode: str | None = None) -> Bond: |
1055 | 1063 | args: dict[str, str | bool | dict[str, str]] = { |
1056 | 1064 | 'network-uuid': network.uuid, |
@@ -1078,3 +1086,35 @@ def create_network(self, label: str, description: str | None = None) -> Network: |
1078 | 1086 | logging.info(f"[{self}] New Network: {uuid}") |
1079 | 1087 |
|
1080 | 1088 | return Network(self, uuid) |
| 1089 | + |
| 1090 | + def create_vlan(self, network: Network, pif: PIF, vlan: int) -> VLAN: |
| 1091 | + args: dict[str, str | bool | dict[str, str]] = { |
| 1092 | + 'network-uuid': network.uuid, |
| 1093 | + 'pif-uuid': pif.uuid, |
| 1094 | + 'vlan': str(vlan), |
| 1095 | + } |
| 1096 | + |
| 1097 | + untagged_pif_uuid = self.xe("vlan-create", args, minimal=True) |
| 1098 | + uuid = self.xe("pif-param-get", { |
| 1099 | + "uuid": untagged_pif_uuid, |
| 1100 | + "param-name": "vlan-master-of", |
| 1101 | + }) |
| 1102 | + logging.info(f"New VLAN: {uuid} (untagged-pif: {untagged_pif_uuid})") |
| 1103 | + |
| 1104 | + return VLAN(self, uuid) |
| 1105 | + |
| 1106 | + def create_tunnel(self, network: Network, pif: PIF, protocol: str) -> Tunnel: |
| 1107 | + args: dict[str, str | bool | dict[str, str]] = { |
| 1108 | + 'network-uuid': network.uuid, |
| 1109 | + 'pif-uuid': pif.uuid, |
| 1110 | + 'protocol': protocol, |
| 1111 | + } |
| 1112 | + |
| 1113 | + access_pif_uuid = self.xe("tunnel-create", args, minimal=True) |
| 1114 | + uuid = self.xe("pif-param-get", { |
| 1115 | + "uuid": access_pif_uuid, |
| 1116 | + "param-name": "tunnel-access-PIF-of", |
| 1117 | + }) |
| 1118 | + logging.info(f"New Tunnel: {uuid} (access-pif: {access_pif_uuid})") |
| 1119 | + |
| 1120 | + return Tunnel(self, uuid) |
0 commit comments