def _create_cluster_service_fip(self, pod_name, pod_namespace, vmi_uuid):
        """
        Isolated Pods in the cluster will be allocated a floating ip
        from the cluster service network, so that the pods can talk
        to cluster services.
        """
        if not self._service_fip_pool:
            return

        # Construct parent ref.
        fip_pool_obj = FloatingIpPool()
        fip_pool_obj.uuid = self._service_fip_pool.uuid
        fip_pool_obj.fq_name = self._service_fip_pool.fq_name
        fip_pool_obj.name = self._service_fip_pool.name

        # Create Floating-Ip object.
        obj_uuid = str(uuid.uuid1())
        display_name = VncCommon.make_display_name(pod_namespace, pod_name)
        name = VncCommon.make_name(pod_name, obj_uuid)
        fip_obj = FloatingIp(name="cluster-svc-fip-%s"% (name),
                             parent_obj=fip_pool_obj,
                             floating_ip_traffic_direction='egress',
                             display_name=display_name)
        fip_obj.uuid = obj_uuid

        # Creation of fip requires the vmi vnc object.
        vmi_obj = self._vnc_lib.virtual_machine_interface_read(id=vmi_uuid)
        fip_obj.set_virtual_machine_interface(vmi_obj)

        FloatingIpKM.add_annotations(self, fip_obj, pod_namespace, pod_name)

        try:
            fip_uuid = self._vnc_lib.floating_ip_create(fip_obj)
        except RefsExistError:
            fip_uuid = self._vnc_lib.floating_ip_update(fip_obj)

        # Cached service floating ip.
        FloatingIpKM.locate(fip_uuid)

        return
Beispiel #2
0
    def _create_cluster_service_fip(self, pod_name, pod_namespace, vmi_uuid):
        """
        Isolated Pods in the cluster will be allocated a floating ip
        from the cluster service network, so that the pods can talk
        to cluster services.
        """
        if not self._service_fip_pool:
            return

        # Construct parent ref.
        fip_pool_obj = FloatingIpPool()
        fip_pool_obj.uuid = self._service_fip_pool.uuid
        fip_pool_obj.fq_name = self._service_fip_pool.fq_name
        fip_pool_obj.name = self._service_fip_pool.name

        # Create Floating-Ip object.
        obj_uuid = str(uuid.uuid1())
        display_name = VncCommon.make_display_name(pod_namespace, pod_name)
        name = VncCommon.make_name(pod_name, obj_uuid)
        fip_obj = FloatingIp(name="cluster-svc-fip-%s" % (name),
                             parent_obj=fip_pool_obj,
                             floating_ip_traffic_direction='egress',
                             display_name=display_name)
        fip_obj.uuid = obj_uuid

        # Creation of fip requires the vmi vnc object.
        vmi_obj = self._vnc_lib.virtual_machine_interface_read(id=vmi_uuid)
        fip_obj.set_virtual_machine_interface(vmi_obj)

        FloatingIpKM.add_annotations(self, fip_obj, pod_namespace, pod_name)

        try:
            fip_uuid = self._vnc_lib.floating_ip_create(fip_obj)
        except RefsExistError:
            fip_uuid = self._vnc_lib.floating_ip_update(fip_obj)

        # Cached service floating ip.
        FloatingIpKM.locate(fip_uuid)

        return
