def create_security_group(self, context, security_group, default_sg=False):
        """Create security group.

        Create a new security group, including the default security group.
        In MidoNet, this means creating a pair of chains, inbound and outbound,
        as well as a new port group.
        """
        LOG.info(_LI("MidonetMixin.create_security_group called: "
                     "security_group=%(security_group)s "
                     "default_sg=%(default_sg)s "),
                 {'security_group': security_group, 'default_sg': default_sg})

        sg = security_group.get('security_group')
        tenant_id = self._get_tenant_id_for_create(context, sg)
        if not default_sg:
            self._ensure_default_security_group(context, tenant_id)

        # Create the Neutron sg first
        sg = super(MidonetMixin, self).create_security_group(
            context, security_group, default_sg)
        task.create_task(context, task.CREATE, data_type_id=task.SECURITYGROUP,
                         resource_id=sg['id'], data=sg)

        try:
            # Process the MidoNet side
            self.api_cli.create_security_group(sg)
        except Exception:
            LOG.error(_LE("Failed to create MidoNet resources for sg %(sg)r"),
                      {"sg": sg})
            with excutils.save_and_reraise_exception():
                super(MidonetMixin, self).delete_security_group(context,
                                                                sg['id'])

        LOG.info(_LI("MidonetMixin.create_security_group exiting: sg=%r"), sg)
        return sg
예제 #2
0
    def create_router(self, context, router):
        """Handle router creation.

        When a new Neutron router is created, its corresponding MidoNet router
        is also created.  In MidoNet, this router is initialized with chains
        for inbound and outbound traffic, which will be used to hold other
        chains that include various rules, such as NAT.

        :param router: Router information provided to create a new router.
        """
        LOG.info(_LI("MidonetMixin.create_router called: router=%(router)s"),
                 {"router": router})
        r = super(MidonetMixin, self).create_router(context, router)
        task.create_task(context,
                         task.CREATE,
                         data_type=task.ROUTER,
                         resource_id=r['id'],
                         data=r)

        try:
            self.api_cli.create_router(r)
        except Exception as ex:
            LOG.error(
                _LE("Failed to create a router %(r_id)s in Midonet:"
                    "%(err)s"), {
                        "r_id": r["id"],
                        "err": ex
                    })
            with excutils.save_and_reraise_exception():
                super(MidonetMixin, self).delete_router(context, r['id'])

        LOG.info(
            _LI("MidonetMixin.create_router exiting: "
                "router=%(router)s."), {"router": r})
        return r
예제 #3
0
    def _process_create_port(self, context, port):
        """Create a L2 port in Neutron/MidoNet."""
        port_data = port['port']
        with context.session.begin(subtransactions=True):
            # Create a Neutron port
            new_port = super(MidonetMixin, self).create_port(context, port)
            task.create_task(context,
                             task.CREATE,
                             data_type=task.PORT,
                             resource_id=new_port['id'],
                             data=new_port)

            # Make sure that the port created is valid
            if "id" not in new_port:
                raise n_exc.BadRequest(resource='port',
                                       msg="Invalid port created")

            # Update fields
            port_data.update(new_port)

            # Bind security groups to the port
            self._ensure_default_security_group_on_port(context, port)
            sg_ids = self._get_security_groups_on_port(context, port)
            self._process_port_create_security_group(context, new_port, sg_ids)

            self._process_portbindings_create_and_update(
                context, port_data, new_port)

        return new_port
예제 #4
0
    def update_port(self, context, id, port):
        """Handle port update, including security groups and fixed IPs."""
        LOG.info(
            _LI("MidonetMixin.update_port called: id=%(id)s "
                "port=%(port)r"), {
                    'id': id,
                    'port': port
                })
        with context.session.begin(subtransactions=True):

            # update the port DB
            p = super(MidonetMixin, self).update_port(context, id, port)
            task.create_task(context,
                             task.UPDATE,
                             data_type=task.PORT,
                             resource_id=id,
                             data=p)

            self._process_port_update(context, id, port, p)
            self._process_portbindings_create_and_update(
                context, port['port'], p)
            self.api_cli.update_port(id, p)

        LOG.info(_LI("MidonetMixin.update_port exiting: p=%r"), p)
        return p
    def create_router(self, context, router):
        """Handle router creation.

        When a new Neutron router is created, its corresponding MidoNet router
        is also created.  In MidoNet, this router is initialized with chains
        for inbound and outbound traffic, which will be used to hold other
        chains that include various rules, such as NAT.

        :param router: Router information provided to create a new router.
        """
        LOG.info(_LI("MidonetMixin.create_router called: router=%(router)s"),
                 {"router": router})
        r = super(MidonetMixin, self).create_router(context, router)
        task.create_task(context, task.CREATE, data_type_id=task.ROUTER,
                         resource_id=r['id'], data=r)

        try:
            self.api_cli.create_router(r)
        except Exception as ex:
            LOG.error(_LE("Failed to create a router %(r_id)s in Midonet:"
                          "%(err)s"), {"r_id": r["id"], "err": ex})
            with excutils.save_and_reraise_exception():
                super(MidonetMixin, self).delete_router(context, r['id'])

        LOG.info(_LI("MidonetMixin.create_router exiting: "
                     "router=%(router)s."), {"router": r})
        return r
    def create_security_group_rule(self, context, security_group_rule):
        """Create a security group rule

        Create a security group rule in the Neutron DB and corresponding
        MidoNet resources in its data store.
        """
        LOG.info(_LI("MidonetMixin.create_security_group_rule called: "
                     "security_group_rule=%(security_group_rule)r"),
                 {'security_group_rule': security_group_rule})

        rule = super(MidonetMixin, self).create_security_group_rule(
            context, security_group_rule)
        task.create_task(context, task.CREATE,
                         data_type_id=task.SECURITYGROUPRULE,
                         resource_id=rule['id'], data=rule)

        try:
            self.api_cli.create_security_group_rule(rule)
        except Exception as ex:
            LOG.error(_LE('Failed to create security group rule %(sg)s,'
                      'error: %(err)s'), {'sg': rule, 'err': ex})
            with excutils.save_and_reraise_exception():
                super(MidonetMixin, self).delete_security_group_rule(
                    context, rule['id'])

        LOG.info(_LI("MidonetMixin.create_security_group_rule exiting: "
                     "rule=%r"), rule)
        return rule
