コード例 #1
0
    def handle_noargs(self, **options):
        b = get_backend()
        try:
            b.pre_exec()
            pending_commissions = b.astakosclient.get_pending_commissions()

            if pending_commissions:
                self.stdout.write("Unresolved commissions: %s\n" %
                                  pending_commissions)
            else:
                self.stdout.write("No unresolved commissions were found\n")
                return

            if options['fix']:
                to_accept = b.commission_serials.lookup(pending_commissions)
                to_reject = list(set(pending_commissions) - set(to_accept))
                response = b.astakosclient.resolve_commissions(
                    accept_serials=to_accept, reject_serials=to_reject)
                accepted = response['accepted']
                rejected = response['rejected']
                failed = response['failed']
                self.stdout.write("Accepted commissions: %s\n" % accepted)
                self.stdout.write("Rejected commissions: %s\n" % rejected)
                self.stdout.write("Failed commissions:\n")
                for i in failed:
                    self.stdout.write('%s\n' % i)

                b.commission_serials.delete_many(accepted)
        except Exception, e:
            logger.exception(e)
            b.post_exec(False)
            raise CommandError(e)
コード例 #2
0
    def handle_noargs(self, **options):
        b = get_backend()
        try:
            b.pre_exec()
            pending_commissions = b.astakosclient.get_pending_commissions()

            if pending_commissions:
                self.stdout.write(
                    "Unresolved commissions: %s\n" % pending_commissions
                )
            else:
                self.stdout.write("No unresolved commissions were found\n")
                return

            if options['fix']:
                to_accept = b.commission_serials.lookup(pending_commissions)
                to_reject = list(set(pending_commissions) - set(to_accept))
                response = b.astakosclient.resolve_commissions(
                    accept_serials=to_accept,
                    reject_serials=to_reject
                )
                accepted = response['accepted']
                rejected = response['rejected']
                failed = response['failed']
                self.stdout.write("Accepted commissions: %s\n" % accepted)
                self.stdout.write("Rejected commissions: %s\n" % rejected)
                self.stdout.write("Failed commissions:\n")
                for i in failed:
                    self.stdout.write('%s\n' % i)

                b.commission_serials.delete_many(accepted)
        except Exception, e:
            logger.exception(e)
            b.post_exec(False)
            raise CommandError(e)
コード例 #3
0
ファイル: file-show.py プロジェクト: AthinaB/synnefo
    def handle(self, *args, **options):
        success_status = False
        try:
            b = get_backend()
            b.pre_exec()

            if len(args) == 3:
                account, container, name = args
            elif len(args) == 1:
                if not is_uuid(args[0]):
                    raise CommandError('Invalid UUID')
                try:
                    account, container, name = b.get_uuid(
                        None, args[0], check_permissions=False)
                except NameError:
                    raise CommandError('Unknown UUID')
            else:
                raise CommandError("Invalid number of arguments")

            kv = b.get_object_meta(account, account, container, name,
                                   options['domain'], options['obj_version'])

            if options['obj_version'] is None:
                _, path, permissions = b.get_object_permissions(account,
                                                                account,
                                                                container,
                                                                name)
                if path is not None:
                    kv['permissions'] = path, dict(permissions)

                public = b.get_object_public(account, account, container, name)
                if public is not None:
                    update_public_meta(public, kv)

            if options['hashmap']:
                _, size, kv['hashmap'] = b.get_object_hashmap(
                    account, account, container, name, options['obj_version'])

            utils.pprint_table(self.stdout, [kv.values()], kv.keys(),
                               options["output_format"], vertical=True)

            success_status = True
        except Exception as e:
            raise CommandError(e)
        finally:
            b.post_exec(success_status)
            b.close()
コード例 #4
0
    def handle(self, *args, **options):
        success_status = False
        try:
            b = get_backend()
            b.pre_exec()

            if len(args) == 3:
                account, container, name = args
            elif len(args) == 1:
                if not is_uuid(args[0]):
                    raise CommandError('Invalid UUID')
                try:
                    account, container, name = b.get_uuid(
                        None, args[0], check_permissions=False)
                except NameError:
                    raise CommandError('Unknown UUID')
            else:
                raise CommandError("Invalid number of arguments")

            kv = b.get_object_meta(account, account, container, name,
                                   options['domain'], options['obj_version'])

            if options['obj_version'] is None:
                _, path, permissions = b.get_object_permissions(
                    account, account, container, name)
                if path is not None:
                    kv['permissions'] = path, dict(permissions)

                public = b.get_object_public(account, account, container, name)
                if public is not None:
                    update_public_meta(public, kv)

            if options['hashmap']:
                _, size, kv['hashmap'] = b.get_object_hashmap(
                    account, account, container, name, options['obj_version'])

            utils.pprint_table(self.stdout, [kv.values()],
                               kv.keys(),
                               options["output_format"],
                               vertical=True)

            success_status = True
        except Exception as e:
            raise CommandError(e)
        finally:
            b.post_exec(success_status)
            b.close()
コード例 #5
0
ファイル: dispatch.py プロジェクト: cstavr/synnefo
def update_md5(m):
    if m['resource'] != 'object' or m['details']['action'] != 'object update':
        return

    backend = get_backend()

    path = m['value']
    account, container, name = path.split('/', 2)
    version = m['details']['version']
    meta = None
    try:
        meta = backend.get_object_meta(
            account, account, container, name, 'pithos', version)
        if meta['checksum'] == '':
            size, hashmap = backend.get_object_hashmap(
                account, account, container, name, version)
            checksum = hashmap_md5(backend, hashmap, size)
            backend.update_object_checksum(
                account, account, container, name, version, checksum)
            print 'INFO: Updated checksum for path "%s"' % (path,)
    except Exception, e:
        print 'WARNING: Can not update checksum for path "%s" (%s)' % (path, e)
コード例 #6
0
def update_md5(m):
    if m['resource'] != 'object' or m['details']['action'] != 'object update':
        return

    backend = get_backend()
    backend.pre_exec()

    path = m['value']
    account, container, name = path.split('/', 2)
    version = m['details']['version']
    meta = None
    try:
        meta = backend.get_object_meta(
            account, account, container, name, 'pithos', version)
        if meta['checksum'] == '':
            _, size, hashmap = backend.get_object_hashmap(
                account, account, container, name, version)
            checksum = hashmap_md5(backend, hashmap, size)
            backend.update_object_checksum(
                account, account, container, name, version, checksum)
            print 'INFO: Updated checksum for path "%s"' % (path,)
    except Exception, e:
        print 'WARNING: Can not update checksum for path "%s" (%s)' % (path, e)
コード例 #7
0
ファイル: __init__.py プロジェクト: cstavr/synnefo
 def __init__(self):
     self.backend = get_backend()
コード例 #8
0
ファイル: __init__.py プロジェクト: vgerak/synnefo
 def __init__(self):
     self.backend = get_backend()
コード例 #9
0
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.

from django.core.management.base import NoArgsCommand

from optparse import make_option

from pithos.api.util import get_backend
from pithos.api.resources import resources
from pithos.backends.modular import DEFAULT_SOURCE

from synnefo.webproject.management import utils

from astakosclient.errors import QuotaLimit, NotFound

backend = get_backend()


class Command(NoArgsCommand):
    help = """Reconcile resource usage of Astakos with Pithos DB.

    Detect unsynchronized usage between Astakos and Pithos DB resources and
    synchronize them if specified so.

    """
    option_list = NoArgsCommand.option_list + (
        make_option("--userid", dest="userid",
                    default=None,
                    help="Reconcile resources only for this user"),
        make_option("--fix", dest="fix",
                    default=False,