def params(cls, datasource, context):
        resource = datasource.talesEval(datasource.resource, context)
        if not resource.startswith('\\') and \
            datasource.strategy not in ('powershell MSSQL',
                'powershell Cluster Services',
                'powershell Cluster Resources',
                'Custom Command',
                'DCDiag'):
            resource = '\\' + resource
        if safe_hasattr(context, 'perfmonInstance') and context.perfmonInstance is not None:
            resource = context.perfmonInstance + resource

        if safe_hasattr(context, 'instancename'):
            instancename = context.instancename
        else:
            instancename = ''

        try:
            contextURL = context.getPrimaryUrlPath()
            deviceURL = urlparse(context.getParentDeviceUrl())
            contextInstance = urllib.quote("/".join((context.getParentNode().id, context.id)))
            contextcompname = contextURL[len(deviceURL.path) + 1:-len(contextInstance) - 1]
            contextrelname = context.getParentNode().id
            contextmodname = context.__module__

        except(AttributeError):
            contextmodname = ''
            contextrelname = ''
            contextcompname = ''

        contexttitle = context.title

        servername = context.device().title
        if contexttitle == servername and resource == 'get-clustergroup':
            contexttitle = ''

        if len(servername) == 0:
            servername = ''

        parser = getParserLoader(context.dmd, datasource.parser)

        try:
            script = datasource.talesEval(datasource.script, context)
        except:
            script = ''
            log.error('Invalid tales expression in custom command script')

        return dict(resource=resource,
            strategy=datasource.strategy,
            instancename=instancename,
            servername=servername,
            script=script,
            parser=parser,
            usePowershell=datasource.usePowershell,
            contextrelname=contextrelname,
            contextcompname=contextcompname,
            contextmodname=contextmodname,
            contexttitle=contexttitle)
    def params(cls, datasource, context):
        resource = datasource.talesEval(datasource.resource, context)
        if not resource.startswith('\\') and \
            datasource.strategy not in ('powershell MSSQL',
                'powershell Cluster Services',
                'powershell Cluster Resources',
                'Custom Command'):
            resource = '\\' + resource
        if safe_hasattr(
                context,
                'perfmonInstance') and context.perfmonInstance is not None:
            resource = context.perfmonInstance + resource

        if safe_hasattr(context, 'instancename'):
            instancename = context.instancename
        else:
            instancename = ''

        try:
            contextURL = context.getPrimaryUrlPath()
            deviceURL = urlparse(context.getParentDeviceUrl())
            contextInstance = urllib.quote("/".join(
                (context.getParentNode().id, context.id)))
            contextcompname = contextURL[len(deviceURL.path) +
                                         1:-len(contextInstance) - 1]
            contextrelname = context.getParentNode().id
            contextmodname = context.__module__

        except (AttributeError):
            contextmodname = ''
            contextrelname = ''
            contextcompname = ''

        contexttitle = context.title

        servername = context.device().title
        if contexttitle == servername and resource == 'get-clustergroup':
            contexttitle = ''

        if len(servername) == 0:
            servername = ''

        parser = getParserLoader(context.dmd, datasource.parser)

        return dict(resource=resource,
                    strategy=datasource.strategy,
                    instancename=instancename,
                    servername=servername,
                    script=datasource.talesEval(datasource.script, context),
                    parser=parser,
                    usePowershell=datasource.usePowershell,
                    contextrelname=contextrelname,
                    contextcompname=contextcompname,
                    contextmodname=contextmodname,
                    contexttitle=contexttitle)
