def install_cadvisor(): config = hookenv.config() install_opts = ('install_sources', 'install_keys') hookenv.status_set('maintenance', 'Installing cAdvisor') os.environ['DEBIAN_FRONTEND'] = 'noninteractive' if config.get('http_proxy'): proxy = { "http": config.get('http_proxy'), "https": config.get('http_proxy'), } else: proxy = {} if config.get('install_file', False): with tempfile.NamedTemporaryFile(suffix='.deb') as f: r = requests.get(config.get('install_file'), stream=True, proxies=proxy) for block in r.iter_content(1024): f.write(block) f.flush() subprocess.check_call(['dpkg', '-i', f.name]) set_flag('cadvisor.installed') else: if install_opts: for opt in install_opts: fetch.configure_sources(update=True) fetch.apt_update() fetch.apt_install(PKGNAMES) hookenv.status_set('active', 'Completed installing cAdvisor') set_flag('cadvisor.installed')
def config_changed(): ''' This hook is run when a config parameter is changed. It also runs on node reboot. ''' charm_config = config() if (charm_config.changed('install_sources') or charm_config.changed('plumgrid-build') or charm_config.changed('networking-build') or charm_config.changed('install_keys')): status_set('maintenance', 'Upgrading apt packages') if charm_config.changed('install_sources'): configure_pg_sources() configure_sources() apt_update() pkgs = determine_packages() for pkg in pkgs: apt_install(pkg, options=['--force-yes'], fatal=True) service_stop('neutron-server') if (charm_config.changed('networking-plumgrid-version') or charm_config.changed('pip-proxy')): ensure_files() service_stop('neutron-server') CONFIGS.write_all() if not service_running('neutron-server'): service_start('neutron-server')
def configure_sources(): """Add user specified package sources from the service configuration. See charmhelpers.fetch.configure_sources for details. """ config = hookenv.config() # We don't have enums, so we need to validate this ourselves. package_status = config.get('package_status') or '' if package_status not in ('hold', 'install'): charms.apt.status_set( 'blocked', 'Unknown package_status {}' ''.format(package_status)) # Die before further hooks are run. This isn't very nice, but # there is no other way to inform the operator that they have # invalid configuration. raise SystemExit(0) sources = config.get('install_sources') or '' keys = config.get('install_keys') or '' if reactive.helpers.data_changed('apt.configure_sources', (sources, keys)): fetch.configure_sources(update=False, sources_var='install_sources', keys_var='install_keys') reactive.set_state('apt.needs_update') # Clumsy 'config.get() or' per Bug #1641362 extra_packages = sorted((config.get('extra_packages') or '').split()) if extra_packages: charms.apt.queue_install(extra_packages)
def install(): hookenv.log('Installing neo4j') config = hookenv.config() hookenv.open_port(config['port']) fetch.configure_sources(True) fetch.apt_install(fetch.filter_installed_packages(['neo4j'])) set_state('neo4j.installed')
def install(): status_set('maintenance', 'Installing...') configure_sources(True, "install-sources", "install-keys") apt_update(fatal=True) apt_upgrade(fatal=True, dist=False) apt_install(PACKAGES, fatal=True) status_set("blocked", "Missing relation to contrail-controller")
def config_changed(): ''' This hook is run when a config parameter is changed. It also runs on node reboot. ''' charm_config = config() if charm_config.changed('lcm-ssh-key'): if add_lcm_key(): log("PLUMgrid LCM Key added") if charm_config.changed('fabric-interfaces'): if not fabric_interface_changed(): log("Fabric interface already set") if (charm_config.changed('install_sources') or charm_config.changed('plumgrid-build') or charm_config.changed('install_keys') or charm_config.changed('iovisor-build')): stop_pg() status_set('maintenance', 'Upgrading apt packages') if charm_config.changed('install_sources'): configure_pg_sources() configure_sources(update=True) pkgs = determine_packages() for pkg in pkgs: apt_install(pkg, options=['--force-yes'], fatal=True) remove_iovisor() load_iovisor() ensure_mtu() CONFIGS.write_all()
def heat_plugin_joined(rel_id=None): configure_sources(True, "install-sources", "install-keys") apt_upgrade(fatal=True, dist=True) apt_install(["contrail-heat"], fatal=True) try: output = check_output( ["dpkg-query", "-f", "${Version}\\n", "-W", "contrail-heat"]) version = output.decode('UTF-8').rstrip() application_version_set(version) except CalledProcessError: return None plugin_dirs = config.get("heat-plugin-dirs") ctx = get_context() sections = { "clients_contrail": [("user", ctx.get("keystone_admin_user")), ("password", ctx.get("keystone_admin_password")), ("tenant", ctx.get("keystone_admin_tenant")), ("api_server", ctx.get("api_server")), ("auth_host_ip", ctx.get("keystone_ip"))] } conf = {"heat": {"/etc/heat/heat.conf": {"sections": sections}}} settings = { "plugin-dirs": plugin_dirs, "subordinate_configuration": json.dumps(conf) } relation_set(relation_id=rel_id, relation_settings=settings)
def install(): configure_installation_source(config["openstack-origin"]) configure_sources(True, "install-sources", "install-keys") apt_upgrade(fatal=True, dist=True) apt_install(PACKAGES, fatal=True) fix_permissions() fix_nodemgr()
def configure_sources(): """Add user specified package sources from the service configuration. See charmhelpers.fetch.configure_sources for details. """ hookenv.log('Initializing Apt Layer') config = hookenv.config() # We don't have enums, so we need to validate this ourselves. package_status = config.get('package_status') if package_status not in ('hold', 'install'): charms.apt.status_set('blocked', 'Unknown package_status {}' ''.format(package_status)) # Die before further hooks are run. This isn't very nice, but # there is no other way to inform the operator that they have # invalid configuration. raise SystemExit(0) sources = config.get('install_sources') keys = config.get('install_keys') if reactive.helpers.data_changed('apt.configure_sources', (sources, keys)): fetch.configure_sources(update=False, sources_var='install_sources', keys_var='install_keys') reactive.set_state('apt.needs_update') extra_packages = sorted(config.get('extra_packages', '').split()) if extra_packages: queue_install(extra_packages)
def install(): configure_installation_source(config["openstack-origin"]) configure_sources(True, "install-sources", "install-keys") apt_upgrade(fatal=True, dist=True) apt_install(PACKAGES, fatal=True) fix_services() write_nodemgr_config() service_restart("contrail-config-nodemgr")
def config_changed(): if config.changed("install-sources") or config.changed("install-keys"): configure_sources(True, "install-sources", "install-keys") apt_update(fatal=True) apt_upgrade(fatal=True, dist=False) if is_leader(): _configure_metadata_shared_secret()
def test_configure_sources_multiple_sources(self, add_source, config): sources = ["sourcea", "sourceb"] keys = ["keya", None] config.side_effect = [yaml.dump(sources), yaml.dump(keys)] fetch.configure_sources() add_source.assert_has_calls( [call('sourcea', 'keya'), call('sourceb', None)])
def config_changed(): if config.changed("install-sources") or config.changed("install-keys"): configure_sources(True, "install-sources", "install-keys") apt_update(fatal=True) apt_upgrade(fatal=True, dist=False) _notify_neutron() if is_leader(): res = _configure_metadata_shared_secret() if res: _notify_controller()
def install_packages(): packages = ['collectd-core'] config = resolve_config() if config.get('http_endpoint', False) and config['http_endpoint'].startswith('127.0.0.1'): # XXX comes from aluria's PPA, check if there is upstream package available hookenv.log( 'prometheus_export set to localhost, installing exporter locally') packages.append('prometheus-node-exporter') fetch.configure_sources() fetch.apt_update() fetch.apt_install(packages)
def install(): ''' Install hook is run when the charm is first deployed on a node. ''' status_set('maintenance', 'Executing pre-install') configure_sources() status_set('maintenance', 'Installing apt packages') apt_update() pkgs = determine_packages() for pkg in pkgs: apt_install(pkg, options=['--force-yes'], fatal=True) ensure_files()
def install(): configure_sources(True, "install-sources", "install-keys") apt_upgrade(fatal=True, dist=True) fix_vrouter_scripts() # bug in 2.0+20141015.1 packages apt_install(PACKAGES, fatal=True) fix_permissions() fix_nodemgr() if config.get("remove-juju-bridge"): remove_juju_bridge() modprobe("vrouter", True, True) configure_vrouter() service_restart("nova-compute")
def install_fluentd(): # Add apt source for fluentd, using the source/key in config.yaml fetch.configure_sources() fetch.apt_update() # Install ruby, fluentd packages = ['ruby', 'td-agent'] fetch.apt_install(fetch.filter_installed_packages(packages)) # Configure fluentd set_state('fluentd.installed')
def install(): ''' Install hook is run when the charm is first deployed on a node. ''' status_set('maintenance', 'Executing pre-install') configure_sources(config('nuage-extra-source'), config('nuage-extra-key')) status_set('maintenance', 'Installing apt packages') apt_update() pkgs = determine_packages() for pkg in pkgs: apt_install(pkg, options=['--force-yes', '--allow-unauthenticated'], fatal=True)
def install(): status_set("maintenance", "Installing...") configure_crashes() configure_sources(True, "install-sources", "install-keys") apt_upgrade(fatal=True, dist=True) packages = list() packages.extend(PACKAGES) if not config.get("dpdk"): packages.extend(PACKAGES_DKMS_INIT) else: # services must not be started before config files creation if not init_is_systemd(): with open("/etc/init/supervisor-vrouter.override", "w") as conf: conf.write("manual\n") else: # and another way with systemd for srv in ("contrail-vrouter-agent", "contrail-vrouter-dpdk"): try: os.remove("/etc/systemd/system/{}.sevice".format(srv)) except OSError: pass os.symlink("/dev/null", "/etc/systemd/system/{}.sevice".format(srv)) packages.extend(PACKAGES_DPDK_INIT) # apt-get upgrade can install new kernel so we need to re-install # packages with dpdk drivers kver = check_output(["uname", "-r"]).rstrip() packages.append("linux-image-extra-" + kver) apt_install(packages, fatal=True) try: output = check_output([ "dpkg-query", "-f", "${Version}\\n", "-W", "contrail-vrouter-agent" ]) version = output.decode('UTF-8').rstrip() application_version_set(version) except CalledProcessError: return None status_set("maintenance", "Configuring...") os.chmod("/etc/contrail", 0o755) os.chown("/etc/contrail", 0, 0) if config.get("dpdk"): install_dpdk() else: # supervisord must be started after installation if not init_is_systemd(): # supervisord service_restart("supervisor-vrouter") install_dkms()
def install(): hookenv.log('Installing neo4j') config = hookenv.config() hookenv.open_port(config['port']) fetch.configure_sources(True) fetch.apt_install(fetch.filter_installed_packages(['neo4j'])) utils.re_edit_in_place('/etc/neo4j/neo4j-server.properties', { r'#org.neo4j.server.webserver.address=0.0.0.0': 'org.neo4j.server.webserver.address=0.0.0.0', }) # utils.re_edit_in_place('/etc/security/limits.conf', { # r'#org.neo4j.server.webserver.address=127.0.0.1': 'org.neo4j.server.webserver.address=0.0.0.0', # }) service_restart('neo4j-service') set_state('neo4j.installed')
def install(): ''' Install hook is run when the charm is first deployed on a node. ''' status_set('maintenance', 'Executing pre-install') load_iptables() configure_sources(update=True) status_set('maintenance', 'Installing apt packages') pkgs = determine_packages() for pkg in pkgs: apt_install(pkg, options=['--force-yes'], fatal=True) load_iovisor() ensure_mtu() ensure_files() add_lcm_key()
def install(): hookenv.log('Installing neo4j') config = hookenv.config() hookenv.open_port(config['port']) fetch.configure_sources(True) fetch.apt_install(fetch.filter_installed_packages(['neo4j'])) utils.re_edit_in_place( '/etc/neo4j/neo4j-server.properties', { r'#org.neo4j.server.webserver.address=0.0.0.0': 'org.neo4j.server.webserver.address=0.0.0.0', }) # utils.re_edit_in_place('/etc/security/limits.conf', { # r'#org.neo4j.server.webserver.address=127.0.0.1': 'org.neo4j.server.webserver.address=0.0.0.0', # }) service_restart('neo4j-service') set_state('neo4j.installed')
def install_packages(): config = hookenv.config() install_opts = ('install_sources', 'install_keys') if config.changed('install_file') and config.get('install_file', False): hookenv.status_set('maintenance', 'Installing deb pkgs') fetch.apt_install(GRAFANA_DEPS) pkg_file = '/tmp/grafana.deb' with open(pkg_file, 'wb') as f: r = requests.get(config.get('install_file'), stream=True) for block in r.iter_content(1024): f.write(block) subprocess.check_call(['dpkg', '-i', pkg_file]) elif any(config.changed(opt) for opt in install_opts): hookenv.status_set('maintenance', 'Installing deb pkgs') packages = ['grafana'] fetch.configure_sources(update=True) fetch.apt_install(packages) hookenv.status_set('maintenance', 'Waiting for start')
def install(): if config.get("install-sources"): configure_sources(update=True, sources_var="install-sources", keys_var="install-keys") # install packages apt_install(PACKAGES, fatal=True) install_url = config["install-url"] if install_url: # install opendaylight from tarball # this extracts the archive too install_remote(install_url, dest="/opt") # The extracted dirname. Look at what's on disk instead of mangling, so # the distribution tar.gz's name doesn't matter. install_dir_name = [ f for f in os.listdir("/opt") if f.startswith("distribution-karaf")][0] if not os.path.exists("/opt/opendaylight-karaf"): os.symlink(install_dir_name, "/opt/opendaylight-karaf") else: apt_install([KARAF_PACKAGE], fatal=True) install_dir_name = "opendaylight-karaf" if init_is_systemd(): shutil.copy("files/odl-controller.service", "/lib/systemd/system") service('enable', 'odl-controller') else: shutil.copy("files/odl-controller.conf", "/etc/init") adduser("opendaylight", system_user=True) mkdir("/home/opendaylight", owner="opendaylight", group="opendaylight", perms=0755) check_call( ["chown", "-R", "opendaylight:opendaylight", os.path.join("/opt", install_dir_name)]) mkdir("/var/log/opendaylight", owner="opendaylight", group="opendaylight", perms=0755) # install features write_mvn_config() service_start("odl-controller")
def install(): status_set("maintenance", "Installing...") configure_sources(True, "install-sources", "install-keys") apt_upgrade(fatal=True, dist=True) packages = list() packages.extend(PACKAGES) # TODO: support dpdk config option packages.extend(PACKAGES_DKMS_INIT) apt_install(packages, fatal=True) try: output = check_output([ "dpkg-query", "-f", "${Version}\\n", "-W", "contrail-vrouter-agent" ]) version = output.decode('UTF-8').rstrip() application_version_set(version) except CalledProcessError: return None status_set("maintenance", "Configuring...") os.chmod("/etc/contrail", 0o755) os.chown("/etc/contrail", 0, 0) # supervisord must be started after installation release = lsb_release()["DISTRIB_CODENAME"] if release == 'trusty': # supervisord service_restart("supervisor-vrouter") try: log("Loading kernel module vrouter") modprobe("vrouter") except CalledProcessError: log("vrouter kernel module failed to load," " clearing pagecache and retrying") drop_caches() modprobe("vrouter") dkms_autoinstall("vrouter") configure_vrouter_interface() config["vrouter-expected-provision-state"] = False status_set("blocked", "Missing relation to contrail-controller")
def config_changed(): ''' This hook is run when a config parameter is changed. It also runs on node reboot. ''' charm_config = config() if (charm_config.changed('nuage_extra_soruce') or charm_config.changed('nuage_extra_key')): configure_sources(config('nuage-extra-source'), config('nuage-extra-key')) if charm_config.changed('nuage_additional_packages'): status_set('maintenance', 'Upgrading apt packages') apt_update() pkgs = determine_packages() for pkg in pkgs: apt_install(pkg, options=['--force-yes', '--allow-unauthenticated'], fatal=True) service_stop('neutron-server') CONFIGS.write_all() if not service_running('neutron-server'): service_start('neutron-server')
def install_packages(): fetch.configure_sources() fetch.apt_update() fetch.apt_install(PKGNAMES, fatal=True) remove_state('ceph-exporter.do-install')
def test_configure_sources_null_source(self, add_source, config): config.side_effect = [None, None] fetch.configure_sources() self.assertEqual(add_source.call_count, 0)
def test_configure_sources_empty_source(self, add_source, config): config.side_effect = ['', ''] fetch.configure_sources() self.assertEqual(add_source.call_count, 0)
def test_configure_sources_single_source_no_key(self, add_source, config): config.side_effect = ['source', None] fetch.configure_sources() add_source.assert_called_with('source', None)
def install_beats_repo(): configure_sources(update=True) set_state('beats.repo.available')
def config_changed(): if config.changed("install-sources") or config.changed("install-keys"): configure_sources(True, "install-sources", "install-keys") apt_update(fatal=True) apt_upgrade(fatal=True, dist=False)
def configure_sources(): '''Standard charmhelpers package source configuration.''' config = hookenv.config() if config.changed('install_sources') or config.changed('install_keys'): fetch.configure_sources(True)
def install(): configure_sources(True, "install-sources", "install-keys") apt_upgrade(fatal=True, dist=True) apt_install(PACKAGES, fatal=True)
def fetch_and_install(java): configure_sources() apt_update() apt_install('logstash', fatal=True) set_state('logstash.installed') status_set('active', 'logstash installed')