Ejemplo n.º 1
0
    def get_context(my, tactic_node_name):
        '''gets the snapshot data on a particular tactic node
        <node>
          <ref context='model' version='3' search_type='prod/asset?project=bar' search_id='4'/>
        </node>

        '''
        node_data = NodeData(tactic_node_name)
        search_type = node_data.get_attr("ref", "context")
        return search_type
Ejemplo n.º 2
0
    def get_context(self, tactic_node_name):
        '''gets the snapshot data on a particular tactic node
        <node>
          <ref context='model' version='3' search_type='prod/asset?project=bar' search_id='4'/>
        </node>

        '''
        node_data = NodeData(tactic_node_name)
        search_type = node_data.get_attr("ref", "context")
        return search_type
Ejemplo n.º 3
0
    def create_default_node(my, node_name, search_key=None, context=None):
        '''Creates a default template structure when loading a context
        that has no snapshots associated with it
        
        @params 
        node_name: the name of the node to be created
        search_key: a search_key representing the sobject that this node belongs
            to

        @return
        the name of the tactic node created
        '''

        # create the node
        type = "transform"
        node_name = my.app.add_node(node_name, type)

        # create the tactic node
        tactic_type = "transform"
        tactic_node_name = "tactic_%s" % node_name
        tactic_node_name = my.app.add_node(tactic_node_name, tactic_type)

        # add the tacticNodeData attribute and record the search type
        node_data = NodeData(tactic_node_name)
        if search_key:
            node_data.set_attr("ref", "search_key", search_key)
        if context:
            node_data.set_attr("ref", "context", context)
        node_data.commit()

        # attache the tactic node to the node
        my.mel("parent %s %s" % (tactic_node_name, node_name))

        return tactic_node_name
Ejemplo n.º 4
0
    def execute(self):

        # create an xml document
        xml_impl = getDOMImplementation()
        doc = xml_impl.createDocument(None, "session", None)
        root = doc.documentElement

        # go through the tactic
        tactic_nodes = self.util.get_all_tactic_nodes()
        tactic_nodes.sort()
        for tactic_node in tactic_nodes:
            node_data = NodeData(tactic_node)
            ref_node = node_data.get_ref_node()
            root.appendChild(ref_node)

        self.xml = doc.toxml()
        return self.xml
Ejemplo n.º 5
0
    def create_default_node(self, node_name, search_key=None, context=None):
        '''Creates a default template structure when loading a context
        that has no snapshots associated with it
        
        @params 
        node_name: the name of the node to be created
        search_key: a search_key representing the sobject that this node belongs
            to

        @return
        the name of the tactic node created
        '''

        # create the node
        type = "transform"
        node_name = self.app.add_node(node_name, type)

        # create the tactic node
        tactic_type = "transform"
        tactic_node_name = "tactic_%s" % node_name
        tactic_node_name = self.app.add_node(tactic_node_name, tactic_type)


        # add the tacticNodeData attribute and record the search type
        node_data = NodeData(tactic_node_name)
        if search_key:
            node_data.set_attr("ref", "search_key", search_key)
        if context:
            node_data.set_attr("ref", "context", context)
        node_data.commit()

        # attache the tactic node to the node
        self.mel("parent %s %s" % (tactic_node_name, node_name) )

        return tactic_node_name
Ejemplo n.º 6
0
    def __init__(self, *args, **kwargs):
        self.output_fact = kwargs.get('output_fact', ui.data['output_fact'])
        #self.yaml_enabled = kwargs.get('yaml', ui.data['yaml'])

        self.node = NodeData()
        self.targets = self.node.targets
        self.facts = self.node.facts

        self.yaml = YamlActions()
Ejemplo n.º 7
0
    def execute(self):


        # create an xml document
        xml_impl = getDOMImplementation()
        doc = xml_impl.createDocument(None, "session", None)
        root = doc.documentElement

        # go through the tactic
        tactic_nodes = self.util.get_all_tactic_nodes() 
        tactic_nodes.sort()
        for tactic_node in tactic_nodes:
            node_data = NodeData(tactic_node)
            ref_node = node_data.get_ref_node()
            root.appendChild(ref_node)

        self.xml = doc.toxml()
        return self.xml
Ejemplo n.º 8
0
    def introspect(my):
        '''introspect the session and create a session xml from it'''
        # create an xml document
        xml_impl = getDOMImplementation()
        my.doc = xml_impl.createDocument(None, "session", None)
        my.root = my.doc.documentElement

        # go through the tactic
        tactic_nodes = my.util.get_all_tactic_nodes()
        tactic_nodes.sort()
        for tactic_node in tactic_nodes:

            node_data = NodeData(tactic_node)
            ref_node = node_data.get_ref_node()

            # set some more info on the ref node
            ref_node.setAttribute("tactic_node", tactic_node)
            my.root.appendChild(ref_node)

        my.xml = my.doc.toprettyxml()
        return my.xml