Ejemplo n.º 3
0
def _search_super(obj, pattern, s, seen):
    vars_ = vars(obj)
    mro = tuple(reversed(obj.__class__.mro()))

    def search_mro(dct, attr_name, attr=None):
        for cls in mro:
            if safe_hasattr(cls, attr_name):
                dct[cls].append((attr_name, attr))
                break

    attrs = defaultdict(lambda: [])
    methods = defaultdict(lambda: [])
    for attr_name in dir(obj):
        if '__' in attr_name:
            continue
        if attr_name in seen:
            continue
        if not safe_hasattr(obj, attr_name):
            continue
        if pattern is not None and not pattern.search(attr_name):
            continue
        attr = vars_[attr_name] if attr_name in vars_ \
                                            else getattr(obj, attr_name)
        if not inspect.ismethod(attr):
            search_mro(attrs, attr_name, attr)
            continue
        search_mro(methods, attr_name, attr)
    mro_slice = mro if s is None else mro[-s - 1:]
    new_seen = set([])
    for key, attr_infos in attrs.items() + methods.items():
        for attr_name, attr in attr_infos:
            new_seen.add(attr_name)
    return new_seen, (mro_slice, attrs, methods)
Ejemplo n.º 4
0
 def __init__(self, dmd):
     self.dmd = dmd
     if not safe_hasattr(dmd, 'callHome') or dmd.callHome is None:
         dmd._p_jar.sync()
         CallHome(dmd).callHome
         transaction.commit()
     self.callhome = dmd.callHome
     self.gatherProtocol = None
Ejemplo n.º 5
0
 def __init__(self, dmd):
     self.dmd = dmd
     if not safe_hasattr(dmd, 'callHome') or dmd.callHome is None:
         dmd._p_jar.sync()
         CallHome(dmd).callHome
         transaction.commit()
     self.callhome = dmd.callHome
     self.gatherProtocol = None
Ejemplo n.º 6
0
 def path(obj):
     path_ = "/".join(x.id for x in reversed(aq_chain(obj)) if safe_hasattr(x, "id") and not inspect.ismethod(x.id))
     if path_ == "":
         return obj
     if path_ == "zport":
         return path_
     if path_ == "zport/dmd":
         return "dmd"
     return path_[len("zport/dmd/") :]
 def remove_mapping(path, instances):
     try:
         org = dmd.Events.getOrganizer(path)
         results = ICatalogTool(org).search(EventClassInst, query=In('id', instances))
         if results.total:
             log.info('Removing deprecated Event Class Instances from {}'.format(path))
             for instance in instances:
                 if safe_hasattr(org, instance):
                     org.removeInstances([instance])
     except Exception:
         pass
Ejemplo n.º 8
0
 def path(obj):
     path_ = '/'.join(x.id for x in reversed(aq_chain(obj)) \
                                         if safe_hasattr(x, 'id') \
                                         and not inspect.ismethod(x.id))
     if path_ == '':
         return obj
     if path_ == 'zport':
         return path_
     if path_ == 'zport/dmd':
         return 'dmd'
     return path_[len('zport/dmd/'):]
Ejemplo n.º 9
0
 def remove_mapping(path, instances):
     try:
         org = dmd.Events.getOrganizer(path)
         results = ICatalogTool(org).search(EventClassInst,
                                            query=In('id', instances))
         if results.total:
             log.info(
                 'Removing deprecated Event Class Instances from {}'.
                 format(path))
             for instance in instances:
                 if safe_hasattr(org, instance):
                     org.removeInstances([instance])
     except Exception:
         pass
    def manage_addRRDDataPoint(self, id, REQUEST=None):
        """Add a new RRDDataPoint object to this datasource."""
        if not id:
            return self.callZenScreen(REQUEST)

        # TODO: refactor core to use some sort of factory for this junk.
        # This is all cut & paste code from the base class with
        # the exception of the object creation.
        dp = AggregatingDataPoint(id)
        if safe_hasattr(operations, id):
            dp.operation = id

        self.datapoints._setObject(dp.id, dp)
        dp = self.datapoints._getOb(dp.id)
        if REQUEST:
            if dp:
                url = '%s/datapoints/%s' % (self.getPrimaryUrlPath(), dp.id)
                REQUEST['RESPONSE'].redirect(url)
            return self.callZenScreen(REQUEST)

        return dp
