def __call__(self, yes=False, **kwargs): super(FixZkIP, self).__call__(**kwargs) for r in self.resources: self.stats = { 'miss_lock': 0, 'miss_lock_fixed': 0, 'miss_lock_fix_failed': 0, 'abusive_lock': 0, 'abusive_lock_fixed': 0, 'abusive_lock_fix_failed': 0, 'healthy_lock': 0 } if (not yes and not self.dry_run and not self.check and not continue_prompt( "Do you really want to repair %s network?" % r.fq_name)): raise CommandError("Exiting.") try: r.fetch() except ResourceNotFound: continue print("Checking VN %s" % r.fq_name) try: api_ips = self.get_api_ip(r) zk_ips = self.get_zk_ip(r) self.check_tuple(api_ips, zk_ips) self.print_stats(r) except SubnetNotFound: print("No subnets found") print()
def __call__(self, paths=None, nova_api_version=None): self.nclient = nclient.Client(nova_api_version, session=Context().session) self.actions = { BackRefsExists: { # we don't want to delete virtual-router objects ('virtual-machine', 'virtual-router'): self._remove_back_ref, ('virtual-machine-interface', 'instance-ip'): self._handle_si_vm, ('virtual-network', 'virtual-machine-interface'): self._remove_vm, ('security-group', 'virtual-machine-interface'): self._remove_vm, }, ChildrenExists: { ('project', 'virtual-machine-interface'): self._remove_vm, } } resources = expand_paths(paths, predicate=lambda r: r.type == 'project') if not continue_prompt( "Do you really want to purge theses projects ? All resources will be destroyed !" ): return for project in resources: self._delete(project)
def __call__(self, uuids=None, cassandra_servers=None, force=False, **kwargs): super(CheckBadRefs, self).__call__(**kwargs) self.force = force pool = ConnectionPool('config_db_uuid', server_list=cassandra_servers) uuid_cf = ColumnFamily(pool, 'obj_uuid_table') if uuids: def uuids_g(): for uuid in uuids: yield uuid else: def uuids_g(): for k, v in uuid_cf.get_range(column_count=1, filter_empty=True): yield k for uuid in uuids_g(): values = dict(uuid_cf.xget(uuid)) res = self._get_current_resource(uuid, values) bad_refs = self._check_resource_refs(uuid, values) if not res or bad_refs: printo(self._props_to_json(values)) if not res and not self.check: if self.force or continue_prompt(message="Delete ?"): self._delete(uuid_cf, uuid)
def __call__(self, paths=None, yes=False, **kwargs): super(FixSg, self).__call__(**kwargs) if (not yes and not self.dry_run and not self.check and not continue_prompt( "Some SGs will be deleted. Are you sure to continue?")): raise CommandError("Exiting.") bad_sg_exists = False for r in self.resources: r.fetch() fq_name = r.fq_name if r.children.security_group: bad_sg = [] good_sg = [] for sg in r.children.security_group: if sg.fq_name[2] == 'default': if not FQName(sg.fq_name[0:2]) == fq_name: bad_sg.append(sg) else: good_sg.append(sg) if bad_sg != []: bad_sg_exists = True print "Tenant %s %s" % (r.uuid, r.fq_name) for sg in bad_sg: self._handle_sg("Bad ", sg) for sg in good_sg: self._handle_sg("Good", sg, delete=False) if self.check and bad_sg_exists: raise CommandError()
def _clean_kv(self, session, stale_subnets, dry_run=False): if continue_prompt("Do you really want to delete these entries ?"): for key in stale_subnets: if not dry_run: session.remove_kv_store(key) printo( "Entry with key \"%s\" has been removed from the KV store" % key)
def _remove_vm(self, vmi, parent): logger.debug("trying to remove vmi vms") # VMs are not linked to the project vmi.fetch() for vm in vmi.refs.virtual_machine: if continue_prompt("Nova VM %s will be deleted" % vm.uuid): printo("deleting nova VM %s" % vm.uuid) self.nclient.servers.delete(vm.uuid) else: raise CommandError("Exiting.") self._delete(vmi)
def __call__(self, resource='', recursive=False, force=False): target = ShellContext.current_path / resource if not target.is_resource: raise CommandError('"%s" is not a resource.' % target.relative_to(ShellContext.current_path)) back_refs = [target] if recursive: back_refs = self._get_back_refs(target, []) if back_refs: message = """About to delete: - %s""" % "\n - ".join([str(p.relative_to(ShellContext.current_path)) for p in back_refs]) if force or utils.continue_prompt(message=message): for ref in reversed(back_refs): print("Deleting %s" % str(ref)) try: APIClient().delete(ref) except HttpError as e: raise CommandError("Failed to delete resource: %s" % str(e))
def _confirm_diff(self, diff, force=False): """Show actions to be made and ask for confirmation unless force is True. """ if not any( [True if diff[action] else False for action in Actions.APPLY]): printo('Nothing to do') return False for action in Actions.APPLY: if not diff[action]: continue printo("\n%s the resources :\n" % action.capitalize()) for key, values in diff[action].items(): printo('%s : %s\n' % (key, json.dumps(values, indent=2))) if force or continue_prompt(): return True else: return False
def __call__(self, vn_paths=None, yes=False, **kwargs): super(FixVnId, self).__call__(**kwargs) if (not yes and not self.dry_run and not self.check and not continue_prompt("Do you really want to repair virtual networks?")): print "Exiting." exit() self.indexes = None result = self.generate(vn_paths) self.indexes = Indexes(self.zk_client) for r in result: if r['reason'] == "nolock": print "No lock for %(path)s with VN Id %(nid)6s" % r if r['reason'] == "badlock": print "Bad lock for %(path)s with VN Id %(nid)6s zk-fqname: %(zk-fqname)s ; api-fqname: %(api-fqname)s" % r if not self.check: self.fix(r, dry_run=self.dry_run)