Ejemplo n.º 9
0
    def introspect(my):
        '''introspect the session and create a session xml from it'''
        # create an xml document
        xml_impl = getDOMImplementation()
        my.doc = xml_impl.createDocument(None, "session", None)
        my.root = my.doc.documentElement

        # go through the tactic
        tactic_nodes = my.util.get_all_tactic_nodes() 
        tactic_nodes.sort()
        for tactic_node in tactic_nodes:

            node_data = NodeData(tactic_node)
            ref_node = node_data.get_ref_node()

            # set some more info on the ref node
            ref_node.setAttribute("tactic_node", tactic_node)
            my.root.appendChild(ref_node)

        my.xml = my.doc.toprettyxml()
        return my.xml
Ejemplo n.º 10
0
 def add_node(self, node_id: int, pos: tuple = None) -> bool:
     """
     Adds a node to the graph.
     @param node_id: The node ID.
     @param pos: The position of the node.
     @return: True if the node was added successfully, False o.w.
     If the node id already exists the node will not be added.
     """
     if node_id in self.__nodes:
         return False
     node = NodeData(node_id, pos)
     self.__nodes[node_id] = node
     self.edges[node_id] = {}
     self.end_edges[node_id] = {}
     self.__mc += 1
     self.__node_size += 1
     return True
Ejemplo n.º 11
0
    def add_snapshot_to_node(my, tactic_node_name, snapshot):
        snapshot_code = snapshot.get('code')
        search_type = snapshot.get('search_type')
        search_id = snapshot.get('search_id')
        context = snapshot.get('context')
        version = snapshot.get('version')
        revision = snapshot.get('revision')

        node_data = NodeData(tactic_node_name)
        node_data.set_attr("ref", "snapshot_code", snapshot_code)
        node_data.set_attr("ref", "search_type", search_type)
        node_data.set_attr("ref", "search_id", search_id)
        node_data.set_attr("ref", "context", context)
        node_data.set_attr("ref", "version", version)
        node_data.set_attr("ref", "revision", revision)

        node_data.commit()
Ejemplo n.º 12
0
    def add_snapshot_to_node(self, tactic_node_name, snapshot):
        snapshot_code = snapshot.get('code')
        search_type = snapshot.get('search_type')
        search_id = snapshot.get('search_id')
        context = snapshot.get('context')
        version = snapshot.get('version')
        revision = snapshot.get('revision')
        
        node_data = NodeData(tactic_node_name)
        node_data.set_attr("ref", "snapshot_code", snapshot_code)
        node_data.set_attr("ref", "search_type", search_type)
        node_data.set_attr("ref", "search_id", search_id)
        node_data.set_attr("ref", "context", context)
        node_data.set_attr("ref", "version", version)
        node_data.set_attr("ref", "revision", revision)

        node_data.commit()
Ejemplo n.º 13
0
class OutputActions(object):
    def __init__(self, *args, **kwargs):
        self.output_fact = kwargs.get('output_fact', ui.data['output_fact'])
        #self.yaml_enabled = kwargs.get('yaml', ui.data['yaml'])

        self.node = NodeData()
        self.targets = self.node.targets
        self.facts = self.node.facts

        self.yaml = YamlActions()



    def __str__(self):
        """
        a newline-deliminated list of output data
        """
        return "\n".join(self.default_output())

    def default_output(self):
        """
        This method is used if we do not have to run a second set of queries 
        against the API to find another fact (other than FQDN).

        The first query to the API will return a list of FQDNs, if we require
        information other than just the FQDN name, we need to run a second 
        set of queries against the API for each of those hostnames. Annoying.
        """
        if self._output_type_is_fqdn():
            return self.node.targets
        else:

            # create a pool, for running curl queries in parallel
#            pool = multiprocessing.Pool()
#            pool.map(self._target_to_fact_dict, self.targets)

            # this loop sucks, since it's fully blocking for each API request
            for t in self.targets:
                self._target_to_fact_dict(t)
            
#            if ui.debug: print 'All done with query batch, preping to return some data:"%s"' % (self.node.facts)
            return self.node.get_fact_from_facts(self.output_fact)

    def _target_to_fact_dict(self, target):
        """
        Feed me a target, and I'll return all facts about that target
        """
        facts = FactSearch(target=target)
        facts.run()
        facts.save()

    def _output_type_is_fqdn(self):
        """
        check to see if the output type matches fqdn (the default)
        If it does match, we'll just return true. However, if it does not match
        That means we'll have to do some more work here
        """
        if ui.debug: print 'output_fact is set to "%s"' % (self.output_fact)
        if self.output_fact == 'fqdn':
            if ui.debug: print 'default output type found'
            return True
        else:
            if ui.debug: print 'non-default output type found'
            return False

    def _yaml_picker(self):
        """
        will output yaml, if yaml == True, otherwise will output text
        """
        raise Tbd
        if self.yaml_enabled:
            return self.output_yaml()
        else:
            return self.output_text()
Ejemplo n.º 14
0
 def get_node_data(my, node_name):
     return NodeData(node_name)
Ejemplo n.º 15
0
 def get_node_data(self, node_name):
     return NodeData(node_name)