コード例 #1
0
    def member(self,
               fmt=None,
               pool_id='pool1id',
               address='127.0.0.1',
               protocol_port=80,
               subnet=None,
               no_delete=False,
               **kwargs):
        if not fmt:
            fmt = self.fmt
        subnet = subnet or self.test_subnet
        with test_db_base_plugin_v2.optional_ctx(subnet,
                                                 self.subnet) as tmp_subnet:

            res = self._create_member(fmt,
                                      pool_id=pool_id,
                                      address=address,
                                      protocol_port=protocol_port,
                                      subnet_id=tmp_subnet['subnet']['id'],
                                      **kwargs)
            if res.status_int >= webob.exc.HTTPClientError.code:
                raise webob.exc.HTTPClientError(
                    explanation=_("Unexpected error code: %s") %
                    res.status_int)

            member = self.deserialize(fmt or self.fmt, res)
        yield member
        if not no_delete:
            self._delete('pools',
                         id=pool_id,
                         subresource='members',
                         sub_id=member['member']['id'])
コード例 #2
0
ファイル: util.py プロジェクト: openstack/neutron-lbaas
    def member(self, fmt=None, pool_id='pool1id', address='127.0.0.1',
               protocol_port=80, subnet=None, no_delete=False,
               **kwargs):
        if not fmt:
            fmt = self.fmt
        subnet = subnet or self.test_subnet
        with test_db_base_plugin_v2.optional_ctx(
                subnet, self.subnet) as tmp_subnet:

            res = self._create_member(fmt,
                                      pool_id=pool_id,
                                      address=address,
                                      protocol_port=protocol_port,
                                      subnet_id=tmp_subnet['subnet']['id'],
                                      **kwargs)
            if res.status_int >= webob.exc.HTTPClientError.code:
                raise webob.exc.HTTPClientError(
                    explanation=_("Unexpected error code: %s") % res.status_int
                )

            member = self.deserialize(fmt or self.fmt, res)
        yield member
        if not no_delete:
            self._delete('pools', id=pool_id, subresource='members',
                         sub_id=member['member']['id'])
コード例 #3
0
 def packet_filter_on_network(self, network=None, fmt=None, **kwargs):
     with test_db_plugin.optional_ctx(network,
                                      self.network) as network_to_use:
         net_id = network_to_use['network']['id']
         pf = self._make_packet_filter(fmt or self.fmt, net_id, **kwargs)
         yield pf
         if not network:
             self._delete('networks', network_to_use['network']['id'])
コード例 #4
0
 def port_with_binding_profile(self, host='host', if_name='if_name'):
     args = {portbindings.PROFILE: {'interface_name': if_name},
             portbindings.HOST_ID: host}
     with test_plugin.optional_ctx(None, self.subnet) as subnet_to_use:
         net_id = subnet_to_use['subnet']['network_id']
         port = self._make_port(self.fmt, net_id,
                                arg_list=(portbindings.PROFILE,
                                          portbindings.HOST_ID,), **args)
         yield port
コード例 #5
0
ファイル: util.py プロジェクト: openstack/neutron-lbaas
    def graph(self, fmt=None, subnet=None, no_delete=False, **kwargs):
        if not fmt:
            fmt = self.fmt

        with test_db_base_plugin_v2.optional_ctx(
                subnet, self.subnet) as tmp_subnet:

            res = self._create_graph(fmt, tmp_subnet['subnet']['id'],
                                     **kwargs)
            if res.status_int >= webob.exc.HTTPClientError.code:
                exc = webob.exc.HTTPClientError(
                    explanation=_("Unexpected error code: %s") %
                    res.status_int
                )
                exc.code = res.status_int
                exc.status_code = res.status_int
                raise exc
            graph = self.deserialize(fmt or self.fmt, res)
            yield graph
            if not no_delete:
                # delete loadbalancer children if this was a loadbalancer
                # graph create call
                lb = graph['graph']['loadbalancer']
                for listener in lb.get('listeners', []):
                    pool = listener.get('default_pool')
                    if pool:
                        hm = pool.get('healthmonitor')
                        if hm:
                            self._delete('healthmonitors', hm['id'])
                        members = pool.get('members', [])
                        for member in members:
                            self._delete('pools', pool['id'],
                                         subresource='members',
                                         sub_id=member['id'])
                        self._delete('pools', pool['id'])
                    policies = listener.get('l7policies', [])
                    for policy in policies:
                        r_pool = policy.get('redirect_pool')
                        if r_pool:
                            r_hm = r_pool.get('healthmonitor')
                            if r_hm:
                                self._delete('healthmonitors', r_hm['id'])
                            r_members = r_pool.get('members', [])
                            for r_member in r_members:
                                self._delete('pools', r_pool['id'],
                                             subresource='members',
                                             sub_id=r_member['id'])
                            self._delete('pools', r_pool['id'])
                        self._delete('l7policies', policy['id'])
                    self._delete('listeners', listener['id'])
                self._delete('loadbalancers', lb['id'])
