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 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' session.flush() adapter = cluster.adapter if not adapter: logging.error('no proper adapter found for cluster %s', cluster.id) return 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 eth 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()
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()
def clean_deployment(cluster_hosts): """Clean deployment 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'): logging.debug('clean 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( cluster_hosts, os_versions, target_systems) manager.sync()
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()
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)
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()
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()
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()
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()
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()
def trigger_install(clusterid, hostids=[]): """Deploy a given cluster. :param clusterid: the id of the cluster to deploy. :type clusterid: int :param hostids: the ids of the hosts to deploy. :type hostids: list of int .. note:: The function should be called in database session. """ logging.debug('trigger install cluster %s hosts %s', clusterid, hostids) 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 cluster.mutable: logging.error('ignore installing cluster %s since it is mutable', cluster) return if not cluster.state: cluster.state = ClusterState() cluster.state.state = 'INSTALLING' cluster.state.progress = 0.0 cluster.state.message = '' cluster.state.severity = 'INFO' all_hostids = [host.id for host in cluster.hosts] update_hostids = [] for host in cluster.hosts: if host.id not in hostids: logging.info('ignore installing %s since it is not in %s', host, hostids) continue if host.mutable: logging.error('ignore installing %s since it is mutable', 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') if not host.state: host.state = HostState() host.state.state = 'INSTALLING' host.state.progress = 0.0 host.state.message = '' host.state.severity = 'INFO' update_hostids.append(host.id) os.system('service rsyslog restart') manager = ConfigManager() manager.update_cluster_and_host_configs( clusterid, all_hostids, update_hostids, adapter.os, adapter.target_system) manager.sync()