(20250211) MikroTik VLAN set up and rollback also ready.
This commit is contained in:
@@ -361,7 +361,7 @@ class MikroTikController(CoreSoftwareController, ABC):
|
||||
password: str,
|
||||
port_no: int | str = None,
|
||||
use_https: bool = True
|
||||
):
|
||||
) -> ApiResponse:
|
||||
|
||||
"""
|
||||
To enlist all the physical connectivity interfaces available on the MikroTik device.
|
||||
@@ -395,42 +395,29 @@ class MikroTikController(CoreSoftwareController, ABC):
|
||||
mikrotik_ip: str,
|
||||
username: str,
|
||||
password: str,
|
||||
interface_id: str,
|
||||
dot_id: str,
|
||||
json_payload: dict,
|
||||
port_no: int | str = None,
|
||||
use_https: bool = True,
|
||||
name: str = None,
|
||||
disabled: bool = False,
|
||||
comment: str = None
|
||||
):
|
||||
use_https: bool = True
|
||||
) -> ApiResponse:
|
||||
|
||||
"""
|
||||
To update an interface's configuration.
|
||||
:param mikrotik_ip: The IP address of the MikroTik device.
|
||||
:param username: The username to get access to the MikroTik device.
|
||||
:param password: The password to get access to the MikroTik device.
|
||||
:param interface_id: The id of the interface that you'd like to modify.
|
||||
:param dot_id: The value of the '.id' field in the list.
|
||||
:param port_no: The port no. to hit the MikroTik device on.
|
||||
:param use_https: Whether to use HTTPS, or HTTP.
|
||||
:param name: The new name for the interface.
|
||||
:param disabled: Whether, or not, you'd like to disable the interface.
|
||||
:param comment: A note that you'd like to attach to the entry. It'll then be available in the listing API.
|
||||
:param json_payload: The JSON to send in the body pf the request.
|
||||
:return: A structured API response.
|
||||
"""
|
||||
|
||||
# Prepare the JSON to give to the API:
|
||||
input_json = {
|
||||
k: v for k, v in {
|
||||
"name": name,
|
||||
"disabled": disabled,
|
||||
"comment": comment
|
||||
}.items() if v is not None
|
||||
}
|
||||
|
||||
# Make the API call:
|
||||
api_response = await self._rest.patch(
|
||||
url = self.get_mikrotik_url(
|
||||
mikrotik_ip = mikrotik_ip,
|
||||
path = f"/interface/{interface_id}",
|
||||
path = f"/interface/{dot_id}",
|
||||
port_no = port_no,
|
||||
use_https = use_https
|
||||
),
|
||||
@@ -438,7 +425,165 @@ class MikroTikController(CoreSoftwareController, ABC):
|
||||
username = username,
|
||||
password = password
|
||||
),
|
||||
json = input_json
|
||||
json = json_payload
|
||||
)
|
||||
|
||||
# Done here:
|
||||
return api_response
|
||||
|
||||
# ┓┏┓ ┏┓┳┓
|
||||
# ┃┃┃ ┣┫┃┃┏
|
||||
# ┗┛┗┛┛┗┛┗┛
|
||||
|
||||
async def list_vlans(
|
||||
self,
|
||||
mikrotik_ip: str,
|
||||
username: str,
|
||||
password: str,
|
||||
port_no: int | str = None,
|
||||
use_https: bool = True
|
||||
) -> ApiResponse:
|
||||
|
||||
"""
|
||||
To enlist all the physical connectivity interfaces available on the MikroTik device.
|
||||
:param mikrotik_ip: The IP address of the MikroTik device.
|
||||
:param username: The username to get access to the MikroTik device.
|
||||
:param password: The password to get access to the MikroTik device.
|
||||
:param port_no: The port no. to hit the MikroTik device on.
|
||||
:param use_https: Whether to use HTTPS, or HTTP.
|
||||
:return: A structured API response.
|
||||
"""
|
||||
|
||||
# Make the API call:
|
||||
api_response = await self._rest.get(
|
||||
url = self.get_mikrotik_url(
|
||||
mikrotik_ip = mikrotik_ip,
|
||||
path = r"/interface/vlan",
|
||||
port_no = port_no,
|
||||
use_https = use_https
|
||||
),
|
||||
auth = httpx.BasicAuth(
|
||||
username = username,
|
||||
password = password
|
||||
)
|
||||
)
|
||||
|
||||
# Done here:
|
||||
return api_response
|
||||
|
||||
async def add_vlan(
|
||||
self,
|
||||
mikrotik_ip: str,
|
||||
username: str,
|
||||
password: str,
|
||||
json_payload: dict,
|
||||
port_no: int | str = None,
|
||||
use_https: bool = True
|
||||
) -> ApiResponse:
|
||||
|
||||
"""
|
||||
To add a new VLAN to the MikroTik's configuration.
|
||||
:param mikrotik_ip: The IP address of the MikroTik device.
|
||||
:param username: The username to get access to the MikroTik device.
|
||||
:param password: The password to get access to the MikroTik device.
|
||||
:param json_payload: The JSON to send in the body pf the request.
|
||||
:param port_no: The port no. to hit the MikroTik device on.
|
||||
:param use_https: Whether to use HTTPS, or HTTP.
|
||||
:return: A structured API response.
|
||||
"""
|
||||
|
||||
# Make the API call:
|
||||
api_response = await self._rest.put(
|
||||
url = self.get_mikrotik_url(
|
||||
mikrotik_ip = mikrotik_ip,
|
||||
path = r"/interface/vlan",
|
||||
port_no = port_no,
|
||||
use_https = use_https
|
||||
),
|
||||
auth = httpx.BasicAuth(
|
||||
username = username,
|
||||
password = password
|
||||
),
|
||||
json = json_payload
|
||||
)
|
||||
|
||||
# Done here:
|
||||
return api_response
|
||||
|
||||
async def update_vlan(
|
||||
self,
|
||||
mikrotik_ip: str,
|
||||
username: str,
|
||||
password: str,
|
||||
dot_id: str,
|
||||
json_payload: dict,
|
||||
port_no: int | str = None,
|
||||
use_https: bool = True,
|
||||
) -> ApiResponse:
|
||||
|
||||
"""
|
||||
To update an existing VLAN in the MikroTik's configuration.
|
||||
:param mikrotik_ip: The IP address of the MikroTik device.
|
||||
:param username: The username to get access to the MikroTik device.
|
||||
:param password: The password to get access to the MikroTik device.
|
||||
:param dot_id: The value of the '.id' field in the list.
|
||||
:param json_payload: The JSON to send in the body pf the request.
|
||||
:param port_no: The port no. to hit the MikroTik device on.
|
||||
:param use_https: Whether to use HTTPS, or HTTP.
|
||||
:return: A structured API response.
|
||||
"""
|
||||
|
||||
# Make the API call:
|
||||
api_response = await self._rest.patch(
|
||||
url = self.get_mikrotik_url(
|
||||
mikrotik_ip = mikrotik_ip,
|
||||
path = f"/interface/vlan/{dot_id}",
|
||||
port_no = port_no,
|
||||
use_https = use_https
|
||||
),
|
||||
auth = httpx.BasicAuth(
|
||||
username = username,
|
||||
password = password
|
||||
),
|
||||
json = json_payload
|
||||
)
|
||||
|
||||
# Done here:
|
||||
return api_response
|
||||
|
||||
async def remove_vlan(
|
||||
self,
|
||||
mikrotik_ip: str,
|
||||
username: str,
|
||||
password: str,
|
||||
dot_id: str,
|
||||
port_no: int | str = None,
|
||||
use_https: bool = True,
|
||||
):
|
||||
|
||||
"""
|
||||
To delete an existing VLAN from the MikroTik's configuration.
|
||||
:param mikrotik_ip: The IP address of the MikroTik device.
|
||||
:param username: The username to get access to the MikroTik device.
|
||||
:param password: The password to get access to the MikroTik device.
|
||||
:param dot_id: The value of the '.id' field in the list.
|
||||
:param port_no: The port no. to hit the MikroTik device on.
|
||||
:param use_https: Whether to use HTTPS, or HTTP.
|
||||
:return: A structured API response.
|
||||
"""
|
||||
|
||||
# Make the API call:
|
||||
api_response = await self._rest.delete(
|
||||
url = self.get_mikrotik_url(
|
||||
mikrotik_ip = mikrotik_ip,
|
||||
path = f"/interface/vlan/{dot_id}",
|
||||
port_no = port_no,
|
||||
use_https = use_https
|
||||
),
|
||||
auth = httpx.BasicAuth(
|
||||
username = username,
|
||||
password = password
|
||||
)
|
||||
)
|
||||
|
||||
# Done here:
|
||||
|
||||
Reference in New Issue
Block a user