Beispiel #1
0
    def create(self, req, body):
        """Create a new cloudpipe instance, if none exists.

        Parameters: {cloudpipe: {'project_id': ''}}
        """

        context = req.environ['nova.context']
        authorize(context)
        params = body.get('cloudpipe', {})
        project_id = params.get('project_id', context.project_id)
        # NOTE(vish): downgrade to project context. Note that we keep
        #             the same token so we can still talk to glance
        context.project_id = project_id
        context.user_id = 'project-vpn'
        context.is_admin = False
        context.roles = []
        instance = self._get_cloudpipe_for_project(context, project_id)
        if not instance:
            try:
                result = self.cloudpipe.launch_vpn_instance(context)
                instance = result[0][0]
            except db.NoMoreNetworks:
                msg = _("Unable to claim IP for VPN instances, ensure it "
                        "isn't running, and try again in a few minutes")
                raise exception.HTTPBadRequest(explanation=msg)
        return {'instance_id': instance['uuid']}
Beispiel #2
0
    def create(self, req, body):
        """Create a new cloudpipe instance, if none exists.

        Parameters: {cloudpipe: {project_id: XYZ}}
        """

        ctxt = req.environ['nova.context']
        authorize(ctxt)
        params = body.get('cloudpipe', {})
        project_id = params.get('project_id', ctxt.project_id)
        instance = self._get_cloudpipe_for_project(ctxt, project_id)
        if not instance:
            proj = self.auth_manager.get_project(project_id)
            user_id = proj.project_manager_id
            try:
                self.cloudpipe.launch_vpn_instance(project_id, user_id)
            except db.NoMoreNetworks:
                msg = _("Unable to claim IP for VPN instances, ensure it "
                        "isn't running, and try again in a few minutes")
                raise exception.HTTPBadRequest(explanation=msg)
            instance = self._get_cloudpipe_for_project(ctxt, proj)
        return {'instance_id': instance['uuid']}