Beispiel #1
0
def getSgEntities(sgName):
    sgx = sp.mgtGet("/" + AmfPfx + "/ServiceGroup/" + sgName)
    if sgx: sg = microdom.LoadString(sgx)
    else:
        raise Error("no service group [%s], or no access" % sgName)
    suNames = csv2List(sg.serviceUnits.data_)
    sg.comp = {}  # add a new variable to the sg object
    sg.su = {
    }  # add a new variable to the sg object that is a dictionary of su objects
    sg.si = {}
    sg.csi = {}
    for sun in suNames:
        if not sun: continue
        sut = sp.mgtGet(sun)
        if sut:
            sumd = microdom.LoadString(sut)
            sg.su[sumd.name.data_] = sumd  # Add this su to the sg's dictionary
            sumd.sg = sg  # Set up parent reference
            compNames = csv2List(sumd.components.data_)
            sumd.comp = {
            }  # add a new variable to the su that is a dictionary of comp objects
            for cn in compNames:
                if not cn: continue
                cux = sp.mgtGet(cn)
                if cux:
                    compMicrodom = microdom.LoadString(cux)
                    sg.comp[compMicrodom.name.data_] = compMicrodom
                    sumd.comp[compMicrodom.name.data_] = compMicrodom
                else:
                    raise Error("no component [%s], or no access" % cn)
        else:
            raise Error("no service unit [%s], or no access" % sun)

    siNames = [x.strip() for x in sg.serviceInstances.data_.split(",")]
    for sin in siNames:
        if not sin: continue
        six = sp.mgtGet(sin)
        if six:
            sim = microdom.LoadString(six)
            sg.si[sim.name.data_] = sim  # Add this su to the sg's dictionary
            sim.csi = {}
            sim.sg = sg  # Set up parent reference
            csiNames = csv2List(sim.componentServiceInstances.data_)
            for csin in csiNames:
                if not csin: continue
                csix = sp.mgtGet(sin)
                csim = microdom.LoadString(csix)
                sg.csi[csim.name.data_] = csim
                sim.csi[csim.name.data_] = csim
                csim.si = sim
                csim.sg = sg
        else:
            raise Error("no service instance [%s], or no access" % sin)

    return sg
def getSgEntities(sgName):
  sgx = sp.mgtGet("/" + AmfPfx + "/ServiceGroup/" + sgName)
  if sgx: sg = microdom.LoadString(sgx)
  else:
    raise Error("no service group [%s], or no access" % sgName)
  suNames = csv2List(sg.serviceUnits.data_)
  sg.comp = {} # add a new variable to the sg object
  sg.su = {}  # add a new variable to the sg object that is a dictionary of su objects
  sg.si = {}
  sg.csi = {}
  for sun in suNames:
    if not sun: continue
    sut = sp.mgtGet(sun)
    if sut:
      sumd = microdom.LoadString(sut)
      sg.su[sumd.name.data_] = sumd # Add this su to the sg's dictionary
      sumd.sg = sg # Set up parent reference
      compNames = csv2List(sumd.components.data_)
      sumd.comp = {} # add a new variable to the su that is a dictionary of comp objects
      for cn in compNames:
        if not cn: continue
        cux = sp.mgtGet(cn)
        if cux:
          compMicrodom = microdom.LoadString(cux)
          sg.comp[compMicrodom.name.data_] = compMicrodom
          sumd.comp[compMicrodom.name.data_] = compMicrodom          
        else:
          raise Error("no component [%s], or no access" % cn)
    else:
      raise Error("no service unit [%s], or no access" % sun)

  siNames = [x.strip() for x in sg.serviceInstances.data_.split(",")]
  for sin in siNames:
    if not sin: continue
    six = sp.mgtGet(sin)
    if six:
      sim = microdom.LoadString(six)
      sg.si[sim.name.data_] = sim # Add this su to the sg's dictionary
      sim.csi = {}
      sim.sg = sg  # Set up parent reference
      csiNames = csv2List(sim.componentServiceInstances.data_)
      for csin in csiNames:
        if not csin: continue
        csix = sp.mgtGet(sin)
        csim = microdom.LoadString(csix)
        sg.csi[csim.name.data_] = csim
        sim.csi[csim.name.data_] = csim
        csim.si = sim
        csim.sg = sg
    else:
          raise Error("no service instance [%s], or no access" % sin)


  return sg
Beispiel #3
0
def getEntity(ent):
    """Given an entity string, or list of entity strings, load them from the AMF and convert to Python objects.  If the entity does not exist, return None"""
    if type(ent) is types.ListType:
        return [getEntity(x) for x in ent]
    xml = sp.mgtGet(ent)
    if xml:
        return microdom.LoadString(xml)
    return None
def getEntity(ent):
  """Given an entity string, or list of entity strings, load them from the AMF and convert to Python objects.  If the entity does not exist, return None"""
  if type(ent) is types.ListType:
    return [getEntity(x) for x in ent]
  xml = sp.mgtGet(ent)
  if xml:
    return microdom.LoadString(xml)
  return None
def activeStandby(si):
  if type(si) in types.StringTypes:
    six = sp.mgtGet("/" + "/".join ([AmfPfx,SiPfx,si]))
    if six: si = microdom.LoadString(six)
    else:
      raise Error("no service instance [%s], or no access" % si)
    # print six
    return (csv2List(si.activeAssignments.data_),csv2List(si.standbyAssignments.data_))
Beispiel #6
0
def activeStandby(si):
    if type(si) in types.StringTypes:
        six = sp.mgtGet("/" + "/".join([AmfPfx, SiPfx, si]))
        if six: si = microdom.LoadString(six)
        else:
            raise Error("no service instance [%s], or no access" % si)
        # print six
        return (csv2List(si.activeAssignments.data_),
                csv2List(si.standbyAssignments.data_))
Beispiel #7
0
def mgtGetItem(path,default=raiseException):
  data = mgtGet(path)
  try:
    t = ET.fromstring(data)
    return t.text
  except IndexError, e:
      pdb.set_trace()
      if default is raiseException:
        raise Error("Invalid element")
      else:
        return default
def commit(dct,prefix="/safplusAmf"):
  for (name,val) in dct.items():
    myPath = "%s/%s" % (prefix,name)
    myPath = str(myPath)  # Rip off the unicode if it has it
    if type(val) is types.DictType:  # its a YANG container
      cur = sp.mgtGet(myPath)
      if cur == "":
        sp.mgtCreate(myPath)
      commit(val,myPath)
    elif type(val) is types.InstanceType:  # another was to describe a YANG container
      assert(0)  # TODO
    elif type(val) is types.ListType: # a YANG list
      assert(0)  # TODO
    else:
      sp.mgtSet(myPath,str(val))
Beispiel #9
0
def commit(dct, prefix="/safplusAmf"):
    for (name, val) in dct.items():
        myPath = "%s/%s" % (prefix, name)
        myPath = str(myPath)  # Rip off the unicode if it has it
        if type(val) is types.DictType:  # its a YANG container
            cur = sp.mgtGet(myPath)
            if cur == "":
                sp.mgtCreate(myPath)
            commit(val, myPath)
        elif type(
                val
        ) is types.InstanceType:  # another was to describe a YANG container
            assert (0)  # TODO
        elif type(val) is types.ListType:  # a YANG list
            assert (0)  # TODO
        else:
            sp.mgtSet(myPath, str(val))