예제 #7
0
    def create_subnet(self, context, subnet):
        """Create Neutron subnet.

        Creates a Neutron subnet and a DHCP entry in MidoNet bridge.
        """
        LOG.info(_LI("MidonetMixin.create_subnet called: subnet=%r"), subnet)

        sn_entry = super(MidonetMixin, self).create_subnet(context, subnet)
        task.create_task(context,
                         task.CREATE,
                         data_type=task.SUBNET,
                         resource_id=sn_entry['id'],
                         data=sn_entry)

        try:
            self.api_cli.create_subnet(sn_entry)
        except Exception as ex:
            LOG.error(
                _LE("Failed to create a subnet %(s_id)s in Midonet:"
                    "%(err)s"), {
                        "s_id": sn_entry["id"],
                        "err": ex
                    })
            with excutils.save_and_reraise_exception():
                super(MidonetMixin,
                      self).delete_subnet(context, sn_entry['id'])

        LOG.info(_LI("MidonetMixin.create_subnet exiting: sn_entry=%r"),
                 sn_entry)
        return sn_entry
예제 #8
0
    def create_floatingip(self, context, floatingip):
        """Handle floating IP creation."""
        LOG.info(_LI("MidonetMixin.create_floatingip called: ip=%r"),
                 floatingip)

        fip = super(MidonetMixin, self).create_floatingip(context, floatingip)
        task.create_task(context,
                         task.CREATE,
                         data_type=task.FLOATING_IP,
                         resource_id=fip['id'],
                         data=fip)

        try:
            self.api_cli.create_floating_ip(fip)
        except Exception as ex:
            LOG.error(_LE("Failed to create floating ip %(fip)s: %(err)s"), {
                "fip": fip,
                "err": ex
            })
            with excutils.save_and_reraise_exception():
                # Try removing the fip
                self.delete_floatingip(context, fip['id'])

        LOG.info(_LI("MidonetMixin.create_floatingip exiting: fip=%r"), fip)
        return fip
예제 #9
0
    def update_network(self, context, id, network):
        """Update Neutron network.

        Update an existing Neutron network and its corresponding MidoNet
        bridge.
        """
        LOG.info(
            _LI("MidonetMixin.update_network called: id=%(id)r, "
                "network=%(network)r"), {
                    'id': id,
                    'network': network
                })

        with context.session.begin(subtransactions=True):
            net = super(MidonetMixin,
                        self).update_network(context, id, network)
            task.create_task(context,
                             task.UPDATE,
                             data_type=task.NETWORK,
                             resource_id=id,
                             data=net)

            self._process_l3_update(context, net, network['network'])
            self.api_cli.update_network(id, net)

        LOG.info(_LI("MidonetMixin.update_network exiting: net=%r"), net)
        return net
    def _process_create_port(self, context, port):
        """Create a L2 port in Neutron/MidoNet."""
        port_data = port['port']
        with context.session.begin(subtransactions=True):
            # Create a Neutron port
            new_port = super(MidonetMixin, self).create_port(context, port)
            task.create_task(context, task.CREATE, data_type_id=task.PORT,
                             resource_id=new_port['id'], data=new_port)

            # Make sure that the port created is valid
            if "id" not in new_port:
                raise n_exc.BadRequest(resource='port',
                                       msg="Invalid port created")

            # Update fields
            port_data.update(new_port)

            # Bind security groups to the port
            self._ensure_default_security_group_on_port(context, port)
            sg_ids = self._get_security_groups_on_port(context, port)
            self._process_port_create_security_group(context, new_port, sg_ids)

            self._process_portbindings_create_and_update(context, port_data,
                                                         new_port)

        return new_port
