def check_mysql_status(self, context, id): """Make a synchronous call to trigger smart agent for checking MySQL status""" instance = dbutils.get_instance(id) LOG.debug("Triggering smart agent on Instance %s (%s) to check MySQL status.", id, instance['remote_hostname']) result = rpc.call(context, instance['remote_hostname'], {"method": "check_mysql_status"}) # update instance state in guest_status table upon receiving smart agent response dbutils.update_guest_status(id, int(result)) return result
def update_instance_state(self, msg): """Update instance state in guest_status table.""" LOG.debug("Updating instance state: %s", msg) # validate input message if not msg['args']['hostname']: raise exception.NotFound("Required element/key 'hostname' was not specified in phone home message.") if '' == msg['args']['state']: raise exception.NotFound("Required element/key 'state' was not specified in phone home message.") # update DB instance = dbutils.get_instance_by_hostname(msg['args']['hostname']) state = result_state.ResultState().name(int(msg['args']['state'])) # Treat running and success the same if state == 'running' or state == 'success': state = 'running' credential_id = instance['credential'] region = instance['availability_zone'] remote_uuid = instance['remote_uuid'] if instance['address'] is None: # Look up the public_ip for nova instance credential = models.Credential.find_by(id=credential_id) try: remote_instance = models.Instance(credential=credential, region=region, uuid=remote_uuid) # as of Oct 24, 2012, the phonehomehandler has not be executed anymore, app server does all the updates towards api db public_ip = self._extract_public_ip(remote_instance.data()) LOG.debug("Updating Instance %s with IP: %s" % (instance['id'], public_ip)) dbutils.update_instance_with_ip(instance['id'], public_ip) except exception.NotFound: LOG.warn("Unable to find Remote instance and extract public ip") except exception.ReddwarfError: LOG.exception("Error occurred updating instance with public ip") LOG.debug("Updating mysql instance state for Instance %s", instance['id']) dbutils.update_guest_status(instance['id'], state)