Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions synology_dsm/api/dsm/network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
"""DSM Network data."""


class SynoDSMNetwork(object):
"""Class containing Network data."""

API_KEY = "SYNO.DSM.Network"

def __init__(self, raw_data):
self._data = {}
self.update(raw_data)

def update(self, raw_data):
"""Updates network data."""
if raw_data:
self._data = raw_data["data"]

@property
def dns(self):
"""DNS of the NAS."""
return self._data.get("dns")

@property
def gateway(self):
"""Gateway of the NAS."""
return self._data.get("gateway")

@property
def hostname(self):
"""Host name of the NAS."""
return self._data.get("hostname")

@property
def interfaces(self):
"""Interfaces of the NAS."""
return self._data.get("interfaces", [])

def interface(self, eth_id):
"""Interface of the NAS."""
for interface in self.interfaces:
if interface["id"] == eth_id:
return interface
return None

@property
def macs(self):
"""MACs of the NAS."""
macs = []
for interface in self.interfaces:
macs.append(interface["mac"])
return macs

@property
def workgroup(self):
"""Workgroup of the NAS."""
return self._data.get("workgroup")
10 changes: 10 additions & 0 deletions synology_dsm/synology_dsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
)
from .api.core.utilization import SynoCoreUtilization
from .api.dsm.information import SynoDSMInformation
from .api.dsm.network import SynoDSMNetwork
from .api.storage.storage import SynoStorage


Expand Down Expand Up @@ -60,6 +61,7 @@ def __init__(
"SYNO.API.Info": {"maxVersion": 1, "minVersion": 1, "path": "query.cgi"}
}
self._information = None
self._network = None
self._utilisation = None
self._storage = None

Expand Down Expand Up @@ -273,6 +275,14 @@ def information(self):
self._information = SynoDSMInformation(data)
return self._information

@property
def network(self):
"""Gets NAS network informations."""
if not self._network:
data = self.get(SynoDSMNetwork.API_KEY, "list")
self._network = SynoDSMNetwork(data)
return self._network

@property
def utilisation(self):
"""Gets NAS utilisation informations."""
Expand Down
6 changes: 6 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from synology_dsm.exceptions import SynologyDSMRequestException
from synology_dsm.api.core.utilization import SynoCoreUtilization
from synology_dsm.api.dsm.information import SynoDSMInformation
from synology_dsm.api.dsm.network import SynoDSMNetwork
from synology_dsm.api.storage.storage import SynoStorage

from .const import (
Expand All @@ -22,6 +23,7 @@
DSM_6_AUTH_LOGIN_2SA,
DSM_6_AUTH_LOGIN_2SA_OTP,
DSM_6_DSM_INFORMATION,
DSM_6_DSM_NETWORK,
DSM_6_CORE_UTILIZATION,
DSM_6_STORAGE_STORAGE_DS213_PLUS_SHR1_2DISKS_2VOLS,
DSM_6_STORAGE_STORAGE_DS918_PLUS_RAID5_3DISKS_1VOL,
Expand Down Expand Up @@ -54,6 +56,7 @@
"AUTH_LOGIN_2SA": DSM_6_AUTH_LOGIN_2SA,
"AUTH_LOGIN_2SA_OTP": DSM_6_AUTH_LOGIN_2SA_OTP,
"DSM_INFORMATION": DSM_6_DSM_INFORMATION,
"DSM_NETWORK": DSM_6_DSM_NETWORK,
"CORE_UTILIZATION": DSM_6_CORE_UTILIZATION,
"STORAGE_STORAGE": {
"RAID": DSM_6_STORAGE_STORAGE_DS918_PLUS_RAID5_3DISKS_1VOL,
Expand Down Expand Up @@ -168,6 +171,9 @@ def _execute_request(self, method, url, **kwargs):
if SynoDSMInformation.API_KEY in url:
return API_SWITCHER[self.dsm_version]["DSM_INFORMATION"]

if SynoDSMNetwork.API_KEY in url:
return API_SWITCHER[self.dsm_version]["DSM_NETWORK"]

if SynoCoreUtilization.API_KEY in url:
return API_SWITCHER[self.dsm_version]["CORE_UTILIZATION"]

Expand Down
1 change: 1 addition & 0 deletions tests/api_data/dsm_6/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
)
from .core.const_6_core_utilization import DSM_6_CORE_UTILIZATION
from .dsm.const_6_dsm_info import DSM_6_DSM_INFORMATION
from .dsm.const_6_dsm_network import DSM_6_DSM_NETWORK
from .storage.const_6_storage_storage import (
DSM_6_STORAGE_STORAGE_DS213_PLUS_SHR1_2DISKS_2VOLS,
DSM_6_STORAGE_STORAGE_DS918_PLUS_RAID5_3DISKS_1VOL,
Expand Down
38 changes: 38 additions & 0 deletions tests/api_data/dsm_6/dsm/const_6_dsm_network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
"""DSM 6 SYNO.DSM.Network data."""

DSM_6_DSM_NETWORK = {
"data": {
"dns": ["192.168.0.35"],
"gateway": "192.168.0.254",
"hostname": "NAS_[NAME]",
"interfaces": [
{
"id": "eth0",
"ip": [{"address": "192.168.0.35", "netmask": "255.255.255.0"}],
"ipv6": [
{
"address": "2a01:e35:2434:d420:211:32ff:fea6:ca59",
"prefix_length": 64,
"scope": "global",
},
{
"address": "fe80::211:32ff:fea6:ca59",
"prefix_length": 64,
"scope": "link",
},
],
"mac": "00-11-32-XX-XX-59",
"type": "lan",
},
{
"id": "eth1",
"ip": [{"address": "169.254.158.209", "netmask": "255.255.0.0"}],
"mac": "00-11-32-XX-XX-5A",
"type": "lan",
},
],
"workgroup": "WORKGROUP",
},
"success": True,
}
12 changes: 12 additions & 0 deletions tests/test_synology_dsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,18 @@ def test_information(self):
assert self.api.information.version == "24922"
assert self.api.information.version_string == "DSM 6.2.2-24922 Update 4"

def test_network(self):
"""Test network."""
assert self.api.network
assert self.api.network.dns
assert self.api.network.gateway
assert self.api.network.hostname
assert self.api.network.interfaces
assert self.api.network.interface("eth0")
assert self.api.network.interface("eth1")
assert self.api.network.macs
assert self.api.network.workgroup

def test_utilisation(self):
"""Test utilization."""
assert self.api.utilisation
Expand Down