コード例 #1
0
    def vnc_pod_task_add(self, obj_labels):
        node_name = obj_labels.node_name
        node_ip = obj_labels.node_ip

        vm = VirtualMachineMM.get(obj_labels.pod_task_uuid)
        if vm:
            if not vm.virtual_router:
                self._link_vm_to_node(vm, node_name, node_ip)
            #TODO: Clear and set new cache
            return vm
        #else:
            #TODO: If needed check for old container with new uuid.
        vn_obj = self._get_network(obj_labels.networks)
        if not vn_obj:
            return

        vm_obj = self._create_vm(obj_labels.pod_task_uuid, node_ip)
        vmi_uuid = self._create_vmi(obj_labels.pod_task_uuid, vm_obj, vn_obj)
        vmi = VirtualMachineInterfaceMM.get(vmi_uuid)

        self._create_iip(vm_obj.name, vn_obj, vmi, obj_labels.pod_subnets)

        self._link_vm_to_node(vm_obj, node_name, node_ip)

        vm = VirtualMachineMM.locate(obj_labels.pod_task_uuid)
        if vm:
            vm.pod_node = node_name
            vm.node_ip = node_ip
            return vm
コード例 #2
0
    def vnc_pod_task_add(self, obj_labels):
        node_name = obj_labels.node_name
        node_ip = obj_labels.node_ip

        vm = VirtualMachineMM.get(obj_labels.pod_task_uuid)
        if vm:
            if not vm.virtual_router:
                self._link_vm_to_node(vm, node_name, node_ip)
            #TODO: Clear and set new cache
            return vm
        #else:
        #TODO: If needed check for old container with new uuid.
        vn_obj = self._get_network(obj_labels.networks)
        if not vn_obj:
            return

        vm_obj = self._create_vm(obj_labels.pod_task_uuid)
        vmi_uuid = self._create_vmi(obj_labels.pod_task_uuid, vm_obj, vn_obj)
        vmi = VirtualMachineInterfaceMM.get(vmi_uuid)

        self._create_iip(vm_obj.name, vn_obj, vmi, obj_labels.pod_subnets)

        self._link_vm_to_node(vm_obj, node_name, node_ip)

        vm = VirtualMachineMM.locate(obj_labels.pod_task_uuid)
        if vm:
            vm.pod_node = node_name
            vm.node_ip = node_ip
            return vm
コード例 #3
0
 def process_event(self, event):
     event_type = event['event_type']
     node_ip = event['labels']['node-ip']
     found = True
     while found:
         #Fix me: Get this as parameter
         time.sleep(2)
         result = PodTaskMonitor.get_task(node_ip)
         for container_info in result['get_containers']['containers']:
             if container_info['container_id'][
                     'value'] == event_type.encode('utf-8'):
                 task_name = container_info['executor_id']['value']
                 vm = VirtualMachineMM.find_by_name_or_uuid(
                     container_info['container_id']['value'])
                 if not vm:
                     # It is possible our cache may not have the VN yet. Locate it.
                     vm = VirtualMachineMM.locate(
                         container_info['container_id']['value'])
                 vm_obj = self._vnc_lib.virtual_machine_read(
                     fq_name=vm.fq_name)
                 vm_obj.display_name = task_name
                 vm_uuid = self._vnc_lib.virtual_machine_update(vm_obj)
                 VirtualMachineMM.locate(vm_uuid)
                 if vm_obj:
                     found = False
コード例 #4
0
 def process_event(self, event):
     event_type = event['event_type']
     node_ip = event['labels']['node-ip']
     found = True
     interval = vnc_mesos_config.get_mesos_agent_retry_sync_count()
     while (interval > 0) and found:
         time.sleep(vnc_mesos_config.get_mesos_agent_retry_sync_hold_time())
         result = PodTaskMonitor.get_task(node_ip)
         for container_info in result['get_containers']['containers']:
             if container_info['container_id'][
                     'value'] == event_type.encode('utf-8'):
                 task_name = container_info['executor_id']['value']
                 vm = VirtualMachineMM.find_by_name_or_uuid(
                     container_info['container_id']['value'])
                 if not vm:
                     # It is possible our cache may not have the VN yet. Locate it.
                     vm = VirtualMachineMM.locate(
                         container_info['container_id']['value'])
                 vm_obj = self._vnc_lib.virtual_machine_read(
                     fq_name=vm.fq_name)
                 vm_obj.display_name = task_name
                 vm_uuid = self._vnc_lib.virtual_machine_update(vm_obj)
                 VirtualMachineMM.locate(vm_uuid)
                 if vm_obj:
                     found = False
         interval -= 1