コード例 #6
0
    def graph(self, fmt=None, subnet=None, no_delete=False, **kwargs):
        if not fmt:
            fmt = self.fmt

        with test_db_base_plugin_v2.optional_ctx(subnet,
                                                 self.subnet) as tmp_subnet:

            res = self._create_graph(fmt, tmp_subnet['subnet']['id'], **kwargs)
            if res.status_int >= webob.exc.HTTPClientError.code:
                exc = webob.exc.HTTPClientError(
                    explanation=_("Unexpected error code: %s") %
                    res.status_int)
                exc.code = res.status_int
                exc.status_code = res.status_int
                raise exc
            graph = self.deserialize(fmt or self.fmt, res)
            yield graph
            if not no_delete:
                # delete loadbalancer children if this was a loadbalancer
                # graph create call
                lb = graph['graph']['loadbalancer']
                for listener in lb.get('listeners', []):
                    pool = listener.get('default_pool')
                    if pool:
                        hm = pool.get('healthmonitor')
                        if hm:
                            self._delete('healthmonitors', hm['id'])
                        members = pool.get('members', [])
                        for member in members:
                            self._delete('pools',
                                         pool['id'],
                                         subresource='members',
                                         sub_id=member['id'])
                        self._delete('pools', pool['id'])
                    policies = listener.get('l7policies', [])
                    for policy in policies:
                        r_pool = policy.get('redirect_pool')
                        if r_pool:
                            r_hm = r_pool.get('healthmonitor')
                            if r_hm:
                                self._delete('healthmonitors', r_hm['id'])
                            r_members = r_pool.get('members', [])
                            for r_member in r_members:
                                self._delete('pools',
                                             r_pool['id'],
                                             subresource='members',
                                             sub_id=r_member['id'])
                            self._delete('pools', r_pool['id'])
                        self._delete('l7policies', policy['id'])
                    self._delete('listeners', listener['id'])
                self._delete('loadbalancers', lb['id'])
コード例 #7
0
    def floatingip_with_assoc(self,
                              port_id=None,
                              fmt=None,
                              fixed_ip=None,
                              public_cidr='11.0.0.0/24',
                              set_context=False,
                              tenant_id=None,
                              **kwargs):
        # Override super implementation to avoid changing the network to
        # external after creation
        with self._create_l3_ext_network() as ext_net,\
            self.subnet(network=ext_net, cidr=public_cidr,
                        set_context=set_context,
                        tenant_id=tenant_id,
                        enable_dhcp=False) as public_sub:
            private_port = None
            if port_id:
                private_port = self._show('ports', port_id)
            with test_plugin.optional_ctx(private_port,
                                          self.port,
                                          set_context=set_context,
                                          tenant_id=tenant_id) as private_port:
                with self.router(set_context=set_context,
                                 tenant_id=tenant_id) as r:
                    sid = private_port['port']['fixed_ips'][0]['subnet_id']
                    private_sub = {'subnet': {'id': sid}}
                    floatingip = None

                    self._add_external_gateway_to_router(
                        r['router']['id'], public_sub['subnet']['network_id'])
                    self._router_interface_action('add', r['router']['id'],
                                                  private_sub['subnet']['id'],
                                                  None)

                    floatingip = self._make_floatingip(
                        fmt or self.fmt,
                        public_sub['subnet']['network_id'],
                        port_id=private_port['port']['id'],
                        fixed_ip=fixed_ip,
                        tenant_id=tenant_id,
                        set_context=set_context,
                        **kwargs)
                    yield floatingip

                    if floatingip:
                        self._delete('floatingips',
                                     floatingip['floatingip']['id'])
コード例 #8
0
 def port_with_binding_profile(self, host='host', if_name='if_name'):
     args = {
         portbindings.PROFILE: {
             'interface_name': if_name
         },
         portbindings.HOST_ID: host
     }
     with test_plugin.optional_ctx(None, self.subnet) as subnet_to_use:
         net_id = subnet_to_use['subnet']['network_id']
         port = self._make_port(self.fmt,
                                net_id,
                                arg_list=(
                                    portbindings.PROFILE,
                                    portbindings.HOST_ID,
                                ),
                                **args)
         yield port
