예제 #1
0
 def get_project_and_global_net_ids(self, context, project_id):
     """Fetches all networks associated with this project, or
        that are "global" (i.e., have no project set).
        Returns list sorted by 'priority'.
     """
     admin_context = context.elevated()
     networks = db.project_get_networks(admin_context, project_id, False)
     networks.extend(db.project_get_networks(admin_context, None, False))
     id_priority_map = {}
     net_list = []
     for n in networks:
         net_id = n['uuid']
         net_list.append((net_id, n["project_id"]))
         id_priority_map[net_id] = n['priority']
     return sorted(net_list, key=lambda x: id_priority_map[x[0]])
예제 #2
0
 def get_project_and_global_net_ids(self, context, project_id):
     """Fetches all networks associated with this project, or
        that are "global" (i.e., have no project set).
        Returns list sorted by 'priority'.
     """
     admin_context = context.elevated()
     networks = db.project_get_networks(admin_context, project_id, False)
     networks.extend(db.project_get_networks(admin_context, None, False))
     id_priority_map = {}
     net_list = []
     for n in networks:
         net_id = n['uuid']
         net_list.append((net_id, n["project_id"]))
         id_priority_map[net_id] = n['priority']
     return sorted(net_list, key=lambda x: id_priority_map[x[0]])
    def update(self, req, id, body):
        """Configure cloudpipe parameters for the project."""

        context = req.environ['nova.context']
        authorize(context)

        if id != "configure-project":
            msg = _("Unknown action %s") % id
            raise webob.exc.HTTPBadRequest(explanation=msg)

        project_id = context.project_id

        try:
            params = body['configure_project']
            vpn_ip = params['vpn_ip']
            vpn_port = params['vpn_port']
        except (TypeError, KeyError):
            raise webob.exc.HTTPUnprocessableEntity()

        networks = db.project_get_networks(context, project_id)
        for network in networks:
            db.network_update(context, network['id'],
                              {'vpn_public_address': vpn_ip,
                               'vpn_public_port': int(vpn_port)})
        return webob.exc.HTTPAccepted()
예제 #4
0
    def update(self, req, id, body):
        """Configure cloudpipe parameters for the project."""

        context = req.environ['nova.context']
        authorize(context)

        if id != "configure-project":
            msg = _("Unknown action %s") % id
            raise webob.exc.HTTPBadRequest(explanation=msg)

        project_id = context.project_id

        try:
            params = body['configure_project']
            vpn_ip = params['vpn_ip']
            vpn_port = params['vpn_port']
        except (TypeError, KeyError):
            raise webob.exc.HTTPUnprocessableEntity()

        networks = db.project_get_networks(context, project_id)
        for network in networks:
            db.network_update(context, network['id'], {
                'vpn_public_address': vpn_ip,
                'vpn_public_port': int(vpn_port)
            })
        return webob.exc.HTTPAccepted()
예제 #5
0
 def scrub(self, project_id):
     """Deletes data associated with project."""
     admin_context = context.get_admin_context()
     networks = db.project_get_networks(admin_context, project_id)
     for network in networks:
         db.network_disassociate(admin_context, network['id'])
     groups = db.security_group_get_by_project(admin_context, project_id)
     for group in groups:
         db.security_group_destroy(admin_context, group['id'])
예제 #6
0
 def index(self, req):
     tenant_id = urlparse.parse_qs(req.environ['QUERY_STRING']).get('tenant_id', [None])[0]
     context = req.environ['nova.context']
     LOG.audit(_("Getting networks for project %s"), tenant_id or '<all>')
     if context.is_admin and not tenant_id:
         networks = db.network_get_all(context)
     elif tenant_id:
         networks = db.project_get_networks(context, tenant_id, associate=False)
     else:
         raise exc.HTTPNotFound()
     result = [network_dict(net_ref) for net_ref in networks]
     return  {'networks': result}
예제 #7
0
파일: manage.py 프로젝트: comstud/nova
    def change(self, project_id, ip, port):
        """Change the ip and port for a vpn.

        this will update all networks associated with a project
        not sure if that's the desired behavior or not, patches accepted

        """
        # TODO(tr3buchet): perhaps this shouldn't update all networks
        # associated with a project in the future
        admin_context = context.get_admin_context()
        networks = db.project_get_networks(admin_context, project_id)
        for network in networks:
            db.network_update(admin_context, network["id"], {"vpn_public_address": ip, "vpn_public_port": int(port)})
예제 #8
0
def _setup_networking(instance_id, ip="1.2.3.4", flo_addr="1.2.1.2"):
    ctxt = context.get_admin_context()
    network_ref = db.project_get_networks(ctxt, "fake", associate=True)[0]
    vif = {"address": "56:12:12:12:12:12", "network_id": network_ref["id"], "instance_id": instance_id}
    vif_ref = db.virtual_interface_create(ctxt, vif)

    fixed_ip = {
        "address": ip,
        "network_id": network_ref["id"],
        "virtual_interface_id": vif_ref["id"],
        "allocated": True,
        "instance_id": instance_id,
    }
    db.fixed_ip_create(ctxt, fixed_ip)
    fix_ref = db.fixed_ip_get_by_address(ctxt, ip)
    db.floating_ip_create(ctxt, {"address": flo_addr, "fixed_ip_id": fix_ref["id"]})
