|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import logging |
| 4 | + |
| 5 | +from lib.common import _param_add, _param_clear, _param_get, _param_remove, _param_set |
| 6 | +from lib.pif import PIF |
| 7 | + |
| 8 | +from typing import TYPE_CHECKING |
| 9 | + |
| 10 | +if TYPE_CHECKING: |
| 11 | + from lib.host import Host |
| 12 | + |
| 13 | +class VLAN: |
| 14 | + xe_prefix = "vlan" |
| 15 | + |
| 16 | + def __init__(self, host: Host, uuid: str): |
| 17 | + self.host = host |
| 18 | + self.uuid = uuid |
| 19 | + |
| 20 | + def param_get(self, param_name, key=None, accept_unknown_key=False): |
| 21 | + return _param_get(self.host, VLAN.xe_prefix, self.uuid, param_name, key, accept_unknown_key) |
| 22 | + |
| 23 | + def param_set(self, param_name, value, key=None): |
| 24 | + _param_set(self.host, VLAN.xe_prefix, self.uuid, param_name, value, key) |
| 25 | + |
| 26 | + def param_add(self, param_name, value, key=None): |
| 27 | + _param_add(self.host, VLAN.xe_prefix, self.uuid, param_name, value, key) |
| 28 | + |
| 29 | + def param_clear(self, param_name): |
| 30 | + _param_clear(self.host, VLAN.xe_prefix, self.uuid, param_name) |
| 31 | + |
| 32 | + def param_remove(self, param_name, key, accept_unknown_key=False): |
| 33 | + _param_remove(self.host, VLAN.xe_prefix, self.uuid, param_name, key, accept_unknown_key) |
| 34 | + |
| 35 | + def destroy(self): |
| 36 | + logging.info(f"Destroying VLAN: {self.uuid}") |
| 37 | + self.host.xe('vlan-destroy', {'uuid': self.uuid}) |
| 38 | + |
| 39 | + def tag(self) -> int: |
| 40 | + tag = self.param_get('tag') |
| 41 | + assert tag |
| 42 | + return int(tag) |
| 43 | + |
| 44 | + def tagged_PIF(self) -> PIF: |
| 45 | + uuid = self.param_get("tagged-PIF") |
| 46 | + assert uuid |
| 47 | + return PIF(uuid, self.host) |
| 48 | + |
| 49 | + def untagged_PIF(self) -> PIF: |
| 50 | + uuid = self.param_get("untagged-PIF") |
| 51 | + assert uuid |
| 52 | + return PIF(uuid, self.host) |
0 commit comments