def _get_network(self, ns_name): set_default_vn = False ns = self._get_namespace(ns_name) vn_fq_name = ns.get_annotated_network_fq_name() if not vn_fq_name: if ns.is_isolated(): vn_fq_name = ns.get_isolated_pod_network_fq_name() if not vn_fq_name: if self._default_vn_obj: return self._default_vn_obj set_default_vn = True vn_fq_name = vnc_kube_config.cluster_default_pod_network_fq_name() try: vn_obj = self._vnc_lib.virtual_network_read(fq_name=vn_fq_name) except NoIdError: self._logger.error("%s - %s Not Found" % (self._name, vn_fq_name)) return None if set_default_vn: self._default_vn_obj = vn_obj return vn_obj
def _update_default_virtual_network_perms2(self, ns_name, proj_uuid, oper='add'): if DBBaseKM.is_nested(): return try: vn_fq_name = vnc_kube_config.cluster_default_pod_network_fq_name() pod_vn_obj = self._vnc_lib.virtual_network_read(fq_name=vn_fq_name) vn_fq_name = vnc_kube_config.cluster_default_service_network_fq_name( ) service_vn_obj = self._vnc_lib.virtual_network_read( fq_name=vn_fq_name) except NoIdError: return for vn_obj in [pod_vn_obj, service_vn_obj]: perms2 = vn_obj.perms2 share = perms2.share tenant_found = False for item in share: if item.tenant == proj_uuid: tenant_found = True break if oper == 'add': if tenant_found == True: continue else: share_item = ShareType(tenant=proj_uuid, tenant_access=PERMS_R) share.append(share_item) else: share.remove(item) perms2.share = share vn_obj.perms2 = perms2 self._vnc_lib.virtual_network_update(vn_obj)
def _get_network(self, pod_id, pod_name, pod_namespace): """ Get virtual network to be associated with the pod. The heuristics to determine which virtual network to use for the pod is as follows: if (virtual network is annotated in the pod config): Use virtual network configured on the pod. else if (virtual network if annotated in the pod's namespace): Use virtual network configured on the namespace. else if (pod is in a isolated namespace): Use the virtual network associated with isolated namespace. else: Use the pod virtual network associated with kubernetes cluster. """ # Check for virtual-network configured on the pod. pod = PodKM.find_by_name_or_uuid(pod_id) if not pod: self._logger.notice("%s - Pod %s:%s:%s Not Found" "(Might Got Delete Event From K8s)" %(self._name, pod_namespace, pod_name, pod_id)) return vn_fq_name = pod.get_vn_fq_name() ns = self._get_namespace(pod_namespace) # FIXME: Check if ns is not None # Check of virtual network configured on the namespace. if not vn_fq_name: vn_fq_name = ns.get_annotated_network_fq_name() # If the pod's namespace is isolated, use the isolated virtual # network. if not vn_fq_name: if self._is_pod_network_isolated(pod_namespace): vn_fq_name = ns.get_isolated_pod_network_fq_name() # Finally, if no network was found, default to the cluster # pod network. if not vn_fq_name: vn_fq_name = vnc_kube_config.cluster_default_pod_network_fq_name() vn_obj = self._vnc_lib.virtual_network_read(fq_name=vn_fq_name) return vn_obj
def _get_default_network(self, pod_id, pod_name, pod_namespace): """ Get virtual network to be associated with the pod. The heuristics to determine which virtual network to use for the pod is as follows: if (virtual network is annotated in the pod config): Use virtual network configured on the pod. else if (virtual network if annotated in the pod's namespace): Use virtual network configured on the namespace. else if (pod is in a isolated namespace): Use the virtual network associated with isolated namespace. else: Use the pod virtual network associated with kubernetes cluster. """ # Check for virtual-network configured on the pod. pod = PodKM.find_by_name_or_uuid(pod_id) if not pod: self._logger.notice("%s - Pod %s:%s:%s Not Found" "(Might Got Delete Event From K8s)" %(self._name, pod_namespace, pod_name, pod_id)) return vn_fq_name = pod.get_vn_fq_name() ns = self._get_namespace(pod_namespace) # FIXME: Check if ns is not None # Check of virtual network configured on the namespace. if not vn_fq_name: vn_fq_name = ns.get_annotated_network_fq_name() # If the pod's namespace is isolated, use the isolated virtual # network. if not vn_fq_name: if self._is_pod_network_isolated(pod_namespace): vn_fq_name = ns.get_isolated_pod_network_fq_name() # Finally, if no network was found, default to the cluster # pod network. if not vn_fq_name: vn_fq_name = vnc_kube_config.cluster_default_pod_network_fq_name() vn_obj = self._vnc_lib.virtual_network_read(fq_name=vn_fq_name) return vn_obj