예제 #11
0
    def update_floatingip(self, context, id, floatingip):
        """Handle floating IP association and disassociation."""
        LOG.info(
            _LI("MidonetMixin.update_floatingip called: id=%(id)s "
                "floatingip=%(floatingip)s "), {
                    'id': id,
                    'floatingip': floatingip
                })

        with context.session.begin(subtransactions=True):
            fip = super(MidonetMixin,
                        self).update_floatingip(context, id, floatingip)
            task.create_task(context,
                             task.UPDATE,
                             data_type=task.FLOATING_IP,
                             resource_id=id,
                             data=fip)

            # Update status based on association
            if fip.get('port_id') is None:
                fip['status'] = n_const.FLOATINGIP_STATUS_DOWN
            else:
                fip['status'] = n_const.FLOATINGIP_STATUS_ACTIVE
            self.update_floatingip_status(context, id, fip['status'])

            self.api_cli.update_floating_ip(id, fip)

        LOG.info(_LI("MidonetMixin.update_floating_ip exiting: fip=%s"), fip)
        return fip
예제 #12
0
    def update_health_monitor(self, context, id, health_monitor):
        LOG.debug(
            "MidonetMixin.update_health_monitor called: id=%(id)r, "
            "health_monitor=%(health_monitor)r", {
                'id': id,
                'health_monitor': health_monitor
            })

        with context.session.begin(subtransactions=True):
            hm = super(MidonetMixin,
                       self).update_health_monitor(context, id, health_monitor)
            task.create_task(context,
                             task.UPDATE,
                             data_type=task.HEALTH_MONITOR,
                             resource_id=id,
                             data=hm)
            self.api_cli.update_health_monitor(id, hm)

        LOG.debug(
            "MidonetMixin.update_health_monitor exiting: id=%(id)r, "
            "health_monitor=%(health_monitor)r", {
                'id': id,
                'health_monitor': hm
            })
        return hm
    def delete_floatingip(self, context, id):
        """Handle floating IP deletion."""
        LOG.info(_LI("MidonetMixin.delete_floatingip called: id=%s"), id)

        with context.session.begin(subtransactions=True):
            super(MidonetMixin, self).delete_floatingip(context, id)
            task.create_task(context, task.DELETE,
                             data_type_id=task.FLOATINGIP, resource_id=id)
            self.api_cli.delete_floating_ip(id)

        LOG.info(_LI("MidonetMixin.delete_floatingip exiting: id=%r"), id)
    def delete_pool(self, context, id):
        LOG.debug("MidonetMixin.delete_pool called: %(id)r", {'id': id})

        with context.session.begin(subtransactions=True):
            self._delete_resource_router_id_binding(context, id,
                                                    loadbalancer_db.Pool)
            super(MidonetMixin, self).delete_pool(context, id)
            task.create_task(context, task.DELETE, data_type_id=task.POOL,
                             resource_id=id)
            self.api_cli.delete_pool(id)

        LOG.debug("MidonetMixin.delete_pool exiting: %(id)r", {'id': id})
    def update_subnet(self, context, id, subnet):
        """Update the subnet with new info.
        """
        LOG.info(_LI("MidonetMixin.update_subnet called: id=%s"), id)

        with context.session.begin(subtransactions=True):
            s = super(MidonetMixin, self).update_subnet(context, id, subnet)
            task.create_task(context, task.UPDATE, data_type_id=task.SUBNET,
                             resource_id=id, data=s)
            self.api_cli.update_subnet(id, s)

        return s
    def delete_health_monitor(self, context, id):
        LOG.debug("MidonetMixin.delete_health_monitor called: %(id)r",
                  {'id': id})

        with context.session.begin(subtransactions=True):
            super(MidonetMixin, self).delete_health_monitor(context, id)
            task.create_task(context, task.DELETE,
                             data_type_id=task.HEALTHMONITOR, resource_id=id)
            self.api_cli.delete_health_monitor(id)

        LOG.debug("MidonetMixin.delete_health_monitor exiting: %(id)r",
                  {'id': id})
    def delete_vip(self, context, id):
        LOG.debug("MidonetMixin.delete_vip called: id=%(id)r",
                  {'id': id})

        with context.session.begin(subtransactions=True):
            super(MidonetMixin, self).delete_vip(context, id)
            task.create_task(context, task.DELETE, data_type_id=task.VIP,
                             resource_id=id)
            self.api_cli.delete_vip(id)

        LOG.debug("MidonetMixin.delete_vip existing: id=%(id)r",
                  {'id': id})
    def update_router(self, context, id, router):
        """Handle router updates."""
        LOG.info(_LI("MidonetMixin.update_router called: id=%(id)s "
                     "router=%(router)r"), {"id": id, "router": router})

        with context.session.begin(subtransactions=True):
            r = super(MidonetMixin, self).update_router(context, id, router)
            task.create_task(context, task.UPDATE, data_type_id=task.ROUTER,
                             resource_id=id, data=r)
            self.api_cli.update_router(id, r)

        LOG.info(_LI("MidonetMixin.update_router exiting: router=%r"), r)
        return r
    def _process_port_delete(self, context, id):
        """Delete the Neutron and MidoNet ports

        This method is wrapped by 'retry_on_error' decorator.  See the
        explanation in the 'delete_network' comment.
        """
        with context.session.begin(subtransactions=True):
            super(MidonetMixin, self).disassociate_floatingips(
                context, id, do_notify=False)
            super(MidonetMixin, self).delete_port(context, id)
            task.create_task(context, task.DELETE, data_type_id=task.PORT,
                             resource_id=id)
            self.api_cli.delete_port(id)
