#  $3 = Workstation name to check
#
# OUT parameters:
#  $4 = true if the URL is valid or false otherwise
#

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()))
示例#2
0
    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()

    rekey = False
    if (gecosCC.is_registered_chef_node(gecosAccessData,
import nsis
import traceback
import sys
import os

# This scripts check if a URL is valid
#
# IN parameters:
#  $0 = URL to check
#
# OUT parameters:
#  $4 = true if the URL is valid or false otherwise
#

try:
    from gecosws_config_assistant.util.Validation import Validation
    isurl = Validation().isUrl(nsis.getvar('$0'))
    nsis.setvar('4', str(isurl))
except:
    nsis.setvar('4', str(sys.exc_info()[0]))
    nsis.setvar('5', str(traceback.format_exc()))
    raise
示例#4
0
try:
    logging.basicConfig(filename=os.environ["PYLOGFILE"], level=logging.DEBUG)
    logging.info('========== GECOS CC unlink ==============')

    from gecosws_config_assistant.util.GecosCC import GecosCC
    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.dao.GecosAccessDataDAO import GecosAccessDataDAO
    from gecosws_config_assistant.firstboot_lib.firstbootconfig import get_data_file

    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()
    accessDataDao = GecosAccessDataDAO()

    workstationData = WorkstationData()
    workstationData.set_name(nsis.getvar('$3'))
    workstationData.set_node_name(nsis.getvar('$4'))

    logging.info('Saving "validation.pem"')
    # Save validation.pem
    if not os.path.isdir(os.path.join('C:\\', 'chef')):
        os.mkdir(os.path.join('C:\\', 'chef'))

    conf = json.loads(os.environ["AUTOCFGJSON"])
#
# IN parameters:
#  $0 = GECOS CC URL
#  $1 = User
#  $2 = Password
#  $3 = The OU search pattern
#  $4 = Last OU name returned
#
# OUT parameters:
#  $4 = OU name or "" if no more OUs left
#

try:
    import logging
    logging.basicConfig(filename=os.environ["PYLOGFILE"], level=logging.DEBUG)
    last_ou = nsis.getvar('$4')
    logging.info('========== Get OUs ("' + last_ou + '") ==============')

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

    if last_ou == "":
        # Get OUs from the server and return the first OU name
        gecosAccessData = GecosAccessData()
        gecosAccessData.set_url(nsis.getvar('$0'))
        gecosAccessData.set_login(nsis.getvar('$1'))
        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'))
import os.path, sys, nsis

INSTDIR = nsis.getvar('INSTDIR')

for d in ('Lib', 'DLLs'):
    sys.path.insert(0, '%s\\%s' % (INSTDIR, d))

def getexpectedoutput():
    global count
    count = 0
    def walkcount(arg, dirname, names):
        global count
        count += 1 # for Listing: .. line.
        count += len([name for name in names if name.endswith('.py')])
    os.path.walk('%s\\Lib' % INSTDIR, walkcount, None)
    return count # not accurate but close enough to the total output lines

class NSISStream:
    def __init__(self):
        self.buffer = ''
        self.nlines = 0
        nsis.setProgressPos(0)
        nsis.setProgressRange(0, getexpectedoutput())

    def write(self, s):
        self.buffer += s
        if '\n' in self.buffer:
            frags = self.buffer.splitlines(True)
            [self.log(fr.strip()) for fr in frags[:-1]]
            self.buffer = frags[-1]
# 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"
    if os.path.isfile(os.path.join('C:\\', 'chef', 'client.pem')):
        logging.error("Already exists a C:\\chef\\client.pem file")