Exemplo n.º 1
0
        def _allocate_floating_ip(lb, vmi, fip_pool, external_ip=None):
            fip_obj = FloatingIp(lb.name + str(external_ip) + "-externalIP",
                                 fip_pool)
            fip_obj.set_virtual_machine_interface(vmi_obj)
            if external_ip:
                if not (_check_ip_with_fip_pool(external_ip, fip_pool)):
                    err_str = "external_ip " + external_ip + " not in fip_pool subnet"
                    self.logger.error(err_str)
                    return None
                fip_obj.set_floating_ip_address(external_ip)
            project = self._vnc_lib.project_read(id=lb.parent_uuid)
            fip_obj.set_project(project)
            try:
                self._vnc_lib.floating_ip_create(fip_obj)
            except RefsExistError:
                string_buf = StringIO()
                cgitb_hook(file=string_buf, format="text")
                err_msg = string_buf.getvalue()
                self.logger.error("%s" % (err_msg))
            except Exception:
                string_buf = StringIO()
                cgitb_hook(file=string_buf, format="text")
                err_msg = string_buf.getvalue()
                self.logger.error("%s" % (err_msg))

            fip = FloatingIpKM.locate(fip_obj.uuid)
            self.logger.notice("floating ip allocated : %s for Service (%s)" %
                               (fip.address, service_id))
            return (fip.address)
Exemplo n.º 2
0
    def _get_floating_ip(self,
                         name,
                         ns_name,
                         proj_obj,
                         external_ip=None,
                         vmi_obj=None,
                         specified_fip_pool_fq_name_str=None):
        fip_pool_fq_name = None
        if specified_fip_pool_fq_name_str is not None:
            fip_pool_fq_name = get_fip_pool_fq_name_from_dict_string(
                specified_fip_pool_fq_name_str)
        if fip_pool_fq_name is None:
            ns = self._get_namespace(ns_name)
            fip_pool_fq_name = ns.get_annotated_ns_fip_pool_fq_name()
        if fip_pool_fq_name is None:
            if not vnc_kube_config.is_public_fip_pool_configured():
                return None
            try:
                fip_pool_fq_name = get_fip_pool_fq_name_from_dict_string(
                    self._args.public_fip_pool)
            except Exception:
                string_buf = StringIO()
                cgitb_hook(file=string_buf, format="text")
                err_msg = string_buf.getvalue()
                self._logger.error("%s - %s" % (self._name, err_msg))
                return None

        if vmi_obj:
            fip_refs = vmi_obj.get_floating_ip_back_refs()
            for ref in fip_refs or []:
                fip = FloatingIpKM.get(ref['uuid'])
                if fip and fip.fq_name[:-1] == fip_pool_fq_name:
                    return fip
                else:
                    break
        fip_pool = self._get_fip_pool_obj(fip_pool_fq_name)
        if fip_pool is None:
            return None
        fip_uuid = str(uuid.uuid4())
        fip_name = VncCommon.make_name(name, fip_uuid)
        fip_obj = FloatingIp(fip_name, fip_pool)
        fip_obj.uuid = fip_uuid
        fip_obj.set_project(proj_obj)
        if vmi_obj:
            fip_obj.set_virtual_machine_interface(vmi_obj)
        if external_ip:
            fip_obj.floating_ip_address = external_ip
        try:
            self._vnc_lib.floating_ip_create(fip_obj)
            fip = FloatingIpKM.locate(fip_obj.uuid)
        except Exception:
            string_buf = StringIO()
            cgitb_hook(file=string_buf, format="text")
            err_msg = string_buf.getvalue()
            self._logger.error("%s - %s" % (self._name, err_msg))
            return None
        return fip
Exemplo n.º 3
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
Exemplo n.º 4
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