def _delete_namespace(self, ns_name):
     """
     Delete namespace object from cache.
     """
     ns = self._get_namespace(ns_name)
     if ns:
         NamespaceKM.delete(ns.uuid)
 def _build_np_cache(self):
     ns_uuid_set = set(NamespaceKM.keys())
     ns_sg_name_set = set()
     for ns_uuid in ns_uuid_set or []:
         ns = NamespaceKM.get(ns_uuid)
         if not ns:
             continue
         ns_name = ns.name
         ns_sg = "-".join(
             [vnc_kube_config.cluster_name(), ns_name, 'sg'])
         ns_sg_name_set.add(ns_sg)
         default_sg = "-".join(
             [vnc_kube_config.cluster_name(), ns_name, 'default'])
         ns_sg_name_set.add(default_sg)
         self._default_ns_sgs[ns_name] = {}
     sg_uuid_set = set(SecurityGroupKM.keys())
     for sg_uuid in sg_uuid_set or []:
         sg = SecurityGroupKM.get(sg_uuid)
         if not sg or not sg.namespace:
             continue
         if sg.name in ns_sg_name_set:
             sg_dict = {}
             sg_dict[sg.name] = sg_uuid
             self._default_ns_sgs[sg.namespace].update(sg_dict)
         elif sg.np_pod_selector:
             self._update_sg_cache(self._np_pod_label_cache,
                         sg.np_pod_selector, sg.uuid)
         elif sg.ingress_pod_selector:
             self._update_sg_cache(self._ingress_pod_label_cache,
                         sg.ingress_pod_selector, sg.uuid)
         if sg.np_spec:
             #_get_ingress_rule_list update _ingress_ns_label_cache
             self._get_ingress_rule_list(sg.np_spec,
                         sg.namespace, sg.name, sg.uuid)
 def _get_ns_address_list(self, np_sg_uuid, labels=None):
     address_list = []
     if not labels:
         ns_uuid_list = NamespaceKM.keys()
         labels = self._get_ns_allow_all_label()
     else:
         ns_uuid_set = self._find_namespaces(labels)
         ns_uuid_list = list(ns_uuid_set)
     for ns_uuid in ns_uuid_list or []:
         address = {}
         ns = NamespaceKM.get(ns_uuid)
         if not ns:
             continue
         proj_fq_name = vnc_kube_config.cluster_project_fq_name(ns.name)
         ns_sg_fq_name = proj_fq_name[:]
         ns_sg = "-".join([vnc_kube_config.cluster_name(), ns.name, 'sg'])
         ns_sg_fq_name.append(ns_sg)
         address['security_group'] = ns_sg_fq_name
         address['ns_selector'] = labels
         if ns_sg in self._default_ns_sgs[ns.name]:
             address['ns_sg_uuid'] = self._default_ns_sgs[ns.name][ns_sg]
             address_list.append(address)
     for label in labels.items():
         key = self._label_cache._get_key(label)
         self._label_cache._locate_label(key,
                 self._ingress_ns_label_cache, label, np_sg_uuid)
     return address_list
    def tearDownClass(cls):
        for pod in list(PodKM):
            PodKM.delete(pod)
        for namespace in list(NamespaceKM):
            NamespaceKM.delete(namespace)

        super(VncPodTest, cls).tearDownClass()
    def tearDownClass(cls):
        for pod in list(PodKM):
            PodKM.delete(pod)
        for service in list(ServiceKM):
            ServiceKM.delete(service)
        for namespace in list(NamespaceKM):
            NamespaceKM.delete(namespace)

        super(VncEndpointsTestBase, cls).tearDownClass()
 def _add_namespace(self, namespace_name, isolated=False):
     ns_uid = str(uuid.uuid4())
     ns_add_event = self.create_add_namespace_event(namespace_name, ns_uid)
     if isolated:
         ns_add_event['object']['metadata']['annotations'] = {
             'opencontrail.org/isolation': 'true'}
     NamespaceKM.locate(ns_uid, ns_add_event['object'])
     self.enqueue_event(ns_add_event)
     return namespace_name, ns_uid
 def _enqueue_delete_namespace(self, namespace_name, ns_uuid):
     ns_delete_event = self.create_delete_namespace_event(
         namespace_name, ns_uuid)
     NamespaceKM.delete(ns_uuid)
     for project in ProjectKM.objects():
         k8s_namespace_name = project.get_k8s_namespace_name()
         if k8s_namespace_name == namespace_name:
             ProjectKM.delete(project.uuid)
     self.enqueue_event(ns_delete_event)
    def tearDownClass(cls):
        for pod in list(PodKM):
            PodKM.delete(pod)
        for namespace in list(NamespaceKM):
            NamespaceKM.delete(namespace)

        # Cleanup the Vrouter object.
        cls.delete_virtual_router(cls.vrouter_obj.uuid)

        super(VncPodTest, cls).tearDownClass()
 def _enqueue_add_namespace(self, isolated=False):
     ns_uuid = str(uuid.uuid4())
     namespace_name = 'namespace_name'
     ns_add_event = self.create_add_namespace_event(namespace_name, ns_uuid)
     if isolated:
         annotations = {'opencontrail.org/isolation': 'true'}
         ns_add_event['object']['metadata']['annotations'] = annotations
     NamespaceKM.locate(ns_uuid, ns_add_event['object'])
     self.enqueue_event(ns_add_event)
     self.wait_for_all_tasks_done()
     return namespace_name, ns_uuid
