after first test vs real ESX

tested VLAN enumeration - still need to handle the bad performance
This commit is contained in:
itsikkes 2016-05-29 17:49:55 +03:00
parent b1d3bbcc0e
commit 5a8954d055
3 changed files with 37 additions and 13 deletions

View File

@ -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 : {

View File

@ -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 []

View File

@ -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))