예제 #1
0
def open_console(app_name, env_name):
    if utils.is_ssh():
        raise NotSupportedError('The console command is not supported'
                                ' in an ssh type session')

    env = None
    if env_name is not None:
        env = elasticbeanstalk.get_environment(app_name=app_name, env_name=env_name)

    region = aws.get_region_name()
    if env is not None:
        page = 'environment/dashboard'
    else:
        page = 'application/overview'

    app_name = utils.url_encode(app_name)

    console_url = 'console.aws.amazon.com/elasticbeanstalk/home?'
    console_url += 'region=' + region
    console_url += '#/' + page + '?applicationName=' + app_name

    if env is not None:
        console_url += '&environmentId=' + env.id

    commonops.open_webpage_in_browser(console_url, ssl=True)
예제 #2
0
def open_webpage_in_browser(url, ssl=False):
    io.log_info('Opening webpage with default browser.')
    if not url.startswith('http'):
        if ssl:
            url = 'https://' + url
        else:
            url = 'http://' + url
    LOG.debug('url={}'.format(url))
    if utils.is_ssh() or platform.system().startswith('Win'):
        # Preferred way for ssh or windows
        # Windows can't do a fork so we have to do inline
        LOG.debug('Running webbrowser inline.')
        import webbrowser
        webbrowser.open_new_tab(url)
    else:
        # This is the preferred way to open a web browser on *nix.
        # It squashes all output which can be typical on *nix.
        LOG.debug('Running webbrowser as subprocess.')
        from subprocess import Popen, PIPE

        p = Popen(
            [
                '{python} -m webbrowser \'{url}\''.format(
                    python=sys.executable,
                    url=url)
            ],
            stderr=PIPE,
            stdout=PIPE,
            shell=True
        )
        '''
         We need to fork the process for various reasons
            1. Calling p.communicate waits for the thread. Some browsers
                (if opening a new window) dont return to the thread until
                 the browser closes. We dont want the terminal to hang in
                 this case
            2. If we dont call p.communicate, there is a race condition. If
                the main process terminates before the browser call is made,
                the call never gets made and the browser doesn't open.
            Therefor the solution is to fork, then wait for the child
            in the backround.
         '''
        pid = os.fork()
        if pid == 0:  # Is child
            p.communicate()