Beispiel #3
0
    def _update_loadbalancer_props(self, lb_id):
        lb = LoadbalancerSM.get(lb_id)
        if lb is None:
            msg = ('Unable to retrieve loadbalancer %s' % lb_id)
            self._svc_manager.logger.error(msg)
            return

        driver_data = self.db.loadbalancer_driver_info_get(lb_id)
        if driver_data:
            if 'lb_instance_ips' in driver_data:
                lb.instance_ips = driver_data['lb_instance_ips']
            if 'lb_floating_ips' in driver_data:
                lb.floating_ips = driver_data['lb_floating_ips']

        vmi = VirtualMachineInterfaceSM.get(lb.virtual_machine_interface)
        if vmi is None:
            return

        if set(lb.instance_ips) == vmi.instance_ips and \
                set(lb.floating_ips) == vmi.floating_ips:
            return

        old_instance_ips = []
        new_instance_ips = []
        if set(lb.instance_ips) != vmi.instance_ips:
            for iip_id in lb.instance_ips or []:
                if iip_id not in vmi.instance_ips:
                    old_instance_ips.append(iip_id)

            for iip_id in vmi.instance_ips or []:
                if iip_id not in lb.instance_ips:
                    new_instance_ips.append(iip_id)

        old_floating_ips = []
        new_floating_ips = []
        if set(lb.floating_ips) != vmi.floating_ips:
            for fip_id in lb.floating_ips or []:
                if fip_id not in vmi.floating_ips:
                    old_floating_ips.append(fip_id)

            for fip_id in vmi.floating_ips or []:
                if fip_id not in lb.floating_ips:
                    new_floating_ips.append(fip_id)

        for iip_id in old_instance_ips or []:
            fip = self._get_floating_ip(vmi, iip_id=iip_id)
            if fip:
                fip.set_virtual_machine_interface_list([])
                self._api.floating_ip_update(fip)
                self._api.floating_ip_delete(id=fip.uuid)

        for fip_id in old_floating_ips or []:
            fip = self._get_floating_ip(fip_id=fip_id)
            if fip:
                fip.set_virtual_machine_interface_list([])
                fip.set_floating_ip_port_mappings([])
                fip.floating_ip_port_mappings_enable = False
                fip.floating_ip_traffic_direction = "both"
                self._api.floating_ip_update(fip)

        if len(new_instance_ips):
            for iip_id in new_instance_ips:
                iip = self._api.instance_ip_read(id=iip_id)
                fq_name = str(uuid.uuid4())
                fip = FloatingIp(name=fq_name,
                                 parent_obj=iip,
                                 floating_ip_address=iip.instance_ip_address)
                fip.uuid = fq_name
                fip.floating_ip_traffic_direction = "ingress"
                self._api.floating_ip_create(fip)

        if len(new_floating_ips):
            for fip_id in new_floating_ips:
                fip = self._get_floating_ip(fip_id=fip_id)
                fip.floating_ip_traffic_direction = "ingress"
                self._api.floating_ip_update(fip)

        lb_props = {}
        lb_props['old_instance_ips'] = old_instance_ips
        lb_props['old_floating_ips'] = old_floating_ips
        lb_props['new_instance_ips'] = new_instance_ips
        lb_props['new_floating_ips'] = new_floating_ips

        self._update_pool_member_props(lb, lb_props)

        lb.instance_ips = vmi.instance_ips
        lb.floating_ips = vmi.floating_ips

        driver_data = {}
        driver_data['vmi'] = vmi.uuid
        driver_data['lb_instance_ips'] = list(lb.instance_ips)
        driver_data['lb_floating_ips'] = list(lb.floating_ips)

        self.db.loadbalancer_driver_info_insert(lb_id, driver_data)
