Exemplo n.º 1
0
def trigger_install(clusterid):
    '''trigger installer to start install for a given cluster.

    Args:
        clusterid: int, the id of the cluster.

    Returns:
        None
    '''
    manager = ConfigManager()
    session = database.current_session()
    cluster = session.query(Cluster).filter_by(id=clusterid).first()
    if not cluster:
        logging.error('no cluster found for %s', clusterid)
        return

    adapter = cluster.adapter
    if not adapter:
        logging.error('no proper adapter found for cluster %s', cluster.id)
        return

    if not cluster.state:
        cluster.state = ClusterState()

    if cluster.state.state and cluster.state.state != 'UNINITIALIZED':
        logging.error('ignore installing cluster %s since the state is %s',
                      cluster.id, cluster.state)
        return

    cluster.state.state = 'INSTALLING'
    hostids = [host.id for host in cluster.hosts]
    update_hostids = []
    for host in cluster.hosts:
        if not host.state:
            host.state = HostState()
        elif host.state.state and host.state.state != 'UNINITIALIZED':
            logging.info('ignore installing host %s sinc the state is %s',
                         host.id, host.state)
            continue

        host.state.state = 'INSTALLING'
        update_hostids.append(host.id)

    manager.updateClusterAndHostConfigs(clusterid, hostids, update_hostids,
                                        adapter.os, adapter.target_system)
    manager.sync()
Exemplo n.º 2
0
def trigger_install(clusterid):
    """Deploy a given cluster.

    :param clusterid: the id of the cluster to deploy.
    :type clusterid: int

    .. note::
        The function should be called in database session.
    """
    session = database.current_session()
    cluster = session.query(Cluster).filter_by(id=clusterid).first()
    if not cluster:
        logging.error('no cluster found for %s', clusterid)
        return

    adapter = cluster.adapter
    if not adapter:
        logging.error('no proper adapter found for cluster %s', cluster.id)
        return

    if not cluster.state:
        cluster.state = ClusterState()

    if cluster.state.state and cluster.state.state != 'UNINITIALIZED':
        logging.error('ignore installing cluster %s since the state is %s',
                      cluster.id, cluster.state)
        return

    cluster.state.state = 'INSTALLING'
    hostids = [host.id for host in cluster.hosts]
    update_hostids = []
    for host in cluster.hosts:
        if not host.state:
            host.state = HostState()
        elif host.state.state and host.state.state != 'UNINITIALIZED':
            logging.info('ignore installing host %s sinc the state is %s',
                         host.id, host.state)
            continue

        host.state.state = 'INSTALLING'
        update_hostids.append(host.id)

    manager = ConfigManager()
    manager.update_cluster_and_host_configs(clusterid, hostids, update_hostids,
                                            adapter.os, adapter.target_system)
    manager.sync()
Exemplo n.º 3
0
def deploy(cluster_hosts):
    """Deploy clusters.

    :param cluster_hosts: clusters and hosts in each cluster to deploy.
    :type cluster_hosts: dict of int or str to list of int or str

    .. note::
        The function should be called out of database session.
    """
    with util.lock('serialized_action') as lock:
        if not lock:
            raise Exception('failed to acquire lock to deploy')

        logging.debug('deploy cluster_hosts: %s', cluster_hosts)
        with database.session():
            cluster_hosts, os_versions, target_systems = (
                util.update_cluster_hosts(cluster_hosts))
            manager = ConfigManager()
            manager.install_cluster_and_hosts(cluster_hosts, os_versions,
                                              target_systems)
            manager.sync()
Exemplo n.º 4
0
def search(cluster_hosts, cluster_propreties_match,
           cluster_properties_name, host_properties_match,
           host_properties_name):
    """search clusters.

    :param cluster_hosts: clusters and hosts in each cluster to search.
    :type cluster_hosts: dict of int or str to list of int or str

    .. note::
        The function should be called out of database session.
    """
    logging.debug('search cluster_hosts: %s', cluster_hosts)
    with database.session():
        cluster_hosts, os_versions, target_systems = (
            util.update_cluster_hosts(cluster_hosts))
        manager = ConfigManager()
        return manager.filter_cluster_and_hosts(
            cluster_hosts, os_versions,
            target_systems, cluster_propreties_match,
            cluster_properties_name, host_properties_match,
            host_properties_name)
Exemplo n.º 5
0
def clean_installing_progress(cluster_hosts):
    """Clean installing progress of clusters.

    :param cluster_hosts: clusters and hosts in each cluster to clean.
    :type cluster_hosts: dict of int or str to list of int or str

    .. note::
        The function should be called out of database session.
    """
    with util.lock('serialized_action') as lock:
        if not lock:
            raise Exception(
                'failed to acquire lock to clean installation progress')

        logging.info('clean installing progress of cluster_hosts: %s',
                     cluster_hosts)
        with database.session():
            cluster_hosts, os_versions, target_systems = (
                util.update_cluster_hosts(cluster_hosts))
            manager = ConfigManager()
            manager.clean_cluster_and_hosts_installing_progress(
                cluster_hosts, os_versions, target_systems)
            manager.sync()