예제 #9
0
    def change(self, project_id, ip, port):
        """Change the ip and port for a vpn.

        this will update all networks associated with a project
        not sure if that's the desired behavior or not, patches accepted

        """
        # TODO(tr3buchet): perhaps this shouldn't update all networks
        # associated with a project in the future
        admin_context = context.get_admin_context()
        networks = db.project_get_networks(admin_context, project_id)
        for network in networks:
            db.network_update(admin_context,
                              network['id'],
                              {'vpn_public_address': ip,
                               'vpn_public_port': int(port)})
예제 #10
0
파일: test_db_api.py 프로젝트: matiu2/nova
def _setup_networking(instance_id, ip='1.2.3.4', flo_addr='1.2.1.2'):
    ctxt = context.get_admin_context()
    network_ref = db.project_get_networks(ctxt,
                                           'fake',
                                           associate=True)[0]
    vif = {'address': '56:12:12:12:12:12',
           'network_id': network_ref['id'],
           'instance_id': instance_id}
    vif_ref = db.virtual_interface_create(ctxt, vif)

    fixed_ip = {'address': ip,
                'network_id': network_ref['id'],
                'virtual_interface_id': vif_ref['id'],
                'allocated': True,
                'instance_id': instance_id}
    db.fixed_ip_create(ctxt, fixed_ip)
    fix_ref = db.fixed_ip_get_by_address(ctxt, ip)
    db.floating_ip_create(ctxt, {'address': flo_addr,
                                 'fixed_ip_id': fix_ref['id']})
예제 #11
0
def _setup_networking(instance_id, ip='1.2.3.4', flo_addr='1.2.1.2'):
    ctxt = context.get_admin_context()
    network_ref = db.project_get_networks(ctxt,
                                           'fake',
                                           associate=True)[0]
    vif = {'address': '56:12:12:12:12:12',
           'network_id': network_ref['id'],
           'instance_id': instance_id}
    vif_ref = db.virtual_interface_create(ctxt, vif)

    fixed_ip = {'address': ip,
                'network_id': network_ref['id'],
                'virtual_interface_id': vif_ref['id'],
                'allocated': True,
                'instance_id': instance_id}
    db.fixed_ip_create(ctxt, fixed_ip)
    fix_ref = db.fixed_ip_get_by_address(ctxt, ip)
    db.floating_ip_create(ctxt, {'address': flo_addr,
                                 'fixed_ip_id': fix_ref['id']})
예제 #12
0
파일: manager.py 프로젝트: renuka-apte/nova
    def get_project_vpn_data(project):
        """Gets vpn ip and port for project

        @type project: Project or project_id
        @param project: Project from which to get associated vpn data

        @rvalue: tuple of (str, str)
        @return: A tuple containing (ip, port) or None, None if vpn has
        not been allocated for user.
        """

        networks = db.project_get_networks(context.get_admin_context(), Project.safe_id(project), False)
        if not networks:
            return (None, None)

        # TODO(tr3buchet): not sure what you guys plan on doing with this
        # but it's possible for a project to have multiple sets of vpn data
        # for now I'm just returning the first one
        network = networks[0]
        return (network["vpn_public_address"], network["vpn_public_port"])
예제 #13
0
파일: manager.py 프로젝트: mattstep/nova
    def get_project_vpn_data(project):
        """Gets vpn ip and port for project

        :type project: Project or project_id
        :param project: Project from which to get associated vpn data

        :rvalue: tuple of (str, str)
        :return: A tuple containing (ip, port) or None, None if vpn has
                 not been allocated for user.
        """

        networks = db.project_get_networks(context.get_admin_context(),
                                           Project.safe_id(project), False)
        if not networks:
            return (None, None)

        # TODO(tr3buchet): not sure what you guys plan on doing with this
        # but it's possible for a project to have multiple sets of vpn data
        # for now I'm just returning the first one
        network = networks[0]
        return (network['vpn_public_address'], network['vpn_public_port'])
예제 #14
0
 def get_global_networks(self, admin_context):
     return db.project_get_networks(admin_context, None, False)
예제 #15
0
 def get_project_networks(self, admin_context, project_id):
     return db.project_get_networks(admin_context, project_id, False)
예제 #16
0
 def get_by_project(cls, context, project_id, associate=True):
     db_networks = db.project_get_networks(context,
                                           project_id,
                                           associate=associate)
     return obj_base.obj_make_list(context, cls(context), objects.Network,
                                   db_networks)
예제 #17
0
 def get_project_networks(self, admin_context, project_id):
     return db.project_get_networks(admin_context, project_id, False)
예제 #18
0
파일: network.py 프로젝트: EdLeafe/nova
 def get_by_project(cls, context, project_id, associate=True):
     db_networks = db.project_get_networks(context, project_id,
                                           associate=associate)
     return obj_base.obj_make_list(context, cls(context), objects.Network,
                                   db_networks)
예제 #19
0
 def get_global_networks(self, admin_context):
     return db.project_get_networks(admin_context, None, False)