diff --git a/monkey_business/cc/admin/ui/js/monkeysb-admin.js b/monkey_business/cc/admin/ui/js/monkeysb-admin.js index 6ff40cf3d..1dfbd3fdf 100644 --- a/monkey_business/cc/admin/ui/js/monkeysb-admin.js +++ b/monkey_business/cc/admin/ui/js/monkeysb-admin.js @@ -121,14 +121,14 @@ function updateJobs() { } function loadVcenterConfig() { - $.getJSON('/connector?type=vcenter', function(json) { + $.getJSON('/connector?type=VCenterConnector', function(json) { vcenterCfg.setValue(json); }); } function updateVcenterConfig() { var vc_config = vcenterCfg.getValue() - vc_config["type"] = "vcenter"; + vc_config["type"] = "VCenterConnector"; $.ajax({ headers : { diff --git a/monkey_business/cc/connectors/vcenter.py b/monkey_business/cc/connectors/vcenter.py index 1cdf8db7c..30cfc122b 100644 --- a/monkey_business/cc/connectors/vcenter.py +++ b/monkey_business/cc/connectors/vcenter.py @@ -20,21 +20,45 @@ class VCenterConnector(NetControllerConnector): "resource_pool": "" } } - self._job_properties = { - + self._cache = { + "vlans" : [] } def connect(self): - self._service_instance = SmartConnect(host=self._properties["address"], - port=self._properties["port"], - user=self._properties["username"], - pwd=self._properties["password"]) + import ssl + try: + self._service_instance = SmartConnect(host=self._properties["address"], + port=self._properties["port"], + user=self._properties["username"], + pwd=self._properties["password"]) + except ssl.SSLError: + # some organizations use self-signed certificates... + gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1) + self._service_instance = SmartConnect(host=self._properties["address"], + port=self._properties["port"], + user=self._properties["username"], + pwd=self._properties["password"], + sslContext=gcontext) def is_connected(self): - return not self._service_instance == None + if (self._service_instance == None): + return False + try: + self._service_instance.serverClock + except vim.fault.NotAuthenticated, e: + return False def get_vlans_list(self): - return [] + if not self.is_connected(): + self.connect() + if self._cache and self._cache.has_key("vlans") and self._cache["vlans"]: + return self._cache["vlans"] + vcontent = self._service_instance.RetrieveContent() # get updated vsphare state + vimtype = [vim.Network] + objview = vcontent.viewManager.CreateContainerView(vcontent.rootFolder, vimtype, True) + self._cache["vlans"] = [x.name for x in objview.view] + objview.Destroy() + return self._cache["vlans"] def get_entities_on_vlan(self, vlanid): return [] diff --git a/monkey_business/cc/main.py b/monkey_business/cc/main.py index 0723b22fd..a7aa41d4b 100644 --- a/monkey_business/cc/main.py +++ b/monkey_business/cc/main.py @@ -70,7 +70,7 @@ class Job(restful.Resource): class Connector(restful.Resource): def get(self, **kw): type = request.args.get('type') - if (type == 'vcenter'): + if (type == 'VCenterConnector'): vcenter = VCenterConnector() properties = mongo.db.connector.find_one({"type": 'VCenterConnector'}) if properties: @@ -82,7 +82,7 @@ class Connector(restful.Resource): def post(self, **kw): settings_json = json.loads(request.data) - if (settings_json.get("type") == 'vcenter'): + if (settings_json.get("type") == 'VCenterConnector'): # preserve password properties = mongo.db.connector.find_one({"type": 'VCenterConnector'}) @@ -179,8 +179,8 @@ def update_connectors(): if not active_connectors[connector_name].is_connected(): refresh_connector_config(connector_name) try: - active_connectors[connector_name].connect() app.logger.info("Trying to activate connector: %s" % connector_name) + active_connectors[connector_name].connect() except Exception, e: active_connectors.pop(connector_name) app.logger.info("Error activating connector: %s, reason: %s" % (connector_name, e))