예제 #20
0
    def delete_floatingip(self, context, id):
        """Handle floating IP deletion."""
        LOG.info(_LI("MidonetMixin.delete_floatingip called: id=%s"), id)

        with context.session.begin(subtransactions=True):
            super(MidonetMixin, self).delete_floatingip(context, id)
            task.create_task(context,
                             task.DELETE,
                             data_type=task.FLOATING_IP,
                             resource_id=id)
            self.api_cli.delete_floating_ip(id)

        LOG.info(_LI("MidonetMixin.delete_floatingip exiting: id=%r"), id)
    def update_vip(self, context, id, vip):
        LOG.debug("MidonetMixin.update_vip called: id=%(id)r, "
                  "vip=%(vip)r", {'id': id, 'vip': vip})

        with context.session.begin(subtransactions=True):
            v = super(MidonetMixin, self).update_vip(context, id, vip)
            task.create_task(context, task.UPDATE, data_type_id=task.VIP,
                             resource_id=id, data=v)
            self.api_cli.update_vip(id, v)

        LOG.debug("MidonetMixin.update_vip exiting: id=%(id)r, "
                  "vip=%(vip)r", {'id': id, 'vip': v})
        return v
    def update_member(self, context, id, member):
        LOG.debug("MidonetMixin.update_member called: id=%(id)r, "
                  "member=%(member)r", {'id': id, 'member': member})

        with context.session.begin(subtransactions=True):
            m = super(MidonetMixin, self).update_member(context, id, member)
            task.create_task(context, task.UPDATE, data_type_id=task.MEMBER,
                             resource_id=id, data=m)
            self.api_cli.update_member(id, m)

        LOG.debug("MidonetMixin.update_member exiting: id=%(id)r, "
                  "member=%(member)r", {'id': id, 'member': m})
        return m
    def update_pool(self, context, id, pool):
        LOG.debug("MidonetMixin.update_pool called: id=%(id)r, "
                  "pool=%(pool)r", {'id': id, 'pool': pool})

        with context.session.begin(subtransactions=True):
            p = super(MidonetMixin, self).update_pool(context, id, pool)
            task.create_task(context, task.UPDATE, data_type_id=task.POOL,
                             resource_id=id, data=p)
            self.api_cli.update_pool(id, p)

        LOG.debug("MidonetMixin.update_pool exiting: id=%(id)r, "
                  "pool=%(pool)r", {'id': id, 'pool': pool})
        return p
    def _process_create_network(self, context, network):

        net_data = network['network']
        tenant_id = self._get_tenant_id_for_create(context, net_data)
        net_data['tenant_id'] = tenant_id
        self._ensure_default_security_group(context, tenant_id)

        with context.session.begin(subtransactions=True):
            net = super(MidonetMixin, self).create_network(context, network)
            task.create_task(context, task.CREATE, data_type_id=task.NETWORK,
                             resource_id=net['id'], data=net)
            self._process_l3_create(context, net, net_data)

        return net
    def delete_subnet(self, context, id):
        """Delete Neutron subnet.

        Delete neutron network and its corresponding MidoNet bridge.
        """
        LOG.info(_LI("MidonetMixin.delete_subnet called: id=%s"), id)

        with context.session.begin(subtransactions=True):
            super(MidonetMixin, self).delete_subnet(context, id)
            task.create_task(context, task.DELETE, data_type_id=task.SUBNET,
                             resource_id=id)
            self.api_cli.delete_subnet(id)

        LOG.info(_LI("MidonetMixin.delete_subnet exiting"))
    def create_health_monitor(self, context, health_monitor):
        LOG.debug("MidonetMixin.create_health_monitor called: "
                  " %(health_monitor)r", {'health_monitor': health_monitor})

        with context.session.begin(subtransactions=True):
            hm = super(MidonetMixin, self).create_health_monitor(
                context, health_monitor)
            task.create_task(context, task.CREATE,
                             data_type_id=task.HEALTHMONITOR,
                             resource_id=hm['id'], data=hm)
            self.api_cli.create_health_monitor(hm)

        LOG.debug("MidonetMixin.create_health_monitor exiting: "
                  "%(health_monitor)r", {'health_monitor': hm})
        return hm
