Пример #1
0
    def get_availability_zone_info(self):
        res = {}
        def_res = {}
        try:
            source_domains = api.nova.availability_zone_list(self.request)
            if not source_domains:
                return def_res
            plats = []
            try:
                request_api = RequestApi()
                plats = request_api.getRequestInfo(
                    'api/heterogeneous/platforms')
            except Exception:
                plats = []
            if not plats:
                return def_res
            all_clusters = []
            all_templates = []
            for sd in source_domains:
                for pl in plats:
                    if pl.get('domain_name') == sd.zoneName:
                        vtype = pl.get('virtualplatformtype')
                        templates = request_api.getRequestInfo(
                            'api/heterogeneous/platforms/' + vtype +
                            '/templates', {'name': pl.get('name')}) or []
                        templates = [
                            t for t in templates if t.get('name') not in
                            CSERVER_TEMPLATES_BLACK_LIST
                        ]
                        _clusters = request_api.getRequestInfo(
                            'api/heterogeneous/platforms/' + vtype +
                            '/clusters', {'name': pl.get('name')}) or []
                        all_clusters += [(c.get('id'), c.get('name'))
                                         for c in _clusters]
                        all_templates += [(c.get('id'), c.get('name'))
                                          for c in templates]

                        clusters = [{
                            'id': c.get('id'),
                            'name': c.get('name')
                        } for c in _clusters]
                        res[sd.zoneName] = {
                            'vtype': vtype,
                            'clusters': clusters,
                            'templates': templates
                        }
                        break

            return {
                'res': json.dumps(res),
                'all_clusters': all_clusters,
                'all_templates': all_templates
            }
        except Exception:
            res = _(
                'Unable to get vtype|clusters|templates info of source domain.'
            )
            exceptions.handle(self.request, ignore=True)
            return def_res
Пример #2
0
def query_hosts_by_domain(request, domain_id):
    hosts = []
    domain_info = None
    try:
        domain_info = api.nova.aggregate_get(request, domain_id)
        for h in getattr(domain_info, 'hosts'):
            ip = f_getIpByHostname(h)
            hosts.append({'name': ip, 'address': ip})
    except Exception:
        msg = _('Unable to retrieve the aggregate to be updated')
        exceptions.handle(request, msg)

    try:
        request_api = RequestApi()
        hosts2 = request_api.getRequestInfo(
            'api/heterogeneous/platforms/hosts')
        if type(hosts2) != type([]):
            messages.error(request, _('Unable to retrieve hosts list.'))
            hosts2 = []
    except Exception:
        hosts2 = []
        exceptions.handle(request, _('Unable to retrieve hosts list.'))

    if hosts2 and domain_info:
        hosts += [{
            'name': h.get('name'),
            'address': h.get('address')
        } for h in hosts2 if h.get('domain') == domain_info.availability_zone]

    return hosts
Пример #3
0
 def get_cserver_uuid_maps_info(self):
     try:
         request_api = RequestApi()
         uuid_maps = request_api.getRequestInfo('api/heterogeneous/platforms/cserver/uuid_maps') or []
         return uuid_maps
     except Exception:
         return {}
Пример #4
0
def get_plat_info(request, plat_id):
    if plat_id:
        try:
            request_api = RequestApi()
            plat_info_list = request_api.getRequestInfo(
                'api/heterogeneous/platforms/%s' % plat_id) or []
            for plat in plat_info_list:
                if plat:
                    return plat
        except Exception:
            exceptions.handle(
                request, _('Unable to retrieve heterogeneous platforms info.'))
    return {}
Пример #5
0
 def get_hosts(self):
     request = self.request
     datacenters = []
     clusters = []
     try:
         request_api = RequestApi()
         hosts = request_api.getRequestInfo(
             'api/heterogeneous/platforms/hosts')
         if hosts:
             hosts.sort(key=lambda aggregate: aggregate['name'].lower())
             return hosts
     except Exception:
         exceptions.handle(request, _('Unable to retrieve hosts list.'))
     return []
Пример #6
0
    def get_plats(self):
        plats = []
        err_msg = 'Unable to retrieve heterogeneous platforms list.'
        try:
            request_api = RequestApi()
            plats = request_api.getRequestInfo('api/heterogeneous/platforms')

            if plats == None or type(plats) != type([]):
                messages.error(self.request, _(err_msg))
                return []

            plats.sort(key=lambda aggregate: aggregate['name'].lower())
            return plats
        except Exception:
            exceptions.handle(self.request, _(err_msg))
        return []
