def do_open(args, _): """usage: open cluster[/role[/env/job]] Opens the scheduler page for a cluster, role or job in the default web browser. """ cluster_name = role = env = job = None args = args[0].split("/") if len(args) > 0: cluster_name = args[0] if len(args) > 1: role = args[1] if len(args) > 2: env = args[2] if len(args) > 3: job = args[3] else: # TODO(ksweeney): Remove this after MESOS-2945 is completed. die('env scheduler pages are not yet implemented, please specify job') if not cluster_name: die('cluster is required') api = make_client(cluster_name) import webbrowser webbrowser.open_new_tab( synthesize_url(api.scheduler_proxy.scheduler_client().url, role, env, job))
def do_open(args, _): """usage: open cluster[/role[/env/job]] Opens the scheduler page for a cluster, role or job in the default web browser. """ cluster_name = role = env = job = None if len(args) == 0: print('Open command requires a jobkey parameter.') exit(1) v1_deprecation_warning("open", ["job", "open"]) args = args[0].split("/") if len(args) > 0: cluster_name = args[0] if len(args) > 1: role = args[1] if len(args) > 2: env = args[2] if len(args) > 3: job = args[3] else: # TODO(ksweeney): Remove this after MESOS-2945 is completed. die('env scheduler pages are not yet implemented, please specify job' ) if not cluster_name: die('cluster is required') api = make_client(cluster_name) import webbrowser webbrowser.open_new_tab( synthesize_url(api.scheduler_proxy.scheduler_client().url, role, env, job))
def execute(self, context): key_parts = context.options.key.split("/") while len(key_parts) < 4: key_parts.append(None) (cluster, role, env, name) = key_parts api = context.get_api(cluster) webbrowser.open_new_tab(synthesize_url(api.scheduler_proxy.scheduler_client().url, role, env, name)) return EXIT_OK
def test_synthesize_url(self, mock_log, mock_die): base_url = 'http://example.com' role = 'some-role' environment = 'some-environment' job = 'some-job' update_id = 'some-update-id' assert (('%s/scheduler/%s/%s/%s/update/%s' % (base_url, role, environment, job, update_id)) == base.synthesize_url(base_url, role, environment, job, update_id=update_id)) assert (('%s/scheduler/%s/%s/%s' % (base_url, role, environment, job)) == base.synthesize_url( base_url, role, environment, job)) assert (('%s/scheduler/%s/%s' % (base_url, role, environment)) == base.synthesize_url( base_url, role, environment)) assert (('%s/scheduler/%s' % (base_url, role)) == base.synthesize_url( base_url, role)) assert (('%s/scheduler/%s' % (base_url, role)) == base.synthesize_url( base_url, role)) mock_log.reset_mock() scheduler_url = '' out = base.synthesize_url(scheduler_url) self.assertIsNone(out) mock_log.warning.assert_called_once_with( 'Unable to find scheduler web UI!') mock_log.reset_mock() mock_die.reset_mock() scheduler_url = 'foo' env = 'foo' out = base.synthesize_url(scheduler_url, env=env) expected = 'scheduler' self.assertEqual(out, expected) mock_die.assert_called_once_with('If env specified, must specify role') mock_log.reset_mock() mock_die.reset_mock() scheduler_url = 'foo' job = 'bar' out = base.synthesize_url(scheduler_url, job=job) expected = 'scheduler' self.assertEqual(out, expected) mock_die.assert_called_once_with( 'If job specified, must specify role and env')
def execute(self, context): key_parts = context.options.key.split("/") while len(key_parts) < 4: key_parts.append(None) (cluster, role, env, name) = key_parts api = context.get_api(cluster) webbrowser.open_new_tab( synthesize_url(api.scheduler_proxy.scheduler_client().url, role, env, name) ) return EXIT_OK
def test_synthesize_url(self): base_url = 'http://example.com' role = 'some-role' environment = 'some-environment' job = 'some-job' update_id = 'some-update-id' assert (('%s/scheduler/%s/%s/%s/update/%s' % (base_url, role, environment, job, update_id)) == base.synthesize_url(base_url, role, environment, job, update_id=update_id)) assert (('%s/scheduler/%s/%s/%s' % (base_url, role, environment, job)) == base.synthesize_url(base_url, role, environment, job)) assert (('%s/scheduler/%s/%s' % (base_url, role, environment)) == base.synthesize_url(base_url, role, environment)) assert (('%s/scheduler/%s' % (base_url, role)) == base.synthesize_url(base_url, role)) assert (('%s/scheduler/%s' % (base_url, role)) == base.synthesize_url(base_url, role))
def test_synthesize_url(self, mock_log, mock_die): base_url = 'http://example.com' role = 'some-role' environment = 'some-environment' job = 'some-job' update_id = 'some-update-id' assert (('%s/scheduler/%s/%s/%s/update/%s' % (base_url, role, environment, job, update_id)) == base.synthesize_url(base_url, role, environment, job, update_id=update_id)) assert (('%s/scheduler/%s/%s/%s' % (base_url, role, environment, job)) == base.synthesize_url(base_url, role, environment, job)) assert (('%s/scheduler/%s/%s' % (base_url, role, environment)) == base.synthesize_url(base_url, role, environment)) assert (('%s/scheduler/%s' % (base_url, role)) == base.synthesize_url(base_url, role)) assert (('%s/scheduler/%s' % (base_url, role)) == base.synthesize_url(base_url, role)) mock_log.reset_mock() scheduler_url = '' out = base.synthesize_url(scheduler_url) self.assertIsNone(out) mock_log.warning.assert_called_once_with('Unable to find scheduler web UI!') mock_log.reset_mock() mock_die.reset_mock() scheduler_url = 'foo' env = 'foo' out = base.synthesize_url(scheduler_url, env=env) expected = 'scheduler' self.assertEqual(out, expected) mock_die.assert_called_once_with('If env specified, must specify role') mock_log.reset_mock() mock_die.reset_mock() scheduler_url = 'foo' job = 'bar' out = base.synthesize_url(scheduler_url, job=job) expected = 'scheduler' self.assertEqual(out, expected) mock_die.assert_called_once_with('If job specified, must specify role and env')
def open_job_page(self, api, jobkey): """Opens the page for a job in the system web browser.""" self.open_page( synthesize_url(api.scheduler_proxy.scheduler_client().url, jobkey.role, jobkey.env, jobkey.name))
def open_scheduler_page(self, cluster, role, env, name): """Open a scheduler page""" api = self.get_api(cluster) self.open_page( synthesize_url(api.scheduler_proxy.scheduler_client().url, role, env, name))
def get_job_page(self, api, jobkey): return synthesize_url(api.scheduler_proxy.scheduler_client().url, jobkey.role, jobkey.env, jobkey.name)
def open_scheduler_page(self, cluster, role, env, name): """Open a scheduler page""" api = self.get_api(cluster) self.open_page(synthesize_url(api.scheduler_proxy.scheduler_client().url, role, env, name))
def open_job_page(self, api, jobkey): """Opens the page for a job in the system web browser.""" self.open_page(synthesize_url(api.scheduler_proxy.scheduler_client().url, jobkey.role, jobkey.env, jobkey.name))
def handle_open(self, api): if self.options.open_browser: self.open_page(synthesize_url(api.scheduler.scheduler().url, self.options.jobspec.role, self.options.jobspec.env, self.options.jobspec.name))
def open_job_page(self, api, config): self.open_page(synthesize_url(api.scheduler.scheduler().url, config.role(), config.environment(), config.name()))