Пример #1
0
def services_list(request, environment_id):
    """Get environment applications.

       This function collects data from Murano API and modifies it only for
       dashboard purposes. Those changes don't impact application
       deployment parameters.
    """
    def strip(msg, to=100):
        return u'%s...' % msg[:to] if len(msg) > to else msg

    services = []
    # need to create new session to see services deployed be other user
    session_id = Session.get(request, environment_id)

    get_environment = api.muranoclient(request).environments.get
    environment = get_environment(environment_id, session_id)
    try:
        client = api.muranoclient(request)
        reports = client.environments.last_status(environment_id, session_id)
    except exc.HTTPNotFound:
        LOG.exception(
            _('Could not retrieve latest status for '
              'the {0} environment').format(environment_id))
        reports = {}

    for service_item in environment.services or []:
        service_data = service_item
        service_id = service_data['?']['id']

        if service_id in reports and reports[service_id]:
            last_operation = strip(reports[service_id].text)
            time = reports[service_id].updated.replace('T', ' ')
        else:
            last_operation = 'Component draft created' \
                if environment.version == 0 else ''
            try:
                time = service_data['updated'].replace('T', ' ')[:-7]
            except KeyError:
                time = None

        service_data['environment_id'] = environment_id
        service_data['environment_version'] = environment.version
        service_data['operation'] = last_operation
        service_data['operation_updated'] = time
        if service_data['?'].get('name'):
            service_data['name'] = service_data['?']['name']

        services.append(service_data)

    LOG.debug('Service::List')
    return [utils.Bunch(**service) for service in services]
Пример #2
0
    def get_all(self, request):
        env_list = api.environments_list(request)
        stats = []
        LOG.debug('Got env list: {0}'.format(env_list))
        for env in env_list:
            env_entry = utils.Bunch(name=env.name,
                                    id=env.id)
            services = self.build_service_list(request, env)
            LOG.debug('Processing env: {0}'.format(env))
            env_stats = self.get_stats_for_env(request, env.id)
            stats_list = []
            for entry in env_stats:
                instance_id = entry.instance_id
                service = services[instance_id]
                stat_entry = utils.Bunch(**entry.to_dict())
                stat_entry.service = service['name']
                stat_entry.service_type = service['type']
                stats_list.append(stat_entry)
            env_entry.instances = stats_list
            stats.append(env_entry)

        LOG.debug('Created statistics: {0}'.format(stats))
        return stats
Пример #3
0
def services_list(request, environment_id):
    def strip(msg, to=100):
        return '%s...' % msg[:to] if len(msg) > to else msg

    services = []
    # need to create new session to see services deployed be other user
    session_id = Session.get_or_create(request, environment_id)

    get_environment = muranoclient(request).environments.get
    environment = get_environment(environment_id, session_id)
    try:
        reports = muranoclient(request).environments.last_status(
            environment_id, session_id)
    except HTTPNotFound:
        reports = {}

    for service_item in environment.services:
        service_data = service_item
        service_id = service_data['?']['id']

        if service_id in reports and reports[service_id]:
            last_operation = strip(str(reports[service_id].text))
            time = reports[service_id].updated.replace('T', ' ')
        else:
            last_operation = 'Component draft created' \
                if environment.version == 0 else ''
            try:
                time = service_data['updated'].replace('T', ' ')[:-7]
            except KeyError:
                time = None

        service_data['environment_id'] = environment_id
        service_data['environment_version'] = environment.version
        service_data['operation'] = last_operation
        service_data['operation_updated'] = time
        services.append(service_data)

    LOG.debug('Service::List')
    return [utils.Bunch(**service) for service in services]
Пример #4
0
def services_list(request, environment_id):
    """Get environment applications.

       This function collects data from Murano API and modifies it only for
       dashboard purposes. Those changes don't impact application
       deployment parameters.
    """
    def strip(msg, to=100):
        return u'%s...' % msg[:to] if len(msg) > to else msg

    services = []
    # need to create new session to see services deployed by other user
    session_id = Session.get(request, environment_id)

    get_environment = api.muranoclient(request).environments.get
    environment = get_environment(environment_id, session_id)
    try:
        client = api.muranoclient(request)
        reports = client.environments.last_status(environment_id, session_id)
    except exc.HTTPNotFound:
        LOG.exception(
            _('Could not retrieve latest status for '
              'the {0} environment').format(environment_id))
        reports = {}

    for service_item in environment.services or []:
        service_data = service_item
        service_id = service_data['?']['id']

        if service_id in reports and reports[service_id]:
            last_operation = strip(reports[service_id].text)
            time = reports[service_id].updated
        else:
            last_operation = 'Component draft created' \
                if environment.version == 0 else ''
            try:
                time = service_data['updated'][:-7]
            except KeyError:
                time = None

        service_data['environment_id'] = environment_id
        service_data['environment_version'] = environment.version
        service_data['operation'] = last_operation
        service_data['operation_updated'] = time
        if service_data['?'].get('name'):
            service_data['name'] = service_data['?']['name']
        if (consts.DASHBOARD_ATTRS_KEY not in service_data['?'] or
                not service_data['?'][consts.DASHBOARD_ATTRS_KEY].get('name')):
            fqn = service_data['?']['type']
            version = None
            if '/' in fqn:
                version, fqn = fqn.split('/')[1].split('@')
            pkg = packages_api.app_by_fqn(request, fqn, version=version)
            if pkg:
                app_name = pkg.name
                storage = service_data['?'].setdefault(
                    consts.DASHBOARD_ATTRS_KEY, {})
                storage['name'] = app_name

        services.append(service_data)

    LOG.debug('Service::List')
    return [utils.Bunch(**service) for service in services]
Пример #5
0
    def test_del_item(self):
        obj = utils.Bunch(two=20)

        del obj['two']

        self.assertNotIn('two', obj)
Пример #6
0
    def test_del_attr(self):
        obj = utils.Bunch(one=10)

        del obj.one

        self.assertNotIn('one', obj)
Пример #7
0
    def test_set_item(self):
        obj = utils.Bunch()

        obj['two'] = 20

        self.assertEqual(20, obj['two'])
Пример #8
0
    def test_set_attr(self):
        obj = utils.Bunch()

        obj.one = 10

        self.assertEqual(10, obj['one'])
Пример #9
0
    def test_iteration(self):
        obj = utils.Bunch(one=10, two=15)

        sorted_objs = sorted([o for o in obj])

        self.assertEqual([10, 15], sorted_objs)
Пример #10
0
    def test_in(self):
        obj = utils.Bunch(one=10)

        self.assertIn('one', obj)
Пример #11
0
    def test_get_item(self):
        obj = utils.Bunch(two=15)

        self.assertEqual(15, obj['two'])
Пример #12
0
    def test_get_attr(self):
        obj = utils.Bunch(one=10)

        self.assertEqual(10, obj.one)