Beispiel #1
0
    logging.info('========== GECOS CC link - Step 02 ==============')

    from gecosws_config_assistant.util.GecosCC import GecosCC
    from gecosws_config_assistant.util.SSLUtil import SSLUtil
    from gecosws_config_assistant.util.GemUtil import GemUtil
    from gecosws_config_assistant.util.Template import Template
    from gecosws_config_assistant.dto.GecosAccessData import GecosAccessData
    from gecosws_config_assistant.dto.WorkstationData import WorkstationData
    from gecosws_config_assistant.dao.WorkstationDataDAO import WorkstationDataDAO
    from gecosws_config_assistant.firstboot_lib.firstbootconfig import get_data_file

    # List of GEMS required to run GECOS
    necessary_gems = [
        'json', 'rest-client', 'activesupport:4.2.11.1', 'netaddr'
    ]
    nsis.setvar('6', "false")
    gecosAccessData = GecosAccessData()
    gecosAccessData.set_url(nsis.getvar('$0'))
    gecosAccessData.set_login(nsis.getvar('$1'))
    gecosAccessData.set_password(nsis.getvar('$2'))
    gecoscc = GecosCC()

    workstationDataDao = WorkstationDataDAO()
    workstationData = workstationDataDao.load()

    conf = json.loads(os.environ["AUTOCFGJSON"])

    # Get client.pem from server
    logging.info("Get client.pem from server")
    gecosCC = GecosCC()
try:
    logging.basicConfig(filename=os.environ["PYLOGFILE"], level=logging.DEBUG)
    logging.info(
        '========== GECOS CC Unlink - Load connection data from files =============='
    )

    from gecosws_config_assistant.dto.GecosAccessData import GecosAccessData
    from gecosws_config_assistant.dto.WorkstationData import WorkstationData
    from gecosws_config_assistant.dao.WorkstationDataDAO import WorkstationDataDAO
    from gecosws_config_assistant.dao.GecosAccessDataDAO import GecosAccessDataDAO

    accessDataDao = GecosAccessDataDAO()
    gecosAccessData = accessDataDao.load()
    if gecosAccessData is None:
        logging.error("Error reading c:\\etc\\gcc.control")
        nsis.setvar('4', "Error reading c:\\etc\\gcc.control")
        nsis.setvar('5', "")
        sys.exit()

    workstationDataDao = WorkstationDataDAO()
    workstationData = workstationDataDao.load()
    if workstationData is None:
        logging.error("Error reading c:\\etc\\gcc.control or C:\\etc\\pclabel")
        nsis.setvar('4',
                    "Error reading c:\\etc\\gcc.control or C:\\etc\\pclabel")
        nsis.setvar('5', "")
        sys.exit()

    nsis.setvar('0', gecosAccessData.get_url())
    nsis.setvar('1', gecosAccessData.get_login())
    nsis.setvar('2', workstationData.get_name())
Beispiel #3
0
try:
    import logging
    logging.basicConfig(filename=os.environ["PYLOGFILE"], level=logging.DEBUG)
    logging.info('========== Validate GECOS credentials ==============')

    from gecosws_config_assistant.util.GecosCC import GecosCC
    from gecosws_config_assistant.util.SSLUtil import SSLUtil
    from gecosws_config_assistant.dto.GecosAccessData import GecosAccessData

    gecosAccessData = GecosAccessData()
    gecosAccessData.set_url(nsis.getvar('$0'))
    gecosAccessData.set_login(nsis.getvar('$1'))
    gecosAccessData.set_password(nsis.getvar('$2'))
    gecoscc = GecosCC()

    # TODO: Disable certificate validation without asking
    SSLUtil.disableSSLCertificatesVerification()

    isOk = gecoscc.validate_credentials(gecosAccessData)
    nsis.setvar('4', str(isOk))

    if gecoscc.last_request_content is not None:
        os.environ["AUTOCFGJSON"] = gecoscc.last_request_content

except:
    nsis.setvar('4', str(sys.exc_info()[0]))
    nsis.setvar('5', str(traceback.format_exc()))
    logging.error(str(sys.exc_info()[0]))
    logging.error(str(traceback.format_exc()))
    raise
# This script extract some data from autonf JSON
#
# IN parameters:
#  NONE
#
# OUT parameters:
#  $1 = version
#  $2 = organization
#  $3 = notes

