Example #1
0
def _reinstall_hosts(clusters):
    logging.info('reinstall cluster hosts: %s', clusters)
    manager = config_manager.ConfigManager()
    with database.session() as session:
        for clusterid, hostids in clusters.items():
            cluster = session.query(Cluster).filter_by(id=clusterid).first()
            if not cluster:
                continue

            all_hostids = [host.id for host in cluster.hosts]
            logging.debug('all hosts in cluster %s is: %s', clusterid,
                          all_hostids)

            logging.info('reinstall hosts %s in cluster %s', hostids,
                         clusterid)
            adapter = cluster.adapter
            for hostid in hostids:
                host = session.query(ClusterHost).filter_by(id=hostid).first()
                if not host:
                    continue

                log_dir = os.path.join(setting.INSTALLATION_LOGDIR,
                                       '%s.%s' % (host.hostname, clusterid))
                logging.info('clean log dir %s', log_dir)
                shutil.rmtree(log_dir, True)
                session.query(LogProgressingHistory).filter(
                    LogProgressingHistory.pathname.startswith(
                        '%s/' % log_dir)).delete(synchronize_session='fetch')

                logging.info('reinstall host %s', hostid)
                manager.reinstall_host(hostid,
                                       os_version=adapter.os,
                                       target_system=adapter.target_system)
                if host.state and host.state.state != 'UNINITIALIZED':
                    session.query(ClusterHost).filter_by(id=hostid).update(
                        {'mutable': False}, synchronize_session='fetch')
                    session.query(HostState).filter_by(id=hostid).update(
                        {
                            'state': 'INSTALLING',
                            'progress': 0.0,
                            'message': '',
                            'severity': 'INFO'
                        },
                        synchronize_session='fetch')

            if set(all_hostids) == set(hostids):
                logging.info('reinstall cluster %s', clusterid)
                if cluster.state and cluster.state != 'UNINITIALIZED':
                    session.query(Cluster).filter_by(id=clusterid).update(
                        {'mutable': False}, synchronize_session='fetch')
                    session.query(ClusterState).filter_by(id=clusterid).update(
                        {
                            'state': 'INSTALLING',
                            'progress': 0.0,
                            'message': '',
                            'severity': 'INFO'
                        },
                        synchronize_session='fetch')

    manager.sync()
Example #2
0
def _clean_clusters(clusters):
    manager = config_manager.ConfigManager()
    logging.info('clean cluster hosts: %s', clusters)
    with database.session() as session:
        for clusterid, hostids in clusters.items():
            cluster = session.query(Cluster).filter_by(id=clusterid).first()
            if not cluster:
                continue

            all_hostids = [host.id for host in cluster.hosts]
            logging.debug('all hosts in cluster %s is: %s', clusterid,
                          all_hostids)

            logging.info('clean hosts %s in cluster %s', hostids, clusterid)

            adapter = cluster.adapter
            for hostid in hostids:
                host = session.query(ClusterHost).filter_by(id=hostid).first()
                if not host:
                    continue

                log_dir = os.path.join(setting.INSTALLATION_LOGDIR,
                                       '%s.%s' % (host.hostname, clusterid))
                logging.info('clean log dir %s', log_dir)
                shutil.rmtree(log_dir, True)
                session.query(LogProgressingHistory).filter(
                    LogProgressingHistory.pathname.startswith(
                        '%s/' % log_dir)).delete(synchronize_session='fetch')

                logging.info('clean host %s', hostid)
                manager.clean_host_config(hostid,
                                          os_version=adapter.os,
                                          target_system=adapter.target_system)
                session.query(ClusterHost).filter_by(id=hostid).delete(
                    synchronize_session='fetch')
                session.query(HostState).filter_by(id=hostid).delete(
                    synchronize_session='fetch')

            if set(all_hostids) == set(hostids):
                logging.info('clean cluster %s', clusterid)
                manager.clean_cluster_config(
                    clusterid,
                    os_version=adapter.os,
                    target_system=adapter.target_system)
                session.query(Cluster).filter_by(id=clusterid).delete(
                    synchronize_session='fetch')
                session.query(ClusterState).filter_by(id=clusterid).delete(
                    synchronize_session='fetch')

    manager.sync()
Example #3
0
def sync_from_installers():
    manager = config_manager.ConfigManager()
    adapters = manager.getAdapters()
    target_systems = set()
    roles_per_target_system = {}
    for adapter in adapters:
        target_systems.add(adapter['target_system'])
    for target_system in target_systems:
        roles_per_target_system[target_system] = manager.getRoles(
            target_system)
    with database.session() as session:
        session.query(Adapter).delete()
        session.query(Role).delete()
        for adapter in adapters:
            session.add(Adapter(**adapter))
        for target_system, roles in roles_per_target_system.items():
            for role in roles:
                session.add(Role(**role))
Example #4
0
def set_switch_machines():
    """Set switches and machines.

    .. note::
       --switch_machines_file is the filename which stores all switches
       and machines information.
       each line in fake_switches_files presents one machine.
       the format of each line machine,<switch_ip>,<switch_port>,<vlan>,<mac>
       or switch,<switch_ip>,<switch_vendor>,<switch_version>,
       <switch_community>,<switch_state>
    """
    if not flags.OPTIONS.switch_machines_file:
        print 'flag --switch_machines_file is missing'
        return

    switches, switch_machines = util.get_switch_machines_from_file(
        flags.OPTIONS.switch_machines_file)
    with database.session():
        manager = config_manager.ConfigManager()
        manager.update_switch_and_machines(switches, switch_machines)
Example #5
0
def sync_switch_configs():
    """Set switch configs in SwitchConfig table from setting.

    .. note::
       the switch config is stored in SWITCHES list in setting config.
       for each entry in the SWITCHES, its type is dict and must contain
       fields 'switch_ips' and 'filter_ports'.
       The format of switch_ips is
       <ip_blocks>.<ip_blocks>.<ip_blocks>.<ip_blocks>.
       ip_blocks consists of ip_block separated by comma.
       ip_block can be an integer and a range of integer like xx-xx.
       The example of switch_ips is like: xxx.xxx.xxx-yyy,xxx-yyy.xxx,yyy
       The format of filter_ports consists of list of
       <port_prefix><port_range> separated by comma. port_range can be an
       integer or a rnage of integer like xx-xx.
       The example of filter_ports is like: ae1-5,20-40.
    """
    with database.session():
        manager = config_manager.ConfigManager()
        manager.update_switch_filters()
Example #6
0
def sync_from_installers():
    """set adapters in Adapter table from installers."""
    with database.session():
        manager = config_manager.ConfigManager()
        manager.update_adapters_from_installers()