コード例 #9
0
ファイル: common_v3.py プロジェクト: openstack/vmware-nsx
    def floatingip_with_assoc(self, port_id=None, fmt=None, fixed_ip=None,
                              public_cidr='11.0.0.0/24', set_context=False,
                              tenant_id=None, **kwargs):
        # Override super implementation to avoid changing the network to
        # external after creation
        with self._create_l3_ext_network() as ext_net,\
            self.subnet(network=ext_net, cidr=public_cidr,
                        set_context=set_context,
                        tenant_id=tenant_id,
                        enable_dhcp=False) as public_sub:
            private_port = None
            if port_id:
                private_port = self._show('ports', port_id)
            with test_plugin.optional_ctx(
                    private_port, self.port,
                    set_context=set_context,
                    tenant_id=tenant_id) as private_port:
                with self.router(set_context=set_context,
                                 tenant_id=tenant_id) as r:
                    sid = private_port['port']['fixed_ips'][0]['subnet_id']
                    private_sub = {'subnet': {'id': sid}}
                    floatingip = None

                    self._add_external_gateway_to_router(
                        r['router']['id'],
                        public_sub['subnet']['network_id'])
                    self._router_interface_action(
                        'add', r['router']['id'],
                        private_sub['subnet']['id'], None)

                    floatingip = self._make_floatingip(
                        fmt or self.fmt,
                        public_sub['subnet']['network_id'],
                        port_id=private_port['port']['id'],
                        fixed_ip=fixed_ip,
                        tenant_id=tenant_id,
                        set_context=set_context,
                        **kwargs)
                    yield floatingip

                    if floatingip:
                        self._delete('floatingips',
                                     floatingip['floatingip']['id'])
コード例 #10
0
    def loadbalancer(self, fmt=None, subnet=None, no_delete=False, **kwargs):
        if not fmt:
            fmt = self.fmt

        with test_db_base_plugin_v2.optional_ctx(subnet,
                                                 self.subnet) as tmp_subnet:

            res = self._create_loadbalancer(fmt, tmp_subnet['subnet']['id'],
                                            **kwargs)
            if res.status_int >= webob.exc.HTTPClientError.code:
                exc = webob.exc.HTTPClientError(
                    explanation=_("Unexpected error code: %s") %
                    res.status_int)
                exc.code = res.status_int
                exc.status_code = res.status_int
                raise exc
            lb = self.deserialize(fmt or self.fmt, res)
            yield lb
            if not no_delete:
                self._delete('loadbalancers', lb['loadbalancer']['id'])
コード例 #11
0
ファイル: util.py プロジェクト: openstack/neutron-lbaas
    def loadbalancer(self, fmt=None, subnet=None, no_delete=False, **kwargs):
        if not fmt:
            fmt = self.fmt

        with test_db_base_plugin_v2.optional_ctx(
                subnet, self.subnet) as tmp_subnet:

            res = self._create_loadbalancer(fmt,
                                            tmp_subnet['subnet']['id'],
                                            **kwargs)
            if res.status_int >= webob.exc.HTTPClientError.code:
                exc = webob.exc.HTTPClientError(
                    explanation=_("Unexpected error code: %s") %
                    res.status_int)
                exc.code = res.status_int
                exc.status_code = res.status_int
                raise exc
            lb = self.deserialize(fmt or self.fmt, res)
            yield lb
            if not no_delete:
                self._delete('loadbalancers', lb['loadbalancer']['id'])
コード例 #12
0
    def packet_filter_on_port(self,
                              port=None,
                              fmt=None,
                              set_portinfo=True,
                              **kwargs):
        with test_db_plugin.optional_ctx(port, self.port) as port_to_use:
            net_id = port_to_use['port']['network_id']
            port_id = port_to_use['port']['id']

            if set_portinfo:
                portinfo = {
                    'id': port_id,
                    'port_no': kwargs.get('port_no', 123)
                }
                kw = {'added': [portinfo]}
                if 'datapath_id' in kwargs:
                    kw['datapath_id'] = kwargs['datapath_id']
                self.rpcapi_update_ports(**kw)

            kwargs['in_port'] = port_id
            pf = self._make_packet_filter(fmt or self.fmt, net_id, **kwargs)
            self.assertEqual(port_id, pf['packet_filter']['in_port'])
            yield pf
コード例 #13
0
 def port_with_binding_profile(self, host="host", if_name="if_name"):
     args = {portbindings.PROFILE: {"interface_name": if_name}, portbindings.HOST_ID: host}
     with test_plugin.optional_ctx(None, self.subnet) as subnet_to_use:
         net_id = subnet_to_use["subnet"]["network_id"]
         port = self._make_port(self.fmt, net_id, arg_list=(portbindings.PROFILE, portbindings.HOST_ID), **args)
         yield port