Beispiel #4
0
    def _update_loadbalancer_props(self, lb_id):
        lb = LoadbalancerSM.get(lb_id)
        if lb is None:
            msg = ('Unable to retrieve loadbalancer %s' % lb_id)
            self._svc_manager.logger.error(msg)
            return

        driver_data = self.db.loadbalancer_driver_info_get(lb_id)
        if driver_data:
            if 'lb_instance_ips' in driver_data:
                lb.instance_ips = driver_data['lb_instance_ips']
            if 'lb_floating_ips' in driver_data:
                lb.floating_ips = driver_data['lb_floating_ips']

        vmi = VirtualMachineInterfaceSM.get(lb.virtual_machine_interface)
        if vmi is None:
            return

        if set(lb.instance_ips) == vmi.instance_ips and \
                set(lb.floating_ips) == vmi.floating_ips:
            return

        old_instance_ips = []
        new_instance_ips = []
        instance_ips_changed = False
        if set(lb.instance_ips) != vmi.instance_ips:
            instance_ips_changed = True
            for iip_id in lb.instance_ips or []:
                if iip_id not in vmi.instance_ips:
                    old_instance_ips.append(iip_id)

            for iip_id in vmi.instance_ips or []:
                if iip_id not in lb.instance_ips:
                    new_instance_ips.append(iip_id)

        if len(new_instance_ips):
            for iip_id in new_instance_ips:
                iip = self._api.instance_ip_read(id=iip_id)
                fq_name = str(uuid.uuid4())
                fip = FloatingIp(name=fq_name,
                                 parent_obj=iip,
                                 floating_ip_address=iip.instance_ip_address)
                fip.uuid = fq_name
                self._api.floating_ip_create(fip)

        old_floating_ips = []
        new_floating_ips = []
        floating_ips_changed = False
        if set(lb.floating_ips) != vmi.floating_ips:
            floating_ips_changed = True
            for fip_id in lb.floating_ips or []:
                if fip_id not in vmi.floating_ips:
                    old_floating_ips.append(fip_id)

            for fip_id in vmi.floating_ips or []:
                if fip_id not in lb.floating_ips:
                    new_floating_ips.append(fip_id)

        lb_props = {}
        lb_props['old_instance_ips'] = old_instance_ips
        lb_props['new_instance_ips'] = new_instance_ips
        lb_props['old_floating_ips'] = old_floating_ips
        lb_props['new_floating_ips'] = new_floating_ips

        self._update_pool_member_props(lb, lb_props)

        for iip_id in lb_props['old_instance_ips'] or []:
            fip = self._get_floating_ip(vmi, iip_id=iip_id)
            if fip:
                self._api.floating_ip_delete(id=fip['uuid'])

        if instance_ips_changed == True:
            lb.instance_ips = new_instance_ips
        if floating_ips_changed == True:
            lb.floating_ips = new_floating_ips

        driver_data = {}
        driver_data['lb_instance_ips'] = lb.instance_ips
        driver_data['lb_floating_ips'] = lb.floating_ips

        self.db.loadbalancer_driver_info_insert(lb_id, driver_data)
    def _update_loadbalancer_props(self, lb_id):
        lb = LoadbalancerSM.get(lb_id)
        if lb is None:
            msg = ('Unable to retrieve loadbalancer %s' % lb_id)
            self._svc_manager.logger.error(msg)
            return

        driver_data = self.db.loadbalancer_driver_info_get(lb_id)
        if driver_data:
            if 'lb_instance_ips' in driver_data:
                lb.instance_ips = driver_data['lb_instance_ips']
            if 'lb_floating_ips' in driver_data:
                lb.floating_ips = driver_data['lb_floating_ips']

        vmi = VirtualMachineInterfaceSM.get(lb.virtual_machine_interface)
        if vmi is None:
            return

        if set(lb.instance_ips) == vmi.instance_ips and \
                set(lb.floating_ips) == vmi.floating_ips:
            return

        old_instance_ips = []
        new_instance_ips = []
        if set(lb.instance_ips) != vmi.instance_ips:
            for iip_id in lb.instance_ips or []:
                if iip_id not in vmi.instance_ips:
                    old_instance_ips.append(iip_id)

            for iip_id in vmi.instance_ips or []:
                if iip_id not in lb.instance_ips:
                    new_instance_ips.append(iip_id)

        old_floating_ips = []
        new_floating_ips = []
        if set(lb.floating_ips) != vmi.floating_ips:
            for fip_id in lb.floating_ips or []:
                if fip_id not in vmi.floating_ips:
                    old_floating_ips.append(fip_id)

            for fip_id in vmi.floating_ips or []:
                if fip_id not in lb.floating_ips:
                    new_floating_ips.append(fip_id)

        for iip_id in old_instance_ips or []:
            fip = self._get_floating_ip(vmi, iip_id=iip_id)
            if fip:
                fip.set_virtual_machine_interface_list([])
                self._api.floating_ip_update(fip)
                self._api.floating_ip_delete(id=fip.uuid)

        for fip_id in old_floating_ips or []:
            fip = self._get_floating_ip(fip_id=fip_id)
            if fip:
                fip.set_virtual_machine_interface_list([])
                fip.set_floating_ip_port_mappings([])
                fip.floating_ip_port_mappings_enable = False
                fip.floating_ip_traffic_direction = "both"
                self._api.floating_ip_update(fip)

        if len(new_instance_ips):
            proj_obj = None
            if vmi.parent_type == 'project':
                proj_obj = self._api.project_read(id=vmi.parent_key)
            for iip_id in new_instance_ips:
                iip = self._api.instance_ip_read(id=iip_id)
                fq_name = str(uuid.uuid4())
                fip = FloatingIp(name=fq_name, parent_obj=iip,
                             floating_ip_address=iip.instance_ip_address)
                fip.uuid = fq_name
                fip.floating_ip_traffic_direction = "ingress"
                if proj_obj:
                    fip.add_project(proj_obj)
                self._api.floating_ip_create(fip)

        if len(new_floating_ips):
            for fip_id in new_floating_ips:
                fip = self._get_floating_ip(fip_id=fip_id)
                fip.floating_ip_traffic_direction = "ingress"
                fip.floating_ip_fixed_ip_address = None
                self._api.floating_ip_update(fip)

        lb_props = {}
        lb_props['old_instance_ips'] = old_instance_ips
        lb_props['old_floating_ips'] = old_floating_ips
        lb_props['new_instance_ips'] = new_instance_ips
        lb_props['new_floating_ips'] = new_floating_ips

        self._update_pool_member_props(lb, lb_props)

        lb.instance_ips = vmi.instance_ips
        lb.floating_ips = vmi.floating_ips

        driver_data = {}
        driver_data['vmi'] = vmi.uuid
        driver_data['lb_instance_ips'] = list(lb.instance_ips)
        driver_data['lb_floating_ips'] = list(lb.floating_ips)

        self.db.loadbalancer_driver_info_insert(lb_id, driver_data)