Пример #7
0
    def get_clusters(self):
        clusters = []
        err_msg = 'Unable to retrieve clusters list.'
        try:
            request_api = RequestApi()
            clusters = request_api.getRequestInfo(
                'api/heterogeneous/platforms/clusters')

            if clusters == None or type(clusters) != type([]):
                messages.error(self.request, _(err_msg))
                return []

            clusters.sort(key=lambda aggregate: aggregate['name'].lower())
            return clusters
        except Exception:
            exceptions.handle(self.request, _(err_msg))
        return []
Пример #8
0
 def handle(self, request, context):
     GlobalVars.control_center_info = context
     try:
         request_api = RequestApi()
         res = request_api.getRequestInfo('api/heterogeneous/platform',
                                          context)
         if res and not res.get('errormsg'):
             f_res = []
             for dc in res:
                 for cl in res[dc]:
                     val = '%s ( %s )' % (str(cl), str(dc))
                     f_res.append((val, val))
             GlobalVars.avilible_clusters = f_res
             return True
     except Exception:
         exceptions.handle(request, err_msg)
     return False
Пример #9
0
 def get_data(self):
     request = self.request
     plats = []
     try:
         request_api = RequestApi()
         plats = request_api.getRequestInfo(
             'api/heterogeneous/platforms/hosts')
         if plats and type(plats) == type([]):
             plats.sort(key=lambda aggregate: aggregate['name'].lower())
             res = DictList2ObjectList(plats)
             return res
         elif plats and type(plats) == type(
             {}) and plats.get('action') == 'failed':
             messages.error(request, _('Unable to retrieve hosts list.'))
     except Exception:
         exceptions.handle(request, _('Unable to retrieve hosts list.'))
     return []
Пример #10
0
    def get_host_name(self):
        plat_id = ''
        if not hasattr(self, "_object"):
            plat_id = self.kwargs['id']

        if plat_id:
            try:
                request_api = RequestApi()
                plat_info_list = request_api.getRequestInfo(
                    'api/heterogeneous/platforms/%s' % plat_id) or []

                for plat in plat_info_list:
                    if plat and plat.get('hostname'):
                        return plat.get('hostname')
            except Exception:
                exceptions.handle(
                    request,
                    _('Unable to retrieve heterogeneous platforms info.'))
        return ''
Пример #11
0
    def get_occupied(self):
        err_msg = 'Unable to retrieve heterogeneous platforms list.'
        res = {
            'occupied_hostname': [],
            'occupied_name': [],
            'occupied_virtualplatformIP': []
        }
        try:
            request_api = RequestApi()
            plats = request_api.getRequestInfo('api/heterogeneous/platforms')

            if plats and type(plats) == type([]):
                res['occupied_hostname'] = [p.get('hostname') for p in plats]
                res['occupied_name'] = [p.get('name') for p in plats]
                res['occupied_virtualplatformIP'] = [
                    p.get('virtualplatformIP') for p in plats
                ]
        except Exception:
            exceptions.handle(self.request, _(err_msg))
        return res
Пример #12
0
def getAvailableHostsAndVms(request):
    res = []
    allpolicyedhostsvms = allPolicyedHostsVms()
    zones = api.nova.aggregate_details_list(request)

    try:
        request_api = RequestApi()
        hosts2 = request_api.getRequestInfo(
            'api/heterogeneous/platforms/hosts') or []

    except Exception:
        hosts2 = []
        exceptions.handle(request, _('Unable to retrieve hosts list.'))

    for z in zones:
        if z.hosts:
            zone_hosts = [f_getIpByHostname(h) for h in z.hosts]
            for h in zone_hosts + [
                    h.get('address')
                    for h in hosts2 if h.get('domain') == z.availability_zone
            ]:
                if h not in allpolicyedhostsvms:
                    res.append({
                        'zone': z.availability_zone,
                        'type': 'host',
                        'id': h,
                        'name': h
                    })

    instances, _more = api.nova.server_list(request, all_tenants=True)
    for i in instances:
        if getattr(i, 'id', '') not in allpolicyedhostsvms:
            res.append({
                'zone': getattr(i, 'OS-EXT-AZ:availability_zone', ''),
                'type': 'vm',
                'id': getattr(i, 'id', ''),
                'name': getattr(i, 'name', '')
            })
    res = sorted(res, key=lambda n: n.get('name'))
    return res