sanzcarlos / CiscoAXL

Desarrollo para la configuración de un Cisco Unified Communications Manager con AXL
MIT License
1 stars 0 forks source link

Add new field in CSV #3

Closed sanzcarlos closed 3 years ago

sanzcarlos commented 3 years ago

Is your feature request related to a problem? Please describe. We need add the main DDI of site and create a Translation Pattern to Hunt Pilot

Describe the solution you'd like N/A

Additional context N/A

sanzcarlos commented 3 years ago

Solution: Add a new field (DIDMain) in CSV file, now the file example is:

Site ID,User First Name,User Surname,User Id (userPrincipalName),Directory Number,ToIP Model,MAC Address,DID,Calling Search Space,Voice Mail,Locale,SD_Number,SD_Label,Phone Button Template,DIDMain
0011,Carlos,Sanz Peñas,,6001102|6001181,P_Internas|P_LG_Oficinas,8811,SEPF0082F1B738C,913236708,CSS_All,NO,English United States,6001002|6001081,OF0010 - 02|OF0010 - 81,Standard 8811 SIP,913236700

I modify the function AltaSede in file _axlzeep.py:

def AltaSede(logger, service, cspconfigfile, csv_config_file):
    """Function to create a new site

    Args:
        logger (logging): logging service
        service (ServiceProxy): Class zeep.proxy.ServiceProxy
        config_file (configobj): Dict with config of Customer
        csv_config_file ([type]): [description]

    Copyright (C) 2021 Carlos Sanz <carlos.sanzpenas@gmail.com>
    """
    logger.debug('Ha entrado en la funcion AltaSede')

    try:
        csv_file = open(csv_config_file, 'r', encoding='utf-8')
    except Fault as err:
        logger.error('Se ha producido un error al abrir el archivo %s' % (csv_config_file))
        logger.debug(err)
        sys.exit(1)
    else:
        logger.info('Se ha abierto el archivo %s' % (csv_config_file))

        field_names = (
+           'SiteID', 'UserFirstName', 'UserSurname', 'UserId', 'DirectoryNumber', 'routePartitionName' , 'ToIPModel', 'MACAddress', 'DID', 'CallingSearchSpace', 'VoiceMail', 'Locale', 'SD_Number', 'SD_Label', 'Phone_Button_Template', 'DIDMain' )
        file_reader = csv.DictReader(csv_file, field_names)

+      #add_status = PrettyTable(['SiteID', 'UserFirstName', 'UserSurname', 'UserId', 'DirectoryNumber', 'routePartitionName' , 'ToIPModel', 'MACAddress', 'DID', 'CallingSearchSpace', 'VoiceMail', 'Locale', 'SD_Number', 'SD_Label', 'Phone_Button_Template', 'DIDMain'])
        for row in file_reader:
            # Borramos los espacios al principio y final que puedan tener
            row['SiteID']                = row['SiteID'].strip()
            row['UserFirstName']         = row['UserFirstName'].strip()
            row['UserSurname']           = row['UserSurname'].strip()
            row['DirectoryNumber']       = row['DirectoryNumber'].strip()
            row['ToIPModel']             = row['ToIPModel'].strip()
            row['MACAddress']            = row['MACAddress'].strip()
            row['DID']                   = row['DID'].strip()
            row['CallingSearchSpace']    = row['CallingSearchSpace'].strip()
            row['CSSForward']            = row['CallingSearchSpace'].strip()
            row['VoiceMail']             = row['VoiceMail'].strip()
            row['Locale']                = row['Locale'].strip()
            row['routePartitionName']    = row['routePartitionName'].strip()
            row['SD_Number']             = row['SD_Number'].strip()
            row['SD_Label']              = row['SD_Label'].strip()
            row['Phone_Button_Template'] = row['Phone_Button_Template'].strip()
            # Si no incluimos una Partition ponemos una por defecto
            if row['routePartitionName'] == '':
                row['routePartitionName'] = 'P_Internas'

            row['callPickupGroupName']  = 'CPG_OF' + row['SiteID'].strip()
            row['callManagerGroupName'] = 'CMG_Sub21CD1Sub06CD2'
            row['dateTimeSettingName']  = 'GT_Spain'
+           row['DIDMain']              = row['DIDMain'].strip()

            if row['VoiceMail'] == 'YES':
                row['voiceMailProfileName'] = 'CAIXABANK_VMENABLED'
            else:
                row['voiceMailProfileName'] = 'NoVoiceMail'

            # Region
            cspaxl_Region.Add(logger, service, row)

            # Location
            cspaxl_Location.Add(logger, service, row)

            # Device Pool
            cspaxl_DevicePool.Add(logger, service, row)

            # Call Pick Up Group
            cspaxl_CallPickupGroup.Add(logger, service, row)

            # Line Group
            cspaxl_LineGroup.Add(logger, service, row)

            # Hunt List
            cspaxl_HuntList.Add(logger, service, row)

            # Hunt Pilot
            cspaxl_HuntPilot.Add(logger, service, row)

+          # Line
+          # Comprobamos si tenemos un Directory Number
+          if row['DirectoryNumber'] == '':
+              logger.error('No tenemos Directory Number y no podemos crear el Device, Translation Pattern y actualizar el Line Group')
+          else:
+              # Comprobamos el numero de Directory Numbers que han puesto - El separador es |
+              if len(row['DirectoryNumber'].split('|')) == 1:
+                  logger.info('Tenemos que dar de alta un Directory Number')
+                  cspaxl_Line.Add(logger, service, row)
+              else:
+                  logger.info('Tenemos que dar de alta varios Directory Number:: %s' % (row['DirectoryNumber'].split('|')))
+                  row_temp = row.copy()
+                  DN = row['DirectoryNumber'].split('|')
+                  Partiton = row['routePartitionName'].split('|')
+                  for x in range(0,len(DN)):
+                      logger.info('Vamos a dar de alta el siguiente Directory Number: %s' % (DN[x]))
+                      row_temp['DirectoryNumber']    = DN[x]
+                      row_temp['routePartitionName'] = Partiton[x]
+                      cspaxl_Line.Add(logger, service, row_temp)
+              # Device
+              cspaxl_Phone.Add(logger, service, row)
+         
+              # Add Line Group
+              # Comprobamos el numero de Directory Numbers que han puesto - El separador es |
+              if len(row['DirectoryNumber'].split('|')) == 1:
+                  logger.info('We do not have to add the Directory Number to the Line Group')
+              else:
+                  logger.info('We have to add the Directory Number %s to the Line Group' % (row['DirectoryNumber'].split('|')))
+                  row_temp = row.copy()
+                  DN = row['DirectoryNumber'].split('|')
+                  Partiton = row['routePartitionName'].split('|')
+                  # Empezamos por el segundo elemento (1)
+                  for x in range(1,len(DN)):
+                      logger.info('We have to add the Directory Number : %s' % (DN[x]))
+                      row_temp['DirectoryNumber']    = DN[x]
+                      row_temp['routePartitionName'] = Partiton[x]
+                      cspaxl_LineGroup.Update(logger, service, row_temp)
+         
+          # Translation Pattern
+          cspaxl_TransPattern.Add(logger, service, row)
+          if row['DIDMain'] != '':
+              # Tenemos que crearnos el DID Principal
+              row_temp = row.copy()
+              row_temp['DID']    = row['DIDMain']
+              row_temp['DirectoryNumber']    = '8' + row['SiteID'] + '00'
+              cspaxl_TransPattern.Add(logger, service, row_temp)