Openstack Hrozion开发(四)
来源:互联网 发布:淘宝个人主页 编辑:程序博客网 时间:2024/05/16 05:58
在Dashborad 上添加将Volume 备份到指定的Container 功能
在命令行下是可以通过cinder backup-create 来指定将volume 备份到不同的container 中,但是dashborad 并没有提供页面操作。
一、页面修改
进入/project/vouleme/volume/tables.py 页面添加 backup 按钮
class CreateBackup(tables.LinkAction): name = "backup" verbose_name = _("Create Backup") url = "horizon:project:volumes:volumes:create_backup" classes = ("ajax-modal","btn-camera") policy_rules = (("volume","volume:backup"),) def get_policy_target(self, request, datum=None): project_id = None if datum: project_id = getattr(datum,"os-vol-tenant-attr:tenant_id",None) return {"project_id":project_id} def allowed(self, request, volume=None): return volume.status in "available","in-use"
在viwe.py页面添加类
class CreateBackupView(forms.ModalFormView): form_class = project_forms.CreateBackupForm template_name = 'project/volumes/volumes/create_backup.html' success_url = reverse_lazy("horizon:project:containers:index") def get_context_data(self, **kwargs): context = super(CreateBackupView, self).get_context_data(**kwargs) context['volume_id'] = self.kwargs['volume_id'] try: volume = cinder.volume_get(self.request, context['volume_id']) if (volume.status == 'in-use'): context['attached'] = True context['form'].set_warning(_("This volume is currently " "attached to an instance. " "In some cases, creating a " "backup from an attached " "volume can result in a " "corrupted backup.")) context['usages'] = quotas.tenant_limit_usages(self.request) except Exception: exceptions.handle(self.request, _('Unable to retrieve volume information.')) return context def get_initial(self): return {'volume_id': self.kwargs["volume_id"]}在form.py页面添加<pre name="code" class="python">class CreateBackupForm(forms.SelfHandlingForm): name = forms.CharField(max_length="255", label =_("Backup Name")) container_list = forms.ChoiceField(label=_("Backup to container"), help_text=_("Select a container to " "backup to.")) description = forms.CharField(widget=forms.Textarea, label=_("Description"),required=False) def __init__(self, request, *args, **kwargs): super(CreateBackupForm, self).__init__(request, *args, **kwargs) # populate volume_id volume_id = kwargs.get('initial', {}).get('volume_id', []) self.fields['volume_id'] = forms.CharField(widget=forms.HiddenInput(), initial=volume_id) #def populate_avialable_container_choices(self,request,context): try: containers = swift.swift_get_containers(request)[0] except Exception: containers = [] exceptions.handle(request, _('Unable to retrive available container.')) container_list = [] container_list = [(container.get('name'), container.get('name')) for container in containers ] container_list.sort() if not container_list: container_list.insert(0,("",_("No available container."))) elif len(container_list) > 1: container_list.insert(0,("",_("Any Available Container"))) self.fields['container_list'].choices = container_list def handle(self, request, data): try: volume = cinder.volume_get(request, data['volume_id']) force = False message = _('Creating volume backup "%s".') % data['name'] if volume.status == 'in-use': force = True message = _('Forcing to create backup "%s" ' 'from attached volume.') % data['name'] backup = cinder.volume_backup_create(request, data['volume_id'], data['name'], data['container_list'], data['description'])#end add messages.info(request, message) return backup except Exception: redirect = reverse("horizon:project:volumes:index") exceptions.handle(request, _('Unable to create volume backup.'), redirect=redirect) 二、cinder api 的修改因为 cinderclient 已经集成了常用的功能,我们只需要调用api即可<pre name="code" class="python">def volume_backup_create(request,volume_id, name=None,container=None,description=None): data = {'name': name, 'container': container, 'description': description} return VolumeBackup(cinderclient(request).backups.create( volume_id, **data))
0 0
- Openstack Hrozion开发(四)
- Openstack Nova(四)----Instance 创建(Overview)
- 深入理解openstack网络架构(四)
- OpenStack L版官网配置转载(四)
- OpenStack多节点安装(四):Compute
- openstack storlet 文档(四):storlet引擎
- Openstack Horizon 开发 (一)
- Openstack Horizon开发 (二)
- Openstack Horizon开发 (三)
- Openstack学习笔记(五)-OpenStack Dashboard开发环境搭建
- 【OpenStack】OpenStack原理(二)——开发基础
- OpenStack笔记四 Neutron
- 快速搭建OpenStack开发环境(DevStack)
- OpenStack-M版(Mitaka)搭建基于(Centos7.2)+++四、Openstack镜像服务(glance)
- openstack学习笔记(四)-使用devstack自动化部署openstack的实验环境
- openstack plugin 之(四)如何区分 OpenStack Neutron Extension 和 Plugin
- OpenStack设计与实现(四)消息总线(AMQP)
- Openstack学习笔记(十四)-Horizon学习笔记(四)
- Bit(位)与Byte(字节)的区别
- 部署中遇到的问题-UWSGI(一)
- Promises与Javascript异步编程
- 流媒体协议介绍(rtp/rtcp/rtsp/rtmp/mms/hls)
- ios同步机制
- Openstack Hrozion开发(四)
- 线段树离线处理(区间内出现k次的数有多少个)Codeforces Round #136 (Div. 2)
- NAT和IPSec在思考路由器上的实现
- hduoj1087!【DP】
- zoj 1007
- 一元线性回归分析及java实现
- poj 3264 Balanced Lineup(线段树)
- 深入解析Java设计模式之动态代理
- cocos2dx windows phone平台下CCLabelTTF自动换行的实现(2)