Exemple #1
0
def __del_isol_cpus(cpu_core_dict):
    """
    to set isolate cpu  in /etc/default/grub file
    """
    logger.info("setIsolCpus function")
    iplist = []
    playbook_path = pkg_resources.resource_filename(
        'snaps_boot.ansible_p.commission.hardware.playbooks',
        'delIsolCpus.yaml')
    host = cpu_core_dict.get('host')
    for ipCpu1 in host:
        target1 = ipCpu1.get('ip')
        iplist.append(target1)

    for ipCpu in host:
        target = ipCpu.get('ip')
        isolcpus = ipCpu.get('isolcpus')
        hugepagesz = ipCpu.get('hugepagesz')
        hugepages = ipCpu.get('hugepages')
        if isolcpus:
            logger.info("isolate cpu's for " + target + " are " + isolcpus)
            logger.info("hugepagesz for " + target + "  " + hugepagesz)
            logger.info("hugepages for " + target + "  " + hugepages)
            apl.__launch_ansible_playbook(
                iplist, playbook_path, {
                    'target': target,
                    'isolcpus': isolcpus,
                    'hugepagesz': hugepagesz,
                    'hugepages': hugepages
                })
Exemple #2
0
def __static_ip_configure(static_dict, proxy_dict):
    playbook_path = pkg_resources.resource_filename(
        'snaps_boot.ansible_p.commission.hardware.playbooks',
        'setIPConfig.yaml')
    playbook_path_bak = pkg_resources.resource_filename(
        'snaps_boot.ansible_p.commission.hardware.playbooks',
        'interfaceBak.yaml')

    host = static_dict.get('host')
    valid = __validate_static_config(static_dict)
    if valid is False:
        logger.info(
            "Configuration error please define IP for all the interface types")
        exit()
    http_proxy = proxy_dict.get('http_proxy')
    https_proxy = proxy_dict.get('https_proxy')
    iplist = []

    for this_host in host:
        target = this_host.get('access_ip')
        iplist.append(target)
    for host_counter in host:
        target = host_counter.get('access_ip')

        interfaces = host_counter.get('interfaces')
        backup_var = "Y"
        apl.__launch_ansible_playbook(iplist, playbook_path_bak, {
            'target': target,
            'bak': backup_var
        })

        for interface in interfaces:
            address = interface.get('address')
            gateway = interface.get('gateway')
            netmask = interface.get('netmask')
            iface = interface.get('iface')
            dns = interface.get('dns')
            dn = interface.get('dn')
            intf_type = interface.get('type')
            apl.__launch_ansible_playbook(
                iplist, playbook_path, {
                    'target': target,
                    'address': address,
                    'gateway': gateway,
                    'netmask': netmask,
                    'iface': iface,
                    'http_proxy': http_proxy,
                    'https_proxy': https_proxy,
                    'type': intf_type,
                    'dns': dns,
                    'dn': dn
                })
def __centos_pxe_installation(pxe_dict, centos_dict, proxy_dict,
                              build_pxe_server):
    iplist = []
    root_pass = None
    playbook_path = pkg_resources.resource_filename(
        'snaps_boot.ansible_p.commission.hardware.playbooks',
        'centos_pxe.yaml')
    iso_name = centos_dict.get('os')
    print iso_name
    print build_pxe_server
    iplist = pxe_dict.get('serverIp')
    apl.__launch_ansible_playbook(iplist, playbook_path, {
        'isoName': iso_name,
        'pxeServer': build_pxe_server
    })
Exemple #4
0
def __centos_pxe_installation(pxe_dict, centos_dict, build_pxe_server):
    iplist = []
    playbook_path = pkg_resources.resource_filename(
        'snaps_boot.ansible_p.commission.hardware.playbooks',
        'centos_pxe.yaml')
    iso_name = centos_dict.get('os')
    boot_disk = centos_dict.get('boot_disk')
    if boot_disk is None:
        boot_disk = "sda"
    iplist.append(pxe_dict.get('serverIp'))
    apl.__launch_ansible_playbook(
        iplist, playbook_path, {
            'isoName': iso_name,
            'pxeServer': build_pxe_server,
            'bootDisk': boot_disk,
            'cloudInitIp': iplist[0]
        })
