예제 #1
0
def downgrade(upd, with_testing, exception, *args, **kwargs):
    # 00119
    upd.print_log('Allow null in User.package_id field...')
    helpers.downgrade_db(revision='2c64986d76b9')

    # 00118
    upd.print_log('Reverting package count_type column...')
    helpers.downgrade_db(revision='42b36be03945')

    # 00117
    upd.print_log('Downgrade permissions...')
    Permission.query.delete()
    Resource.query.delete()
    add_permissions()
    db.session.commit()

    # 00116
    upd.print_log('Remove system settings for CPU and Memory multipliers')
    for name in ('cpu_multiplier', 'memory_multiplier'):
        entry = SystemSettings.query.filter_by(name=name).first()
        if entry is not None:
            db.session.delete(entry)

    upd.print_log('Drop table "node_actions" if exists')
    table = Table('node_actions', db.metadata)
    table.drop(bind=db.engine, checkfirst=True)
    db.session.commit()

    helpers.close_all_sessions()
예제 #2
0
def upgrade(upd, with_testing, *args, **kwargs):
    upd.print_log('Add roles {}, resources {} and its permissions...'.format(
        ROLES, RESOURCES))
    fixtures.add_permissions(roles=ROLES,
                             resources=RESOURCES,
                             permissions=PERMISSIONS)
    upd.print_log('Add {} user...'.format(USER))
    u = db.session.query(User).filter(User.username == USER).first()
    if not u:
        r = Role.filter_by(rolename='HostingPanel').first()
        u = User.create(username=USER, password=USER, role=r, active=True)
        u.save()
예제 #3
0
def _update_00201_upgrade(upd):
    upd.print_log('Create table for RestrictedPort model if not exists')
    RestrictedPort.__table__.create(bind=db.engine, checkfirst=True)
    upd.print_log('Upgrade permissions')
    fixtures.add_permissions(resources=restricted_ports_resources,
                             permissions=restricted_ports_permissions)
    upd.print_log('reject outgoing not authorized smtp packets '
                  'to prevent spamming from containers')
    try:
        restricted_ports.del_port(25, 'tcp')
    except restricted_ports.RestrictedPortsException.OpenPortError:
        pass
    finally:
        restricted_ports.set_port(25, 'tcp')
예제 #4
0
def upgrade(upd, with_testing, *args, **kwargs):
    upd.print_log('Removing HostingPanel role and user...')
    user_role = Role.query.filter(Role.rolename == 'User').first()
    User.query.filter(User.username == 'hostingPanel').update({
        User.role_id:
        user_role.id,
        User.deleted:
        True
    })
    Permission.query.delete()
    Resource.query.delete()
    Role.query.filter(Role.rolename == 'HostingPanel').delete()
    add_permissions()
    db.session.commit()
예제 #5
0
def upgrade(upd, with_testing, *args, **kwargs):
    upd.print_log('Upgrading db...')
    helpers.upgrade_db()

    # 00103_update.py
    upd.print_log('Enabling restart for ntpd.service on master')
    local('mkdir -p ' + SERVICE_DIR)
    local('echo -e "' + OVERRIDE_CONF + '" > ' + OVERRIDE_FILE)
    local('systemctl daemon-reload')
    local('systemctl restart ntpd')

    # 00104_update.py
    upd.print_log('Restart pods with persistent storage')
    pc = PodCollection()
    pods = Pod.query.with_entities(Pod.id).filter(Pod.persistent_disks).all()
    for pod_id in pods:
        p = pc._get_by_id(pod_id[0])
        if p.status == POD_STATUSES.running:
            pc._stop_pod(p)
            pc._collection.pop((pod_id[0], pod_id[0]))
            pc._merge()
            p = pc._get_by_id(pod_id[0])
            pc._start_pod(p)

    # 00105_update.py
    upd.print_log('Add roles {}, resources {} and its permissions...'.format(
        ROLES, RESOURCES))
    fixtures.add_permissions(roles=ROLES,
                             resources=RESOURCES,
                             permissions=PERMISSIONS)
    upd.print_log('Add MenuRoles...')
    PAUserRole = Role.query.filter(Role.rolename == 'LimitedUser').first()
    for menu_role in Role.query.filter(
            Role.rolename == 'User').first().menus_assocs:
        db.session.add(
            MenuItemRole(role=PAUserRole, menuitem_id=menu_role.menuitem_id))
    db.session.commit()

    # Fixes for celery workers launching
    upd.print_log('Updating uwsgi configuration ...')
    local('test -f "{0}" && cp "{0}" "{1}"'.format(UWSGI_KUBERDOCK_INI_DEST,
                                                   SAVE_KUBERDOCK_INI))
    local('cp "{0}" "{1}"'.format(UWSGI_KUBERDOCK_INI_SOURCE,
                                  UWSGI_KUBERDOCK_INI_DEST))
    local('chmod 644 "{0}"'.format(UWSGI_KUBERDOCK_INI_DEST))
