def postInstallationConfig(logger, config, host, password):
    isExecuteSuccess = False
    cmd = 'usermod -a -G docker ' + config['docker.user']
    output = os_executor.executeRemoteCommand(logger, config, cmd, host,
                                              password)

    if 'error' not in output.lower():
        cmd = 'systemctl enable docker'
        isExecuteSuccess = os_executor.executeRemoteCommand(
            logger, config, cmd, host, password)

    else:
        logger.debug('An error was encountered while adding docker group to ' +
                     config['docker.user'])

    if 'error' not in output.lower():
        ports = config['docker.ports']
        ports = ports.split(',')
        os_executor.openFirewallPorts(logger, config, ports, host, password)

    else:
        logger.debug(
            'An error was encountered while configuring the Docker service to start on system start'
        )

    if 'error' not in output.lower():
        isExecuteSuccess = True

    else:
        logger.debug(
            'An error was encountered while opening the firewall ports')

    return isExecuteSuccess
def installDockerEE(logger, config, host, password):
    isExecuteSuccess = False

    cmd = 'yum -y install docker-ee'
    output = os_executor.executeRemoteCommand(logger, config, cmd, host,
                                              password)

    # if 'error' not in output.lower():
    logger.debug('Successfully installed Docker EE')
    cmd = 'service docker start'
    output = os_executor.executeRemoteCommand(logger, config, cmd, host,
                                              password)

    # else:
    #  logger.debug('An error was encountered installing Docker EE')

    # if 'error' not in output.lower():
    cmd = 'service docker stop'
    output = os_executor.executeRemoteCommand(logger, config, cmd, host,
                                              password)

    # else:
    logger.debug('An error was encountered starting Docker service')

    # if 'error' not in output.lower():
    isExecuteSuccess = True

    # else:
    #  logger.debug('An error was encountered stopping Docker service')

    return isExecuteSuccess
    def addManagerNode(self, logger, config, ucpUrl, ucpPassword, password,
                       host):
        logger.debug('+++ Beginning creation of manager node +++')
        authToken = self.getAuthToken(logger, config, ucpUrl, ucpPassword)
        headers = {'Authorization': 'Bearer ' + authToken}
        managers = self.getManagerNodeList(logger, ucpUrl, authToken)

        swarmToken = None
        isExecuteSuccess = False
        requestUrl = ucpUrl + '/swarm'
        output = None

        response = self.requester.get(logger, requestUrl, headers)

        if response != None:
            swarmToken = response['JoinTokens']['Manager']
            logger.debug('Using worker swarm token: ' + swarmToken)
            cmd = 'docker swarm join --token ' + swarmToken + ' ' + managers[0]
            output = os_executor.executeRemoteCommand(logger, config, cmd,
                                                      host, password)

        else:
            logger.error('An error was encountered getting swarm token. ' +
                         str(response))

        if 'error' not in output.lower():
            isExecuteSuccess = False
            logger.debug('+++ Successfully added a manager node +++')

        else:
            logger.error('An error was encountered adding a manager node')

        return isExecuteSuccess
def preInstallConfig(logger, config, host, password):
    isExecuteSuccess = False

    cmd = "sh -c 'echo \"" + config[
        'docker.ee.url'] + "/centos\" > /etc/yum/vars/dockerurl'"
    output = os_executor.executeRemoteCommand(logger, config, cmd, host,
                                              password)

    # if 'error' not in output.lower():
    logger.debug('Successfully added Docker URL to yum URLs')
    cmd = 'yum install -y yum-utils device-mapper-persistent-data lvm2'
    output = os_executor.executeRemoteCommand(logger, config, cmd, host,
                                              password)

    # else:
    #  logger.debug('An error was encountered adding Docker URL to yum URLs.')

    # if 'error' not in output.lower():
    logger.debug(
        'Successfully installed yum-utils device-mapper-persistent-data lvm2')
    cmd = 'yum-config-manager --add-repo "' + config[
        'docker.ee.url'] + '/centos/docker-ee.repo"'
    output = os_executor.executeRemoteCommand(logger, config, cmd, host,
                                              password)

    # else:
    #  logger.debug('An error was encountered installing yum-utils device-mapper-persistent-data lvm2.')

    # if 'error' not in output.lower():
    isExecuteSuccess = True
    logger.debug('Successfully added Docker repo.')

    # else:
    #  logger.debug('An error was encountered adding Docker repo.')

    return isExecuteSuccess