예제 #27
0
    def update_subnet(self, context, id, subnet):
        """Update the subnet with new info.
        """
        LOG.info(_LI("MidonetMixin.update_subnet called: id=%s"), id)

        with context.session.begin(subtransactions=True):
            s = super(MidonetMixin, self).update_subnet(context, id, subnet)
            task.create_task(context,
                             task.UPDATE,
                             data_type=task.SUBNET,
                             resource_id=id,
                             data=s)
            self.api_cli.update_subnet(id, s)

        return s
    def create_member(self, context, member):
        LOG.debug("MidonetMixin.create_member called: %(member)r",
                  {'member': member})

        with context.session.begin(subtransactions=True):
            m = super(MidonetMixin, self).create_member(context, member)
            task.create_task(context, task.CREATE, data_type_id=task.MEMBER,
                             resource_id=m['id'], data=m)
            self.api_cli.create_member(m)
            m['status'] = constants.ACTIVE
            self.update_status(context, loadbalancer_db.Member, m['id'],
                               m['status'])

        LOG.debug("MidonetMixin.create_member exiting: %(member)r",
                  {'member': m})
        return m
예제 #29
0
    def delete_subnet(self, context, id):
        """Delete Neutron subnet.

        Delete neutron network and its corresponding MidoNet bridge.
        """
        LOG.info(_LI("MidonetMixin.delete_subnet called: id=%s"), id)

        with context.session.begin(subtransactions=True):
            super(MidonetMixin, self).delete_subnet(context, id)
            task.create_task(context,
                             task.DELETE,
                             data_type=task.SUBNET,
                             resource_id=id)
            self.api_cli.delete_subnet(id)

        LOG.info(_LI("MidonetMixin.delete_subnet exiting"))
예제 #30
0
    def _process_port_delete(self, context, id):
        """Delete the Neutron and MidoNet ports

        This method is wrapped by 'retry_on_error' decorator.  See the
        explanation in the 'delete_network' comment.
        """
        with context.session.begin(subtransactions=True):
            super(MidonetMixin, self).disassociate_floatingips(context,
                                                               id,
                                                               do_notify=False)
            super(MidonetMixin, self).delete_port(context, id)
            task.create_task(context,
                             task.DELETE,
                             data_type=task.PORT,
                             resource_id=id)
            self.api_cli.delete_port(id)
    def update_health_monitor(self, context, id, health_monitor):
        LOG.debug("MidonetMixin.update_health_monitor called: id=%(id)r, "
                  "health_monitor=%(health_monitor)r",
                  {'id': id, 'health_monitor': health_monitor})

        with context.session.begin(subtransactions=True):
            hm = super(MidonetMixin, self).update_health_monitor(
                context, id, health_monitor)
            task.create_task(context, task.UPDATE,
                             data_type_id=task.HEALTHMONITOR,
                             resource_id=id, data=hm)
            self.api_cli.update_health_monitor(id, hm)

        LOG.debug("MidonetMixin.update_health_monitor exiting: id=%(id)r, "
                  "health_monitor=%(health_monitor)r",
                  {'id': id, 'health_monitor': hm})
        return hm
예제 #32
0
    def _process_create_network(self, context, network):

        net_data = network['network']
        tenant_id = self._get_tenant_id_for_create(context, net_data)
        net_data['tenant_id'] = tenant_id
        self._ensure_default_security_group(context, tenant_id)

        with context.session.begin(subtransactions=True):
            net = super(MidonetMixin, self).create_network(context, network)
            task.create_task(context,
                             task.CREATE,
                             data_type=task.NETWORK,
                             resource_id=net['id'],
                             data=net)
            self._process_l3_create(context, net, net_data)

        return net
    def delete_router(self, context, id):
        """Handler for router deletion.

        Deleting a router on Neutron simply means deleting its corresponding
        router in MidoNet.

        :param id: router ID to remove
        """
        LOG.info(_LI("MidonetMixin.delete_router called: id=%s"), id)

        with context.session.begin(subtransactions=True):
            super(MidonetMixin, self).delete_router(context, id)
            task.create_task(context, task.DELETE, data_type_id=task.ROUTER,
                             resource_id=id)
            self.api_cli.delete_router(id)

        LOG.info(_LI("MidonetMixin.delete_router exiting: id=%s"), id)
    def update_port(self, context, id, port):
        """Handle port update, including security groups and fixed IPs."""
        LOG.info(_LI("MidonetMixin.update_port called: id=%(id)s "
                     "port=%(port)r"), {'id': id, 'port': port})
        with context.session.begin(subtransactions=True):

            # update the port DB
            p = super(MidonetMixin, self).update_port(context, id, port)
            task.create_task(context, task.UPDATE, data_type_id=task.PORT,
                             resource_id=id, data=p)

            self._process_port_update(context, id, port, p)
            self._process_portbindings_create_and_update(context,
                                                         port['port'], p)
            self.api_cli.update_port(id, p)

        LOG.info(_LI("MidonetMixin.update_port exiting: p=%r"), p)
        return p