try:
    conf = json.loads(os.environ["AUTOCFGJSON"])

    if ('version' in conf) and (conf['version'] is not None):
        nsis.setvar('1', str(conf['version']))
    else:
        nsis.setvar('1', '')

    if ('organization' in conf) and (conf['organization'] is not None):
        nsis.setvar('2', conf['organization'].encode('iso-8859-1'))
    else:
        nsis.setvar('2', '')

    if ('notes' in conf) and (conf['notes'] is not None):
        nsis.setvar('3', conf['notes'].encode('iso-8859-1'))
    else:
        nsis.setvar('3', '')

except:
    nsis.setvar('1', str(sys.exc_info()[0]))
#

try:
    import logging
    logging.basicConfig(filename=os.environ["PYLOGFILE"], level=logging.DEBUG)
    logging.info('========== Check workstation name ==============')

    from gecosws_config_assistant.util.GecosCC import GecosCC
    from gecosws_config_assistant.dto.GecosAccessData import GecosAccessData

    gecosAccessData = GecosAccessData()
    gecosAccessData.set_url(nsis.getvar('$0'))
    gecosAccessData.set_login(nsis.getvar('$1'))
    gecosAccessData.set_password(nsis.getvar('$2'))
    gecoscc = GecosCC()
    computer_names = gecoscc.get_computer_names(gecosAccessData)
    is_in_computer_names = False
    for cn in computer_names:
        if cn['name'] == nsis.getvar('$3'):
            is_in_computer_names = True
            break

    nsis.setvar('4', str(is_in_computer_names))

except:
    nsis.setvar('4', str(sys.exc_info()[0]))
    nsis.setvar('5', str(traceback.format_exc()))
    logging.error(str(sys.exc_info()[0]))
    logging.error(str(traceback.format_exc()))
    raise
        gecosAccessData.set_password(nsis.getvar('$2'))
        gecoscc = GecosCC()
        ou_names = gecoscc.search_ou_by_text(
            gecosAccessData,
            nsis.getvar('$3').decode('iso-8859-1').encode('utf-8'))
        if ou_names and (len(ou_names) > 0):
            os.environ["OUNAMES"] = ''
            os.environ["OUIDS"] = ''
            for ou in ou_names:
                # If a name appears twice use only the first one
                if not ou[1].encode(
                        'iso-8859-1') + '|' in os.environ["OUNAMES"]:
                    os.environ["OUIDS"] += ou[0] + '|'
                    os.environ["OUNAMES"] += ou[1].encode('iso-8859-1') + '|'

            nsis.setvar('4', ou_names[0][1].encode('iso-8859-1'))
        else:
            nsis.setvar('4', "")

    else:
        # Get OUs from environ and return the next OU name
        ou_names = os.environ["OUNAMES"].split('|')
        nsis.setvar('4', "")
        next_one = False
        for ou in ou_names:
            if next_one:
                nsis.setvar('4', ou)
                break

            if ou == last_ou:
                next_one = True
#  $5 = Node name
#
# OUT parameters:
#  $6 = true if success
#

try:
    logging.basicConfig(filename=os.environ["PYLOGFILE"],level=logging.DEBUG)
    logging.info('========== GECOS CC link - Step 01 ==============')
    
    from gecosws_config_assistant.util.GecosCC import GecosCC
    from gecosws_config_assistant.dto.GecosAccessData import GecosAccessData
    from gecosws_config_assistant.dto.WorkstationData import WorkstationData
    from gecosws_config_assistant.dao.WorkstationDataDAO import WorkstationDataDAO

    nsis.setvar('6', "false")
    gecosAccessData = GecosAccessData()
    gecosAccessData.set_url(nsis.getvar('$0'))
    gecosAccessData.set_login(nsis.getvar('$1'))
    gecosAccessData.set_password(nsis.getvar('$2'))
    
    if not os.path.isdir(os.path.join('C:\\', 'etc')):
        os.mkdir(os.path.join('C:\\', 'etc'))
    
    workstationData = WorkstationData()
    workstationData.set_ou(nsis.getvar('$3').decode('iso-8859-1').encode('utf-8'))
    workstationData.set_name(nsis.getvar('$4'))
    workstationData.set_node_name( binascii.hexlify(base64.b64decode(nsis.getvar('$5'))) )
    workstationDataDao = WorkstationDataDAO()

    # Check if exists "C:\chef\client.pem"