Example #1
0
 def _vpn_for(self, context, project_id):
     """Get the VPN instance for a project ID."""
     for instance in db.instance_get_all_by_project(context, project_id):
         if (instance['image_id'] == str(FLAGS.vpn_image_id)
                 and not instance['state_description']
                 in ['shutting_down', 'shutdown']):
             return instance
Example #2
0
 def _vpn_for(self, context, project_id):
     """Get the VPN instance for a project ID."""
     for instance in db.instance_get_all_by_project(context, project_id):
         if (instance['image_id'] == str(FLAGS.vpn_image_id)
             and not instance['state_description'] in
                 ['shutting_down', 'shutdown']):
             return instance
Example #3
0
 def _get_cloudpipe_for_project(self, context, project_id):
     """Get the cloudpipe instance for a project ID."""
     # NOTE(todd): this should probably change to compute_api.get_all
     #             or db.instance_get_project_vpn
     for instance in db.instance_get_all_by_project(context, project_id):
         if (instance['image_id'] == str(FLAGS.vpn_image_id)
             and instance['vm_state'] != vm_states.DELETED):
             return instance
Example #4
0
 def _get_cloudpipe_for_project(self, context, project_id):
     """Get the cloudpipe instance for a project ID."""
     # NOTE(todd): this should probably change to compute_api.get_all
     #             or db.instance_get_project_vpn
     for instance in db.instance_get_all_by_project(context, project_id):
         if (instance['image_id'] == str(FLAGS.vpn_image_id)
             and instance['vm_state'] != vm_states.DELETED):
             return instance
Example #5
0
 def _vpn_for(self, context, project_id):
     """Get the VPN instance for a project ID."""
     for instance in db.instance_get_all_by_project(context, project_id):
         if instance["image_id"] == str(FLAGS.vpn_image_id) and not instance["state_description"] in [
             "shutting_down",
             "shutdown",
         ]:
             return instance
Example #6
0
    def update(self, req, id, body):
        """Add new filesystem."""
        name = id
        try:
            entry = body['fs_entry']
            size = entry['size']
            scope = entry['scope']
        except (TypeError, KeyError):
            raise webob.exc.HTTPUnprocessableEntity()
        if scope not in ['project', 'instance', 'global']:
            LOG.error(_("scope must be one of project, instance, or global"))
            raise webob.exc.HTTPUnprocessableEntity()

        context = req.environ['nova.context']
        project = context.project_id

        try:
            if self.has_db_support:
                sharedfs_db.filesystem_add(context, name, scope, project)

            self.fs_driver.create_fs(name, project, size)
        except exception.NotAuthorized:
            msg = _("Filesystem creation requires admin permissions.")
            raise webob.exc.HTTPForbidden(msg)

        if self.has_db_support:
            # Attach global or project-wide shares immediately.
            instance_list = []
            if scope == 'global':
                instance_list = db.instance_get_all(context)
            elif scope == 'project':
                instance_list = db.instance_get_all_by_project(context,
                                                               project)

            for instance in instance_list:
                try:
                    fixed_ips = db.fixed_ip_get_by_instance(context,
                                                            instance.id)
                    for ip in fixed_ips:
                        LOG.debug(_("attaching %(ip)s to filesystem %(fs)s.")
                                  % {'ip': ip['address'], 'fs': name})
                        try:
                            self.fs_driver.attach(name, ip['address'])
                        except exception.NotAuthorized:
                            LOG.warning(_("Insufficient permissions to attach"
                                       " %(instance)s to filesystem %(fs)s.") %
                                       {'instance': instance.name, 'fs': name})
                except exception.FixedIpNotFound:
                    LOG.warning(_("Unable to get IP address for %s.")
                              % instance.id)

        return _translate_fs_entry_view({'name': name,
                                         'size': size,
                                         'scope': scope,
                                         'project': project})
Example #7
0
    def delete(self, req, id):
        """Delete the filesystem identified by id."""
        name = id

        if self.has_db_support:
            # Unattach global or project-wide shares immediately.
            context = req.environ['nova.context']
            fs_entry = sharedfs_db.filesystem_get(context, name)
            if not fs_entry:
                msg = _("Filesystem %s not found.") % name
                raise webob.exc.HTTPNotFound(msg)
            scope = fs_entry.scope
            project = fs_entry.project_id
            instance_list = []
            if scope == 'global':
                instance_list = db.instance_get_all(context)
            elif scope == 'project':
                instance_list = db.instance_get_all_by_project(context,
                                                               project)

            for instance in instance_list:
                try:
                    fixed_ips = db.fixed_ip_get_by_instance(context,
                                                            instance.id)
                    for ip in fixed_ips:
                        LOG.debug(_("unattaching %(ip)s from fs %(fs)s.") %
                                  {'ip': ip['address'], 'fs': name})
                        try:
                            self.fs_driver.unattach(name, ip['address'])
                        except exception.NotAuthorized:
                            LOG.warning(_("Insufficient permission to unattach"
                                     " %(instance)s from filesystem %(fs)s.") %
                                          {'instance': instance.name,
                                           'fs': name})
                except exception.FixedIpNotFound:
                    LOG.warning(_("Unable to get IP address for %s.")
                              % instance.id)

            sharedfs_db.filesystem_delete(context, name)

        try:
            self.fs_driver.delete_fs(name, project)
        except exception.NotAuthorized:
            msg = _("Filesystem deletion requires admin permissions.")
            raise webob.exc.HTTPForbidden(msg)
        except exception.NotFound:
            msg = _("Filesystem %s does not exist.") % name
            raise webob.exc.HTTPNotFound(msg)

        return webob.Response(status_int=202)
Example #8
0
 def _vpn_for(self, context, project_id):
     """Get the VPN instance for a project ID."""
     for instance in db.instance_get_all_by_project(context, project_id):
         if (instance['image_id'] == str(FLAGS.vpn_image_id)
                 and not instance['vm_state'] in [vm_states.DELETED]):
             return instance
Example #9
0
 def _vpn_for(self, context, project_id):
     """Get the VPN instance for a project ID."""
     for instance in db.instance_get_all_by_project(context, project_id):
         if (instance['image_ref'] == str(FLAGS.vpn_image_id)
             and not instance['vm_state'] in [vm_states.DELETED]):
             return instance