def start(params, processes_to_wait_for, retry_interval, daemon_client=None, **_): """ cloudify.docker.container type start lifecycle operation. Any properties and runtime_properties set in the create lifecycle operation also available in start. Similar to the docker start command, but doesn't support attach options. :param daemon_client: optional configuration for client creation :param retry_interval: The number of seconds between retries during the wait_for_processes bit. """ daemon_client = daemon_client or {} client = docker_client.get_client(daemon_client) if ctx.node.properties['use_external_resource']: if utils.get_container_dictionary(client) is None: raise NonRecoverableError('{} does not exist.'.format( ctx.instance.runtime_properties.get('container_id'))) container_id = ctx.instance.runtime_properties['container_id'] arguments = {'container': container_id} arguments.update(params) ctx.logger.info('Start arguments: {0}'.format(arguments)) try: response = client.start(**arguments) except APIError as e: raise NonRecoverableError('Failed to start container: {0}.'.format( str(e))) ctx.logger.info('Container started: {}.'.format(response)) if params.get('processes_to_wait_for'): utils.wait_for_processes(processes_to_wait_for, retry_interval, client) ctx.logger.info('Started container: {0}.'.format( ctx.instance.runtime_properties['container_id'])) if utils.get_container_dictionary(client): inspect_output = utils.inspect_container(client) if inspect_output is not None: ctx.instance.runtime_properties['ports'] = \ inspect_output.get('Ports', None) ctx.instance.runtime_properties['network_settings'] = \ inspect_output.get('NetworkSettings', None) else: ctx.logger.info( 'Failed to get inspect_output: {0}'.format(arguments)) top_info = utils.get_top_info(client) ctx.logger.info('Container: {0} Forwarded ports: {1} Top: {2}.'.format( ctx.instance.runtime_properties['container_id'], 'Ports', top_info))
def start(params, processes_to_wait_for, retry_interval, daemon_client=None, **_): """ cloudify.docker.container type start lifecycle operation. Any properties and runtime_properties set in the create lifecycle operation also available in start. Similar to the docker start command, but doesn't support attach options. :param daemon_client: optional configuration for client creation :param retry_interval: The number of seconds between retries during the wait_for_processes bit. """ daemon_client = daemon_client or {} client = docker_client.get_client(daemon_client) if ctx.node.properties['use_external_resource']: if utils.get_container_dictionary(client) is None: raise NonRecoverableError('{} does not exist.'.format( ctx.instance.runtime_properties.get('container_id'))) container_id = ctx.instance.runtime_properties['container_id'] arguments = {'container': container_id} arguments.update(params) ctx.logger.info('Start arguments: {0}'.format(arguments)) try: response = client.start(**arguments) except APIError as e: raise NonRecoverableError( 'Failed to start container: {0}.'.format(str(e))) ctx.logger.info('Container started: {}.'.format(response)) if params.get('processes_to_wait_for'): utils.wait_for_processes(processes_to_wait_for, retry_interval, client) ctx.logger.info('Started container: {0}.'.format( ctx.instance.runtime_properties['container_id'])) if utils.get_container_dictionary(client): inspect_output = utils.inspect_container(client) if inspect_output is not None: ctx.instance.runtime_properties['ports'] = \ inspect_output.get('Ports', None) ctx.instance.runtime_properties['network_settings'] = \ inspect_output.get('NetworkSettings', None) else: ctx.logger.info('Failed to get inspect_output: {0}'.format(arguments)) top_info = utils.get_top_info(client) ctx.logger.info('Container: {0} Forwarded ports: {1} Top: {2}.'.format( ctx.instance.runtime_properties['container_id'], 'Ports', top_info))
def test_wait_for_processes(self): name = 'test_wait_for_processes' client = self.get_docker_client() self.pull_image(client) ctx = self.get_mock_context(name) for image in self.get_docker_images(client): if 'docker-test-image:latest' in \ self.get_tags_for_docker_image(image): image_id = self.get_id_from_image(image) container = self.create_container(client, name, image_id) ctx.instance.runtime_properties['container_id'] = container.get('Id') processes = ['/bin/sh'] client.start(name) out = utils.wait_for_processes(processes, 1, client, ctx=ctx) client.stop(container=container, timeout=1) client.remove_container( container=container) self.assertEquals(True, out)
def test_wait_for_processes(self): name = 'test_wait_for_processes' client = self.get_docker_client() self.pull_image(client) ctx = self.get_mock_context(name) for image in self.get_docker_images(client): if 'docker-test-image:latest' in \ self.get_tags_for_docker_image(image): image_id = self.get_id_from_image(image) container = self.create_container(client, name, image_id) ctx.instance.runtime_properties['container_id'] = container.get('Id') processes = ['/bin/sh'] client.start(name) out = utils.wait_for_processes(processes, 1, client, ctx=ctx) client.stop(container=container, timeout=1) client.remove_container(container=container) self.assertEquals(True, out)
def test_wait_for_processes(self): name = 'test_wait_for_processes' client = self.get_docker_client() self.pull_image(client) ctx = self.get_mock_context(name) current_ctx.set(ctx=ctx) for image in self.get_docker_images(client): if '{0}:latest'.format(TEST_IMAGE) in \ self.get_tags_for_docker_image(image): image_id = self.get_id_from_image(image) container = self.create_container(client, name, image_id) self.addCleanup(client.remove_container, container=container) self.addCleanup(client.stop, container=container, timeout=1) ctx.instance.runtime_properties['container_id'] = container.get('Id') processes = ['/bin/sh'] client.start(name) out = utils.wait_for_processes(processes, 1, client) self.assertEquals(True, out)