Ejemplo n.º 1
0
def reboot(nova_client, **_):
    server = get_server_by_context(nova_client)
    ctx.logger.info('Rebooting machine')
    nova_client.servers.reboot(server)
    i = 0
    vm_started = False
    while i < VM_ATTEMPTS and not vm_started:
        ctx.logger.info('Waiting for vm to reboot, attempt {0}'.format(i + 1))
        time.sleep(INTERVAL)
        server = get_server_by_context(nova_client)
        vm_started = server.status == SERVER_STATUS_ACTIVE
        i += 1
    if vm_started:
        ctx.logger.info('Machine rebooted')
    else:
        raise NonRecoverableError('Could not reboot machine')

    agent_name = ctx.instance.runtime_properties['cloudify_agent']['name']
    i = 0
    agent_alive = False
    amqp_client = get_client(amqp_vhost=ctx.tenant['rabbitmq_vhost'],
                             amqp_user=ctx.tenant['rabbitmq_username'],
                             amqp_pass=ctx.tenant['rabbitmq_password'])
    while i < AGENT_ATTEMPTS and not agent_alive:
        ctx.logger.info('Waiting for agent, attempt {0}'.format(i + 1))
        time.sleep(INTERVAL)
        agent_alive = is_agent_alive(agent_name, amqp_client)
        i += 1
    if agent_alive:
        ctx.logger.info('Agent started')
    else:
        raise NonRecoverableError('Agent did not start')
Ejemplo n.º 2
0
def start(cloudify_agent, **_):
    """
    Only called in "init_script"/"plugin" mode, where the agent is started
    externally (e.g. userdata script), and all we have to do is wait for it
    """
    update_agent_record(cloudify_agent, AgentState.STARTING)
    tenant = cloudify_utils.get_tenant()
    client = get_client(
        amqp_user=tenant['rabbitmq_username'],
        amqp_pass=tenant['rabbitmq_password'],
        amqp_vhost=tenant['rabbitmq_vhost']
    )
    agent_alive = utils.is_agent_alive(cloudify_agent['queue'], client)

    if not agent_alive:
        if ctx.operation.retry_number > 3:
            ctx.logger.warning('Waiting too long for Agent to start')
            update_agent_record(cloudify_agent, AgentState.NONRESPONSIVE)
        return ctx.operation.retry(
            message='Waiting for Agent to start...')

    ctx.logger.info('Agent has started')
    update_agent_record(cloudify_agent, AgentState.STARTED)
    if not cloudify_agent.is_provided:
        script.cleanup_scripts()
Ejemplo n.º 3
0
def reboot(nova_client, **_):
    server = get_server_by_context(nova_client)
    ctx.logger.info('Rebooting machine')
    nova_client.servers.reboot(server)
    i = 0
    vm_started = False
    while i < VM_ATTEMPTS and not vm_started:
        ctx.logger.info('Waiting for vm to reboot, attempt {0}'.format(i + 1))
        time.sleep(INTERVAL)
        server = get_server_by_context(nova_client)
        vm_started = server.status == SERVER_STATUS_ACTIVE
        i += 1
    if vm_started:
        ctx.logger.info('Machine rebooted')
    else:
        raise NonRecoverableError('Could not reboot machine')

    agent_name = ctx.instance.runtime_properties['cloudify_agent']['name']
    i = 0
    agent_alive = False
    amqp_client = get_client(
        amqp_vhost=ctx.tenant['rabbitmq_vhost'],
        amqp_user=ctx.tenant['rabbitmq_username'],
        amqp_pass=ctx.tenant['rabbitmq_password']
    )
    while i < AGENT_ATTEMPTS and not agent_alive:
        ctx.logger.info('Waiting for agent, attempt {0}'.format(i + 1))
        time.sleep(INTERVAL)
        agent_alive = is_agent_alive(agent_name, amqp_client)
        i += 1
    if agent_alive:
        ctx.logger.info('Agent started')
    else:
        raise NonRecoverableError('Agent did not start')
Ejemplo n.º 4
0
 def _is_daemon_running(self):
     self._logger.debug('Checking if agent daemon is running...')
     client = self._get_client()
     with client:
         # precreate the queue that the agent will use, so that the
         # message is already waiting for the agent when it starts up
         client.channel_method('queue_declare',
                               queue='{0}_service'.format(self.queue),
                               auto_delete=False,
                               durable=True)
         return utils.is_agent_alive(self.queue,
                                     client,
                                     timeout=3,
                                     connect=False)
Ejemplo n.º 5
0
def start(cloudify_agent, **_):
    """
    Only called in "init_script"/"plugin" mode, where the agent is started
    externally (e.g. userdata script), and all we have to do is wait for it
    """
    tenant = cloudify_utils.get_tenant()
    client = get_client(
        amqp_user=tenant['rabbitmq_username'],
        amqp_pass=tenant['rabbitmq_password'],
        amqp_vhost=tenant['rabbitmq_vhost']
    )
    agent_alive = utils.is_agent_alive(cloudify_agent['queue'], client)

    if not agent_alive:
        return ctx.operation.retry(
            message='Waiting for Agent to start...')

    ctx.logger.info('Agent has started')
    if not cloudify_agent.is_provided:
        script.cleanup_scripts()
Ejemplo n.º 6
0
def start(cloudify_agent, **_):
    """
    Only called in "init_script"/"plugin" mode, where the agent is started
    externally (e.g. userdata script), and all we have to do is wait for it
    """
    update_agent_record(cloudify_agent, AgentState.STARTING)
    tenant = cloudify_utils.get_tenant()
    client = get_client(amqp_user=tenant['rabbitmq_username'],
                        amqp_pass=tenant['rabbitmq_password'],
                        amqp_vhost=tenant['rabbitmq_vhost'])
    agent_alive = utils.is_agent_alive(cloudify_agent['queue'], client)

    if not agent_alive:
        if ctx.operation.retry_number > 3:
            ctx.logger.warning('Waiting too long for Agent to start')
            update_agent_record(cloudify_agent, AgentState.NONRESPONSIVE)
        return ctx.operation.retry(message='Waiting for Agent to start...')

    ctx.logger.info('Agent has started')
    update_agent_record(cloudify_agent, AgentState.STARTED)
    if not cloudify_agent.is_provided:
        script.cleanup_scripts()
Ejemplo n.º 7
0
 def _is_agent_alive(self, name, timeout=10):
     return agent_utils.is_agent_alive(name, get_client(), timeout=timeout)
Ejemplo n.º 8
0
def _validate_cloudify_amqp(agent):
    with _get_amqp_client(agent) as client:
        return utils.is_agent_alive(agent['name'], client)
Ejemplo n.º 9
0
 def _is_agent_alive(self, name, timeout=10):
     return agent_utils.is_agent_alive(
         name,
         get_client(),
         timeout=timeout)
Ejemplo n.º 10
0
 def _is_daemon_running(self):
     self._logger.debug('Checking if agent daemon is running...')
     return utils.is_agent_alive(self.queue, self._get_client(), timeout=3)
Ejemplo n.º 11
0
def _validate_cloudify_amqp(agent):
    with _get_amqp_client(agent) as client:
        return utils.is_agent_alive(agent['name'], client)
Ejemplo n.º 12
0
 def _is_daemon_running(self):
     self._logger.debug('Checking if agent daemon is running...')
     return utils.is_agent_alive(self.queue, self._get_client(), timeout=3)