def __del_isol_cpus(cpu_core_dict):
    """
    to set isolate cpu  in /etc/default/grub file
    """
    logger.info("setIsolCpus function")
    iplist = []
    root_pass = None
    with open("conf/pxe_cluster/ks.cfg") as openfile:
        for line in openfile:
            list_word = line.split()
            for part in line.split():
                if "rootpw" in part:
                    root_pass = list_word[list_word.index("rootpw") + 1]
    user_name = 'root'
    playbook_path = pkg_resources.resource_filename(
        'snaps_boot.ansible_p.commission.hardware.playbooks',
        'delIsolCpus.yaml')
    host = cpu_core_dict.get('host')
    for ipCpu1 in host:
        target1 = ipCpu1.get('ip')
        iplist.append(target1)

    for ipCpu in host:
        target = ipCpu.get('ip')
        isolcpus = ipCpu.get('isolcpus')
        hugepagesz = ipCpu.get('hugepagesz')
        hugepages = ipCpu.get('hugepages')
        if isolcpus:
            logger.info("isolate cpu's for " + target + " are " + isolcpus)
            logger.info("hugepagesz for " + target + "  " + hugepagesz)
            logger.info("hugepages for " + target + "  " + hugepages)
            subprocess.call(
                'echo -e y|ssh-keygen -b 2048 -t rsa -f '
                '/root/.ssh/id_rsa -q -N ""',
                shell=True)
            command = 'sshpass -p %s ssh-copy-id -o ' \
                      'StrictHostKeyChecking=no %s@%s' \
                      % (root_pass, user_name, target)
            subprocess.call(command, shell=True)
            apl.__launch_ansible_playbook(
                iplist, playbook_path, {
                    'target': target,
                    'isolcpus': isolcpus,
                    'hugepagesz': hugepagesz,
                    'hugepages': hugepages
                })
Exemple #6
0
def __static_ip_cleanup(static_dict):
    playbook_path = pkg_resources.resource_filename(
        'snaps_boot.ansible_p.commission.hardware.playbooks',
        'delIPConfig.yaml')
    playbook_path_bak = pkg_resources.resource_filename(
        'snaps_boot.ansible_p.commission.hardware.playbooks',
        'interfaceBak.yaml')

    host = static_dict.get('host')
    iplist = []

    for this_host in host:
        iplist.append(this_host.get('access_ip'))
    for host_counter in host:
        target = host_counter.get('access_ip')
        interfaces = host_counter.get('interfaces')
        backup_var = "N"
        apl.__launch_ansible_playbook(iplist, playbook_path_bak, {
            'target': target,
            'bak': backup_var
        })

        for interface in interfaces:
            address = interface.get('address')
            gateway = interface.get('gateway')
            netmask = interface.get('netmask')
            iface = interface.get('iface')
            dns = interface.get('dns')
            dn = interface.get('dn')
            intf_type = interface.get('type')
            apl.__launch_ansible_playbook(
                iplist, playbook_path, {
                    'target': target,
                    'address': address,
                    'gateway': gateway,
                    'netmask': netmask,
                    'iface': iface,
                    'type': intf_type,
                    'dns': dns,
                    'dn': dn
                })
Exemple #7
0
def __add_cloud_init_files(pxe_dict, subnet_list, user_name, user_pass,
                           root_pass):
    """
    Create cloud init files on the web server for each traget node
    """
    playbook_path = pkg_resources.resource_filename(
        'snaps_boot.ansible_p.commission.hardware.playbooks',
        'create_cloud_config.yaml')
    mac_list = []
    for subnet in subnet_list:
        mac_ip_list = subnet.get('bind_host')
        for mac_ip in mac_ip_list:
            mac_list.append(mac_ip.get('mac'))

    iplist = [pxe_dict.get('serverIp')]
    apl.__launch_ansible_playbook(
        iplist, playbook_path, {
            'target': ["localhost"],
            'target_macs': mac_list,
            'user_pass': user_pass,
            'user_name': user_name,
            'root_pass': root_pass
        })
