forked from ProtoThis/python-synology
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API SYNO.DSM.Network (ProtoThis#44)
- Loading branch information
Showing
6 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters