def install_builtin_server(): """Install the builtin server code.""" log("Installing the builtin server dependencies.") deps = os.path.join(CURRENT_DIR, "deps") requirements = os.path.join(CURRENT_DIR, "server-requirements.pip") # Install the builtin server dependencies avoiding to download requirements # from the network. # XXX frankban: this pip installation here implicitly depends on juju-gui # dependencies to be installed. In essence, this function does not fetch # dependencies from the network only incidentally, because setup_gui() has # been already called in the unit. with su("root"): cmd_log( run( "pip2", "install", "--no-index", "--no-dependencies", "--find-links", "file:///{}".format(deps), "-r", requirements, ) ) log("Installing the builtin server.") setup_cmd = os.path.join(SERVER_DIR, "setup.py") with su("root"): cmd_log(run("/usr/bin/python", setup_cmd, "install"))
def install_builtin_server(): """Install the builtin server code.""" log('Installing the builtin server dependencies.') deps = os.path.join(CURRENT_DIR, 'deps') requirements = os.path.join(CURRENT_DIR, 'server-requirements.pip') # Install the builtin server dependencies avoiding to download requirements # from the network. with su('root'): cmd_log( run('pip', 'install', '--no-index', '--no-dependencies', '--find-links', 'file:///{}'.format(deps), '-r', requirements)) log('Installing the builtin server.') setup_cmd = os.path.join(SERVER_DIR, 'setup.py') with su('root'): cmd_log(run('/usr/bin/python', setup_cmd, 'install'))
def stop_improv(): """Stop a simulated Juju environment.""" log('Stopping the staging backend.') with su('root'): service_control(IMPROV, STOP) log('Removing the staging Upstart script.') cmd_log(run('rm', '-f', IMPROV_INIT_PATH))
def stop_agent(): """Stop the Juju agent.""" log('Stopping the API agent.') with su('root'): service_control(AGENT, STOP) log('Removing the API agent Upstart script.') cmd_log(run('rm', '-f', AGENT_INIT_PATH))
def install_builtin_server(): """Install the builtin server code.""" log('Installing the builtin server dependencies.') deps = os.path.join(CURRENT_DIR, 'deps') requirements = os.path.join(CURRENT_DIR, 'server-requirements.pip') # Install the builtin server dependencies avoiding to download requirements # from the network. with su('root'): cmd_log(run( 'pip', 'install', '--no-index', '--no-dependencies', '--find-links', 'file:///{}'.format(deps), '-r', requirements )) log('Installing the builtin server.') setup_cmd = os.path.join(SERVER_DIR, 'setup.py') with su('root'): cmd_log(run('/usr/bin/python', setup_cmd, 'install'))
def stop_haproxy_apache(): """Stop the haproxy and Apache services.""" log('Stopping the haproxy and Apache services.') with su('root'): service_control(HAPROXY, STOP) service_control(APACHE, STOP) remove_haproxy_setup() remove_apache_setup()
def install_builtin_server(): """Install the builtin server code.""" log('Installing the builtin server dependencies.') deps = os.path.join(CURRENT_DIR, 'deps') requirements = os.path.join(CURRENT_DIR, 'server-requirements.pip') # Install the builtin server dependencies avoiding to download requirements # from the network. # XXX frankban: this pip installation here implicitly depends on juju-gui # dependencies to be installed. In essence, this function does not fetch # dependencies from the network only incidentally, because setup_gui() has # been already called in the unit. with su('root'): cmd_log(run( 'pip2', 'install', '--no-index', '--no-dependencies', '--find-links', 'file:///{}'.format(deps), '-r', requirements)) log('Installing the builtin server.') setup_cmd = os.path.join(SERVER_DIR, 'setup.py') with su('root'): cmd_log(run('/usr/bin/python', setup_cmd, 'install'))
def setup_gui(): """Set up Juju GUI.""" # Install ensuring network access is not used. All dependencies should # already be installed from the deps directory. jujugui_deps = os.path.join(CURRENT_DIR, "jujugui-deps") release_tarball_path = get_release_file_path() log("Installing Juju GUI from {}.".format(release_tarball_path)) cmd = ("pip2", "install", "--no-index", "--find-links", "file:///{}".format(jujugui_deps), release_tarball_path) with su("root"): cmd_log(run(*cmd))
def start_haproxy_apache( build_dir, serve_tests, ssl_cert_path, secure): """Set up and start the haproxy and Apache services.""" log('Setting up Apache and haproxy.') setup_apache_config(build_dir, serve_tests) setup_haproxy_config(ssl_cert_path, secure) log('Starting the haproxy and Apache services.') with su('root'): service_control(APACHE, RESTART) service_control(HAPROXY, RESTART)
def install_builtin_server(): """Install the builtin server code.""" log('Installing the builtin server dependencies.') deps = os.path.join(CURRENT_DIR, 'deps') requirements = os.path.join(CURRENT_DIR, 'server-requirements.pip') # Install the builtin server dependencies avoiding to download requirements # from the network. # XXX frankban: this pip installation here implicitly depends on juju-gui # dependencies to be installed. In essence, this function does not fetch # dependencies from the network only incidentally, because setup_gui() has # been already called in the unit. with su('root'): cmd_log( run('pip2', 'install', '--no-index', '--no-dependencies', '--find-links', 'file:///{}'.format(deps), '-r', requirements)) log('Installing the builtin server.') setup_cmd = os.path.join(SERVER_DIR, 'setup.py') with su('root'): cmd_log(run('/usr/bin/python', setup_cmd, 'install'))
def setup_gui(): """Set up Juju GUI.""" # Install ensuring network access is not used. All dependencies should # already be installed from the deps directory. jujugui_deps = os.path.join(CURRENT_DIR, 'jujugui-deps') release_tarball_path = get_release_file_path() log('Installing Juju GUI from {}.'.format(release_tarball_path)) cmd = ('pip2', 'install', '--no-index', '--find-links', 'file:///{}'.format(jujugui_deps), release_tarball_path) with su('root'): cmd_log(run(*cmd))
def remove_apache_setup(): """Remove Apache setup.""" if os.path.exists(APACHE_SITE): log('Removing Apache setup.') cmd_log(run('rm', '-f', APACHE_SITE)) with su('root'): run('a2dismod', 'headers') run('a2dissite', 'juju-gui') run('a2ensite', 'default') if os.path.exists(APACHE_PORTS): cmd_log(run('rm', '-f', APACHE_PORTS))
def start_builtin_server( build_dir, ssl_cert_path, serve_tests, sandbox, builtin_server_logging, insecure, charmworld_url): """Start the builtin server.""" write_builtin_server_startup( build_dir, ssl_cert_path, serve_tests=serve_tests, sandbox=sandbox, builtin_server_logging=builtin_server_logging, insecure=insecure, charmworld_url=charmworld_url) log('Starting the builtin server.') with su('root'): service_control(BUILTIN_SERVER, RESTART)
def setup_gui(): """Set up Juju GUI.""" # Install ensuring network access is not used. All dependencies should # already be installed from the deps directory. jujugui_deps = os.path.join(CURRENT_DIR, 'jujugui-deps') release_tarball_path = get_release_file_path() log('Installing Juju GUI from {}.'.format(release_tarball_path)) cmd = ( 'pip2', 'install', '--no-index', '--find-links', 'file:///{}'.format(jujugui_deps), release_tarball_path) with su('root'): cmd_log(run(*cmd))
def compute_build_dir(juju_gui_debug, serve_tests): """Compute the build directory.""" with su('root'): run('chown', '-R', 'ubuntu:', JUJU_GUI_DIR) # XXX 2013-02-05 frankban bug=1116320: # External insecure resources are still loaded when testing in the # debug environment. For now, switch to the production environment if # the charm is configured to serve tests. if juju_gui_debug and not serve_tests: build_dirname = 'build-debug' else: build_dirname = 'build-prod' return os.path.join(JUJU_GUI_DIR, build_dirname)
def start_improv(staging_env, ssl_cert_path): """Start a simulated juju environment using ``improv.py``.""" log('Setting up the staging Upstart script.') context = { 'juju_dir': JUJU_AGENT_DIR, 'keys': ssl_cert_path, 'port': API_PORT, 'staging_env': staging_env, } render_to_file('juju-api-improv.conf.template', context, IMPROV_INIT_PATH) log('Starting the staging backend.') with su('root'): service_control(IMPROV, START)
def start_improv(staging_env, ssl_cert_path, config_path='/etc/init/juju-api-improv.conf'): """Start a simulated juju environment using ``improv.py``.""" log('Setting up staging start up script.') context = { 'juju_dir': JUJU_DIR, 'keys': ssl_cert_path, 'port': API_PORT, 'staging_env': staging_env, } render_to_file('config/juju-api-improv.conf.template', context, config_path) log('Starting the staging backend.') with su('root'): service_start(IMPROV)
def setup_apache(): """Set up apache.""" log('Setting up apache.') if not os.path.exists(JUJU_GUI_SITE): cmd_log(run('touch', JUJU_GUI_SITE)) cmd_log(run('chown', 'ubuntu:', JUJU_GUI_SITE)) cmd_log( run('ln', '-s', JUJU_GUI_SITE, '/etc/apache2/sites-enabled/juju-gui')) if not os.path.exists(JUJU_GUI_PORTS): cmd_log(run('touch', JUJU_GUI_PORTS)) cmd_log(run('chown', 'ubuntu:', JUJU_GUI_PORTS)) with su('root'): run('a2dissite', 'default') run('a2ensite', 'juju-gui')
def setup_apache_config(build_dir, serve_tests=False): """Set up the Apache configuration.""" log('Generating the Apache site configuration files.') tests_root = os.path.join(JUJU_GUI_DIR, 'test', '') if serve_tests else '' context = { 'port': WEB_PORT, 'server_root': build_dir, 'tests_root': tests_root, } render_to_file('apache-ports.template', context, APACHE_PORTS) cmd_log(run('chown', 'ubuntu:', APACHE_PORTS)) render_to_file('apache-site.template', context, APACHE_SITE) cmd_log(run('chown', 'ubuntu:', APACHE_SITE)) with su('root'): run('a2dissite', 'default') run('a2ensite', 'juju-gui') run('a2enmod', 'headers')
def start_builtin_server( ssl_cert_path, serve_tests, sandbox, builtin_server_logging, insecure, charmworld_url, env_password=None, env_uuid=None, juju_version=None, debug=False, port=None, bundleservice_url=None, interactive_login=False, gzip=True, gtm_enabled=False, gisf_enabled=False, charmstore_url=None, ): """Start the builtin server.""" if (port is not None) and not port_in_range(port): # Do not use the user provided port if it is not valid. port = None write_builtin_server_startup( ssl_cert_path, serve_tests=serve_tests, sandbox=sandbox, builtin_server_logging=builtin_server_logging, insecure=insecure, charmworld_url=charmworld_url, env_password=env_password, env_uuid=env_uuid, juju_version=juju_version, debug=debug, port=port, bundleservice_url=bundleservice_url, interactive_login=interactive_login, gzip=gzip, gtm_enabled=gtm_enabled, gisf_enabled=gisf_enabled, charmstore_url=charmstore_url, ) log("Starting the builtin server.") with su("root"): service(RESTART, GUISERVER)
def start_builtin_server( ssl_cert_path, serve_tests, sandbox, builtin_server_logging, insecure, charmworld_url, env_password=None, env_uuid=None, juju_version=None, debug=False, port=None, jem_location=None, interactive_login=False): """Start the builtin server.""" if (port is not None) and not port_in_range(port): # Do not use the user provided port if it is not valid. port = None write_builtin_server_startup( ssl_cert_path, serve_tests=serve_tests, sandbox=sandbox, builtin_server_logging=builtin_server_logging, insecure=insecure, charmworld_url=charmworld_url, env_password=env_password, env_uuid=env_uuid, juju_version=juju_version, debug=debug, port=port, jem_location=jem_location, interactive_login=interactive_login) log('Starting the builtin server.') with su('root'): service_control(GUISERVER, RESTART)
def start_agent(ssl_cert_path, read_only=False): """Start the Juju agent and connect to the current environment.""" # Retrieve the Zookeeper address from the start up script. unit_name = os.path.basename( os.path.realpath(os.path.join(CURRENT_DIR, '..'))) agent_file = os.path.join(SYS_INIT_DIR, 'juju-{}.conf'.format(unit_name)) zookeeper = get_zookeeper_address(agent_file) log('Setting up the API agent Upstart script.') context = { 'juju_dir': JUJU_AGENT_DIR, 'keys': ssl_cert_path, 'port': API_PORT, 'zookeeper': zookeeper, 'read_only': read_only } render_to_file('juju-api-agent.conf.template', context, AGENT_INIT_PATH) log('Starting the API agent.') with su('root'): service_control(AGENT, START)
def start_agent(ssl_cert_path, config_path='/etc/init/juju-api-agent.conf', read_only=False): """Start the Juju agent and connect to the current environment.""" # Retrieve the Zookeeper address from the start up script. unit_dir = os.path.realpath(os.path.join(CURRENT_DIR, '..')) agent_file = '/etc/init/juju-{0}.conf'.format(os.path.basename(unit_dir)) zookeeper = get_zookeeper_address(agent_file) log('Setting up API agent start up script.') context = { 'juju_dir': JUJU_DIR, 'keys': ssl_cert_path, 'port': API_PORT, 'zookeeper': zookeeper, 'read_only': read_only } render_to_file('config/juju-api-agent.conf.template', context, config_path) log('Starting API agent.') with su('root'): service_start(AGENT)
def start_agent( ssl_cert_path, config_path='/etc/init/juju-api-agent.conf', read_only=False): """Start the Juju agent and connect to the current environment.""" # Retrieve the Zookeeper address from the start up script. unit_dir = os.path.realpath(os.path.join(CURRENT_DIR, '..')) agent_file = '/etc/init/juju-{0}.conf'.format(os.path.basename(unit_dir)) zookeeper = get_zookeeper_address(agent_file) log('Setting up API agent start up script.') context = { 'juju_dir': JUJU_DIR, 'keys': ssl_cert_path, 'port': API_PORT, 'zookeeper': zookeeper, 'read_only': read_only } render_to_file('config/juju-api-agent.conf.template', context, config_path) log('Starting API agent.') with su('root'): service_start(AGENT)
def start_builtin_server(ssl_cert_path, serve_tests, sandbox, builtin_server_logging, insecure, charmworld_url, env_password=None, env_uuid=None, juju_version=None, debug=False, port=None, bundleservice_url=None, interactive_login=False, gzip=True, gtm_enabled=False, gisf_enabled=False, charmstore_url=None): """Start the builtin server.""" if (port is not None) and not port_in_range(port): # Do not use the user provided port if it is not valid. port = None write_builtin_server_startup(ssl_cert_path, serve_tests=serve_tests, sandbox=sandbox, builtin_server_logging=builtin_server_logging, insecure=insecure, charmworld_url=charmworld_url, env_password=env_password, env_uuid=env_uuid, juju_version=juju_version, debug=debug, port=port, bundleservice_url=bundleservice_url, interactive_login=interactive_login, gzip=gzip, gtm_enabled=gtm_enabled, gisf_enabled=gisf_enabled, charmstore_url=charmstore_url) log('Starting the builtin server.') with su('root'): service(RESTART, GUISERVER)
def start_builtin_server(build_dir, ssl_cert_path, serve_tests, sandbox, builtin_server_logging, insecure, charmworld_url, port=None): """Start the builtin server.""" if (port is not None) and not port_in_range(port): # Do not use the user provided port if it is not valid. port = None write_builtin_server_startup(build_dir, ssl_cert_path, serve_tests=serve_tests, sandbox=sandbox, builtin_server_logging=builtin_server_logging, insecure=insecure, charmworld_url=charmworld_url, port=port) log('Starting the builtin server.') with su('root'): service_control(GUISERVER, RESTART)
def stop_builtin_server(): """Stop the builtin server.""" log("Stopping the builtin server.") with su("root"): service(STOP, GUISERVER) cmd_log(run("rm", "-f", GUISERVER_INIT_PATH))
def stop_builtin_server(): """Stop the builtin server.""" log('Stopping the builtin server.') with su('root'): service(STOP, GUISERVER) cmd_log(run('rm', '-f', GUISERVER_INIT_PATH))
def start_gui( console_enabled, login_help, readonly, in_staging, ssl_cert_path, charmworld_url, serve_tests, haproxy_path='/etc/haproxy/haproxy.cfg', config_js_path=None, secure=True, sandbox=False): """Set up and start the Juju GUI server.""" with su('root'): run('chown', '-R', 'ubuntu:', JUJU_GUI_DIR) # XXX 2013-02-05 frankban bug=1116320: # External insecure resources are still loaded when testing in the # debug environment. For now, switch to the production environment if # the charm is configured to serve tests. if in_staging and not serve_tests: build_dirname = 'build-debug' else: build_dirname = 'build-prod' build_dir = os.path.join(JUJU_GUI_DIR, build_dirname) log('Generating the Juju GUI configuration file.') is_legacy_juju = legacy_juju() user, password = None, None if (is_legacy_juju and in_staging) or sandbox: user, password = '******', 'admin' else: user, password = None, None api_backend = 'python' if is_legacy_juju else 'go' if secure: protocol = 'wss' else: log('Running in insecure mode! Port 80 will serve unencrypted.') protocol = 'ws' context = { 'raw_protocol': protocol, 'address': unit_get('public-address'), 'console_enabled': json.dumps(console_enabled), 'login_help': json.dumps(login_help), 'password': json.dumps(password), 'api_backend': json.dumps(api_backend), 'readonly': json.dumps(readonly), 'user': json.dumps(user), 'protocol': json.dumps(protocol), 'sandbox': json.dumps(sandbox), 'charmworld_url': json.dumps(charmworld_url), } if config_js_path is None: config_js_path = os.path.join( build_dir, 'juju-ui', 'assets', 'config.js') render_to_file('config/config.js.template', context, config_js_path) write_apache_config(build_dir, serve_tests) log('Generating haproxy configuration file.') if is_legacy_juju: # The PyJuju API agent is listening on localhost. api_address = '127.0.0.1:{0}'.format(API_PORT) else: # Retrieve the juju-core API server address. api_address = get_api_address(os.path.join(CURRENT_DIR, '..')) context = { 'api_address': api_address, 'api_pem': JUJU_PEM, 'legacy_juju': is_legacy_juju, 'ssl_cert_path': ssl_cert_path, # In PyJuju environments, use the same certificate for both HTTPS and # WebSocket connections. In juju-core the system already has the proper # certificate installed. 'web_pem': JUJU_PEM, 'web_port': WEB_PORT, 'secure': secure } render_to_file('config/haproxy.cfg.template', context, haproxy_path) log('Starting Juju GUI.')
def stop_builtin_server(): """Stop the builtin server.""" log('Stopping the builtin server.') with su('root'): service_control(BUILTIN_SERVER, STOP) cmd_log(run('rm', '-f', GUISERVER_INIT_PATH))
def start_gui(console_enabled, login_help, readonly, in_staging, ssl_cert_path, charmworld_url, serve_tests, haproxy_path='/etc/haproxy/haproxy.cfg', config_js_path=None, secure=True, sandbox=False): """Set up and start the Juju GUI server.""" with su('root'): run('chown', '-R', 'ubuntu:', JUJU_GUI_DIR) # XXX 2013-02-05 frankban bug=1116320: # External insecure resources are still loaded when testing in the # debug environment. For now, switch to the production environment if # the charm is configured to serve tests. if in_staging and not serve_tests: build_dirname = 'build-debug' else: build_dirname = 'build-prod' build_dir = os.path.join(JUJU_GUI_DIR, build_dirname) log('Generating the Juju GUI configuration file.') is_legacy_juju = legacy_juju() user, password = None, None if (is_legacy_juju and in_staging) or sandbox: user, password = '******', 'admin' else: user, password = None, None api_backend = 'python' if is_legacy_juju else 'go' if secure: protocol = 'wss' else: log('Running in insecure mode! Port 80 will serve unencrypted.') protocol = 'ws' context = { 'raw_protocol': protocol, 'address': unit_get('public-address'), 'console_enabled': json.dumps(console_enabled), 'login_help': json.dumps(login_help), 'password': json.dumps(password), 'api_backend': json.dumps(api_backend), 'readonly': json.dumps(readonly), 'user': json.dumps(user), 'protocol': json.dumps(protocol), 'sandbox': json.dumps(sandbox), 'charmworld_url': json.dumps(charmworld_url), } if config_js_path is None: config_js_path = os.path.join(build_dir, 'juju-ui', 'assets', 'config.js') render_to_file('config/config.js.template', context, config_js_path) write_apache_config(build_dir, serve_tests) log('Generating haproxy configuration file.') if is_legacy_juju: # The PyJuju API agent is listening on localhost. api_address = '127.0.0.1:{0}'.format(API_PORT) else: # Retrieve the juju-core API server address. api_address = get_api_address(os.path.join(CURRENT_DIR, '..')) context = { 'api_address': api_address, 'api_pem': JUJU_PEM, 'legacy_juju': is_legacy_juju, 'ssl_cert_path': ssl_cert_path, # In PyJuju environments, use the same certificate for both HTTPS and # WebSocket connections. In juju-core the system already has the proper # certificate installed. 'web_pem': JUJU_PEM, 'web_port': WEB_PORT, 'secure': secure } render_to_file('config/haproxy.cfg.template', context, haproxy_path) log('Starting Juju GUI.')