def GetNodes(self):
   """Return a list of existing nodes where each node is a dictionary
   The \ref clusterinfo module provides a much more extensive API
   """
   nodes = self.GetConfiguredNodeNames()
   running = asppycustom.GetRunningNodeList()
   name2slot = {}
   for r in running:
     name2slot[r['name']] = r['slot']
   ret = []
   for nodename in nodes:
     config = asp.clAmsMgmtNodeGetConfig(self.hdl,nodename)
     state = asp.clAmsMgmtNodeGetStatus(self.hdl,nodename)
     slot = name2slot.get(nodename, None)
     n = AmfNode(nodename,slot)
     n.setConfig(config)
     n.setState(state)
     ret.append(n)
   return ret
 def GetNodes(self):
     """Return a list of existing nodes where each node is a dictionary
 The \ref clusterinfo module provides a much more extensive API
 """
     nodes = self.GetConfiguredNodeNames()
     running = asppycustom.GetRunningNodeList()
     name2slot = {}
     for r in running:
         name2slot[r['name']] = r['slot']
     ret = []
     for nodename in nodes:
         config = asp.clAmsMgmtNodeGetConfig(self.hdl, nodename)
         state = asp.clAmsMgmtNodeGetStatus(self.hdl, nodename)
         slot = name2slot.get(nodename, None)
         n = AmfNode(nodename, slot)
         n.setConfig(config)
         n.setState(state)
         ret.append(n)
     return ret
def TestGetConfig():
  """Internal module unit test"""
  s = Session()
  nodes = s.GetConfiguredNodeNames()
  config = asp.ClAmsNodeConfigT()

  print "Nodes: ", nodes
  for n in nodes:
    config = asp.clAmsMgmtNodeGetConfig(s.hdl,n[1])
    print config   

  sgs = s.GetConfiguredEntities(ServiceGroupType)
  print sgs
  for sg in sgs:
    config = asp.clAmsMgmtServiceGroupGetConfig(s.hdl,sg[1])
    print config

  sus = s.GetConfiguredEntities(ServiceUnitType)
  print sus
  for su in sgs:
    config = asp.clAmsMgmtServiceUnitGetConfig(s.hdl,su[1])
    print config

  sis = s.GetConfiguredEntities(WorkAssignmentType)
  print "SIs: ", sis
  for si in sis:
    config = asp.clAmsMgmtServiceInstanceGetConfig(s.hdl,si[1])
    print config

  csis = s.GetConfiguredEntities(ComponentWorkAssignmentType)
  print "CSIs: ", csis
  for csi in csis:
    config = asp.clAmsMgmtCompServiceInstanceGetConfig(s.hdl,csi[1])
    print config

  comps = s.GetConfiguredEntities(ComponentType)
  print "comps: ", comps
  for comp in comps:
    config = asp.clAmsMgmtCompGetConfig(s.hdl,comp[1])
    print config
