def _get_annotations(cls, vnc_caller, namespace, name, k8s_type, **custom_ann_kwargs): """Get all annotations. Annotations are aggregated from multiple sources like infra info, input params and custom annotations. This method is meant to be an aggregator of all possible annotations. """ # Get annotations declared on the caller. annotations = dict(vnc_caller.get_annotations()) # Update annotations with infra specific annotations. infra_anns = cls.get_infra_annotations() infra_anns['project'] = vnc_kube_config.cluster_project_name(namespace) annotations.update(infra_anns) # Update annotations based on explicity input params. input_anns = {} input_anns['namespace'] = namespace input_anns['name'] = name if k8s_type: input_anns['kind'] = k8s_type annotations.update(input_anns) # Append other custom annotations. annotations.update(custom_ann_kwargs) return annotations
def _get_annotations(cls, vnc_caller, namespace, name, k8s_type, **custom_ann_kwargs): """Get all annotations. Annotations are aggregated from multiple sources like infra info, input params and custom annotations. This method is meant to be an aggregator of all possible annotations. """ # Get annotations declared on the caller. annotations = dict(vnc_caller.get_annotations()) # Update annotations with infra specific annotations. infra_anns = cls.get_infra_annotations() infra_anns['project'] = vnc_kube_config.cluster_project_name(namespace) annotations.update(infra_anns) # Update annotations based on explicity input params. input_anns = {} input_anns['namespace'] = namespace input_anns['name'] = name if k8s_type: input_anns['kind'] = k8s_type annotations.update(input_anns) # Append other custom annotations. annotations.update(custom_ann_kwargs) return annotations
def vnc_namespace_delete(self, namespace_id, name): proj_fq_name = vnc_kube_config.cluster_project_fq_name(name) project_uuid = ProjectKM.get_fq_name_to_uuid(proj_fq_name) if not project_uuid: self.logger.error("Unable to locate project for k8s namespace " "[%s]" % (name)) return project = ProjectKM.get(project_uuid) if not project: self.logger.error("Unable to locate project for k8s namespace " "[%s]" % (name)) return default_sg_fq_name = proj_fq_name[:] sg = "-".join([vnc_kube_config.cluster_name(), name, 'default']) default_sg_fq_name.append(sg) ns_sg_fq_name = proj_fq_name[:] ns_sg = "-".join([vnc_kube_config.cluster_name(), name, 'sg']) ns_sg_fq_name.append(ns_sg) sg_list = [default_sg_fq_name, ns_sg_fq_name] try: # If the namespace is isolated, delete its virtual network. if self._is_namespace_isolated(name) == True: vn_name = self._get_namespace_vn_name(name) self._delete_isolated_ns_virtual_network( name, vn_name=vn_name, proj_fq_name=proj_fq_name) # delete default-sg and ns-sg security groups security_groups = project.get_security_groups() for sg_uuid in security_groups: sg = SecurityGroupKM.get(sg_uuid) if sg and sg.fq_name in sg_list[:]: self._vnc_lib.security_group_delete(id=sg_uuid) sg_list.remove(sg.fq_name) if not len(sg_list): break # delete the label cache if project: self._clear_namespace_label_cache(namespace_id, project) # delete the namespace self._delete_namespace(name) # If namespace=project, delete the project if vnc_kube_config.cluster_project_name(name) == name: self._vnc_lib.project_delete(fq_name=proj_fq_name) except Exception as e: pass
def vnc_namespace_delete(self,namespace_id, name): proj_fq_name = vnc_kube_config.cluster_project_fq_name(name) project_uuid = ProjectKM.get_fq_name_to_uuid(proj_fq_name) if not project_uuid: self._logger.error("Unable to locate project for k8s namespace " "[%s]" % (name)) return project = ProjectKM.get(project_uuid) if not project: self._logger.error("Unable to locate project for k8s namespace " "[%s]" % (name)) return default_sg_fq_name = proj_fq_name[:] sg = "-".join([vnc_kube_config.cluster_name(), name, 'default']) default_sg_fq_name.append(sg) ns_sg_fq_name = proj_fq_name[:] ns_sg = "-".join([vnc_kube_config.cluster_name(), name, 'sg']) ns_sg_fq_name.append(ns_sg) sg_list = [default_sg_fq_name, ns_sg_fq_name] try: # If the namespace is isolated, delete its virtual network. if self._is_namespace_isolated(name) == True: vn_name = self._get_namespace_vn_name(name) self._delete_isolated_ns_virtual_network(name, vn_name=vn_name, proj_fq_name=proj_fq_name) # delete default-sg and ns-sg security groups security_groups = project.get_security_groups() for sg_uuid in security_groups: sg = SecurityGroupKM.get(sg_uuid) if sg and sg.fq_name in sg_list[:]: self._vnc_lib.security_group_delete(id=sg_uuid) sg_list.remove(sg.fq_name) if not len(sg_list): break # delete the label cache if project: self._clear_namespace_label_cache(namespace_id, project) # delete the namespace self._delete_namespace(name) # If namespace=project, delete the project if vnc_kube_config.cluster_project_name(name) == name: self._vnc_lib.project_delete(fq_name=proj_fq_name) except Exception as e: pass
def _get_annotations(self, namespace, name, k8s_event_type=None, **kwargs): annotations = self.annotations infra_anns = {} infra_anns['project'] = vnc_kube_config.cluster_project_name(namespace) infra_anns['namespace'] = namespace infra_anns['name'] = name if k8s_event_type: infra_anns['kind'] = k8s_event_type # Update annotations with infra specific annotations. annotations.update(infra_anns) # Append other custom annotations. annotations.update(kwargs) return annotations