2016-06-04 21:46:07 +08:00
|
|
|
def _load_prop_dict(self, target, prop):
|
|
|
|
for property in prop:
|
|
|
|
if not target.has_key(property):
|
|
|
|
continue
|
|
|
|
if type(prop[property]) is dict:
|
|
|
|
_load_prop_dict(self, target[property], prop[property])
|
|
|
|
else:
|
|
|
|
target[property] = prop[property]
|
|
|
|
|
2016-05-29 04:45:51 +08:00
|
|
|
|
|
|
|
class NetControllerConnector(object):
|
|
|
|
def __init__(self):
|
2016-05-29 19:32:06 +08:00
|
|
|
self._properties = {}
|
2016-05-29 04:45:51 +08:00
|
|
|
|
2016-05-29 16:44:19 +08:00
|
|
|
def is_connected(self):
|
|
|
|
return False
|
|
|
|
|
2016-05-29 04:45:51 +08:00
|
|
|
def connect(self):
|
|
|
|
return
|
|
|
|
|
|
|
|
def get_properties(self):
|
|
|
|
return self._properties
|
|
|
|
|
|
|
|
def load_properties(self, properties):
|
2016-06-04 21:46:07 +08:00
|
|
|
_load_prop_dict(self, self._properties, properties)
|
2016-05-29 04:45:51 +08:00
|
|
|
|
|
|
|
def get_vlans_list(self):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def get_entities_on_vlan(self, vlanid):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def deploy_monkey(self, vlanid):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def disconnect(self):
|
|
|
|
return
|
|
|
|
|
2016-06-05 23:52:04 +08:00
|
|
|
def log(self, text):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def set_logger(self, logger):
|
|
|
|
self.log = logger
|
2016-06-05 18:55:41 +08:00
|
|
|
|
2016-06-06 16:50:33 +08:00
|
|
|
|
2016-05-29 19:32:06 +08:00
|
|
|
class NetControllerJob(object):
|
2016-06-05 23:52:04 +08:00
|
|
|
connector_type = NetControllerConnector
|
2016-06-06 16:50:33 +08:00
|
|
|
|
2016-06-05 23:52:04 +08:00
|
|
|
_connector = None
|
|
|
|
_logger = None
|
|
|
|
|
2016-06-04 21:46:07 +08:00
|
|
|
_properties = {
|
|
|
|
# property: value
|
|
|
|
}
|
|
|
|
|
|
|
|
_enumerations = {
|
|
|
|
|
|
|
|
}
|
2016-05-29 19:32:06 +08:00
|
|
|
|
2016-06-05 23:52:04 +08:00
|
|
|
def __init__(self, existing_connector=None, logger=None):
|
|
|
|
self._connector = existing_connector
|
|
|
|
self._logger = logger
|
|
|
|
if logger:
|
|
|
|
self._connector.set_logger(self.log)
|
|
|
|
|
|
|
|
def log(self, text):
|
|
|
|
if self._logger:
|
|
|
|
self._logger.log(text)
|
2016-05-29 19:32:06 +08:00
|
|
|
|
2016-06-06 04:41:12 +08:00
|
|
|
# external API
|
|
|
|
|
2016-05-29 19:32:06 +08:00
|
|
|
def get_job_properties(self):
|
|
|
|
return self._properties
|
|
|
|
|
2016-06-04 21:46:07 +08:00
|
|
|
def load_job_properties(self, properties):
|
|
|
|
_load_prop_dict(self, self._properties, properties)
|
|
|
|
|
|
|
|
def get_property_function(self, property):
|
|
|
|
if property in self._enumerations.keys():
|
|
|
|
return self._enumerations[property]
|
|
|
|
return None
|
2016-05-29 19:32:06 +08:00
|
|
|
|
|
|
|
def run(self):
|
2016-06-05 18:55:41 +08:00
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def get_results(self):
|
2016-06-06 04:41:12 +08:00
|
|
|
return []
|
|
|
|
|
|
|
|
def get_state(self):
|
|
|
|
return None
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
raise NotImplementedError()
|