def stop(args): """`conduct stop` command""" log = logging.getLogger(__name__) path = 'bundles/{}?scale=0'.format(args.bundle) url = conduct_url.url(path, args) response = conduct_request.put(args.dcos_mode, conductr_host(args), url, auth=args.conductr_auth, verify=args.server_verification_file, timeout=DEFAULT_HTTP_TIMEOUT) validation.raise_for_status_inc_3xx(response) if log.is_verbose_enabled(): log.verbose(validation.pretty_json(response.text)) response_json = json.loads(response.text) bundle_id = response_json[ 'bundleId'] if args.long_ids else bundle_utils.short_id( response_json['bundleId']) log.info('Bundle stop request sent.') if not args.no_wait: bundle_scale.wait_for_scale(response_json['bundleId'], 0, args) if not args.disable_instructions: log.info('Unload bundle with: {} unload{} {}'.format( args.command, args.cli_parameters, bundle_id)) log.info('Print ConductR info with: {} info{}'.format( args.command, args.cli_parameters)) return True
def stop(args): """`conduct stop` command""" log = logging.getLogger(__name__) path = "bundles/{}?scale=0".format(args.bundle) url = conduct_url.url(path, args) response = conduct_request.put( args.dcos_mode, conductr_host(args), url, auth=args.conductr_auth, verify=args.server_verification_file, timeout=DEFAULT_HTTP_TIMEOUT, ) validation.raise_for_status_inc_3xx(response) if log.is_verbose_enabled(): log.verbose(validation.pretty_json(response.text)) response_json = json.loads(response.text) bundle_id = response_json["bundleId"] if args.long_ids else bundle_utils.short_id(response_json["bundleId"]) log.info("Bundle stop request sent.") if not args.no_wait: bundle_scale.wait_for_scale(response_json["bundleId"], 0, args) if not args.disable_instructions: log.info("Unload bundle with: {} unload{} {}".format(args.command, args.cli_parameters, bundle_id)) log.info("Print ConductR info with: {} info{}".format(args.command, args.cli_parameters)) return True
def run(args): """`conduct run` command""" log = logging.getLogger(__name__) if args.affinity is not None and args.api_version == '1': log.error('Affinity feature is only available for v1.1 onwards of ConductR') return elif args.affinity is not None: path = 'bundles/{}?scale={}&affinity={}'.format(args.bundle, args.scale, args.affinity) else: path = 'bundles/{}?scale={}'.format(args.bundle, args.scale) url = conduct_url.url(path, args) response = conduct_request.put(args.dcos_mode, conductr_host(args), url, auth=args.conductr_auth, verify=args.server_verification_file) validation.raise_for_status_inc_3xx(response) if log.is_verbose_enabled(): log.verbose(validation.pretty_json(response.text)) response_json = json.loads(response.text) bundle_id = response_json['bundleId'] if args.long_ids else bundle_utils.short_id(response_json['bundleId']) log.info('Bundle run request sent.') if not args.no_wait: bundle_scale.wait_for_scale(response_json['bundleId'], args.scale, args) if not args.disable_instructions: log.info('Stop bundle with: {} stop{} {}'.format(args.command, args.cli_parameters, bundle_id)) log.info('Print ConductR info with: {} info{}'.format(args.command, args.cli_parameters)) return True
def run(args): """`conduct run` command""" log = logging.getLogger(__name__) if args.affinity is not None and args.api_version == '1': log.error( 'Affinity feature is only available for v1.1 onwards of ConductR') return elif args.affinity is not None: path = 'bundles/{}?scale={}&affinity={}'.format( args.bundle, args.scale, args.affinity) else: path = 'bundles/{}?scale={}'.format(args.bundle, args.scale) url = conduct_url.url(path, args) response = conduct_request.put(args.dcos_mode, conductr_host(args), url, auth=args.conductr_auth, verify=args.server_verification_file) validation.raise_for_status_inc_3xx(response) if log.is_verbose_enabled(): log.verbose(validation.pretty_json(response.text)) response_json = json.loads(response.text) bundle_id = response_json[ 'bundleId'] if args.long_ids else bundle_utils.short_id( response_json['bundleId']) log.info('Bundle run request sent.') if not args.no_wait: bundle_scale.wait_for_scale(response_json['bundleId'], args.scale, wait_for_is_active=True, args=args) if not args.disable_instructions: log.info('Stop bundle with: {} stop{} {}'.format( args.command, args.cli_parameters, bundle_id)) log.info('Print ConductR info with: {} info{}'.format( args.command, args.cli_parameters)) log.info('Print bundle info with: {} info{} {}'.format( args.command, args.cli_parameters, bundle_id)) return True
def test_put(self): enriched_args = {'enriched': 'args'} enrich_args_mock = MagicMock(return_value=enriched_args) dcos_http_response = 'dcos_http_response' dcos_http_mock = MagicMock(return_value=dcos_http_response) requests_http_response = 'requests_http_response' requests_http_mock = MagicMock(return_value=requests_http_response) with patch('conductr_cli.conduct_request.enrich_args', enrich_args_mock), \ patch('dcos.http.put', dcos_http_mock), \ patch('requests.put', requests_http_mock): result = conduct_request.put(self.dcos_mode, self.host, self.url, **self.kwargs) self.assertEqual(requests_http_response, result) enrich_args_mock.assert_called_with(self.host, **self.kwargs) requests_http_mock.assert_called_with(self.url, **enriched_args) dcos_http_mock.assert_not_called()