コード例 #5
0
    def _link_vm_to_node(self, vm_obj, node_name, node_ip):
        if node_ip is None:
            return

        vm = VirtualMachineMM.locate(vm_obj.uuid)
        if vm:
            vm.node_ip = node_ip

        vr_uuid = VirtualRouterMM.get_ip_addr_to_uuid(node_ip)
        if vr_uuid is None:
            for vr in VirtualRouterMM.values():
                if vr.name == node_name:
                    vr_uuid = vr.uuid
        if vr_uuid is None:
            self._logger.debug("%s - Vrouter %s Not Found for PodTask %s" %
                               (self._name, node_ip, vm_obj.uuid))
            return

        try:
            vrouter_obj = self._vnc_lib.virtual_router_read(id=vr_uuid)
        except Exception as e:
            self._logger.debug("%s - Vrouter %s Not Found for Pod %s" %
                               (self._name, node_ip, vm_obj.uuid))
            string_buf = StringIO()
            cgitb_hook(file=string_buf, format="text")
            err_msg = string_buf.getvalue()
            self._logger.error("_link_vm_to_node: %s - %s" %
                               (self._name, err_msg))
            return

        self._vnc_lib.ref_update('virtual-router', vrouter_obj.uuid,
                                 'virtual-machine', vm_obj.uuid, None, 'ADD')
        if vm:
            vm.virtual_router = vrouter_obj.uuid
コード例 #6
0
    def _link_vm_to_node(self, vm_obj, node_name, node_ip):
        if node_ip is None:
            return

        vm = VirtualMachineMM.locate(vm_obj.uuid)
        if vm:
            vm.node_ip = node_ip

        vr_uuid = VirtualRouterMM.get_ip_addr_to_uuid(node_ip)
        if vr_uuid is None:
            for vr in VirtualRouterMM.values():
                if vr.name == node_name:
                    vr_uuid = vr.uuid
        if vr_uuid is None:
            self._logger.debug("%s - Vrouter %s Not Found for PodTask %s"
                %(self._name, node_ip, vm_obj.uuid))
            return

        try:
            vrouter_obj = self._vnc_lib.virtual_router_read(id=vr_uuid)
        except Exception as e:
            self._logger.debug("%s - Vrouter %s Not Found for Pod %s"
                %(self._name, node_ip, vm_obj.uuid))
            string_buf = StringIO()
            cgitb_hook(file=string_buf, format="text")
            err_msg = string_buf.getvalue()
            self._logger.error("_link_vm_to_node: %s - %s" %(self._name, err_msg))
            return

        self._vnc_lib.ref_update('virtual-router', vrouter_obj.uuid,
            'virtual-machine', vm_obj.uuid, None, 'ADD')
        if vm:
            vm.virtual_router = vrouter_obj.uuid
コード例 #7
0
    def _create_vm(self, pod_task_id):
        pod_task_name = PodTaskMonitor.get_task_pod_name_from_cid(pod_task_id)
        if pod_task_name is None:
            vm_obj = VirtualMachine(name=pod_task_id)
        else:
            vm_obj = VirtualMachine(name=pod_task_name)

        vm_obj.uuid = pod_task_id
        vm_obj.set_server_type("container")

        VirtualMachineMM.add_annotations(self, vm_obj, pod_task_id)
        try:
            self._vnc_lib.virtual_machine_create(vm_obj)
        except RefsExistError:
            vm_obj = self._vnc_lib.virtual_machine_read(id=pod_task_id)
        VirtualMachineMM.locate(vm_obj.uuid)
        return vm_obj