def TestGetConfig():
    """Internal module unit test"""
    s = Session()
    nodes = s.GetConfiguredNodeNames()
    config = asp.ClAmsNodeConfigT()

    print "Nodes: ", nodes
    for n in nodes:
        config = asp.clAmsMgmtNodeGetConfig(s.hdl, n[1])
        print config

    sgs = s.GetConfiguredEntities(ServiceGroupType)
    print sgs
    for sg in sgs:
        config = asp.clAmsMgmtServiceGroupGetConfig(s.hdl, sg[1])
        print config

    sus = s.GetConfiguredEntities(ServiceUnitType)
    print sus
    for su in sgs:
        config = asp.clAmsMgmtServiceUnitGetConfig(s.hdl, su[1])
        print config

    sis = s.GetConfiguredEntities(WorkAssignmentType)
    print "SIs: ", sis
    for si in sis:
        config = asp.clAmsMgmtServiceInstanceGetConfig(s.hdl, si[1])
        print config

    csis = s.GetConfiguredEntities(ComponentWorkAssignmentType)
    print "CSIs: ", csis
    for csi in csis:
        config = asp.clAmsMgmtCompServiceInstanceGetConfig(s.hdl, csi[1])
        print config

    comps = s.GetConfiguredEntities(ComponentType)
    print "comps: ", comps
    for comp in comps:
        config = asp.clAmsMgmtCompGetConfig(s.hdl, comp[1])
        print config
    def loadNodes(self, oldObj=None):
        """Private:  Reloads the node information from the C layers (call load() instead)"""
        self.log("Loading node config and status")
        if fake: return
        nodes = asppycustom.GetConfiguredEntities(NodeType)

        self.log("Loading live node list")
        #livenodelist = asppycustom.GetRunningNodeList()
        livenodes = self.alive = self.amf.GetAllWorkAssignments()
        self.log("Loading live nodes complete")

        for node in nodes:
            name = node[1]

            liveInfo = livenodes.get(name, None)

            # Create the node
            if liveInfo: nodeSlot = liveInfo['slot']
            else: nodeSlot = 0
            n = AmfNode(name, nodeSlot)

            try:
                installInfo = asp.clAmsMgmtGetAspInstallInfo(
                    self.amf.hdl, name, 255)
                installInfo = dict(
                    [x.split("=") for x in installInfo.split(",")])
                n.setIntraclusterAccess(installInfo['interface'].split(":")[1],
                                        None, None,
                                        installInfo.get('dir', None))
                n.aspVersion = installInfo['version']
            except SystemError, e:
                pass

            # Add the configured info
            try:
                nsd = self.suppliedData.nodes[name]
            except KeyError:
                self.log(
                    "Supplied configuration does not contain blade definition [%s]"
                    % name)
                nsd = None
            except AttributeError:  # it doesn't even have .nodes
                self.log(
                    "Supplied configuration does not contain any blade definitions"
                )
                nsd = None

            # Add the AMF status and config
            config = asp.clAmsMgmtNodeGetConfig(self.amf.hdl, name)
            status = asp.clAmsMgmtNodeGetStatus(self.amf.hdl, name)
            n.setConfig(config)
            n.setStatus(status)

            if nsd:
                # Set Intracluster Access
                n.setIntraclusterAccess(nsd.ip, nsd.user, nsd.password,
                                        nsd.aspdir)
                # Allow it to be indexed by IP
                self.nodes[nsd.ip] = n

            if oldObj:
                oldnode = oldObj.entities.get(name, None)
                if oldnode:
                    n.copyLocalState(oldnode)

            # Allow it to be indexed by name
            self.nodes[name] = n
            self.entities[name] = n
            # Allow it to be indexed by slot (if it has one)
            if n.slot: self.nodes[n.slot] = n
            # Allow an iterator to hit only the nodes
            self.nodeList.append(n)
  def loadNodes(self,oldObj=None):
    """Private:  Reloads the node information from the C layers (call load() instead)"""
    self.log("Loading node config and status")
    if fake: return
    nodes = asppycustom.GetConfiguredEntities(NodeType)
    
    self.log("Loading live node list")
    #livenodelist = asppycustom.GetRunningNodeList()
    livenodes = self.alive = self.amf.GetAllWorkAssignments()
    self.log("Loading live nodes complete")

    for node in nodes:
      name = node[1]

      liveInfo = livenodes.get(name,None)

      # Create the node
      if liveInfo: nodeSlot = liveInfo['slot']
      else: nodeSlot = 0
      n = AmfNode(name,nodeSlot)

      try:
        installInfo = asp.clAmsMgmtGetAspInstallInfo(self.amf.hdl,name,255)        
        installInfo = dict([x.split("=") for x in installInfo.split(",")])
        n.setIntraclusterAccess(installInfo['interface'].split(":")[1],None,None,installInfo.get('dir',None))
        n.aspVersion = installInfo['version']
      except SystemError,e:
        pass
      
      # Add the configured info
      try:
        nsd = self.suppliedData.nodes[name]
      except KeyError:
        self.log("Supplied configuration does not contain blade definition [%s]" % name)
        nsd = None
      except AttributeError:  # it doesn't even have .nodes
        self.log("Supplied configuration does not contain any blade definitions")
        nsd = None

      # Add the AMF status and config
      config = asp.clAmsMgmtNodeGetConfig(self.amf.hdl,name)
      status = asp.clAmsMgmtNodeGetStatus(self.amf.hdl,name)
      n.setConfig(config)
      n.setStatus(status)

      if nsd:
        # Set Intracluster Access
        n.setIntraclusterAccess(nsd.ip,nsd.user,nsd.password,nsd.aspdir)
        # Allow it to be indexed by IP 
        self.nodes[nsd.ip] = n

      if oldObj:
        oldnode=oldObj.entities.get(name,None)
        if oldnode:
          n.copyLocalState(oldnode)

      # Allow it to be indexed by name
      self.nodes[name] = n
      self.entities[name] = n
      # Allow it to be indexed by slot (if it has one)
      if n.slot: self.nodes[n.slot] = n
      # Allow an iterator to hit only the nodes
      self.nodeList.append(n)