- def _query_if_alive(self, nodes_id=None, hostname=None):
- """
- Query PLCAPI for nodes that register activity recently, using filters
- related to the state of the node, e.g. last time it was contacted
- """
- if nodes_id is None and hostname is None:
- msg = "Specify nodes_id or hostname"
- raise RuntimeError, msg
-
- if nodes_id is not None and hostname is not None:
- msg = "Specify either nodes_id or hostname"
- raise RuntimeError, msg
-
- # define PL filters to check the node is alive
- filters = dict()
- filters['run_level'] = 'boot'
- filters['boot_state'] = 'boot'
- filters['node_type'] = 'regular'
- #filters['>last_contact'] = int(time.time()) - 2*3600
-
- # adding node_id or hostname to the filters to check for the particular
- # node
- if nodes_id:
- filters['node_id'] = list(nodes_id)
- alive_nodes_id = self._get_nodes_id(filters)
- elif hostname:
- filters['hostname'] = hostname
- alive_nodes_id = self._get_nodes_id(filters)
-
- if len(alive_nodes_id) == 0:
- self.fail_node_not_alive(hostname)
- else:
- nodes_id = list()
- for node_id in alive_nodes_id:
- nid = node_id['node_id']
- nodes_id.append(nid)
-
- return nodes_id
-