-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhosts.py
More file actions
31 lines (24 loc) · 893 Bytes
/
hosts.py
File metadata and controls
31 lines (24 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import json, base64
import coloredlogs, logging
from onos_api import OnosAPI
logger = logging.getLogger(__name__)
coloredlogs.install(level='INFO')
class Hosts:
def __init__(self):
self.__hosts = OnosAPI().get_hosts()
def get_host_id(self, hostname):
hostname = hostname.strip("H")
mac = "00:00:00:00:00:{:02x}".format(int(hostname))
logger.info("Parsed host: " + mac)
for host in self.__hosts.get("hosts"):
if host.get("mac") == mac:
return host.get("id")
return ""
def get_host_mac(self, hostname):
hostname = hostname.strip("H")
mac = "00:00:00:00:00:{:02x}".format(int(hostname))
logger.info("Parsed host: " + mac)
for host in self.__hosts.get("hosts"):
if host.get("mac") == mac:
return host.get("mac")
return ""