def __static_ip_cleanup(static_dict):
    playbook_path = pkg_resources.resource_filename(
        'snaps_boot.ansible_p.commission.hardware.playbooks',
        'delIPConfig.yaml')
    playbook_path_bak = pkg_resources.resource_filename(
        'snaps_boot.ansible_p.commission.hardware.playbooks',
        'interfaceBak.yaml')

    host = static_dict.get('host')
    iplist = []
    next_word = None
    with open("conf/pxe_cluster/ks.cfg") as openfile:
        for line in openfile:
            list_word = line.split()
            for part in line.split():
                if "rootpw" in part:
                    next_word = list_word[list_word.index("rootpw") + 1]

    user_name = 'root'
    password = next_word
    check_dir = os.path.isdir(consts.SSH_PATH)
    if not check_dir:
        os.makedirs(consts.SSH_PATH)
    for i in range(len(host)):
        target = host[i].get('access_ip')
        iplist.append(target)
    print iplist
    for i in range(len(host)):
        target = host[i].get('access_ip')
        subprocess.call(
            'echo -e y|ssh-keygen -b 2048 -t rsa -f '
            '/root/.ssh/id_rsa -q -N ""',
            shell=True)
        command = 'sshpass -p %s ssh-copy-id -o ' \
                  'StrictHostKeyChecking=no %s@%s' \
                  % (password, user_name, target)
        subprocess.call(command, shell=True)
        interfaces = host[i].get('interfaces')
        backup_var = "N"
        apl.__launch_ansible_playbook(iplist, playbook_path_bak, {
            'target': target,
            'bak': backup_var
        })

        # TODO/FIXME - why is the var 'i' being used in both the inner and
        # outer loops???
        for i in range(len(interfaces)):
            address = interfaces[i].get('address')
            gateway = interfaces[i].get('gateway')
            netmask = interfaces[i].get('netmask')
            iface = interfaces[i].get('iface')
            dns = interfaces[i].get('dns')
            dn = interfaces[i].get('dn')
            intf_type = interfaces[i].get('type')
            apl.__launch_ansible_playbook(
                iplist, playbook_path, {
                    'target': target,
                    'address': address,
                    'gateway': gateway,
                    'netmask': netmask,
                    'iface': iface,
                    'type': intf_type,
                    'dns': dns,
                    'dn': dn
                })
def __static_ip_configure(static_dict, proxy_dict):
    playbook_path = pkg_resources.resource_filename(
        'snaps_boot.ansible_p.commission.hardware.playbooks',
        'setIPConfig.yaml')
    playbook_path_bak = pkg_resources.resource_filename(
        'snaps_boot.ansible_p.commission.hardware.playbooks',
        'interfaceBak.yaml')

    host = static_dict.get('host')
    print "HOSTS---------------"
    print host
    valid = __validate_static_config(static_dict)
    if valid is False:
        logger.info(
            "Configuration error please define IP for all the interface types")
        exit()
    http_proxy = proxy_dict.get('http_proxy')
    https_proxy = proxy_dict.get('https_proxy')
    print host[0]
    iplist = []
    next_word = None
    with open("conf/pxe_cluster/ks.cfg") as openfile:
        for line in openfile:
            list_word = line.split()
            for part in line.split():
                if "rootpw" in part:
                    next_word = list_word[list_word.index("rootpw") + 1]

    user_name = 'root'
    password = next_word
    check_dir = os.path.isdir(consts.SSH_PATH)
    if not check_dir:
        os.makedirs(consts.SSH_PATH)
    for i in range(len(host)):
        target = host[i].get('access_ip')
        iplist.append(target)
    for i in range(len(host)):
        target = host[i].get('access_ip')
        __create_and_save_keys()

        command = 'sshpass -p \'%s\' ssh-copy-id -o ' \
                  'StrictHostKeyChecking=no %s@%s' \
                  % (password, user_name, target)

        logger.info('Issuing following command - %s', command)
        retval = subprocess.call(command, shell=True)

        if retval != 0:
            raise Exception('System command failed - ' + command)

        interfaces = host[i].get('interfaces')
        backup_var = "Y"
        apl.__launch_ansible_playbook(iplist, playbook_path_bak, {
            'target': target,
            'bak': backup_var
        })

        # TODO/FIXME - why is the var 'i' being used in both the inner and
        # outer loops???
        for i in range(len(interfaces)):
            address = interfaces[i].get('address')
            gateway = interfaces[i].get('gateway')
            netmask = interfaces[i].get('netmask')
            iface = interfaces[i].get('iface')
            dns = interfaces[i].get('dns')
            dn = interfaces[i].get('dn')
            intf_type = interfaces[i].get('type')
            apl.__launch_ansible_playbook(
                iplist, playbook_path, {
                    'target': target,
                    'address': address,
                    'gateway': gateway,
                    'netmask': netmask,
                    'iface': iface,
                    'http_proxy': http_proxy,
                    'https_proxy': https_proxy,
                    'type': intf_type,
                    'dns': dns,
                    'dn': dn
                })