def get_package_candidate(pkg): """ Return the package version from the repo if different than the version that is currently installed. :param: str pkg: package name as known by apt :returns: str ver_str: version of new repo package, or None """ # NB: we cannot use the charmhelpers.fetch.apt_cache nor the # apt module from the python3-apt deb as they are only available # as system packages. Charms with use_system_packages=False in # layer.yaml would fail. Subprocess apt-cache policy instead. policy_cmd = ['apt-cache', 'policy', pkg] grep_cmd = ['grep', 'Candidate:'] p1 = subprocess.Popen(policy_cmd, stdout=subprocess.PIPE) p2 = subprocess.Popen(grep_cmd, stdin=p1.stdout, stdout=subprocess.PIPE) p1.stdout.close() policy_output = p2.communicate()[0].strip().decode() p1.wait() # policy_output will look like this: # Candidate: 5.6.9 try: new_ver = policy_output.split(':', 1)[1].strip() except IndexError: return None else: cur_ver = get_package_version(pkg, full_version=True) return new_ver if new_ver != cur_ver else None
def version(self): ''' Will attempt to get the version from the version fieldof the Kafka application. If there is a reader exception or a parser exception, unknown will be returned ''' return apt.get_package_version(KAFKA_APP) or 'unknown'
def version(self): ''' Will attempt to get the version from the version fieldof the registry application. If there is a reader exception or a parser exception, unknown will be returned ''' return apt.get_package_version(SCHEMA_REG) or 'unknown'
def install_nimsoft_robot(): '''Install the nimsoft robot software that is used for LMA.''' nimsoft_robot_resource = None try: # Try to get the resource from Juju. nimsoft_robot_resource = resource_get('nimsoft-robot-package') except Exception as e: message = 'An error occurred fetching the nimsoft-robot-package resource.' hookenv.log(message) hookenv.log(e) hookenv.status_set('blocked', message) return if not nimsoft_robot_resource: hookenv.status_set('blocked', 'The nimsoft_robot_resource resource is missing.') return # Handle null resource publication, we check if filesize < 1mb filesize = os.stat(nimsoft_robot_resource).st_size if filesize < 1000000: hookenv.status_set('blocked', 'Incomplete nimsoft_robot_resource resource.') return hookenv.status_set('maintenance', 'Installing nimsoft_robot resource.') cmd = ['dpkg', '-i', nimsoft_robot_resource] hookenv.log(cmd) check_call(cmd) set_state('nimsoft-robot.installed') cur_ver = get_package_version(nimsoft_robot, full_version=True) # Do your setup here. # # If your charm has other dependencies before it can install, # add those as @when() clauses above., or as additional @when() # decorated handlers below # # See the following for information about reactive charms: # # * https://jujucharms.com/docs/devel/developer-getting-started # * https://github.com/juju-solutions/layer-basic#overview # set_flag('nimsoft-robot.installed')
def configure(): cfg = hookenv.config() zookeeper = Zookeeper() changed = any(( data_changed('zkpeer.nodes', zookeeper.read_peers()), data_changed('zk.autopurge_purge_interval', cfg.get('autopurge_purge_interval')), data_changed('zk.autopurge_snap_retain_count', cfg.get('autopurge_snap_retain_count')), data_changed('zk.storage.data_dir', unitdata.kv().get('zookeeper.storage.data_dir')), data_changed('zk.jmx_port', cfg.get('jmx_port')), )) if changed or is_flag_set('zookeeper.force-reconfigure'): zookeeper.install() zookeeper.open_ports() clear_flag('zookeeper.force-reconfigure') set_flag('zookeeper.started') set_flag('zookeeper.configured') hookenv.status_set('active', 'ready {}'.format(zookeeper.quorum_check())) # set app version string for juju status output zoo_version = apt.get_package_version(APP_NAME) or 'unknown' hookenv.application_version_set(zoo_version)