def installUCP(logger, config, ucpPassword, licenseFilePath, host, password):
    isExecuteSuccess = False
    
    logger.debug('+++ Beginning installation of UCP +++')
    ips = subprocess.check_output(['hostname', '--all-ip-addresses'])  
    # host = ips.split(' ')[1]
    
    src = licenseFilePath
    dest = config['bootstrap.user.path'] + licenseFilePath.split('/')[-1]
    os_executor.transferFile(logger, config, host, password, src, dest)
    
    cmd = 'docker container run --rm -it --name ucp -v /var/run/docker.sock:/var/run/docker.sock docker/ucp:'+ str(config['docker.ucp.version']) +' install --host-address ' + host + ' --admin-username ' + config['docker.ucp.user'] + ' --admin-password ' + ucpPassword + ' --license "$(cat ' + dest + ')"' 
    output = os_executor.executeRemoteCommand(logger, config, cmd, host, password)
    
    if 'error' not in output.lower():
        isExecuteSuccess = True 
        logger.debug('+++ Successfully finished installation of UCP +++')

    else:
        logger.error('An error was encountered installing the UCP')
    
    return isExecuteSuccess
    def registerWithDTR(self,
                        logger,
                        config,
                        host,
                        dtrHost,
                        dtrIp,
                        ucpPassword,
                        password,
                        local=False):
        logger.debug('+++ Beginning registration of ' + str(dtrIp) +
                     ' with DTR +++')
        if dtrHost is None or "":
            dtrHost = config["aws.dockerReg"]

        # I know this sucks.  But I will remove the additional parameters once we test this and it working.
        if dtrHost is dtrIp:
            hostname = socket.gethostbyaddr(dtrIp)[0]
            dtrHost = hostname

        url = 'https://' + dtrHost + '/ca'
        certName = dtrHost + '.crt'
        downloadLocation = config['download.location'] + '/' + certName
        isExecuteSuccess = self.requester.downloadFile(logger, url,
                                                       downloadLocation)
        output = ''

        if isExecuteSuccess is True:
            saveLocation = config['docker.dtr.cert.location'] + '/' + certName
            moveCmd = 'mv ' + downloadLocation + ' ' + saveLocation

            if local is True:
                logger.debug('Moving certificate')
                output = os_executor.executeCmd(logger, moveCmd)

            else:
                logger.debug('Transferring certificate to ' + host)
                cmd = 'mkdir -p ' + config[
                    'download.location'] + ' && sudo chown centos:centos ' + config[
                        'download.location']
                os_executor.executeRemoteCommand(logger, config, cmd, host,
                                                 password)
                output = os_executor.transferFile(logger, config, host,
                                                  password, downloadLocation,
                                                  downloadLocation)
                output = os_executor.executeRemoteCommand(
                    logger, config, moveCmd, host, password)
        else:
            logger.error(
                'An error was encountered downloading the DTR certificate.')

        if 'error' not in output.lower():
            logger.debug('+++ Successfully transferred certificate to ' +
                         host + ' +++')
            logger.debug('Beginning update of ca trust on ' + host)
            cmd = 'update-ca-trust'
            if local is True:
                output = os_executor.executeCmd(logger, cmd)
            else:
                output = os_executor.executeRemoteCommand(
                    logger, config, cmd, host, password)

        else:
            logger.error(
                'An error was encountered transferring the DTR certificate to '
                + host)

        if 'error' not in output.lower():
            logger.debug(
                '+++ Successfully updated the ca trust on the worker node +++')
            logger.debug('Beginning restart of the Docker service on ' + host)
            cmd = 'service docker restart'
            if local is True:
                output = os_executor.executeCmd(logger, cmd)
            else:
                output = os_executor.executeRemoteCommand(
                    logger, config, cmd, host, password)

        else:
            logger.error('An error was encountered updating the ca trust on ' +
                         host)

        if 'error' not in output.lower():
            logger.debug('Successfully restarted the Docker service on ' +
                         host)
            cmd = 'docker login -u admin -p ' + ucpPassword + ' ' + dtrHost
            if local is True:
                output = os_executor.executeCmd(logger, cmd)
            else:
                output = os_executor.executeRemoteCommand(
                    logger, config, cmd, host, password)

        else:
            logger.error(
                'An error was encountered restarting the Docker service on ' +
                host)

        if 'error' not in output.lower():
            isExecuteSuccess = True
        else:
            logger.error('An error was encountered logging into the DTR on ' +
                         dtrHost)

        return isExecuteSuccess