コード例 #8
0
    def _create_vm(self, pod_task_id, node_ip):
        pod_task_name = PodTaskMonitor.get_task_pod_name_from_cid(pod_task_id,
                                                                  node_ip)
        if pod_task_name is None:
            vm_obj = VirtualMachine(name=pod_task_id)
        else:
            vm_obj = VirtualMachine(name=pod_task_name)

        vm_obj.uuid = pod_task_id
        vm_obj.set_server_type("container")

        VirtualMachineMM.add_annotations(self, vm_obj, pod_task_id)
        try:
            self._vnc_lib.virtual_machine_create(vm_obj)
        except RefsExistError:
            vm_obj = self._vnc_lib.virtual_machine_read(id=pod_task_id)
        VirtualMachineMM.locate(vm_obj.uuid)
        return vm_obj
コード例 #9
0
 def process_event(self, event):
     event_type = event['event_type']
     node_ip = event['labels']['node-ip']
     found = True;
     interval = vnc_mesos_config.get_mesos_agent_retry_sync_count()
     while (interval > 0) and found:
         time.sleep(vnc_mesos_config.get_mesos_agent_retry_sync_hold_time())
         result = PodTaskMonitor.get_task(node_ip)
         for container_info in result['get_containers']['containers']:
             if container_info['container_id']['value'] == event_type.encode('utf-8'):
                 task_name = container_info['executor_id']['value']
                 vm = VirtualMachineMM.find_by_name_or_uuid(container_info['container_id']['value'])
                 if not vm:
                     # It is possible our cache may not have the VN yet. Locate it.
                     vm = VirtualMachineMM.locate(container_info['container_id']['value'])
                 vm_obj = self._vnc_lib.virtual_machine_read(fq_name=vm.fq_name)
                 vm_obj.display_name = task_name
                 vm_uuid = self._vnc_lib.virtual_machine_update(vm_obj)
                 VirtualMachineMM.locate(vm_uuid)
                 if vm_obj:
                     found = False
         interval -= 1
コード例 #10
0
    def vnc_pod_task_delete(self, pod_task_id):
        vm = VirtualMachineMM.get(pod_task_id)
        if not vm:
            return

        # If this VM's vrouter info is not available in our config db,
        # then it is a case of race between delete and ref updates.
        # So explicitly update this entry in config db.
        if not vm.virtual_router:
            try:
                vm.update()
            except NoIdError:
                pass

        self._clear_label_to_pod_cache(vm)

        try:
            vm_obj = self._vnc_lib.virtual_machine_read(id=vm.uuid)
        except NoIdError:
            # Unable to find VM object in cache. Cleanup local cache.
            VirtualMachineMM.delete(vm.uuid)
            return

        if vm.virtual_router:
            self._vnc_lib.ref_update('virtual-router', vm.virtual_router,
                                     'virtual-machine', vm.uuid, None,
                                     'DELETE')

        for vmi_id in list(vm.virtual_machine_interfaces):
            self.vnc_port_delete(vmi_id, pod_task_id)

        try:
            self._vnc_lib.virtual_machine_delete(id=pod_task_id)
        except NoIdError:
            pass

        # Cleanup local cache.
        VirtualMachineMM.delete(pod_task_id)
コード例 #11
0
    def vnc_pod_task_delete(self, pod_task_id):
        vm = VirtualMachineMM.get(pod_task_id)
        if not vm:
            return

        # If this VM's vrouter info is not available in our config db,
        # then it is a case of race between delete and ref updates.
        # So explicitly update this entry in config db.
        if not vm.virtual_router:
            try:
                vm.update()
            except NoIdError:
                pass

        self._clear_label_to_pod_cache(vm)

        try:
            vm_obj = self._vnc_lib.virtual_machine_read(id=vm.uuid)
        except NoIdError:
            # Unable to find VM object in cache. Cleanup local cache.
            VirtualMachineMM.delete(vm.uuid)
            return

        if vm.virtual_router:
            self._vnc_lib.ref_update('virtual-router', vm.virtual_router,
                                     'virtual-machine', vm.uuid, None,
                                     'DELETE')

        for vmi_id in list(vm.virtual_machine_interfaces):
            self.vnc_port_delete(vmi_id, pod_task_id)

        try:
            self._vnc_lib.virtual_machine_delete(id=pod_task_id)
        except NoIdError:
            pass

        # Cleanup local cache.
        VirtualMachineMM.delete(pod_task_id)