コード例 #1
0
    def get_host_log(body):
        try:
            records = body.get("records", {})
            response = {}
            for host_id in records.keys():
                host_name = yield list_simple_hosts(host_id)
                if host_name:
                    log_total = count_operation_log(region=CONF.keystone.region_name, obj=host_name.get("name"))
                    response[host_id] = ""
                    if records.get(host_id) and records.get(host_id) != log_total:
                        response[host_id] = "refresh"
                    records[host_id] = log_total
                else:
                    response[host_id] = "quit"

            body = {
                "total": {},
                "records": records,
                "response": response,
                "type": "host_log"
            }

        except Exception, e:
            LOG.error("compute detail log handler push message error is %s", e)
            raise gen.Return(body)
コード例 #2
0
    def run_host_state(body):
        try:
            records = body.get("records", {})
            result = {}

            for host_id in records.keys():
                try:
                    host = yield list_simple_hosts(host_id)
                except BaseException:
                    continue
                state = host[0].get("state") if host else "quit"
                result[host_id] = state

            response = {}
            for k, v in result.items():
                response[k] = v
                if not records or (k in records and v == records.get(k)):
                    response.pop(k)

            body = {
                "total": 0,
                "records": result,
                "response": response,
                "type": "state"
            }
        except Exception, e:
            LOG.error("host detail state handler push message error is %s", e)
コード例 #3
0
    def get_alarm(body):
        try:
            records = body.get("records") if body.get("records") else {}
            result = {}
            response = {}
            for host_id in records.keys():
                host_name = yield list_simple_hosts(host_id=host_id)
                if host_name:
                    try:
                        host_alarm_count = yield get_count_alarm(target=host_name[0].get("name"))
                    except BaseException:
                        continue
                    result[host_id] = host_alarm_count.get("count")

                    response[host_id] = ""
                    if records.get(host_id) and records.get(host_id) != host_alarm_count.get("count"):
                        response[host_id] = "refresh"
                else:
                    response[host_id] = "quit"

            body = {
                "total": 0,
                "records": result,
                "response": response,
                "type": "host_alarm"
            }
        except Exception, e:
            LOG.error("detail alarm handler push message error is %s", e)
コード例 #4
0
 def run_host_state(body):
     try:
         total = body.get("total")
         records = body.get("records")
         hosts = yield list_simple_hosts()
         response = {}
         result = {}
         for host in hosts:
             result[host.get("id")] = host.get("state")
         if total and total != len(hosts):
             LOG.debug("current redis total is %s  list total is %s ", total, len(hosts))
             response = "refresh"
         else:
             if records:
                 for k, v in result.items():
                     response[k] = v
                     if str(k) in records and v == records.get(str(k)):
                         response.pop(k)
         body = {
             "total": len(hosts),
             "records": result,
             "response": response,
             "type": "states"
         }
     except Exception, e:
         LOG.error("compute list socket monitor error %s", e)
コード例 #5
0
 def _net_vms(net_id):
     hosts = yield get_network_hosts(vlan_id=net_id)
     result = {}
     if hosts:
         hosts_info = yield list_simple_hosts(host_id=hosts)
         for host in hosts_info:
             result[str(host.get("id"))] = host.get("state")
     raise gen.Return(result)
コード例 #6
0
ファイル: subnet.py プロジェクト: 1026237416/Python
 def delete_tenant_host(self, tenant_id, host_id):
     yield delete_tenant_host(tenant_id, int(host_id))
     host_info = yield list_simple_hosts(host_id=host_id)
     for host in host_info:
         pass
     tenant = yield get_tenant_by_id(tenant_id)
     optLog.write(self.request, Type.TENANT, tenant['name'],
                  Operator.CONFIG_TENANT_DELETE_HOST, host['name'])
     self.response(Response())
コード例 #7
0
 def _host_meter(counter_name, host_id, limit):
     host_info = yield list_simple_hosts(host_id=host_id)
     if host_info:
         data = yield SampleQuery().meters_query(counter_name, **{'host': host_info[0]["ip"], "limit": limit})
         res = gen_host_chart_rst(counter_name, data)
         rst_data = {
             "type": counter_name,
             "records": res,
             "limit": limit
         }
         raise gen.Return(rst_data)
コード例 #8
0
ファイル: subnet.py プロジェクト: 1026237416/Python
 def set_tenant_hosts(self, tenant_id, body):
     hosts = body.get("host_ids")
     if not tenant_id:
         raise InvalidateParam
     hosts_info = yield list_simple_hosts(host_id=hosts)
     tenant = yield get_tenant_by_id(tenant_id)
     yield set_tenant_hosts(tenant_id, hosts)
     for host in hosts_info:
         optLog.write(self.request, Type.TENANT, tenant['name'],
                      Operator.CONFIG_TENANT_ADD_HOST, host['name'])
     self.response(Response())
コード例 #9
0
 def del_vlan_hosts(self, network_id, host_id):
     """ set vlan hosts
     :param network_id: id of network
     :param host_id: can alter network' s hosts
     """
     network = yield get_network(network_id)
     if not network:
         raise NetworkNotExist
     old_network = yield get_network(network_id)
     yield delete_network_hosts(network_id, host_id)
     hosts_info = yield list_simple_hosts(host_id=host_id)
     hosts_name = []
     for host in hosts_info:
         hosts_name.append(host['name'])
     optLog.write(self.request, Type.NETWORK, old_network['name'],
                  Operator.DEL_HOST, ','.join(map(str, hosts_name)))
     self.response(Response())
コード例 #10
0
 def _host_vms(host_id):
     host_info = yield list_simple_hosts(host_id=host_id)
     result = {}
     if host_info:
         host_name = host_info[0]["name"]
         vms_info = yield list_server(hosts=host_name, detailed=False, with_task=False)
         if vms_info:
             vms = [{"name": itm["name"], "id": itm["id"], "state": itm["state"]} for itm in vms_info]
             for vm_item in vms:
                 vm_id = vm_item["id"]
                 res = {
                     "state": vm_item["state"]
                 }
                 if "active" == vm_item["state"]:
                     for meter_name in VM_METER:
                         limit = 1
                         data = yield SampleQuery().meters_query(meter_name, **{'vm': vm_id, 'limit': limit})
                         res_data = gen_host_chart_rst(meter_name, data)
                         res[meter_name] = res_data[0] if res_data else {}
                 result[vm_item["name"]] = res
     raise gen.Return(result)
コード例 #11
0
    def set_vlan_hosts(self, network_id, body):
        """ set vlan hosts
        :param network_id: id of network
        :param body: can alter network' s hosts
        """
        network = yield get_network(network_id)
        if not network:
            raise NetworkNotExist
        hosts = body.get("hosts")

        hosts_info = yield list_simple_hosts(host_id=hosts)

        old_network = yield get_network(network_id)
        if old_network:
            name = old_network['name']
            yield add_network_hosts(network_id=network_id,
                                    network_name=name,
                                    hosts=hosts)
        else:
            raise InvalidateParam(args=['network_id'])
        for host in hosts_info:
            optLog.write(self.request, Type.NETWORK, old_network['name'],
                         Operator.ADD_HOST, host['name'])
        self.response(Response())
コード例 #12
0
 def get_host_storage_capacity(self, host_name):
     host = yield host_package.list_simple_hosts(name=host_name)
     if not host:
         raise InvalidateParam()
     disks = get_host_storage_capacity(host_name)
     self.response(Response(result=disks))