Ejemplo n.º 1
0
def delete_nodes():
    """ Delete all nodes from restored cluster.

    When restoring cluster after a full crush it makes sense to drop nodes
    from restored db because they will be added again (re-deployed). This also
    implies purging of the pods - in this case they also need to be re-deployed
    (or restored from pod backups)
    """

    from kubedock.core import db
    from kubedock.api import create_app
    from kubedock.pods.models import PersistentDisk, Pod, PodIP
    from kubedock.usage.models import IpState, ContainerState, PodState
    from kubedock.domains.models import PodDomain
    from kubedock.nodes.models import Node
    from kubedock.kapi.nodes import delete_node_from_db

    create_app(fake_sessions=True).app_context().push()
    IpState.query.delete()
    PodIP.query.delete()
    ContainerState.query.delete()
    PodDomain.query.delete()
    PersistentDisk.query.delete()
    PodState.query.delete()
    Pod.query.delete()
    logger.info("All pod data purged.")
    db.session.commit()

    devnull = open(os.devnull, 'w')
    subprocess.call(['kubectl', 'delete', '--all', 'namespaces'],
                    stderr=devnull,
                    stdout=devnull)
    subprocess.call(['kubectl', 'delete', '--all', 'nodes'],
                    stderr=devnull,
                    stdout=devnull)
    logger.info("Etcd data purged.")

    for node in Node.get_all():
        delete_node_from_db(node)
        logger.info("Node `{0}` purged.".format(node.hostname))
Ejemplo n.º 2
0
def fetch_nodes():
    """
    Gets basic nodes data: IP address, cpu cores and memory
    """
    return [{'_ip': node.ip} for node in Node.get_all()]