예제 #35
0
    def delete_router(self, context, id):
        """Handler for router deletion.

        Deleting a router on Neutron simply means deleting its corresponding
        router in MidoNet.

        :param id: router ID to remove
        """
        LOG.info(_LI("MidonetMixin.delete_router called: id=%s"), id)

        with context.session.begin(subtransactions=True):
            super(MidonetMixin, self).delete_router(context, id)
            task.create_task(context,
                             task.DELETE,
                             data_type=task.ROUTER,
                             resource_id=id)
            self.api_cli.delete_router(id)

        LOG.info(_LI("MidonetMixin.delete_router exiting: id=%s"), id)
예제 #36
0
    def create_health_monitor(self, context, health_monitor):
        LOG.debug(
            "MidonetMixin.create_health_monitor called: "
            " %(health_monitor)r", {'health_monitor': health_monitor})

        with context.session.begin(subtransactions=True):
            hm = super(MidonetMixin,
                       self).create_health_monitor(context, health_monitor)
            task.create_task(context,
                             task.CREATE,
                             data_type=task.HEALTH_MONITOR,
                             resource_id=hm['id'],
                             data=hm)
            self.api_cli.create_health_monitor(hm)

        LOG.debug(
            "MidonetMixin.create_health_monitor exiting: "
            "%(health_monitor)r", {'health_monitor': hm})
        return hm
    def delete_security_group(self, context, id):
        """Delete chains for Neutron security group."""
        LOG.info(_LI("MidonetMixin.delete_security_group called: id=%s"), id)

        sg = super(MidonetMixin, self).get_security_group(context, id)
        if not sg:
            raise ext_sg.SecurityGroupNotFound(id=id)

        if sg["name"] == 'default' and not context.is_admin:
            raise ext_sg.SecurityGroupCannotRemoveDefault()

        with context.session.begin(subtransactions=True):
            super(MidonetMixin, self).delete_security_group(context, id)
            task.create_task(context, task.DELETE,
                             data_type_id=task.SECURITYGROUP, resource_id=id)

            self.api_cli.delete_security_group(id)

        LOG.info(_LI("MidonetMixin.delete_security_group exiting: id=%r"), id)
    def delete_security_group_rule(self, context, sg_rule_id):
        """Delete a security group rule

        Delete a security group rule from the Neutron DB and corresponding
        MidoNet resources from its data store.
        """
        LOG.info(_LI("MidonetMixin.delete_security_group_rule called: "
                     "sg_rule_id=%s"), sg_rule_id)

        with context.session.begin(subtransactions=True):
            super(MidonetMixin, self).delete_security_group_rule(context,
                                                                 sg_rule_id)
            task.create_task(context, task.DELETE,
                             data_type_id=task.SECURITYGROUPRULE,
                             resource_id=sg_rule_id)
            self.api_cli.delete_security_group_rule(sg_rule_id)

        LOG.info(_LI("MidonetMixin.delete_security_group_rule exiting: "
                     "id=%r"), id)
    def create_vip(self, context, vip):
        LOG.debug("MidonetMixin.create_vip called: %(vip)r",
                  {'vip': vip})

        with context.session.begin(subtransactions=True):

            self._validate_vip_subnet(context, vip['vip']['subnet_id'],
                                      vip['vip']['pool_id'])

            v = super(MidonetMixin, self).create_vip(context, vip)
            task.create_task(context, task.CREATE, data_type_id=task.VIP,
                             resource_id=v['id'], data=v)
            self.api_cli.create_vip(v)
            v['status'] = constants.ACTIVE
            self.update_status(context, loadbalancer_db.Vip, v['id'],
                               v['status'])

        LOG.debug("MidonetMixin.create_vip exiting: id=%r", v['id'])
        return v
    def create_pool(self, context, pool):
        LOG.debug("MidonetMixin.create_pool called: %(pool)r",
                  {'pool': pool})

        subnet = db_util.get_subnet(context, pool['pool']['subnet_id'])
        if db_util.is_subnet_external(context, subnet):
            msg = _("pool subnet must not be public")
            raise n_exc.BadRequest(resource='subnet', msg=msg)

        router_id = db_util.get_router_from_subnet(context, subnet)

        if not router_id:
            msg = _("pool subnet must be associated with router")
            raise n_exc.BadRequest(resource='router', msg=msg)

        pool['pool'].update({'router_id': router_id})

        if self._get_resource_router_id_binding(context, loadbalancer_db.Pool,
                                                router_id=router_id):
            msg = _("A pool is already associated with the router")
            raise n_exc.BadRequest(resource='router', msg=msg)

        with context.session.begin(subtransactions=True):
            p = super(MidonetMixin, self).create_pool(context, pool)
            task.create_task(context, task.CREATE, data_type_id=task.POOL,
                             resource_id=p['id'], data=p)
            res = {
                'id': p['id'],
                rsi.ROUTER_ID: router_id
            }
            self._process_create_resource_router_id(context, res,
                                                    loadbalancer_db.Pool)
            p[rsi.ROUTER_ID] = router_id

            self.api_cli.create_pool(p)

            p['status'] = constants.ACTIVE
            self.update_status(context, loadbalancer_db.Pool, p['id'],
                               p['status'])

        LOG.debug("MidonetMixin.create_pool exiting: %(pool)r",
                  {'pool': p})
        return p