示例#10
0
    def _create_namespace(self, ns_name, ns_eval_vn_dict, is_isolated=False, labels={}):
        ns_uuid = str(uuid.uuid4())
        ns_add_event = self.create_add_namespace_event(ns_name, ns_uuid)
        ns_object = ns_add_event['object']
        ns_object['spec'] = {}
        ns_meta = ns_object['metadata']
        ns_meta['annotations'] = {}

        ns_meta['name'] = ns_name
        ns_meta['uid'] = ns_uuid
        ns_meta['namespace'] = ns_name
        ns_meta['labels'] = labels

        if ns_eval_vn_dict:
            ns_meta['annotations']['opencontrail.org/network'] = \
                ns_eval_vn_dict
        if is_isolated:
            ns_meta['annotations']['opencontrail.org/isolation'] = 'true'

        NamespaceKM.delete(ns_name)
        NamespaceKM.delete(ns_uuid)
        NamespaceKM.locate(ns_name, ns_object)
        NamespaceKM.locate(ns_uuid, ns_object)

        self.enqueue_event(ns_add_event)
        self.wait_for_all_tasks_done()

        return ns_uuid
 def _enqueue_add_custom_isolated_namespace(self, project, network):
     custom_network_config = {'virtual_network': network,
                              'domain': 'default-domain',
                              'project': project,
                              'name': network}
     kube_config.VncKubernetesConfig.args().cluster_network = str(
         custom_network_config)
     ns_uuid = str(uuid.uuid4())
     namespace_name = 'custom_isolated_namespace'
     ns_add_event = self.create_add_namespace_event(namespace_name, ns_uuid)
     annotations = {'opencontrail.org/network':
                        str({'domain': 'default-domain',
                             'project': project,
                             'name': network})}
     ns_add_event['object']['metadata']['annotations'] = annotations
     NamespaceKM.locate(ns_uuid, ns_add_event['object'])
     self.enqueue_event(ns_add_event)
     return namespace_name, ns_uuid
示例#12
0
    def _get_namespace_labels(pod_namespace):
        labels = {}

        # Get the explicit labels on a pod.
        ns = NamespaceKM.find_by_name_or_uuid(pod_namespace)
        if ns and ns.labels:
            labels = dict(ns.labels)

        # Append the implicit namespace tag to a pod.
        labels['namespace'] = pod_namespace

        return labels
示例#13
0
 def _get_namespace(pod_namespace):
     return NamespaceKM.find_by_name_or_uuid(pod_namespace)
 def _enqueue_delete_namespace(self, namespace_name, ns_uuid):
     ns_delete_event = self.create_delete_namespace_event(namespace_name,
                                                          ns_uuid)
     NamespaceKM.delete(ns_uuid)
     self.enqueue_event(ns_delete_event)
示例#15
0
 def _get_namespace(self, ns_name):
     return NamespaceKM.find_by_name_or_uuid(ns_name)
 def _get_namespace(self, ns_name):
     """
     Get namesapce object from cache.
     """
     return NamespaceKM.find_by_name_or_uuid(ns_name)
示例#17
0
 def _get_namespace(pod_namespace):
     return NamespaceKM.find_by_name_or_uuid(pod_namespace)
 def _get_namespace(self, ns_name):
     return NamespaceKM.find_by_name_or_uuid(ns_name)
示例#19
0
 def _get_namespace(self, ns_name):
     """
     Get namesapce object from cache.
     """
     return NamespaceKM.find_by_name_or_uuid(ns_name)
示例#20
0
 def _get_namespace(service_namespace):
     return NamespaceKM.find_by_name_or_uuid(service_namespace)
示例#21
0
 def _get_namespace(service_namespace):
     return NamespaceKM.find_by_name_or_uuid(service_namespace)
示例#22
0
 def _enqueue_delete_namespace(self, namespace_name, ns_uuid):
     ns_delete_event = self.create_delete_namespace_event(namespace_name,
                                                          ns_uuid)
     NamespaceKM.delete(ns_uuid)
     self.enqueue_event(ns_delete_event)
     self.wait_for_all_tasks_done()
 def _enqueue_delete_namespace(self, namespace_name, ns_uuid):
     ns_delete_event = self.create_delete_namespace_event(namespace_name,
                                                          ns_uuid)
     NamespaceKM.delete(ns_uuid)
     self.enqueue_event(ns_delete_event)
     self.wait_for_all_tasks_done()