예제 #6
0
def upgrade(upd, with_testing, *args, **kwargs):
    upd.print_log('Upgrading DB...')
    helpers.upgrade_db()

    # 00116
    upd.print_log('Add system settings for CPU and Memory multipliers')
    db.session.add_all([
        SystemSettings(name='cpu_multiplier',
                       value=CPU_MULTIPLIER,
                       label='CPU multiplier',
                       description='Cluster CPU multiplier',
                       placeholder='Enter value for CPU multiplier'),
        SystemSettings(name='memory_multiplier',
                       value=MEMORY_MULTIPLIER,
                       label='Memory multiplier',
                       description='Cluster Memory multiplier',
                       placeholder='Enter value for Memory multiplier'),
    ])

    upd.print_log('Create table for NodeAction model if not exists')
    NodeAction.__table__.create(bind=db.engine, checkfirst=True)
    db.session.commit()

    # 00117
    upd.print_log('Update permissions...')
    Permission.query.delete()
    Resource.query.delete()
    add_permissions()
    db.session.commit()

    # Fix wrong pd_states if exists.
    wrong_states = db.session.query(PersistentDiskState).join(
        PersistentDisk,
        db.and_(
            PersistentDisk.name == PersistentDiskState.pd_name,
            PersistentDisk.owner_id == PersistentDiskState.user_id,
            PersistentDisk.state == PersistentDiskStatuses.DELETED)).filter(
                PersistentDiskState.end_time == None)
    for state in wrong_states:
        state.end_time = datetime.datetime.utcnow()
    db.session.commit()

    helpers.close_all_sessions()
예제 #7
0
def _update_00197_upgrade(upd):
    upd.print_log('Create table for AllowedPort model if not exists')
    AllowedPort.__table__.create(bind=db.engine, checkfirst=True)
    upd.print_log('Upgrade permissions')
    fixtures.add_permissions(resources=allowed_ports_resources,
                             permissions=allowed_ports_permissions)
예제 #8
0
def upgrade(upd, with_testing, *args, **kwargs):
    upgrade_db()

    # === 00124_update.py ===
    # Move index file of k8s2etcd service from / to /var/lib/kuberdock
    try:
        stop_service(u124_service_name)
        if os.path.isfile(u124_old) and not os.path.isfile(u124_new):
            shutil.move(u124_old, u124_new)
    finally:
        start_service(u124_service_name)

    # === 00126_update.py ===

    pod_collection = PodCollection()
    for pod_dict in pod_collection.get(as_json=False):
        pod = pod_collection._get_by_id(pod_dict['id'])
        db_config = get_pod_config(pod.id)
        cluster_ip = db_config.pop('clusterIP', None)
        if cluster_ip is None:
            service_name = db_config.get('service')
            if service_name is None:
                continue
            namespace = db_config.get('namespace') or pod.id
            service = KubeQuery().get(['services', service_name],
                                      ns=namespace)
            cluster_ip = service.get('spec', {}).get('clusterIP')
            if cluster_ip is not None:
                db_config['podIP'] = cluster_ip
        replace_pod_config(pod, db_config)

    # === 00127_update.py ===

    upd.print_log('Upgrading menu...')
    MenuItemRole.query.delete()
    MenuItem.query.delete()
    Menu.query.delete()
    generate_menu()

    # === 00130_update.py ===

    upd.print_log('Update permissions...')
    Permission.query.delete()
    Resource.query.delete()
    add_permissions()
    db.session.commit()

    # === 00135_update.py ===
    # upd.print_log('Changing session_data schema...')
    # upgrade_db(revision='220dacf65cba')


    # === 00137_update.py ===
    upd.print_log('Upgrading db...')
    # upgrade_db(revision='3c832810a33c')
    upd.print_log('Raise max kubes to 64')
    max_kubes = 'max_kubes_per_container'
    old_value = SystemSettings.get_by_name(max_kubes)
    if old_value == '10':
        SystemSettings.set_by_name(max_kubes, 64)
    upd.print_log('Update kubes')
    small = Kube.get_by_name('Small')
    standard = Kube.get_by_name('Standard')
    if small:
        small.cpu = 0.12
        small.name = 'Tiny'
        small.memory = 64
        if small.is_default and standard:
            small.is_default = False
            standard.is_default = True
        small.save()
    if standard:
        standard.cpu = 0.25
        standard.memory = 128
        standard.save()
    high = Kube.get_by_name('High memory')
    if high:
        high.cpu = 0.25
        high.memory = 256
        high.disk_space = 3
        high.save()

    # === 00138_update.py ===

    if not (CEPH or AWS):
        upgrade_localstorage_paths(upd)

    # === added later ===

    secret_key = SystemSettings.query.filter(
        SystemSettings.name == 'sso_secret_key').first()
    if not secret_key.value:
        secret_key.value = randstr(16)
    secret_key.description = (
    'Used for Single sign-on. Must be shared between '
    'Kuberdock and billing system or other 3rd party '
    'application.')
    db.session.commit()

    upd.print_log('Close all sessions...')
    close_all_sessions()