예제 #41
0
    def create_security_group(self, context, security_group, default_sg=False):
        """Create security group.

        Create a new security group, including the default security group.
        In MidoNet, this means creating a pair of chains, inbound and outbound,
        as well as a new port group.
        """
        LOG.info(
            _LI("MidonetMixin.create_security_group called: "
                "security_group=%(security_group)s "
                "default_sg=%(default_sg)s "), {
                    'security_group': security_group,
                    'default_sg': default_sg
                })

        sg = security_group.get('security_group')
        tenant_id = self._get_tenant_id_for_create(context, sg)
        if not default_sg:
            self._ensure_default_security_group(context, tenant_id)

        # Create the Neutron sg first
        sg = super(MidonetMixin,
                   self).create_security_group(context, security_group,
                                               default_sg)
        task.create_task(context,
                         task.CREATE,
                         data_type=task.SECURITY_GROUP,
                         resource_id=sg['id'],
                         data=sg)

        try:
            # Process the MidoNet side
            self.api_cli.create_security_group(sg)
        except Exception:
            LOG.error(_LE("Failed to create MidoNet resources for sg %(sg)r"),
                      {"sg": sg})
            with excutils.save_and_reraise_exception():
                super(MidonetMixin,
                      self).delete_security_group(context, sg['id'])

        LOG.info(_LI("MidonetMixin.create_security_group exiting: sg=%r"), sg)
        return sg
예제 #42
0
    def update_router(self, context, id, router):
        """Handle router updates."""
        LOG.info(
            _LI("MidonetMixin.update_router called: id=%(id)s "
                "router=%(router)r"), {
                    "id": id,
                    "router": router
                })

        with context.session.begin(subtransactions=True):
            r = super(MidonetMixin, self).update_router(context, id, router)
            task.create_task(context,
                             task.UPDATE,
                             data_type=task.ROUTER,
                             resource_id=id,
                             data=r)
            self.api_cli.update_router(id, r)

        LOG.info(_LI("MidonetMixin.update_router exiting: router=%r"), r)
        return r
    def update_network(self, context, id, network):
        """Update Neutron network.

        Update an existing Neutron network and its corresponding MidoNet
        bridge.
        """
        LOG.info(_LI("MidonetMixin.update_network called: id=%(id)r, "
                     "network=%(network)r"), {'id': id, 'network': network})

        with context.session.begin(subtransactions=True):
            net = super(MidonetMixin, self).update_network(
                context, id, network)
            task.create_task(context, task.UPDATE, data_type_id=task.NETWORK,
                             resource_id=id, data=net)

            self._process_l3_update(context, net, network['network'])
            self.api_cli.update_network(id, net)

        LOG.info(_LI("MidonetMixin.update_network exiting: net=%r"), net)
        return net
예제 #44
0
    def delete_security_group(self, context, id):
        """Delete chains for Neutron security group."""
        LOG.info(_LI("MidonetMixin.delete_security_group called: id=%s"), id)

        sg = super(MidonetMixin, self).get_security_group(context, id)
        if not sg:
            raise ext_sg.SecurityGroupNotFound(id=id)

        if sg["name"] == 'default' and not context.is_admin:
            raise ext_sg.SecurityGroupCannotRemoveDefault()

        with context.session.begin(subtransactions=True):
            super(MidonetMixin, self).delete_security_group(context, id)
            task.create_task(context,
                             task.DELETE,
                             data_type=task.SECURITY_GROUP,
                             resource_id=id)

            self.api_cli.delete_security_group(id)

        LOG.info(_LI("MidonetMixin.delete_security_group exiting: id=%r"), id)
    def delete_network(self, context, id):
        """Delete a network and its corresponding MidoNet bridge.

        This method is wrapped by 'retry_on_error' decorator because concurrent
        requests to the API server often causes DB deadlock error because
        eventlet green threads do not yield properly when they block inside
        the transaction.  This hack should no longer become available once
        we moved to the model where API requests are asynchronous or when
        eventlet-compatible mysqlconnector is used for the DB driver instead.
        """
        LOG.info(_LI("MidonetMixin.delete_network called: id=%r"), id)

        with context.session.begin(subtransactions=True):
            self._process_l3_delete(context, id)
            task.create_task(context, task.DELETE, data_type_id=task.NETWORK,
                             resource_id=id)
            super(MidonetMixin, self).delete_network(context, id)

            self.api_cli.delete_network(id)

        LOG.info(_LI("MidonetMixin.delete_network exiting: id=%r"), id)
    def create_floatingip(self, context, floatingip):
        """Handle floating IP creation."""
        LOG.info(_LI("MidonetMixin.create_floatingip called: ip=%r"),
                 floatingip)

        fip = super(MidonetMixin, self).create_floatingip(context,
                                                          floatingip)
        task.create_task(context, task.CREATE, data_type_id=task.FLOATINGIP,
                         resource_id=fip['id'], data=fip)

        try:
            self.api_cli.create_floating_ip(fip)
        except Exception as ex:
            LOG.error(_LE("Failed to create floating ip %(fip)s: %(err)s"),
                      {"fip": fip, "err": ex})
            with excutils.save_and_reraise_exception():
                # Try removing the fip
                self.delete_floatingip(context, fip['id'])

        LOG.info(_LI("MidonetMixin.create_floatingip exiting: fip=%r"),
                 fip)
        return fip
