Пример #1
0
def downgrade(upd, with_testing, exception, *args, **kwargs):
    # 00090_update.py
    upd.print_log('Downgrade system_settings scheme...')

    redis = ConnectionPool.get_connection()
    SystemSettings.query.delete()
    db.session.add_all([
        SystemSettings(name='billing_apps_link',
                       label='Link to billing system script',
                       description='Link to predefined application request processing script',
                       placeholder='http://whmcs.com/script.php',
                       value=redis.get('old_billing_apps_link')),
        SystemSettings(name='persitent_disk_max_size',
                       value=redis.get('old_persitent_disk_max_size'),
                       label='Persistent disk maximum size',
                       description='maximum capacity of a user container persistent disk in GB',
                       placeholder='Enter value to limit PD size')
    ])
    db.session.commit()

    helpers.downgrade_db(revision='27ac98113841')

    # 00094_update.py
    try:
        from kubedock.nodes.models import NodeMissedAction
    except ImportError:
        upd.print_log('Cannot find NodeMissedAction model')
    else:
        upd.print_log('Create table for NodeMissedAction model if not exists')
        NodeMissedAction.__table__.create(bind=db.engine, checkfirst=True)
        db.session.commit()

    # 00099_update.py
    helpers.downgrade_db(revision='46bba639e6fb')   # first of rc4
Пример #2
0
def upgrade(upd, with_testing, *args, **kwargs):
    #00109_update.py
    upd.print_log('Update system settings scheme...')
    helpers.upgrade_db()

    redis = ConnectionPool.get_connection()
    old_settings = SystemSettings.get_all()

    # backup for downgrade
    if not redis.get('old_system_settings'):
        redis.set('old_system_settings',
                  json.dumps(old_settings),
                  ex=int(timedelta(days=7).total_seconds()))

    SystemSettings.query.delete()
    add_system_settings()
    for param in old_settings:
        SystemSettings.set_by_name(param.get('name'),
                                   param.get('value'),
                                   commit=False)
    db.session.commit()

    #00111_update.py
    helpers.restart_master_kubernetes()

    #00113_update.py
    upd.print_log('Adding "count_type" column to packages...')
    helpers.upgrade_db(revision='42b36be03945')
Пример #3
0
def upgrade(upd, with_testing, *args, **kwargs):
    helpers.upgrade_db()
    # 00077_update.py
    upd.print_log('Clear cache...')
    from kubedock.core import ConnectionPool
    redis = ConnectionPool.get_connection()
    redis.delete('KDCOLLECTION')
    # 00081_update.py
    upd.print_log('Fix urls in main menu...')
    for item in MenuItem.query.all():
        if item.path:
            item.path = item.path.replace('/', '#', 1).rstrip('/')
    db.session.commit()
Пример #4
0
def upgrade(upd, with_testing, *args, **kwargs):
    # 00090_update.py
    upd.print_log('Update system settings scheme...')
    helpers.upgrade_db()

    redis = ConnectionPool.get_connection()

    billing_apps_link = SystemSettings.get_by_name('billing_apps_link')
    persitent_disk_max_size = SystemSettings.get_by_name('persitent_disk_max_size')

    # backup for downgrade
    if not redis.get('old_billing_apps_link'):
        redis.set('old_billing_apps_link', billing_apps_link or '',
                  ex=int(timedelta(days=7).total_seconds()))
    if not redis.get('old_persitent_disk_max_size'):
        redis.set('old_persitent_disk_max_size', persitent_disk_max_size,
                  ex=int(timedelta(days=7).total_seconds()))

    billing_url = (urlparse(billing_apps_link)._replace(path='', query='',
                                                        params='').geturl()
                   if billing_apps_link else None)
    SystemSettings.query.delete()
    add_system_settings()
    SystemSettings.set_by_name(
        'persitent_disk_max_size', persitent_disk_max_size, commit=False)
    SystemSettings.set_by_name('billing_url', billing_url, commit=False)
    db.session.commit()

    # 00094_update.py
    upd.print_log('Drop table "node_missed_actions" if exists')
    table = Table('node_missed_actions', db.metadata)
    table.drop(bind=db.engine, checkfirst=True)
    db.session.commit()

    # 00095_update.py
    upd.print_log('Restart k8s2etcd service')
    upd.print_log(helpers.local('systemctl restart kuberdock-k8s2etcd'))

    # 00098_update.py
    copyfile('/var/opt/kuberdock/conf/sudoers-nginx.conf', '/etc/sudoers.d/nginx')
    local('chown nginx:nginx /etc/nginx/conf.d/shared-kubernetes.conf')
    local('chown nginx:nginx /etc/nginx/conf.d/shared-etcd.conf')

    helpers.close_all_sessions()
def post_upgrade(for_successful=True, reason=None):  # teardown
    """
    Teardown after upgrade
    :return: Error or True if any error else False
    """
    if helpers.set_evicting_timeout('5m0s'):
        print >> sys.stderr, "Can't bring back old pods evicting interval."
        for_successful = False
    if for_successful:
        helpers.restart_service(settings.KUBERDOCK_SERVICE)
        helpers.set_maintenance(False)
        redis = ConnectionPool.get_connection()
        # We should clear cache for licencing info after successful upgrade:
        redis.delete('KDCOLLECTION')
        print SUCCESSFUL_UPDATE_MESSAGE
        health_check(post_upgrade_check=True)
    else:
        if reason is not None:
            print >> sys.stderr, reason
        print >> sys.stderr, FAILED_MESSAGE
Пример #6
0
def downgrade(upd, with_testing, exception, *args, **kwargs):
    #00109_update.py
    upd.print_log('Downgrade system_settings scheme...')

    redis = ConnectionPool.get_connection()
    old_settings = redis.get('old_system_settings')
    if old_settings:
        # restore old settings
        SystemSettings.query.delete()
        for param in json.loads(old_settings):
            db.session.add(
                SystemSettings(name=param.get('name'),
                               label=param.get('label'),
                               description=param.get('description'),
                               placeholder=param.get('placeholder'),
                               options=json.dumps(param.get('options')),
                               value=param.get('value')))
        db.session.commit()

    #00113_update.py
    upd.print_log('Removing "count_type" column from packages...')
    helpers.downgrade_db(revision='27c8f4c5f242')
Пример #7
0
def send(data):
    r = requests.post(
        STAT_URL,
        headers={'Content-Type': 'application/json'},
        json=data
    )
    # TODO: process licensing information in server response when some
    # licensing
    # schema will be implemented
    answer = {'status': 'ERROR'}
    if r.status_code != 200:
        msg = 'Failed to send request to CLN server.'
        current_app.logger.exception(msg + ' %s: %s', r.status_code, r.text)
        answer['data'] = msg
    else:
        try:
            res = r.json()
        except:
            msg = 'Invalid answer from CLN.'
            current_app.logger.exception(msg + ' %s', r.text)
            answer['data'] = msg
        else:
            if not res.get('success'):
                msg = format(res.get('message', ''))
                current_app.logger.warn(msg)
                answer['data'] = msg
            else:
                answer['status'] = 'OK'
                answer['data'] = 'License information was updated successfully'
                licensing.update_license_data(res.get('data', {}))
    redis = ConnectionPool.get_connection()
    try:
        redis.set('KDCOLLECTION', json.dumps(data))
    except:
        pass
    return answer