Example #1
0
 def handler(self):
     self.logger.info("Checking assets")
     result = self.object.scripts.get_inventory()
     self.find_managed()
     # Submit objects
     for o in result:
         self.logger.info("Submit %s", str_dict(o))
         self.submit(
             type=o["type"],
             number=o.get("number"),
             builtin=o["builtin"],
             vendor=o.get("vendor"),
             part_no=o["part_no"],
             revision=o.get("revision"),
             serial=o.get("serial"),
             mfg_date=o.get("mfg_date"),
             description=o.get("description"),
         )
     # Assign stack members
     self.submit_stack_members()
     #
     self.submit_connections()
     #
     self.check_management()
     #
     self.disconnect_connections()
Example #2
0
 def submit_connections(self):
     # Check connection rule is set
     if not self.rule:
         return
     for i, o in enumerate(self.objects):
         type, object, context, serial = o
         self.logger.info("Trying to connect #%d. %s (%s)", i, type,
                          str_dict(context))
         if type not in self.rule:
             continue
         # Find applicable rule
         for r in self.rule[type]:
             found = False
             t_n = self.expand_context(r.target_number, context)
             if r.scope.startswith("-"):
                 scope = r.scope[1:]
                 fwd = True
             else:
                 scope = r.scope
                 fwd = False
             for t_type, t_object, t_ctx in self.iter_object(
                     i, scope, context.get(scope), r.target_type, fwd=fwd):
                 if isinstance(t_object, str):
                     continue
                 if not t_n or t_n == t_ctx["N"]:
                     # Check target object has proper connection
                     t_c = self.expand_context(r.target_connection, context)
                     if not t_object.has_connection(t_c):
                         continue
                     # Check source object has proper connection
                     m_c = self.expand_context(r.match_connection, context)
                     if isinstance(object, str):
                         # Resolving unknown object
                         o = self.resolve_object(object, m_c, t_object, t_c,
                                                 serial)
                         if not o:
                             continue
                         object = o
                     if not object.has_connection(m_c):
                         continue
                     # Connect
                     self.logger.info(
                         "Connecting %s %s:%s -> %s %s:%s",
                         type,
                         context["N"],
                         m_c,
                         t_type,
                         t_ctx["N"],
                         t_c,
                     )
                     if object.get_data(
                             "twinax", "twinax") and m_c == object.get_data(
                                 "twinax", "alias"):
                         self.connect_twinax(object, m_c, t_object, t_c)
                     else:
                         self.connect_p2p(object, m_c, t_object, t_c)
                     found = True
                     break
             if found:
                 break
Example #3
0
 def reset_context(self, names):
     for n in names:
         if n in self.ctx:
             del self.ctx[n]
         m = "N%s" % n
         if m in self.ctx:
             del self.ctx[m]
     self.logger.debug("Reset context scopes %s -> %s", ", ".join(names), str_dict(self.ctx))
Example #4
0
 def set_context(self, name, value):
     self.ctx[name] = value
     n = "N%s" % name
     if n not in self.ctx:
         self.ctx[n] = 0
     else:
         self.ctx[n] += 1
     self.logger.debug("Set context %s = %s -> %s", name, value, str_dict(self.ctx))