예제 #47
0
    def delete_network(self, context, id):
        """Delete a network and its corresponding MidoNet bridge.

        This method is wrapped by 'retry_on_error' decorator because concurrent
        requests to the API server often causes DB deadlock error because
        eventlet green threads do not yield properly when they block inside
        the transaction.  This hack should no longer become available once
        we moved to the model where API requests are asynchronous or when
        eventlet-compatible mysqlconnector is used for the DB driver instead.
        """
        LOG.info(_LI("MidonetMixin.delete_network called: id=%r"), id)

        with context.session.begin(subtransactions=True):
            self._process_l3_delete(context, id)
            task.create_task(context,
                             task.DELETE,
                             data_type=task.NETWORK,
                             resource_id=id)
            super(MidonetMixin, self).delete_network(context, id)

            self.api_cli.delete_network(id)

        LOG.info(_LI("MidonetMixin.delete_network exiting: id=%r"), id)
    def create_subnet(self, context, subnet):
        """Create Neutron subnet.

        Creates a Neutron subnet and a DHCP entry in MidoNet bridge.
        """
        LOG.info(_LI("MidonetMixin.create_subnet called: subnet=%r"), subnet)

        sn_entry = super(MidonetMixin, self).create_subnet(context, subnet)
        task.create_task(context, task.CREATE, data_type_id=task.SUBNET,
                         resource_id=sn_entry['id'], data=sn_entry)

        try:
            self.api_cli.create_subnet(sn_entry)
        except Exception as ex:
            LOG.error(_LE("Failed to create a subnet %(s_id)s in Midonet:"
                          "%(err)s"), {"s_id": sn_entry["id"], "err": ex})
            with excutils.save_and_reraise_exception():
                super(MidonetMixin, self).delete_subnet(context,
                                                        sn_entry['id'])

        LOG.info(_LI("MidonetMixin.create_subnet exiting: sn_entry=%r"),
                 sn_entry)
        return sn_entry
예제 #49
0
    def create_security_group_rule(self, context, security_group_rule):
        """Create a security group rule

        Create a security group rule in the Neutron DB and corresponding
        MidoNet resources in its data store.
        """
        LOG.info(
            _LI("MidonetMixin.create_security_group_rule called: "
                "security_group_rule=%(security_group_rule)r"),
            {'security_group_rule': security_group_rule})

        rule = super(MidonetMixin,
                     self).create_security_group_rule(context,
                                                      security_group_rule)
        task.create_task(context,
                         task.CREATE,
                         data_type=task.SECURITY_GROUP_RULE,
                         resource_id=rule['id'],
                         data=rule)

        try:
            self.api_cli.create_security_group_rule(rule)
        except Exception as ex:
            LOG.error(
                _LE('Failed to create security group rule %(sg)s,'
                    'error: %(err)s'), {
                        'sg': rule,
                        'err': ex
                    })
            with excutils.save_and_reraise_exception():
                super(MidonetMixin,
                      self).delete_security_group_rule(context, rule['id'])

        LOG.info(
            _LI("MidonetMixin.create_security_group_rule exiting: "
                "rule=%r"), rule)
        return rule
    def update_floatingip(self, context, id, floatingip):
        """Handle floating IP association and disassociation."""
        LOG.info(_LI("MidonetMixin.update_floatingip called: id=%(id)s "
                     "floatingip=%(floatingip)s "),
                 {'id': id, 'floatingip': floatingip})

        with context.session.begin(subtransactions=True):
            fip = super(MidonetMixin, self).update_floatingip(context, id,
                                                              floatingip)
            task.create_task(context, task.UPDATE,
                             data_type_id=task.FLOATINGIP, resource_id=id,
                             data=fip)

            # Update status based on association
            if fip.get('port_id') is None:
                fip['status'] = n_const.FLOATINGIP_STATUS_DOWN
            else:
                fip['status'] = n_const.FLOATINGIP_STATUS_ACTIVE
            self.update_floatingip_status(context, id, fip['status'])

            self.api_cli.update_floating_ip(id, fip)

        LOG.info(_LI("MidonetMixin.update_floating_ip exiting: fip=%s"), fip)
        return fip