Ejemplo n.º 11
0
 def search(obj, p=None, s=None, a=None):
     """Search obj for matching attribute and method names.
        p: pattern to match
        s: super depth (how many inheritance levels to search)
        a: acquisition depth
     (ignores any attribute with '__' in its name)
     """
     pattern = None if p is None else re.compile(p, re.IGNORECASE)
     aq_end = None if a is None else a + 1
     seen = set([])
     all_print_args = {}
     chain = [x for x in aq_chain(obj)[:aq_end] if safe_hasattr(x, "id") and not inspect.ismethod(x.id)]
     for obj_ in chain:
         new_seen, print_args = _search_super(aq_base(obj_), pattern, s, seen)
         seen |= new_seen
         all_print_args[obj_.id] = print_args
     for obj_ in reversed(chain):
         mro_slice, attrs, methods = all_print_args[obj_.id]
         for cls in mro_slice:
             if attrs[cls] or methods[cls]:
                 print "\n", "=" * 79, "\n", path(obj_)
                 _search_print(mro_slice, attrs, methods)
                 break
Ejemplo n.º 12
0
 def search(obj, p=None, s=None, a=None):
     """Search obj for matching attribute and method names.
        p: pattern to match
        s: super depth (how many inheritance levels to search)
        a: acquisition depth
     (ignores any attribute with '__' in its name)
     """
     pattern = None if p is None else re.compile(p, re.IGNORECASE)
     aq_end = None if a is None else a + 1
     seen = set([])
     all_print_args = {}
     chain = [x for x in aq_chain(obj)[:aq_end] if safe_hasattr(x, 'id') \
                                         and not inspect.ismethod(x.id)]
     for obj_ in chain:
         new_seen, print_args = _search_super(aq_base(obj_), pattern, s, seen)
         seen |= new_seen
         all_print_args[obj_.id] = print_args
     for obj_ in reversed(chain):
         mro_slice, attrs, methods = all_print_args[obj_.id]
         for cls in mro_slice:
             if attrs[cls] or methods[cls]:
                 print '\n', '=' * 79, '\n', path(obj_)
                 _search_print(mro_slice, attrs, methods)
                 break
Ejemplo n.º 13
0
 def getMonitoredStartModes(self, uid):
     ob = self._getObject(uid)
     if safe_hasattr(ob, 'monitoredStartModes'):
         for startMode in ob.monitoredStartModes:
             yield [startMode]
Ejemplo n.º 14
0
 def getMonitoredStartModes(self, uid):
     ob = self._getObject(uid)
     if safe_hasattr(ob, 'monitoredStartModes'):
         for startMode in ob.monitoredStartModes:
             yield [startMode]
Ejemplo n.º 15
0
    def params(cls, datasource, context):
        resource = datasource.talesEval(datasource.resource, context)
        if not resource.startswith('\\') and \
            datasource.strategy not in ('powershell MSSQL',
                                        'Custom Command',
                                        'DCDiag',
                                        'powershell MSSQL Instance',
                                        'powershell MSSQL Job'):
            resource = '\\' + resource
        if safe_hasattr(
                context,
                'perfmonInstance') and context.perfmonInstance is not None:
            resource = context.perfmonInstance + resource

        instancename = getattr(context, 'instancename', '')

        instanceid = getattr(context, 'id', '')

        version = getattr(context, 'sql_server_version', 0)
        if version:
            # ensure version is a string
            match = re.match('(\d+)\..*', str(version))
            if match:
                version = match.groups()[0]
            else:
                version = 0

        owner_node_ip = None
        if hasattr(context, 'cluster_node_server'):
            owner_node, _ = context.cluster_node_server.split('//')
            owner_node_ip = getattr(context, 'owner_node_ip', None)
            if not owner_node_ip:
                try:
                    owner_node_ip = context.device(
                    ).clusterhostdevicesdict.get(owner_node, None)
                except Exception:
                    pass

        try:
            contextURL = context.getPrimaryUrlPath()
            deviceURL = urlparse(context.getParentDeviceUrl())
            contextInstance = urllib.quote("/".join(
                (context.getParentNode().id, context.id)))
            contextcompname = contextURL[len(deviceURL.path) +
                                         1:-len(contextInstance) - 1]
            contextrelname = context.getParentNode().id
            contextmodname = context.__module__

        except (AttributeError):
            contextmodname = ''
            contextrelname = ''
            contextcompname = ''

        contexttitle = context.title

        servername = context.device().title

        if len(servername) == 0:
            servername = ''

        parser = getParserLoader(context.dmd, datasource.parser)

        script = get_script(datasource, context)

        return dict(resource=resource,
                    strategy=datasource.strategy,
                    instancename=instancename,
                    instanceid=instanceid,
                    servername=servername,
                    script=script,
                    parser=parser,
                    usePowershell=datasource.usePowershell,
                    contextrelname=contextrelname,
                    contextcompname=contextcompname,
                    contextmodname=contextmodname,
                    contexttitle=contexttitle,
                    version=version,
                    owner_node_ip=owner_node_ip)
