Ejemplo n.º 1
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
Ejemplo n.º 2
0
    def get_infra_annotations():
        """Get infra annotations."""
        annotations = {}
        annotations['owner'] = vnc_mesos_config.cluster_owner()
        annotations['cluster'] = vnc_mesos_config.cluster_name()

        return annotations
Ejemplo n.º 3
0
    def get_infra_annotations():
        """Get infra annotations."""
        annotations = {}
        annotations['owner'] = vnc_mesos_config.cluster_owner()
        annotations['cluster'] = vnc_mesos_config.cluster_name()

        return annotations
Ejemplo n.º 4
0
 def __init__(self):
     super(VncPodTask, self).__init__('PodTask')
     self._name = type(self).__name__
     self._vnc_lib = vnc_mesos_config.vnc_lib()
     self._queue = vnc_mesos_config.queue()
     self._sync_queue = vnc_mesos_config.sync_queue()
     self._args = vnc_mesos_config.args()
     self._logger = vnc_mesos_config.logger()
     if not VncPodTask.vnc_pod_task_instance:
         VncPodTask.vnc_pod_task_instance = self
Ejemplo n.º 5
0
 def __init__(self):
     super(VncPodTask, self).__init__('PodTask')
     self._name = type(self).__name__
     self._vnc_lib = vnc_mesos_config.vnc_lib()
     self._queue = vnc_mesos_config.queue()
     self._sync_queue = vnc_mesos_config.sync_queue()
     self._args = vnc_mesos_config.args()
     self._logger = vnc_mesos_config.logger()
     if not VncPodTask.vnc_pod_task_instance:
         VncPodTask.vnc_pod_task_instance = self
Ejemplo n.º 6
0
    def _create_vmi(self, pod_task_id, vm_obj, vn_obj):
        proj_fq_name = vnc_mesos_config.cluster_project_fq_name('default')
        proj_obj = self._vnc_lib.project_read(fq_name=proj_fq_name)

        vmi_prop = None
        obj_uuid = str(uuid.uuid1())
        vmi_obj = VirtualMachineInterface(
            name=vm_obj.name,
            parent_obj=proj_obj,
            virtual_machine_interface_properties=vmi_prop,
            display_name=vm_obj.name)

        vmi_obj.uuid = obj_uuid
        vmi_obj.set_virtual_network(vn_obj)
        vmi_obj.set_virtual_machine(vm_obj)
        vmi_obj.add_annotations(KeyValuePair(key='index', value='0/1'))
        vmi_obj.port_security_enabled = True
        VirtualMachineInterfaceMM.add_annotations(self, vmi_obj, pod_task_id)

        try:
            vmi_uuid = self._vnc_lib.virtual_machine_interface_create(vmi_obj)
        except RefsExistError:
            vmi_uuid = self._vnc_lib.virtual_machine_interface_update(vmi_obj)

        VirtualMachineInterfaceMM.locate(vmi_uuid)
        return vmi_uuid
Ejemplo n.º 7
0
    def _create_iip(self, pod_task_id, vn_obj, vmi, custom_ipam=None):
        vn = VirtualNetworkMM.find_by_name_or_uuid(vn_obj.get_uuid())
        if not vn:
            # It is possible our cache may not have the VN yet. Locate it.
            vn = VirtualNetworkMM.locate(vn_obj.get_uuid())
        if custom_ipam is None:
            ipam_fq_name = vnc_mesos_config.pod_task_ipam_fq_name()
        else:
            ipam_fq_name = custom_ipam.split(':')
        pod_ipam_subnet_uuid = vn.get_ipam_subnet_uuid(ipam_fq_name)

        # Create instance-ip.
        iip_uuid = str(uuid.uuid1())
        iip_obj = InstanceIp(name=pod_task_id,
                             subnet_uuid=pod_ipam_subnet_uuid)
        iip_obj.uuid = iip_uuid
        iip_obj.add_virtual_network(vn_obj)

        # Creation of iip requires the vmi vnc object.
        vmi_obj = self._vnc_lib.virtual_machine_interface_read(
            fq_name=vmi.fq_name)
        iip_obj.add_virtual_machine_interface(vmi_obj)

        InstanceIpMM.add_annotations(self, iip_obj, pod_task_id)
        self._logger.debug("%s: Create IIP from ipam_fq_name [%s]"
                            " pod_ipam_subnet_uuid [%s]"
                            " vn [%s] vmi_fq_name [%s]" %\
                            (self._name, ipam_fq_name, pod_ipam_subnet_uuid,
                            vn.name, vmi.fq_name))
        try:
            self._vnc_lib.instance_ip_create(iip_obj)
        except RefsExistError:
            self._vnc_lib.instance_ip_update(iip_obj)
        InstanceIpMM.locate(iip_obj.uuid)
        return iip_obj