Beispiel #6
0
    def _update_loadbalancer_props(self, lb_id):
        lb = LoadbalancerSM.get(lb_id)
        if lb is None:
            msg = ('Unable to retrieve loadbalancer %s' % lb_id)
            self._svc_manager.logger.error(msg)
            return

        driver_data = self.db.loadbalancer_driver_info_get(lb_id)
        if driver_data:
            if 'lb_instance_ips' in driver_data:
                lb.instance_ips = driver_data['lb_instance_ips']
            if 'lb_floating_ips' in driver_data:
                lb.floating_ips = driver_data['lb_floating_ips']

        vmi = VirtualMachineInterfaceSM.get(lb.virtual_machine_interface)
        if vmi is None:
            return

        if set(lb.instance_ips) == vmi.instance_ips and \
                set(lb.floating_ips) == vmi.floating_ips:
            return

        old_instance_ips = []
        new_instance_ips = []
        instance_ips_changed = False
        if set(lb.instance_ips) != vmi.instance_ips:
            instance_ips_changed = True
            for iip_id in lb.instance_ips or []:
                if iip_id not in vmi.instance_ips:
                    old_instance_ips.append(iip_id)

            for iip_id in vmi.instance_ips or []:
                if iip_id not in lb.instance_ips:
                    new_instance_ips.append(iip_id)

        if len(new_instance_ips):
            for iip_id in new_instance_ips:
                iip = self._api.instance_ip_read(id=iip_id)
                fq_name = str(uuid.uuid4())
                fip = FloatingIp(name=fq_name, parent_obj=iip,
                             floating_ip_address=iip.instance_ip_address)
                fip.uuid = fq_name
                self._api.floating_ip_create(fip)

        old_floating_ips = []
        new_floating_ips = []
        floating_ips_changed = False
        if set(lb.floating_ips) != vmi.floating_ips:
            floating_ips_changed = True
            for fip_id in lb.floating_ips or []:
                if fip_id not in vmi.floating_ips:
                    old_floating_ips.append(fip_id)

            for fip_id in vmi.floating_ips or []:
                if fip_id not in lb.floating_ips:
                    new_floating_ips.append(fip_id)

        lb_props = {}
        lb_props['old_instance_ips'] = old_instance_ips
        lb_props['new_instance_ips'] = new_instance_ips
        lb_props['old_floating_ips'] = old_floating_ips
        lb_props['new_floating_ips'] = new_floating_ips

        self._update_pool_member_props(lb, lb_props)

        for iip_id in lb_props['old_instance_ips'] or []:
            fip = self._get_floating_ip(vmi, iip_id=iip_id)
            if fip:
                self._api.floating_ip_delete(id=fip['uuid'])

        if instance_ips_changed == True:
            lb.instance_ips = new_instance_ips
        if floating_ips_changed == True:
            lb.floating_ips = new_floating_ips

        driver_data = {}
        driver_data['lb_instance_ips'] = lb.instance_ips
        driver_data['lb_floating_ips'] = lb.floating_ips

        self.db.loadbalancer_driver_info_insert(lb_id, driver_data)