Ejemplo n.º 16
0
def _isRunningFromUI(context):
    if not safe_hasattr(context, "REQUEST"):
        return False

    return safe_hasattr(context.REQUEST, "SESSION")
Ejemplo n.º 17
0
 def usesMonitorAttribute(self):
     return (not safe_hasattr(self._object, "startMode") \
             or self._object.startMode != "Disabled")
    def params(cls, datasource, context):
        resource = datasource.talesEval(datasource.resource, context)
        if not resource.startswith('\\') and \
            datasource.strategy not in ('powershell MSSQL',
                                        'Custom Command',
                                        'DCDiag',
                                        'powershell MSSQL Instance',
                                        'powershell MSSQL Job'):
            resource = '\\' + resource
        if safe_hasattr(context, 'perfmonInstance') and context.perfmonInstance is not None:
            resource = context.perfmonInstance + resource

        instancename = getattr(context, 'instancename', '')

        instanceid = getattr(context, 'id', '')

        version = getattr(context, 'sql_server_version', 0)
        if version:
            # ensure version is a string
            match = re.match('(\d+)\..*', str(version))
            if match:
                version = match.groups()[0]
            else:
                version = 0

        owner_node_ip = None
        if hasattr(context, 'cluster_node_server'):
            owner_node, _ = context.cluster_node_server.split('//')
            owner_node_ip = getattr(context, 'owner_node_ip', None)
            if not owner_node_ip:
                try:
                    owner_node_ip = context.device().clusterhostdevicesdict.get(owner_node, None)
                except Exception:
                    pass

        try:
            contextURL = context.getPrimaryUrlPath()
            deviceURL = urlparse(context.getParentDeviceUrl())
            contextInstance = urllib.quote("/".join((context.getParentNode().id, context.id)))
            contextcompname = contextURL[len(deviceURL.path) + 1:-len(contextInstance) - 1]
            contextrelname = context.getParentNode().id
            contextmodname = context.__module__

        except(AttributeError):
            contextmodname = ''
            contextrelname = ''
            contextcompname = ''

        contexttitle = context.title

        servername = context.device().title

        if len(servername) == 0:
            servername = ''

        parser = getParserLoader(context.dmd, datasource.parser)

        script = get_script(datasource, context)

        return dict(resource=resource,
                    strategy=datasource.strategy,
                    instancename=instancename,
                    instanceid=instanceid,
                    servername=servername,
                    script=script,
                    parser=parser,
                    usePowershell=datasource.usePowershell,
                    contextrelname=contextrelname,
                    contextcompname=contextcompname,
                    contextmodname=contextmodname,
                    contexttitle=contexttitle,
                    version=version,
                    owner_node_ip=owner_node_ip)
Ejemplo n.º 19
0
def _isRunningFromUI( context):
    if not safe_hasattr( context, 'REQUEST'):
        return False

    return safe_hasattr( context.REQUEST, 'SESSION')
Ejemplo n.º 20
0
def _isRunningFromUI(context):
    if not safe_hasattr(context, 'REQUEST'):
        return False

    return safe_hasattr(context.REQUEST, 'SESSION')
Ejemplo n.º 21
0
 def search_mro(dct, attr_name, attr=None):
     for cls in mro:
         if safe_hasattr(cls, attr_name):
             dct[cls].append((attr_name, attr))
             break