def configLogicalVolume(logger, config, host, password):
    isExecuteSuccess = False

    cmd = 'yum install -y yum-utils device-mapper-persistent-data lvm2'
    output = os_executor.executeRemoteCommand(logger, config, cmd, host,
                                              password)

    if 'error' not in output.lower():
        cmd = 'pvcreate ' + config['block.disk.path']
        output = os_executor.executeRemoteCommand(logger, config, cmd, host,
                                                  password)

    else:
        logger.debug(
            'An error was encountered installing device-mapper-persistent-data and lvm2 packages'
        )

    if 'error' not in output.lower():
        cmd = 'vgcreate docker ' + config['block.disk.path']
        output = os_executor.executeRemoteCommand(logger, config, cmd, host,
                                                  password)

    else:
        logger.debug('An error was encountered creating the physical volume')

    if 'error' not in output.lower():
        cmd = 'lvcreate --wipesignatures y -n thinpool docker -l 95%VG'
        output = os_executor.executeRemoteCommand(logger, config, cmd, host,
                                                  password)

    else:
        logger.debug('An error was encountered creating the volume group')

    if 'error' not in output.lower():
        cmd = 'lvcreate --wipesignatures y -n thinpoolmeta docker -l 1%VG'
        output = os_executor.executeRemoteCommand(logger, config, cmd, host,
                                                  password)

    else:
        logger.debug(
            'An error was encountered creating the logical volume thinpool docker'
        )

    if 'error' not in output.lower():
        cmd = 'lvconvert -y --zero n -c 512K --thinpool docker/thinpool --poolmetadata docker/thinpoolmeta'
        output = os_executor.executeRemoteCommand(logger, config, cmd, host,
                                                  password)

    else:
        logger.debug(
            'An error was encountered creating logical volume thinpoolmeta docker'
        )

    if 'error' not in output.lower():
        filePath = config['docker.disk.profile']
        content = 'activation { \n thin_pool_autoextend_threshold=80 \n thin_pool_autoextend_percent=20 \n }'
        os_executor.updateFile(logger, filePath, content)

        src = config['docker.disk.profile']
        dest = config['bootstrap.user.path'] + config[
            'docker.disk.profile.name']
        os_executor.transferFile(logger, config, host, password, src, dest)

        cmd = 'mv ' + dest + ' ' + src
        output = os_executor.executeRemoteCommand(logger, config, cmd, host,
                                                  password)

    else:
        logger.debug(
            'An error was encountered while changing the mirrored volume configuration'
        )

    if 'error' not in output.lower():
        cmd = 'lvchange --metadataprofile docker-thinpool docker/thinpool'
        output = os_executor.executeRemoteCommand(logger, config, cmd, host,
                                                  password)

    else:
        logger.debug(
            'An error was encountered while updating the disk profile')

    if 'error' not in output.lower():
        cmd = 'lvs -o+seg_monitor'
        output = os_executor.executeRemoteCommand(logger, config, cmd, host,
                                                  password)

    else:
        logger.debug('An error was encountered while applying the LVM profile')

    if 'error' not in output.lower():
        filePath = config['bootstrap.user.path'] + config[
            'docker.daemon.config.name']
        content = '{ \n "storage-driver": "devicemapper", \n "storage-opts": [ \n "dm.thinpooldev=/dev/mapper/docker-thinpool", \n "dm.use_deferred_removal=true", \n "dm.use_deferred_deletion=true" \n ]}'
        os_executor.updateFile(logger, filePath, content)

        src = filePath
        dest = config['docker.daemon.config']
        os_executor.transferFile(logger, config, host, password, src, src)

        cmd = 'mv ' + src + ' ' + dest
        output = os_executor.executeRemoteCommand(logger, config, cmd, host,
                                                  password)
    else:
        logger.debug(
            'An error was encountered while creating a linux virtual server')

    if 'error' not in output.lower():
        os.remove(filePath)
        cmd = 'service docker start'
        output = os_executor.executeRemoteCommand(logger, config, cmd, host,
                                                  password)

    else:
        logger.debug('An error was encountered while updating daemon.json')

    if 'error' not in output.lower():
        isExecuteSuccess = True

    else:
        logger.debug('An error was encountered starting Docker service')

    return isExecuteSuccess