def remove_zovp_account(self, zovPushKey=None): if zovPushKey == None: return DirectResponse.fail("Missing zovPushKey") dmdRoot = _dmdRoot(self.context) accounts = getattr(dmdRoot, 'zovp_accounts', []) foundaccount = False this_account_details = models.zovpaccount.ZOVPAccount("None", "None") for accountDetails in accounts: if accountDetails.zovPushKey == zovPushKey: foundaccount = True this_account_details = accountDetails break if foundaccount == True: accounts.remove(this_account_details) setattr(dmdRoot, 'zovp_accounts', accounts) return DirectResponse.succeed() else: return DirectResponse.fail("Account not found")
def get_services(self, wants_messages=False): dmdRoot = _dmdRoot(self.context) no_account_msg = 'PagerDuty account info not set.' set_up_api_key_inline_msg = 'Set up your account info in "Advanced... PagerDuty Settings"' msg = no_account_msg if wants_messages else None if not hasattr(dmdRoot, ACCOUNT_ATTR): return DirectResponse.fail(msg=msg, inline_message=set_up_api_key_inline_msg) account = getattr(dmdRoot, ACCOUNT_ATTR) if not account.api_access_key or not account.subdomain: return DirectResponse.fail(msg=msg, inline_message=set_up_api_key_inline_msg) try: api_services = _retrieve_services(account) except requests.InvalidTokenException: msg = 'Your api_access_key was denied.' if wants_messages else None return DirectResponse.fail(msg=msg, inline_message='Access key denied: Go to "Advanced... PagerDuty Settings"') except requests.PagerDutyUnreachableException as pdue: msg = pdue.message if wants_messages else None return DirectResponse.fail(msg=msg, inline_message=pdue.message) if not api_services: msg = ("No generic event services were found for %s.pagerduty.com." % account.subdomain) if wants_messages else None return DirectResponse.fail(msg=msg) return _success(api_services)
def getServices(self, wantsMessages=False): dmdRoot = _dmdRoot(self.context) noAccountMsg = 'PagerDuty account info not set.' setUpApiKeyInlineMsg = 'Set up your account info in "Advanced... PagerDuty Settings"' msg = noAccountMsg if wantsMessages else None if not hasattr(dmdRoot, ACCOUNT_ATTR): return DirectResponse.fail(msg=msg, inlineMessage=setUpApiKeyInlineMsg) account = getattr(dmdRoot, ACCOUNT_ATTR) if not account.apiAccessKey or not account.subdomain: return DirectResponse.fail(msg=msg, inline_message=setUpApiKeyInlineMsg) try: apiServices = _retrieveServices(account) except requests.InvalidTokenException: msg = 'Your API Access Key was denied.' if wantsMessages else None return DirectResponse.fail(msg=msg, inline_message='Access key denied: Go to "Advanced... PagerDuty Settings"') except requests.PagerDutyUnreachableException as pdue: msg = pdue.message if wantsMessages else None return DirectResponse.fail(msg=msg, inline_message=pdue.message) if not apiServices: msg = ("No services with events integration v2 were found for %s.pagerduty.com." % account.subdomain) if wantsMessages else None return DirectResponse.fail(msg=msg) data = [service.getDict() for service in apiServices] return DirectResponse.succeed(msg=None, data=data)
def add_ovirt(self, url, username, domain, password, collector='localhost'): # Check the permissions on the context context = self.context.dmd.Devices.oVirt if not Zuul.checkPermission(ZEN_MANAGE_DMD, context): message = "Insufficient privileges to add an oVirt infrastructure" audit('UI.oVirt.Login', url=url) return DirectResponse.fail(message) facade = self._getFacade() success, message = facade.add_ovirt(url, username, domain, password, collector) if success: audit('UI.oVirt.Add', url=url, username=username, domain=domain, password=password, collector=collector, jobId=message) return DirectResponse.succeed(jobId=message) else: return DirectResponse.fail(message)
def executeScript(self, script, commit=False): try: results = {} exec(script, get_zendmd_globals(self.context), results) except Exception as e: return DirectResponse.fail(msg=str(e)) results.pop("_", None) try: return DirectResponse.succeed(**marshal(info(results))) except Exception as e: return DirectResponse.fail(msg=str(e))
def addNode(self, contextUid='', id='', type=''): """ Add an organizer or new blank MIB. @type contextUid: string @param contextUid: Context to attach new node @type id: string @param id: Id of the new orgainzer or blank MIB @type type: string @param type: Type of new node. Can be 'organizer' or 'MIB' @rtype: DirectResponse @return: B{Properties}: - tree: ([dictionary]) Object representing the new tree """ # GAH! JS passes back a keyword of 'type' nodeType = type if nodeType not in ['organizer', 'MIB']: return DirectResponse.fail('Not creating "%s"' % nodeType) try: if nodeType == 'organizer': uid = contextUid + '/' + id maoUid = uid.replace('/zport/dmd', '') self.context.dmd.Mibs.manage_addOrganizer(maoUid) self.context.dmd.restrictedTraverse(uid) audit('UI.Organizer.Add', uid) else: container = self.context.dmd.restrictedTraverse(contextUid) container.manage_addMibModule(id) audit('UI.Mib.Add', contextUid + '/' + id) return DirectResponse.succeed(tree=self.getTree()) except Exception, e: return DirectResponse.exception(e)
def deleteTrap(self, uid): if uid.find('/notifications/') == -1: return DirectResponse.fail('"%s" does not appear to refer to a trap' % uid) mibUid, trapId = uid.split('/notifications/') self.api.deleteTrap(mibUid, trapId) audit('UI.Mib.DeleteTrap', mibUid, trap=trapId) return DirectResponse.succeed()
def deleteOidMapping(self, uid): if uid.find('/nodes/') == -1: return DirectResponse.fail('"%s" does not appear to refer to an OID Mapping' % uid) mibUid, mappingId = uid.split('/nodes/') self.api.deleteOidMapping(mibUid, mappingId) audit('UI.Mib.DeleteOidMapping', mibUid, mapping=mappingId) return DirectResponse.succeed()
def getTree(self, id): """ Returns the tree structure of the application and collector hierarchy. @type id: string @param id: Id of the root node of the tree to be returned @rtype: [dictionary] @return: Object representing the tree """ try: appfacade = self._getFacade() monitorfacade = Zuul.getFacade("monitors", self.context) nodes = [ITreeNode(m) for m in monitorfacade.query()] for monitor in nodes: apps = appfacade.queryMonitorDaemons(monitor.name) for app in apps: monitor.addChild(IInfo(app)) apps = appfacade.queryMasterDaemons() for app in apps: nodes.append(IInfo(app)) return Zuul.marshal(nodes) except URLError as e: log.exception(e) return DirectResponse.fail( "Error fetching daemons list: " + str(e.reason) )
def update_zovp_account(self, zovPushKey=None , triggers=None): if zovPushKey == None: return DirectResponse.fail("Missing zovPushKey") dmdRoot = _dmdRoot(self.context) accounts = getattr(dmdRoot, 'zovp_accounts', []) this_account_details = models.zovpaccount.ZOVPAccount(zovPushKey, triggers) index = 0 newaccount = True for accountDetails in accounts: if accountDetails.zovPushKey == zovPushKey: newaccount = False break else: index += 1 if newaccount == True: accounts.append(this_account_details) else: accounts[index] = this_account_details setattr(dmdRoot, 'zovp_accounts', accounts) return DirectResponse.succeed("Account updated")
def getTree(self, id): """ Returns the tree structure of the application and collector hierarchy. @type id: string @param id: Id of the root node of the tree to be returned @rtype: [dictionary] @return: Object representing the tree """ try: appfacade = self._getFacade() monitorfacade = Zuul.getFacade("monitors", self.context) nodes = [ITreeNode(m) for m in monitorfacade.query()] for monitor in nodes: apps = appfacade.queryMonitorDaemons(monitor.name) for app in apps: monitor.addChild(IInfo(app)) apps = appfacade.queryMasterDaemons() for app in apps: nodes.append(IInfo(app)) return Zuul.marshal(nodes) except URLError as e: log.exception(e) return DirectResponse.fail("Error fetching daemons list: " + str(e.reason))
def addTrap(self, uid, id, oid, nodetype='notification'): if not self._validateOid(oid): msg = "Invalid OID value %s" % oid return DirectResponse.fail(msg) self.api.addTrap(uid, id, oid, nodetype) audit('UI.Mib.AddTrap', uid, id=id, oid=oid, nodetype=nodetype) return DirectResponse.succeed()
def updateConfigFiles(self, id, configFiles): """ Updates the configuration files for an application specified by id. The configFiles parameters is an array of dictionaries of the form: { filename: "blah", content: "line 1\nline 2\n..." } The filename parameter serves as the "id" of each configFile passed in. """ if not Zuul.checkPermission('Manage DMD'): return DirectResponse.fail("You don't have permission to set update config files", sticky=False) facade = self._getFacade() deployedApp = facade.get(id) newConfigs = [] for deployedAppConfig in deployedApp.configurations: if deployedAppConfig.filename in [ cf['filename'] for cf in configFiles ]: audit('UI.Applications.UpdateConfigFiles', service=id, servicename=deployedApp.name, filename=deployedAppConfig.filename) deployedAppConfig.content = next((cf['content'] for cf in configFiles if cf['filename'] == deployedAppConfig.filename)) newConfigs.append(deployedAppConfig) deployedApp.configurations = newConfigs return DirectResponse.succeed()
def manage_addJitterSLAs(self, newId, rttIndex, deviceIp, community, rttMonEchoAdminTargetAddress, rttMonEchoAdminTargetPort, rttMonEchoAdminInterval=60, rttMonEchoAdminNumPackets=100, rttMonScheduleAdminRttStartTime=1, rttMonCtrlAdminOwner="zenoss"): facade = self._getFacade() success, message = facade.manage_addJitterSLAs( newId, rttIndex, deviceIp, community, rttMonEchoAdminTargetAddress, rttMonEchoAdminTargetPort, rttMonEchoAdminInterval=60, rttMonEchoAdminNumPackets=100, rttMonScheduleAdminRttStartTime=1, rttMonCtrlAdminOwner="zenoss") if success: return DirectResponse.succeed(jobId=message) else: return DirectResponse.fail(message)
def addnrpeComponent(self, title, nrpe_cmd, nrpe_args, nrpe_timeout, nrpe_min, nrpe_max, nrpe_type, userCreated=None, REQUEST=None): """ Adds NRPE Check/Component monitor """ title = prepId(title) nrpecomponent = nrpeComponent(title) nrpecomponent.nrpe_cmd = nrpe_cmd nrpecomponent.nrpe_args = nrpe_args nrpecomponent.nrpe_timeout = int(nrpe_timeout) nrpecomponent.nrpe_min = nrpe_min nrpecomponent.nrpe_max = nrpe_max nrpecomponent.nrpe_type = nrpe_type nrpecomponent.lockFromDeletion() for nrpeCheck in d.os.nrpeComponent(): if nrpeCheck.title == nrpecomponent.title: return DirectResponse.fail(_t("A NRPE Check %s already exists." % nrpecomponent.title)) self.context.os._setObject(nrpecomponent.id, nrpecomponent) _zNRPEChecks = self.context.zNRPEChecks nrpe_dict = "{ 'title': '%s', 'cmd': '%s', 'args': %s , 'timeout': %d, 'min': %d, 'max': %d, 'type': '%s' }" \ % (prepId(title), nrpe_cmd, nrpe_args, int(nrpe_timeout), nrpe_min, nrpe_max, nrpe_type) _zNRPEChecks.append(nrpe_dict) eventDict = { 'eventClass': Change_Add, 'device': self.device().id, 'component': nrpecomponent or '', 'summary': 'Added by user: %s' % 'user', 'severity': Event.Info, } self.dmd.ZenEventManager.sendEvent(eventDict) return DirectResponse.succeed(_t("NRPE Check %s added." % nrpecomponent.title))
def manage_addHttpSLAs(self, newId, rttIndex, deviceIp, community, rttMonEchoAdminURL, rttMonScheduleAdminRttStartTime=1, rttMonCtrlAdminFrequency=60, rttMonCtrlAdminOwner="zenoss", rttMonCtrlAdminThreshold=5000, rttMonCtrlAdminTimeout=5): facade = self._getFacade() success, message = facade.manage_addHttpSLAs( newId, rttIndex, deviceIp, community, rttMonEchoAdminURL, rttMonScheduleAdminRttStartTime=1, rttMonCtrlAdminFrequency=60, rttMonCtrlAdminOwner="zenoss", rttMonCtrlAdminThreshold=5000, rttMonCtrlAdminTimeout=5) if success: return DirectResponse.succeed(jobId=message) else: return DirectResponse.fail(message)
def getSavedSearch(self, searchName): """ @params string searchName: identifier of the search we are looking for @return DirectResponse: the data attribute will have our search terms """ facade = self._getFacade() if facade.noSaveSearchProvidersPresent(): return DirectResponse.fail(message=_t('Unable to find the specified search')) # look for our search savedSearch = facade.getSavedSearch(searchName) if savedSearch: return DirectResponse.succeed(data=Zuul.marshal(savedSearch)) # we could not find the search term return DirectResponse.fail(message=_t('Unable to find the specified search'))
def asyncGetTree(self, id): """ Returns the tree structure of the application and collector hierarchy. @type id: string @param id: Id of the root node of the tree to be returned @rtype: [dictionary] @return: Object representing the tree """ try: if not hasattr(id, '__iter__'): return self._getOneTree(id) trees = {i: self._getOneTree(i) for i in id} treeKeys = self._getParentTreeKeys(trees) # replace any children with expanded tree for key in treeKeys: children = trees[key]['children'] for i in range(len(children)): currentChild = children[i] if trees.has_key(currentChild['id']): children[i] = trees[currentChild['id']] return trees['root'] except URLError as e: log.exception(e) return DirectResponse.fail( "Error fetching daemons list: " + str(e.reason) )
def addNode(self, contextUid='', id='', type=''): """ Add an organizer or new blank MIB. @type contextUid: string @param contextUid: Context to attach new node @type id: string @param id: Id of the new orgainzer or blank MIB @type type: string @param type: Type of new node. Can be 'organizer' or 'MIB' @rtype: DirectResponse @return: B{Properties}: - tree: ([dictionary]) Object representing the new tree """ # GAH! JS passes back a keyword of 'type' nodeType = type try: if nodeType == 'organizer': uid = contextUid + '/' + id maoUid = uid.replace('/zport/dmd', '') self.context.dmd.Mibs.manage_addOrganizer(maoUid) self.context.dmd.restrictedTraverse(uid) audit('UI.Organizer.Add', uid) elif nodeType == 'MIB': container = self.context.dmd.restrictedTraverse(contextUid) container.manage_addMibModule(id) audit('UI.Mib.Add', contextUid + '/' + id) else: return DirectResponse.fail('Invalid node type "%s"' % nodeType) return DirectResponse.succeed(tree=self.getTree()) except Exception as ex: log.exception(ex) return DirectResponse.exception( ex, message="Failed to create '{}'".format(id))
def manage_delSLAs(self, rttIndex, deviceIp, community): facade = self._getFacade() success, message = facade.manage_delSLAs(rttIndex, deviceIp, community) if success: return DirectResponse.succeed(jobId=message) else: return DirectResponse.fail(message)
def deleteTrap(self, uid): if uid.find('/notifications/') == -1: return DirectResponse.fail( '"%s" does not appear to refer to a trap' % uid) mibUid, trapId = uid.split('/notifications/') self.api.deleteTrap(mibUid, trapId) audit('UI.Mib.DeleteTrap', mibUid, trap=trapId) return DirectResponse.succeed()
def deleteOidMapping(self, uid): if uid.find('/nodes/') == -1: return DirectResponse.fail( '"%s" does not appear to refer to an OID Mapping' % uid) mibUid, mappingId = uid.split('/nodes/') self.api.deleteOidMapping(mibUid, mappingId) audit('UI.Mib.DeleteOidMapping', mibUid, mapping=mappingId) return DirectResponse.succeed()
def add_xenserver(self, name, address, username, password, collector='localhost'): success = self._getFacade().add_xenserver( name, address, username, password, collector=collector) if success: return DirectResponse.succeed() else: return DirectResponse.fail("Failed to add XenServer")
def manage_addDhcpSLAs(self, newId, rttIndex, deviceIp, community, rttMonScheduleAdminRttStartTime=1, rttMonCtrlAdminOwner="zenoss"): facade = self._getFacade() success, message = facade.manage_addDhcpSLAs(newId, rttIndex, deviceIp, community, rttMonScheduleAdminRttStartTime=1, rttMonCtrlAdminOwner="zenoss") if success: return DirectResponse.succeed(jobId=message) else: return DirectResponse.fail(message)
def serviceConnectionError(func, *args, **kwargs): try: return func(*args, **kwargs) except ZepConnectionError: msg = 'Connection refused. Check zeneventserver status on <a href="/zport/About/zenossInfo">Daemons</a>' except ServiceConnectionError: msg = 'Connection refused to a required daemon. Check status on <a href="/zport/About/zenossInfo">Daemons</a>' return DirectResponse.fail(msg, sticky=True)
def manage_addHttpSLAs(self, newId, rttIndex, deviceIp, community, rttMonEchoAdminURL, rttMonScheduleAdminRttStartTime=1, rttMonCtrlAdminFrequency=60, rttMonCtrlAdminOwner="zenoss", rttMonCtrlAdminThreshold=5000, rttMonCtrlAdminTimeout=5): facade = self._getFacade() success, message = facade.manage_addHttpSLAs(newId, rttIndex, deviceIp, community, rttMonEchoAdminURL, rttMonScheduleAdminRttStartTime=1, rttMonCtrlAdminFrequency=60, rttMonCtrlAdminOwner="zenoss", rttMonCtrlAdminThreshold=5000, rttMonCtrlAdminTimeout=5) if success: return DirectResponse.succeed(jobId=message) else: return DirectResponse.fail(message)
def manage_addJitterSLAs(self, newId, rttIndex, deviceIp, community, rttMonEchoAdminTargetAddress, rttMonEchoAdminTargetPort, rttMonEchoAdminInterval=60, rttMonEchoAdminNumPackets=100, rttMonScheduleAdminRttStartTime=1, rttMonCtrlAdminOwner="zenoss"): facade = self._getFacade() success, message = facade.manage_addJitterSLAs(newId, rttIndex, deviceIp, community, rttMonEchoAdminTargetAddress, rttMonEchoAdminTargetPort, rttMonEchoAdminInterval=60, rttMonEchoAdminNumPackets=100, rttMonScheduleAdminRttStartTime=1, rttMonCtrlAdminOwner="zenoss") if success: return DirectResponse.succeed(jobId=message) else: return DirectResponse.fail(message)
def add_ec2account(self, accountname, accesskey, secretkey, collector): success = self._getFacade().add_ec2account( accountname, accesskey, secretkey, collector) if success: return DirectResponse.succeed() else: return DirectResponse.fail("Failed to add EC2 account")
def add_ec2account(self, accountname, accesskey, secretkey, collector): success = self._getFacade().add_ec2account(accountname, accesskey, secretkey, collector) if success: return DirectResponse.succeed() else: return DirectResponse.fail("Failed to add EC2 account")
def deleteDevices(self, uids, deleteEvents=True): """ Delete devices using a job """ success, data = self.facade.deleteDevices(uids, deleteEvents) if success: return DirectResponse.succeed(data=Zuul.marshal(data)) else: return DirectResponse.fail(msg=data)
def testRegex(self, regex, example): """ Test our regex using the example event string. """ facade = self._getFacade() reg = facade.testRegex(regex, example) if reg is True: return DirectResponse.succeed() return DirectResponse.fail(reg)
def get_zovp_account(self, zovPushKey): dmdRoot = _dmdRoot(self.context) accounts = getattr(dmdRoot, 'zovp_accounts', []) for accountDetail in accounts: if accountDetail.zovPushKey == zovPushKey: return _success(accountDetail) return DirectResponse.fail()
def getRouters(self, name_instead_of_ip): # noqa """Get rancid router.db file.""" facade = self._getFacade() success, message = facade.getRouters(name_instead_of_ip) if success: return DirectResponse.succeed(result=message) else: return DirectResponse.fail(message)
def addOpenStack(self, hostname, authUrl, username, apiKey): facade = self._getFacade() success, message = facade.addOpenStack( hostname, authUrl, username, apiKey) if success: return DirectResponse.succeed(jobId=message) else: return DirectResponse.fail(message)
def getOid(self, oid): try: node = next(iter(self.api.getOidList(oid)), None) except Exception as ex: log.warn("Error while looking up OID '%s': %s", oid, ex) node = None if node is None: return DirectResponse.fail() return DirectResponse.succeed(info=Zuul.marshal(IInfo(node)))
def add_cloudstack(self, url, api_key, secret_key): facade = self._getFacade() success, message = facade.add_cloudstack( url, api_key, secret_key) if success: return DirectResponse.succeed(jobId=message) else: return DirectResponse.fail(message)
def addNode(self, newSubnet, contextUid): """ Add a new subnet. @type newSubnet: string @param newSubnet: New subnet to add @type contextUid: string @param contextUid: Unique identifier of the network parent of the new subnet @rtype: DirectResponse @return: B{Properties}: - newNode: (dictionary) An object representing the new subnet node """ # If the user doesn't include a mask, reject the request. if '/' not in newSubnet: response = DirectResponse.fail('You must include a subnet mask.') else: try: contextUid = getUtility(IVirtualRoot).strip_virtual_root( contextUid) netip, netmask = newSubnet.split('/') netmask = int(netmask) foundSubnet = self.api.findSubnet(netip, netmask, contextUid) if foundSubnet is not None: response = DirectResponse.fail( 'Did not add duplicate subnet: %s (%s/%s)' % (newSubnet, foundSubnet.id, foundSubnet.netmask)) else: newNet = self.api.addSubnet(newSubnet, contextUid) node = ITreeNode(newNet) audit('UI.Network.AddSubnet', contextUid, subnet=newSubnet) response = DirectResponse.succeed( newNode=Zuul.marshal(node)) except IpAddressError as error: response = DirectResponse.exception(error, 'Error adding subnet.') except Exception as error: log.exception("Error adding subnet.") response = DirectResponse.exception(error, 'Error adding subnet.') return response
def add_cloudstack(self, url, api_key, secret_key, collector='localhost'): facade = self._getFacade() success, message = facade.add_cloudstack(url, api_key, secret_key, collector) audit('UI.Cloudstack.Add', url=url, collector=collector) if success: return DirectResponse.succeed(jobId=message) else: return DirectResponse.fail(message)
def addHttpComponentRouter(self, httpPort, httpUseSSL, httpUrl, httpAuthUser, httpAuthPassword, httpJsonPost, httpFindString): facade = self._getFacade() ob = self.context success, message = facade.addHttpComponent(ob, httpPort, httpUseSSL, httpUrl, httpAuthUser, httpAuthPassword, httpJsonPost, httpFindString) if success: return DirectResponse.succeed(message) else: return DirectResponse.fail(message)
def add_cloudstack(self, url, api_key, secret_key,collector='localhost'): facade = self._getFacade() success, message = facade.add_cloudstack( url, api_key, secret_key,collector) audit('UI.Cloudstack.Add', url=url, collector=collector) if success: return DirectResponse.succeed(jobId=message) else: return DirectResponse.fail(message)
def addOpenStack(self, username, api_key, project_id, auth_url, region_name=None): facade = self._getFacade() success, message = facade.addOpenStack( username, api_key, project_id, auth_url, region_name=region_name) if success: return DirectResponse.succeed(jobId=message) else: return DirectResponse.fail(message)
def add_cloudstack(self, device_name, url, api_key, secret_key,collector='localhost'): facade = self._getFacade() success = facade.add_cloudstack( device_name, url, api_key, secret_key,collector) audit('UI.Cloudstack.Add', url=url, collector=collector) if success: return DirectResponse.succeed() else: return DirectResponse.fail("Failed to add CloudStack device: %s" % device_name)
def update_zovp_server(self, zovpServerKey=None, zovpServerEndPointURL=None): if zovpServerKey == None or zovpServerEndPointURL == None: return DirectResponse.fail("Missing zovpServerKey or zovpServerEndPointURL") zovp_server_details = models.zovpserver.ZOVPServer(zovpServerKey, zovpServerEndPointURL) dmdRoot = _dmdRoot(self.context) setattr(dmdRoot, 'zovp_server', zovp_server_details) return DirectResponse.succeed("Server set or updated")
def importDevices(self, data, options={}): """ Create zenbatchload format file starting from the device class. """ facade = self._getFacade() try: stats = facade.importDevices(data=data, options=options) except Exception: log.exception("Unable to import devices: %s", data) msg = "Failed -- see $ZENHOME/logs/event.log for details." return DirectResponse.fail(msg=msg) return DirectResponse.succeed(data=data, stats=stats)
def addOpenStack(self, device_name, username, api_key, project_id, auth_url, region_name=None, collector='localhost'): facade = self._getFacade() success, message = facade.addOpenStack( device_name, username, api_key, project_id, auth_url, region_name=region_name, collector=collector) if success: return DirectResponse.succeed(jobId=message) else: return DirectResponse.fail(message)
def setInfo(self, **data): """ Set attributes on a process. This method accepts any keyword argument for the property that you wish to set. The only required property is "uid". @type uid: string @keyword uid: Unique identifier of a process @rtype: DirectResponse @return: B{Properties} - data: (dictionary) Object representing a process's new properties """ facade = self._getFacade() processUid = data['uid'] for regexParam in ['includeRegex', 'excludeRegex', 'replaceRegex']: regex = data.get(regexParam) if regex: try: re.compile(regex) except re.error as e: m = "%s : %s" % (regexParam, e) return DirectResponse.fail(msg=m) replaceRegex = data.get('replaceRegex') if replaceRegex: replaceRegex = re.compile(replaceRegex) replacement = data.get('replacement') if replacement: try: groups, literals = parse_template(replacement,replaceRegex) for index, group in groups: if group > replaceRegex.groups: m = "Group (%s) referenced in replacement must be defined in replaceRegex" % group return DirectResponse.fail(msg=m) except re.error as e: m = "replacement : %s" % (e,) return DirectResponse.fail(msg=m) process = facade.getInfo(processUid) audit('UI.Process.Edit', processUid, data_=data, skipFields_=('uid')) return DirectResponse.succeed(data=Zuul.unmarshal(data, process))
def addEndpoint(self, target, email, password, collector=None): if not collector: collector = 'localhost' facade = self._getFacade() success, message = facade.addEndpoint( target, email, password, collector) audit('UI.CloudFoundry.Add', target=target,email=email, collector=collector) if success: return DirectResponse.succeed(jobId=message) else: return DirectResponse.fail(message)
def routerfpc(self, deviceip, frupowercontrol): ''' routerFPC ''' facade = self._getFacade() devobject = self.context frunum = 1 success, message = facade.frupowerctrl(devobject, deviceip, frunum, frupowercontrol) if success: return DirectResponse.succeed(message) return DirectResponse.fail(message)
def routerbs(self, deviceip, bootsequence, cfgboottype): ''' routerBS ''' facade = self._getFacade() # The object that is being operated on is in self.context devobject = self.context success, message = facade.bootsequence(devobject, deviceip, bootsequence, cfgboottype) if success: return DirectResponse.succeed(message) return DirectResponse.fail(message)
def discoverDevices(self, uid, collector=None): """Discover devices on a network. @type uid: string @param uid: Unique identifier of the network to discover @rtype: DirectResponse @return: B{Properties}: - jobId: (integer) The id of the discovery job """ jobStatus = self.api.discoverDevices(uid, collector) if jobStatus: audit("UI.Network.DiscoverDevices", uid) return DirectResponse.succeed(new_jobs=Zuul.marshal( [jobStatus], keys=("uuid", "description", "started"))) else: return DirectResponse.fail()