def filter_deployment_details(self, details): return run_func_on_iterable( details['environment'], lambda d: { 'name': d['name'], 'revision': [revision['name'] for revision in d['revision']], }, )
def get_cache_dependencies(self, files): def _func(f, _state): try: name = et.parse(f).find('.//CacheResource').text if name and name not in _state: _state.add(name) return name except Exception as e: logging.warning(f'{e}; file={f}', exc_info=True) return run_func_on_iterable(files, _func, args=(set(), ))
def get_cache_dependencies(self, files): def _func(f, _state): try: name = et.parse(f).find('.//CacheResource').text if name and name not in _state: _state.add(name) return name except: pass return run_func_on_iterable(files, _func, args=(set(), ))
def get_targetserver_dependencies(self, files): def _func(f, _state): try: root = et.parse(f).getroot() for child in root.iter('Server'): if child.attrib['name'] not in _state: _state.add(child.attrib['name']) return child.attrib['name'] except Exception as e: logging.warning(f'{e}; file={f}', exc_info=True) return run_func_on_iterable(files, _func, args=(set(), ))
def get_keyvaluemap_dependencies(self, files): def _func(f, _state): try: root = et.parse(f).getroot() if root.tag == 'KeyValueMapOperations': if root.attrib['mapIdentifier'] not in _state: _state.add(root.attrib['mapIdentifier']) return root.attrib['mapIdentifier'] except Exception as e: logging.warning(f'{e}; file={f}', exc_info=True) return run_func_on_iterable(files, _func, args=(set(), ))
def get_targetserver_dependencies(self, files): def _func(f, _state): try: root = et.parse(f).getroot() for child in root.iter('Server'): if child.attrib['name'] not in _state: _state.add(child.attrib['name']) return child.attrib['name'] except: pass return run_func_on_iterable(files, _func, args=(set(), ))
def get_keyvaluemap_dependencies(self, files): def _func(f, _state): try: root = et.parse(f).getroot() if root.tag == 'KeyValueMapOperations': if root.attrib['mapIdentifier'] not in _state: _state.add(root.attrib['mapIdentifier']) return root.attrib['mapIdentifier'] except: pass return run_func_on_iterable(files, _func, args=(set(), ))
def export_targetserver_dependencies(self, environment, targetservers, force=False, expc_verbosity=1): make_dirs(self._targetservers_dir) def _func(ts): ts_file = str(Path(self._targetservers_dir) / ts) if not force: path_exists(os.path.relpath(ts_file)) resp = Targetservers(self._auth, self._org_name, ts).get_targetserver(environment).text console.echo(resp, expc_verbosity=1) with open(ts_file, 'w') as f: f.write(resp) return run_func_on_iterable(targetservers, _func)
def export_cache_dependencies(self, environment, caches, force=False, expc_verbosity=1): make_dirs(self._caches_dir) def _func(cache): cache_file = str(Path(self._caches_dir) / cache) if not force: path_exists(os.path.relpath(cache_file)) resp = (Caches( self._auth, self._org_name, cache).get_information_about_a_cache(environment).text) console.echo(resp, expc_verbosity=1) with open(cache_file, 'w') as f: f.write(resp) return run_func_on_iterable(caches, _func)
def export_keyvaluemap_dependencies(self, environment, keyvaluemaps, force=False, expc_verbosity=1): make_dirs(self._keyvaluemaps_dir) def _func(kvm): kvm_file = str(Path(self._keyvaluemaps_dir) / kvm) if not force: path_exists(os.path.relpath(kvm_file)) resp = (Keyvaluemaps( self._auth, self._org_name, kvm).get_keyvaluemap_in_an_environment(environment).text) console.echo(resp, expc_verbosity=1) with open(kvm_file, 'w') as f: f.write(resp) return run_func_on_iterable(keyvaluemaps, _func)
def delete_undeployed_revisions(self, api_name, save_last=0, dry_run=False): details = ApisSerializer().filter_deployment_details( Deployments(self._auth, self._org_name, api_name).get_api_proxy_deployment_details().json()) undeployed = ApisSerializer().filter_undeployed_revisions( self.list_api_proxy_revisions(api_name).json(), ApisSerializer().filter_deployed_revisions(details), save_last=save_last, ) console.echo(f'Undeployed revisions to be deleted: {undeployed}') if dry_run: return undeployed def _func(revision): console.echo(f'Deleting revison {revision}') self.delete_api_proxy_revision(api_name, revision) return run_func_on_iterable(undeployed, _func)
def filter_deployed_revisions(self, details): return list(set(run_func_on_iterable(details, lambda d: d['revision'], state_op='extend')))