Ejemplo n.º 8
0
    def _create_vmi(self, pod_task_id, vm_obj, vn_obj):
        proj_fq_name = vnc_mesos_config.cluster_project_fq_name('default')
        proj_obj = self._vnc_lib.project_read(fq_name=proj_fq_name)

        vmi_prop = None
        obj_uuid = str(uuid.uuid1())
        vmi_obj = VirtualMachineInterface(
            name=vm_obj.name, parent_obj=proj_obj,
            virtual_machine_interface_properties=vmi_prop,
            display_name=vm_obj.name)

        vmi_obj.uuid = obj_uuid
        vmi_obj.set_virtual_network(vn_obj)
        vmi_obj.set_virtual_machine(vm_obj)
        vmi_obj.add_annotations(KeyValuePair(key='index', value='0/1'))
        vmi_obj.port_security_enabled = True
        VirtualMachineInterfaceMM.add_annotations(self, vmi_obj, pod_task_id)

        try:
            vmi_uuid = self._vnc_lib.virtual_machine_interface_create(vmi_obj)
        except RefsExistError:
            vmi_uuid = self._vnc_lib.virtual_machine_interface_update(vmi_obj)

        VirtualMachineInterfaceMM.locate(vmi_uuid)
        return vmi_uuid
Ejemplo n.º 9
0
 def _get_network(self, custom_network=None):
     if custom_network == None:
         vn_fq_name = vnc_mesos_config.cluster_default_pod_task_network_fq_name()
     else:
         vn_fq_name = custom_network.split(':')
     vn_obj = self._vnc_lib.virtual_network_read(fq_name=vn_fq_name)
     return vn_obj
Ejemplo n.º 10
0
    def _create_iip(self, pod_task_id, vn_obj, vmi, custom_ipam=None):
        vn = VirtualNetworkMM.find_by_name_or_uuid(vn_obj.get_uuid())
        if not vn:
            # It is possible our cache may not have the VN yet. Locate it.
            vn = VirtualNetworkMM.locate(vn_obj.get_uuid())
        if custom_ipam is None:
            ipam_fq_name = vnc_mesos_config.pod_task_ipam_fq_name()
        else:
            ipam_fq_name = custom_ipam.split(':')
        pod_ipam_subnet_uuid = vn.get_ipam_subnet_uuid(ipam_fq_name)

        # Create instance-ip.
        iip_uuid = str(uuid.uuid1())
        iip_obj = InstanceIp(name=pod_task_id, subnet_uuid=pod_ipam_subnet_uuid)
        iip_obj.uuid = iip_uuid
        iip_obj.add_virtual_network(vn_obj)

        # Creation of iip requires the vmi vnc object.
        vmi_obj = self._vnc_lib.virtual_machine_interface_read(
            fq_name=vmi.fq_name)
        iip_obj.add_virtual_machine_interface(vmi_obj)

        InstanceIpMM.add_annotations(self, iip_obj, pod_task_id)
        self._logger.debug("%s: Create IIP from ipam_fq_name [%s]"
                            " pod_ipam_subnet_uuid [%s]"
                            " vn [%s] vmi_fq_name [%s]" %\
                            (self._name, ipam_fq_name, pod_ipam_subnet_uuid,
                            vn.name, vmi.fq_name))
        try:
            self._vnc_lib.instance_ip_create(iip_obj)
        except RefsExistError:
            self._vnc_lib.instance_ip_update(iip_obj)
        InstanceIpMM.locate(iip_obj.uuid)
        return iip_obj
Ejemplo n.º 11
0
    def _get_annotations(cls, vnc_caller, name, mesos_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_mesos_config.cluster_project_name()
        annotations.update(infra_anns)

        # Update annotations based on explicity input params.
        input_anns = {}
        input_anns['name'] = name
        if mesos_type:
            input_anns['kind'] = mesos_type
        annotations.update(input_anns)

        # Append other custom annotations.
        annotations.update(custom_ann_kwargs)

        return annotations
Ejemplo n.º 12
0
    def _get_annotations(cls, vnc_caller, name, mesos_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_mesos_config.cluster_project_name()
        annotations.update(infra_anns)

        # Update annotations based on explicity input params.
        input_anns = {}
        input_anns['name'] = name
        if mesos_type:
            input_anns['kind'] = mesos_type
        annotations.update(input_anns)

        # Append other custom annotations.
        annotations.update(custom_ann_kwargs)

        return annotations
Ejemplo n.º 13
0
 def _get_network(self, custom_network=None):
     if custom_network == None:
         vn_fq_name = vnc_mesos_config.cluster_default_pod_task_network_fq_name(
         )
     else:
         vn_fq_name = custom_network.split(':')
     vn_obj = self._vnc_lib.virtual_network_read(fq_name=vn_fq_name)
     return vn_obj
Ejemplo n.º 14
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
Ejemplo n.º 15
0
 def __init__(self, args=None, logger=None, q=None):
     self.args = args
     self.logger = logger
     self.queue = q
     self._vnc_lib = vnc_mesos_config.vnc_lib()
 def __init__(self, args=None, logger=None, q=None):
     self.args = args
     self.logger = logger
     self.queue = q
     self._vnc_lib = vnc_mesos_config.vnc_lib()