Code
stringlengths
103
85.9k
Summary
listlengths
0
94
Please provide a description of the function:def determine_apache_port(public_port, singlenode_mode=False): ''' Description: Determine correct apache listening port based on public IP + state of the cluster. public_port: int: standard public port for given service singlenode_mode: boolean: Shuffle...
[]
Please provide a description of the function:def get_hacluster_config(exclude_keys=None): ''' Obtains all relevant configuration from charm configuration required for initiating a relation to hacluster: ha-bindiface, ha-mcastport, vip, os-internal-hostname, os-admin-hostname, os-public-host...
[]
Please provide a description of the function:def valid_hacluster_config(): ''' Check that either vip or dns-ha is set. If dns-ha then one of os-*-hostname must be set. Note: ha-bindiface and ha-macastport both have defaults and will always be set. We only care that either vip or dns-ha is set. ...
[]
Please provide a description of the function:def canonical_url(configs, vip_setting='vip'): ''' Returns the correct HTTP URL to this host given the state of HTTPS configuration and hacluster. :configs : OSTemplateRenderer: A config tempating object to inspect for ...
[]
Please provide a description of the function:def distributed_wait(modulo=None, wait=None, operation_name='operation'): ''' Distribute operations by waiting based on modulo_distribution If modulo and or wait are not set, check config_get for those values. If config values are not set, default to modulo=3 an...
[]
Please provide a description of the function:def filter_installed_packages(packages): yb = yum.YumBase() package_list = yb.doPackageLists() temp_cache = {p.base_package_name: 1 for p in package_list['installed']} _pkgs = [p for p in packages if not temp_cache.get(p, False)] return _pkgs
[ "Return a list of packages that require installation." ]
Please provide a description of the function:def install(packages, options=None, fatal=False): cmd = ['yum', '--assumeyes'] if options is not None: cmd.extend(options) cmd.append('install') if isinstance(packages, six.string_types): cmd.append(packages) else: cmd.extend(...
[ "Install one or more packages." ]
Please provide a description of the function:def upgrade(options=None, fatal=False, dist=False): cmd = ['yum', '--assumeyes'] if options is not None: cmd.extend(options) cmd.append('upgrade') log("Upgrading with options: {}".format(options)) _run_yum_command(cmd, fatal)
[ "Upgrade all packages." ]
Please provide a description of the function:def update(fatal=False): cmd = ['yum', '--assumeyes', 'update'] log("Update with fatal: {}".format(fatal)) _run_yum_command(cmd, fatal)
[ "Update local yum cache." ]
Please provide a description of the function:def purge(packages, fatal=False): cmd = ['yum', '--assumeyes', 'remove'] if isinstance(packages, six.string_types): cmd.append(packages) else: cmd.extend(packages) log("Purging {}".format(packages)) _run_yum_command(cmd, fatal)
[ "Purge one or more packages." ]
Please provide a description of the function:def yum_search(packages): output = {} cmd = ['yum', 'search'] if isinstance(packages, six.string_types): cmd.append(packages) else: cmd.extend(packages) log("Searching for {}".format(packages)) result = subprocess.check_output(cmd...
[ "Search for a package." ]
Please provide a description of the function:def add_source(source, key=None): if source is None: log('Source is not present. Skipping') return if source.startswith('http'): directory = '/etc/yum.repos.d/' for filename in os.listdir(directory): with open(directo...
[ "Add a package source to this system.\n\n @param source: a URL with a rpm package\n\n @param key: A key to be added to the system's keyring and used\n to verify the signatures on packages. Ideally, this should be an\n ASCII format GPG public key including the block headers. A GPG key\n id may also be...
Please provide a description of the function:def _run_yum_command(cmd, fatal=False): env = os.environ.copy() if fatal: retry_count = 0 result = None # If the command is considered "fatal", we need to retry if the yum # lock was not acquired. while result is None o...
[ "Run an YUM command.\n\n Checks the output and retry if the fatal flag is set to True.\n\n :param: cmd: str: The yum command to run.\n :param: fatal: bool: Whether the command's output should be checked and\n retried.\n " ]
Please provide a description of the function:def describe_arguments(func): argspec = inspect.getargspec(func) # we should probably raise an exception somewhere if func includes **kwargs if argspec.defaults: positional_args = argspec.args[:-len(argspec.defaults)] keyword_names = argspec...
[ "\n Analyze a function's signature and return a data structure suitable for\n passing in as arguments to an argparse parser's add_argument() method." ]
Please provide a description of the function:def raw(self, output): if isinstance(output, (list, tuple)): output = '\n'.join(map(str, output)) self.outfile.write(str(output))
[ "Output data as raw string (default)" ]
Please provide a description of the function:def py(self, output): import pprint pprint.pprint(output, stream=self.outfile)
[ "Output data as a nicely-formatted python data structure" ]
Please provide a description of the function:def csv(self, output): import csv csvwriter = csv.writer(self.outfile) csvwriter.writerows(output)
[ "Output data as excel-compatible CSV" ]
Please provide a description of the function:def tab(self, output): import csv csvwriter = csv.writer(self.outfile, dialect=csv.excel_tab) csvwriter.writerows(output)
[ "Output data in excel-compatible tab-delimited format" ]
Please provide a description of the function:def subcommand(self, command_name=None): def wrapper(decorated): cmd_name = command_name or decorated.__name__ subparser = self.subparsers.add_parser(cmd_name, description=decorated._...
[ "\n Decorate a function as a subcommand. Use its arguments as the\n command-line arguments" ]
Please provide a description of the function:def subcommand_builder(self, command_name, description=None): def wrapper(decorated): subparser = self.subparsers.add_parser(command_name) func = decorated(subparser) subparser.set_defaults(func=func) subparser...
[ "\n Decorate a function that builds a subcommand. Builders should accept a\n single argument (the subparser instance) and return the function to be\n run as the command." ]
Please provide a description of the function:def run(self): "Run cli, processing arguments and executing subcommands." arguments = self.argument_parser.parse_args() argspec = inspect.getargspec(arguments.func) vargs = [] for arg in argspec.args: vargs.append(getattr(a...
[]
Please provide a description of the function:def collect_authed_hosts(peer_interface): '''Iterate through the units on peer interface to find all that have the calling host in its authorized hosts list''' hosts = [] for r_id in (relation_ids(peer_interface) or []): for unit in related_units(r_id...
[]
Please provide a description of the function:def sync_path_to_host(path, host, user, verbose=False, cmd=None, gid=None, fatal=False): cmd = cmd or copy(BASE_CMD) if not verbose: cmd.append('-silent') # removing trailing slash from directory paths, unison # doesn't lik...
[ "Sync path to an specific peer host\n\n Propagates exception if operation fails and fatal=True.\n " ]
Please provide a description of the function:def sync_to_peer(host, user, paths=None, verbose=False, cmd=None, gid=None, fatal=False): if paths: for p in paths: sync_path_to_host(p, host, user, verbose, cmd, gid, fatal)
[ "Sync paths to an specific peer host\n\n Propagates exception if any operation fails and fatal=True.\n " ]
Please provide a description of the function:def sync_to_peers(peer_interface, user, paths=None, verbose=False, cmd=None, gid=None, fatal=False): if paths: for host in collect_authed_hosts(peer_interface): sync_to_peer(host, user, paths, verbose, cmd, gid, fatal)
[ "Sync all hosts to an specific path\n\n The type of group is integer, it allows user has permissions to\n operate a directory have a different group id with the user id.\n\n Propagates exception if any operation fails and fatal=True.\n " ]
Please provide a description of the function:def pip_execute(*args, **kwargs): try: _path = sys.path try: from pip import main as _pip_execute except ImportError: apt_update() if six.PY2: apt_install('python-pip') else: ...
[ "Overriden pip_execute() to stop sys.path being changed.\n\n The act of importing main from the pip module seems to cause add wheels\n from the /usr/share/python-wheels which are installed by various tools.\n This function ensures that sys.path remains the same after the call is\n executed.\n " ]
Please provide a description of the function:def parse_options(given, available): for key, value in sorted(given.items()): if not value: continue if key in available: yield "--{0}={1}".format(key, value)
[ "Given a set of options, check if available" ]
Please provide a description of the function:def pip_install_requirements(requirements, constraints=None, **options): command = ["install"] available_options = ('proxy', 'src', 'log', ) for option in parse_options(options, available_options): command.append(option) command.append("-r {0}"...
[ "Install a requirements file.\n\n :param constraints: Path to pip constraints file.\n http://pip.readthedocs.org/en/stable/user_guide/#constraints-files\n " ]
Please provide a description of the function:def pip_install(package, fatal=False, upgrade=False, venv=None, constraints=None, **options): if venv: venv_python = os.path.join(venv, 'bin/pip') command = [venv_python, "install"] else: command = ["install"] availab...
[ "Install a python package" ]
Please provide a description of the function:def pip_uninstall(package, **options): command = ["uninstall", "-q", "-y"] available_options = ('proxy', 'log', ) for option in parse_options(options, available_options): command.append(option) if isinstance(package, list): command.exte...
[ "Uninstall a python package" ]
Please provide a description of the function:def pip_create_virtualenv(path=None): if six.PY2: apt_install('python-virtualenv') else: apt_install('python3-virtualenv') if path: venv_path = path else: venv_path = os.path.join(charm_dir(), 'venv') if not os.path....
[ "Create an isolated Python environment." ]
Please provide a description of the function:def configure_sources(update=False, sources_var='install_sources', keys_var='install_keys'): sources = safe_load((config(sources_var) or '').strip()) or [] keys = safe_load((config(keys_var) or '').strip()) or None ...
[ "Configure multiple sources from charm configuration.\n\n The lists are encoded as yaml fragments in the configuration.\n The fragment needs to be included as a string. Sources and their\n corresponding keys are of the types supported by add_source().\n\n Example config:\n install_sources: |\n ...
Please provide a description of the function:def install_remote(source, *args, **kwargs): # We ONLY check for True here because can_handle may return a string # explaining why it can't handle a given source. handlers = [h for h in plugins() if h.can_handle(source) is True] for handler in handlers: ...
[ "Install a file tree from a remote source.\n\n The specified source should be a url of the form:\n scheme://[host]/path[#[option=value][&...]]\n\n Schemes supported are based on this modules submodules.\n Options supported are submodule-specific.\n Additional arguments are passed through to the s...
Please provide a description of the function:def base_url(self, url): parts = list(self.parse_url(url)) parts[4:] = ['' for i in parts[4:]] return urlunparse(parts)
[ "Return url without querystring or fragment" ]
Please provide a description of the function:def is_mapped_luks_device(dev): _, dirs, _ = next(os.walk( '/sys/class/block/{}/holders/' .format(os.path.basename(os.path.realpath(dev)))) ) is_held = len(dirs) > 0 return is_held and is_luks_device(dev)
[ "\n Determine if dev is a mapped LUKS device\n :param: dev: A full path to a block device to be checked\n :returns: boolean: indicates whether a device is mapped\n " ]
Please provide a description of the function:def is_block_device(path): ''' Confirm device at path is a valid block device node. :returns: boolean: True if path is a block device, False if not. ''' if not os.path.exists(path): return False return S_ISBLK(os.stat(path).st_mode)
[]
Please provide a description of the function:def zap_disk(block_device): ''' Clear a block device of partition table. Relies on sgdisk, which is installed as pat of the 'gdisk' package in Ubuntu. :param block_device: str: Full path of block device to clean. ''' # https://github.com/ceph/ceph/co...
[]
Please provide a description of the function:def is_device_mounted(device): '''Given a device path, return True if that device is mounted, and False if it isn't. :param device: str: Full path of the device to check. :returns: boolean: True if the path represents a mounted device, False if it do...
[]
Please provide a description of the function:def mkfs_xfs(device, force=False): cmd = ['mkfs.xfs'] if force: cmd.append("-f") cmd += ['-i', 'size=1024', device] check_call(cmd)
[ "Format device with XFS filesystem.\n\n By default this should fail if the device already has a filesystem on it.\n :param device: Full path to device to format\n :ptype device: tr\n :param force: Force operation\n :ptype: force: boolean" ]
Please provide a description of the function:def wait_for_machine(num_machines=1, timeout=300): # You may think this is a hack, and you'd be right. The easiest way # to tell what environment we're working in (LXC vs EC2) is to check # the dns-name of the first machine. If it's localhost we're in LXC ...
[ "Wait `timeout` seconds for `num_machines` machines to come up.\n\n This wait_for... function can be called by other wait_for functions\n whose timeouts might be too short in situations where only a bare\n Juju setup has been bootstrapped.\n\n :return: A tuple of (num_machines, time_taken). This is used...
Please provide a description of the function:def wait_for_unit(service_name, timeout=480): wait_for_machine(num_machines=1) start_time = time.time() while True: state = unit_info(service_name, 'agent-state') if 'error' in state or state == 'started': break if time.ti...
[ "Wait `timeout` seconds for a given service name to come up." ]
Please provide a description of the function:def wait_for_relation(service_name, relation_name, timeout=120): start_time = time.time() while True: relation = unit_info(service_name, 'relations').get(relation_name) if relation is not None and relation['state'] == 'up': break ...
[ "Wait `timeout` seconds for a given relation to come up." ]
Please provide a description of the function:def ensure_init(path): ''' ensure directories leading up to path are importable, omitting parent directory, eg path='/hooks/helpers/foo'/: hooks/ hooks/helpers/__init__.py hooks/helpers/foo/__init__.py ''' for d, dirs, files in os....
[]
Please provide a description of the function:def service_available(service_name): try: subprocess.check_output( ['service', service_name, 'status'], stderr=subprocess.STDOUT).decode('UTF-8') except subprocess.CalledProcessError as e: return b'unrecognized service' no...
[ "Determine whether a system service is available" ]
Please provide a description of the function:def lsb_release(): d = {} with open('/etc/lsb-release', 'r') as lsb: for l in lsb: k, v = l.split('=') d[k.strip()] = v.strip() return d
[ "Return /etc/lsb-release in a dict" ]
Please provide a description of the function:def cmp_pkgrevno(package, revno, pkgcache=None): import apt_pkg if not pkgcache: from charmhelpers.fetch import apt_cache pkgcache = apt_cache() pkg = pkgcache[package] return apt_pkg.version_compare(pkg.current_ver.ver_str, revno)
[ "Compare supplied revno with the revno of the installed package.\n\n * 1 => Installed revno is greater than supplied arg\n * 0 => Installed revno is the same as supplied arg\n * -1 => Installed revno is less than supplied arg\n\n This function imports apt_cache function from charmhelpers.fetch if\n ...
Please provide a description of the function:def install_salt_support(from_ppa=True): if from_ppa: subprocess.check_call([ '/usr/bin/add-apt-repository', '--yes', 'ppa:saltstack/salt', ]) subprocess.check_call(['/usr/bin/apt-get', 'update']) # We ...
[ "Installs the salt-minion helper for machine state.\n\n By default the salt-minion package is installed from\n the saltstack PPA. If from_ppa is False you must ensure\n that the salt-minion package is available in the apt cache.\n " ]
Please provide a description of the function:def update_machine_state(state_path): charmhelpers.contrib.templating.contexts.juju_state_to_yaml( salt_grains_path) subprocess.check_call([ 'salt-call', '--local', 'state.template', state_path, ])
[ "Update the machine state using the provided state declaration." ]
Please provide a description of the function:def validator(value, valid_type, valid_range=None): assert isinstance(value, valid_type), "{} is not a {}".format( value, valid_type) if valid_range is not None: assert isinstance(valid_range, list), \ "valid_range must be a l...
[ "\n Used to validate these: http://docs.ceph.com/docs/master/rados/operations/pools/#set-pool-values\n Example input:\n validator(value=1,\n valid_type=int,\n valid_range=[0, 2])\n This says I'm testing value=1. It must be an int inclusive in [0,2]\n\n :param va...
Please provide a description of the function:def get_mon_map(service): try: mon_status = check_output(['ceph', '--id', service, 'mon_status', '--format=json']) if six.PY3: mon_status = mon_status.decode('UTF-8') try: return json...
[ "\n Returns the current monitor map.\n :param service: six.string_types. The Ceph user name to run the command under\n :return: json string. :raise: ValueError if the monmap fails to parse.\n Also raises CalledProcessError if our ceph command fails\n " ]
Please provide a description of the function:def hash_monitor_names(service): try: hash_list = [] monitor_list = get_mon_map(service=service) if monitor_list['monmap']['mons']: for mon in monitor_list['monmap']['mons']: hash_list.append( h...
[ "\n Uses the get_mon_map() function to get information about the monitor\n cluster.\n Hash the name of each monitor. Return a sorted list of monitor hashes\n in an ascending order.\n :param service: six.string_types. The Ceph user name to run the command under\n :rtype : dict. json dict of moni...
Please provide a description of the function:def monitor_key_delete(service, key): try: check_output( ['ceph', '--id', service, 'config-key', 'del', str(key)]) except CalledProcessError as e: log("Monitor config-key put failed with message: {}".format( e...
[ "\n Delete a key and value pair from the monitor cluster\n :param service: six.string_types. The Ceph user name to run the command under\n Deletes a key value pair on the monitor cluster.\n :param key: six.string_types. The key to delete.\n " ]
Please provide a description of the function:def monitor_key_set(service, key, value): try: check_output( ['ceph', '--id', service, 'config-key', 'put', str(key), str(value)]) except CalledProcessError as e: log("Monitor config-key put failed with message: {}".forma...
[ "\n Sets a key value pair on the monitor cluster.\n :param service: six.string_types. The Ceph user name to run the command under\n :param key: six.string_types. The key to set.\n :param value: The value to set. This will be converted to a string\n before setting\n " ]
Please provide a description of the function:def monitor_key_get(service, key): try: output = check_output( ['ceph', '--id', service, 'config-key', 'get', str(key)]).decode('UTF-8') return output except CalledProcessError as e: log("Monitor config-key get fa...
[ "\n Gets the value of an existing key in the monitor cluster.\n :param service: six.string_types. The Ceph user name to run the command under\n :param key: six.string_types. The key to search for.\n :return: Returns the value of that key or None if not found.\n " ]
Please provide a description of the function:def monitor_key_exists(service, key): try: check_call( ['ceph', '--id', service, 'config-key', 'exists', str(key)]) # I can return true here regardless because Ceph returns # ENOENT if the key wasn't found ret...
[ "\n Searches for the existence of a key in the monitor cluster.\n :param service: six.string_types. The Ceph user name to run the command under\n :param key: six.string_types. The key to search for\n :return: Returns True if the key exists, False if not and raises an\n exception if an unknown error...
Please provide a description of the function:def get_erasure_profile(service, name): try: out = check_output(['ceph', '--id', service, 'osd', 'erasure-code-profile', 'get', name, '--format=json']) if six.PY3: out = out.decode('...
[ "\n :param service: six.string_types. The Ceph user name to run the command under\n :param name:\n :return:\n " ]
Please provide a description of the function:def pool_set(service, pool_name, key, value): cmd = ['ceph', '--id', service, 'osd', 'pool', 'set', pool_name, key, str(value).lower()] try: check_call(cmd) except CalledProcessError: raise
[ "\n Sets a value for a RADOS pool in ceph.\n :param service: six.string_types. The Ceph user name to run the command under\n :param pool_name: six.string_types\n :param key: six.string_types\n :param value:\n :return: None. Can raise CalledProcessError\n " ]
Please provide a description of the function:def snapshot_pool(service, pool_name, snapshot_name): cmd = ['ceph', '--id', service, 'osd', 'pool', 'mksnap', pool_name, snapshot_name] try: check_call(cmd) except CalledProcessError: raise
[ "\n Snapshots a RADOS pool in ceph.\n :param service: six.string_types. The Ceph user name to run the command under\n :param pool_name: six.string_types\n :param snapshot_name: six.string_types\n :return: None. Can raise CalledProcessError\n " ]
Please provide a description of the function:def remove_pool_snapshot(service, pool_name, snapshot_name): cmd = ['ceph', '--id', service, 'osd', 'pool', 'rmsnap', pool_name, snapshot_name] try: check_call(cmd) except CalledProcessError: raise
[ "\n Remove a snapshot from a RADOS pool in ceph.\n :param service: six.string_types. The Ceph user name to run the command under\n :param pool_name: six.string_types\n :param snapshot_name: six.string_types\n :return: None. Can raise CalledProcessError\n " ]
Please provide a description of the function:def set_pool_quota(service, pool_name, max_bytes=None, max_objects=None): cmd = ['ceph', '--id', service, 'osd', 'pool', 'set-quota', pool_name] if max_bytes: cmd = cmd + ['max_bytes', str(max_bytes)] if max_objects: cmd = cmd + ['max_objects...
[ "\n :param service: The Ceph user name to run the command under\n :type service: str\n :param pool_name: Name of pool\n :type pool_name: str\n :param max_bytes: Maximum bytes quota to apply\n :type max_bytes: int\n :param max_objects: Maximum objects quota to apply\n :type max_objects: int\n...
Please provide a description of the function:def create_erasure_profile(service, profile_name, erasure_plugin_name='jerasure', failure_domain='host', data_chunks=2, coding_chunks=1, locality=None, durability_estimator=None, ...
[ "\n Create a new erasure code profile if one does not already exist for it. Updates\n the profile if it exists. Please see http://docs.ceph.com/docs/master/rados/operations/erasure-code-profile/\n for more details\n :param service: six.string_types. The Ceph user name to run the command under\n :par...
Please provide a description of the function:def rename_pool(service, old_name, new_name): validator(value=old_name, valid_type=six.string_types) validator(value=new_name, valid_type=six.string_types) cmd = ['ceph', '--id', service, 'osd', 'pool', 'rename', old_name, new_name] check_call(cmd)
[ "\n Rename a Ceph pool from old_name to new_name\n :param service: six.string_types. The Ceph user name to run the command under\n :param old_name: six.string_types\n :param new_name: six.string_types\n :return: None\n " ]
Please provide a description of the function:def erasure_profile_exists(service, name): validator(value=name, valid_type=six.string_types) try: check_call(['ceph', '--id', service, 'osd', 'erasure-code-profile', 'get', name]) return True except Ca...
[ "\n Check to see if an Erasure code profile already exists.\n :param service: six.string_types. The Ceph user name to run the command under\n :param name: six.string_types\n :return: int or None\n " ]
Please provide a description of the function:def get_cache_mode(service, pool_name): validator(value=service, valid_type=six.string_types) validator(value=pool_name, valid_type=six.string_types) out = check_output(['ceph', '--id', service, 'osd', 'dump', '--format=json']) if...
[ "\n Find the current caching mode of the pool_name given.\n :param service: six.string_types. The Ceph user name to run the command under\n :param pool_name: six.string_types\n :return: int or None\n " ]
Please provide a description of the function:def pool_exists(service, name): try: out = check_output(['rados', '--id', service, 'lspools']) if six.PY3: out = out.decode('UTF-8') except CalledProcessError: return False return name in out.split()
[ "Check to see if a RADOS pool already exists." ]
Please provide a description of the function:def get_osds(service, device_class=None): luminous_or_later = cmp_pkgrevno('ceph-common', '12.0.0') >= 0 if luminous_or_later and device_class: out = check_output(['ceph', '--id', service, 'osd', 'crush', 'class', ...
[ "Return a list of all Ceph Object Storage Daemons currently in the\n cluster (optionally filtered by storage device class).\n\n :param device_class: Class of storage device for OSD's\n :type device_class: str\n " ]
Please provide a description of the function:def install(): ceph_dir = "/etc/ceph" if not os.path.exists(ceph_dir): os.mkdir(ceph_dir) apt_install('ceph-common', fatal=True)
[ "Basic Ceph client installation." ]
Please provide a description of the function:def rbd_exists(service, pool, rbd_img): try: out = check_output(['rbd', 'list', '--id', service, '--pool', pool]) if six.PY3: out = out.decode('UTF-8') except CalledProcessError: return False r...
[ "Check to see if a RADOS block device exists." ]
Please provide a description of the function:def create_rbd_image(service, pool, image, sizemb): cmd = ['rbd', 'create', image, '--size', str(sizemb), '--id', service, '--pool', pool] check_call(cmd)
[ "Create a new RADOS block device." ]
Please provide a description of the function:def set_app_name_for_pool(client, pool, name): if cmp_pkgrevno('ceph-common', '12.0.0') >= 0: cmd = ['ceph', '--id', client, 'osd', 'pool', 'application', 'enable', pool, name] check_call(cmd)
[ "\n Calls `osd pool application enable` for the specified pool name\n\n :param client: Name of the ceph client to use\n :type client: str\n :param pool: Pool to set app name for\n :type pool: str\n :param name: app name for the specified pool\n :type name: str\n\n :raises: CalledProcessError...
Please provide a description of the function:def create_pool(service, name, replicas=3, pg_num=None): if pool_exists(service, name): log("Ceph pool {} already exists, skipping creation".format(name), level=WARNING) return if not pg_num: # Calculate the number of placeme...
[ "Create a new RADOS pool." ]
Please provide a description of the function:def add_key(service, key): keyring = _keyring_path(service) if os.path.exists(keyring): with open(keyring, 'r') as ring: if key in ring.read(): log('Ceph keyring exists at %s and has not changed.' % keyring, ...
[ "\n Add a key to a keyring.\n\n Creates the keyring if it doesn't already exist.\n\n Logs and returns if the key is already in the keyring.\n " ]
Please provide a description of the function:def delete_keyring(service): keyring = _keyring_path(service) if not os.path.exists(keyring): log('Keyring does not exist at %s' % keyring, level=WARNING) return os.remove(keyring) log('Deleted ring at %s.' % keyring, level=INFO)
[ "Delete an existing Ceph keyring." ]
Please provide a description of the function:def create_key_file(service, key): keyfile = _keyfile_path(service) if os.path.exists(keyfile): log('Keyfile exists at %s.' % keyfile, level=WARNING) return with open(keyfile, 'w') as fd: fd.write(key) log('Created new keyfile a...
[ "Create a file containing key." ]
Please provide a description of the function:def get_ceph_nodes(relation='ceph'): hosts = [] for r_id in relation_ids(relation): for unit in related_units(r_id): hosts.append(relation_get('private-address', unit=unit, rid=r_id)) return hosts
[ "Query named relation to determine current nodes." ]
Please provide a description of the function:def configure(service, key, auth, use_syslog): add_key(service, key) create_key_file(service, key) hosts = get_ceph_nodes() with open('/etc/ceph/ceph.conf', 'w') as ceph_conf: ceph_conf.write(CEPH_CONF.format(auth=auth, ...
[ "Perform basic configuration of Ceph." ]
Please provide a description of the function:def image_mapped(name): try: out = check_output(['rbd', 'showmapped']) if six.PY3: out = out.decode('UTF-8') except CalledProcessError: return False return name in out
[ "Determine whether a RADOS block device is mapped locally." ]
Please provide a description of the function:def map_block_storage(service, pool, image): cmd = [ 'rbd', 'map', '{}/{}'.format(pool, image), '--user', service, '--secret', _keyfile_path(service), ] check_call(cmd)
[ "Map a RADOS block device for local use." ]
Please provide a description of the function:def make_filesystem(blk_device, fstype='ext4', timeout=10): count = 0 e_noent = os.errno.ENOENT while not os.path.exists(blk_device): if count >= timeout: log('Gave up waiting on block device %s' % blk_device, level=ERROR)...
[ "Make a new filesystem on the specified block device." ]
Please provide a description of the function:def place_data_on_block_device(blk_device, data_src_dst): # mount block device into /mnt mount(blk_device, '/mnt') # copy data to /mnt copy_files(data_src_dst, '/mnt') # umount block device umount('/mnt') # Grab user/group ID's from original ...
[ "Migrate data in data_src_dst to blk_device and then remount." ]
Please provide a description of the function:def ensure_ceph_storage(service, pool, rbd_img, sizemb, mount_point, blk_device, fstype, system_services=[], replicas=3): # Ensure pool, RBD image, RBD mappings are in place. if not pool_exists(service, pool): ...
[ "NOTE: This function must only be called from a single service unit for\n the same rbd_img otherwise data loss will occur.\n\n Ensures given pool and RBD image exists, is mapped to a block device,\n and the device is formatted and mounted at the given mount_point.\n\n If formatting a device for the firs...
Please provide a description of the function:def ensure_ceph_keyring(service, user=None, group=None, relation='ceph', key=None): if not key: for rid in relation_ids(relation): for unit in related_units(rid): key = relation_get('key', rid=rid, unit=uni...
[ "Ensures a ceph keyring is created for a named service and optionally\n ensures user and group ownership.\n\n @returns boolean: Flag to indicate whether a key was successfully written\n to disk based on either relation data or a supplied key\n " ]
Please provide a description of the function:def get_previous_request(rid): request = None broker_req = relation_get(attribute='broker_req', rid=rid, unit=local_unit()) if broker_req: request_data = json.loads(broker_req) request = CephBrokerRq(api_version=...
[ "Return the last ceph broker request sent on a given relation\n\n @param rid: Relation id to query for request\n " ]
Please provide a description of the function:def get_request_states(request, relation='ceph'): complete = [] requests = {} for rid in relation_ids(relation): complete = False previous_request = get_previous_request(rid) if request == previous_request: sent = True ...
[ "Return a dict of requests per relation id with their corresponding\n completion state.\n\n This allows a charm, which has a request for ceph, to see whether there is\n an equivalent request already being processed and if so what state that\n request is in.\n\n @param request: A CephBrokerRq objec...
Please provide a description of the function:def is_request_sent(request, relation='ceph'): states = get_request_states(request, relation=relation) for rid in states.keys(): if not states[rid]['sent']: return False return True
[ "Check to see if a functionally equivalent request has already been sent\n\n Returns True if a similair request has been sent\n\n @param request: A CephBrokerRq object\n " ]
Please provide a description of the function:def is_request_complete_for_rid(request, rid): broker_key = get_broker_rsp_key() for unit in related_units(rid): rdata = relation_get(rid=rid, unit=unit) if rdata.get(broker_key): rsp = CephBrokerRsp(rdata.get(broker_key)) ...
[ "Check if a given request has been completed on the given relation\n\n @param request: A CephBrokerRq object\n @param rid: Relation ID\n " ]
Please provide a description of the function:def send_request_if_needed(request, relation='ceph'): if is_request_sent(request, relation=relation): log('Request already sent but not complete, not sending new request', level=DEBUG) else: for rid in relation_ids(relation): ...
[ "Send broker request if an equivalent request has not already been sent\n\n @param request: A CephBrokerRq object\n " ]
Please provide a description of the function:def is_broker_action_done(action, rid=None, unit=None): rdata = relation_get(rid, unit) or {} broker_rsp = rdata.get(get_broker_rsp_key()) if not broker_rsp: return False rsp = CephBrokerRsp(broker_rsp) unit_name = local_unit().partition('/'...
[ "Check whether broker action has completed yet.\n\n @param action: name of action to be performed\n @returns True if action complete otherwise False\n " ]
Please provide a description of the function:def mark_broker_action_done(action, rid=None, unit=None): rdata = relation_get(rid, unit) or {} broker_rsp = rdata.get(get_broker_rsp_key()) if not broker_rsp: return rsp = CephBrokerRsp(broker_rsp) unit_name = local_unit().partition('/')[2]...
[ "Mark action as having been completed.\n\n @param action: name of action to be performed\n @returns None\n " ]
Please provide a description of the function:def add_cache_tier(self, cache_pool, mode): # Check the input types and values validator(value=cache_pool, valid_type=six.string_types) validator(value=mode, valid_type=six.string_types, valid_range=["readonly", "writeback"]) check_c...
[ "\n Adds a new cache tier to an existing pool.\n :param cache_pool: six.string_types. The cache tier pool name to add.\n :param mode: six.string_types. The caching mode to use for this pool. valid range = [\"readonly\", \"writeback\"]\n :return: None\n " ]
Please provide a description of the function:def remove_cache_tier(self, cache_pool): # read-only is easy, writeback is much harder mode = get_cache_mode(self.service, cache_pool) if mode == 'readonly': check_call(['ceph', '--id', self.service, 'osd', 'tier', 'cache-mode', c...
[ "\n Removes a cache tier from Ceph. Flushes all dirty objects from writeback pools and waits for that to complete.\n :param cache_pool: six.string_types. The cache tier pool name to remove.\n :return: None\n " ]
Please provide a description of the function:def get_pgs(self, pool_size, percent_data=DEFAULT_POOL_WEIGHT, device_class=None): # Note: This calculation follows the approach that is provided # by the Ceph PG Calculator located at http://ceph.com/pgcalc/. validator(value...
[ "Return the number of placement groups to use when creating the pool.\n\n Returns the number of placement groups which should be specified when\n creating the pool. This is based upon the calculation guidelines\n provided by the Ceph Placement Group Calculator (located online at\n http:/...
Please provide a description of the function:def add_op_request_access_to_group(self, name, namespace=None, permission=None, key_name=None, object_prefix_permissions=None): self.ops.append({ 'op': 'add-permissions...
[ "\n Adds the requested permissions to the current service's Ceph key,\n allowing the key to access only the specified pools or\n object prefixes. object_prefix_permissions should be a dictionary\n keyed on the permission with the corresponding value being a list\n of prefixes to a...
Please provide a description of the function:def add_op_create_pool(self, name, replica_count=3, pg_num=None, weight=None, group=None, namespace=None, app_name=None, max_bytes=None, max_objects=None): return self.add_op_create_replicated_pool( ...
[ "DEPRECATED: Use ``add_op_create_replicated_pool()`` or\n ``add_op_create_erasure_pool()`` instead.\n " ]
Please provide a description of the function:def add_op_create_replicated_pool(self, name, replica_count=3, pg_num=None, weight=None, group=None, namespace=None, app_name=None, max_bytes=None, max_objects=N...
[ "Adds an operation to create a replicated pool.\n\n :param name: Name of pool to create\n :type name: str\n :param replica_count: Number of copies Ceph should keep of your data.\n :type replica_count: int\n :param pg_num: Request specific number of Placement Groups to create\n ...
Please provide a description of the function:def add_op_create_erasure_pool(self, name, erasure_profile=None, weight=None, group=None, app_name=None, max_bytes=None, max_objects=None): self.ops.append({'op': 'create-pool', 'name': na...
[ "Adds an operation to create a erasure coded pool.\n\n :param name: Name of pool to create\n :type name: str\n :param erasure_profile: Name of erasure code profile to use. If not\n set the ceph-mon unit handling the broker\n request...
Please provide a description of the function:def get_nagios_unit_name(relation_name='nrpe-external-master'): host_context = get_nagios_hostcontext(relation_name) if host_context: unit = "%s:%s" % (host_context, local_unit()) else: unit = local_unit() return unit
[ "\n Return the nagios unit name prepended with host_context if needed\n\n :param str relation_name: Name of relation nrpe sub joined to\n " ]
Please provide a description of the function:def add_init_service_checks(nrpe, services, unit_name, immediate_check=True): for svc in services: # Don't add a check for these services from neutron-gateway if svc in ['ext-port', 'os-charm-phy-nic-mtu']: next upstart_init = '/...
[ "\n Add checks for each service in list\n\n :param NRPE nrpe: NRPE object to add check to\n :param list services: List of services to check\n :param str unit_name: Unit name to use in check description\n :param bool immediate_check: For sysv init, run the service check immediately\n " ]
Please provide a description of the function:def copy_nrpe_checks(nrpe_files_dir=None): NAGIOS_PLUGINS = '/usr/local/lib/nagios/plugins' if nrpe_files_dir is None: # determine if "charmhelpers" is in CHARMDIR or CHARMDIR/hooks for segment in ['.', 'hooks']: nrpe_files_dir = os.p...
[ "\n Copy the nrpe checks into place\n\n " ]
Please provide a description of the function:def add_haproxy_checks(nrpe, unit_name): nrpe.add_check( shortname='haproxy_servers', description='Check HAProxy {%s}' % unit_name, check_cmd='check_haproxy.sh') nrpe.add_check( shortname='haproxy_queue', description='Chec...
[ "\n Add checks for each service in list\n\n :param NRPE nrpe: NRPE object to add check to\n :param str unit_name: Unit name to use in check description\n " ]