Merge pull request #36 from mszilagyi/swiftCopy_93
Added copy support for swift objects from the dash.
This commit is contained in:
commit
ff677bfdb3
@ -498,6 +498,29 @@ def swift_get_objects(container_name):
|
|||||||
return [SwiftObject(o) for o in container.get_objects()]
|
return [SwiftObject(o) for o in container.get_objects()]
|
||||||
|
|
||||||
|
|
||||||
|
def swift_object_exists(container_name, object_name):
|
||||||
|
container = swift_api().get_container(container_name)
|
||||||
|
|
||||||
|
try:
|
||||||
|
container.get_object(object_name)
|
||||||
|
return True
|
||||||
|
except cloudfiles.errors.NoSuchObject:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def swift_copy_object(orig_container_name, orig_object_name,
|
||||||
|
new_container_name, new_object_name):
|
||||||
|
|
||||||
|
container = swift_api().get_container(orig_container_name)
|
||||||
|
|
||||||
|
if swift_object_exists(new_container_name, new_object_name) == True:
|
||||||
|
raise Exception('Object with name %s already exists in container %s'
|
||||||
|
% (new_object_name, new_container_name))
|
||||||
|
|
||||||
|
orig_obj = container.get_object(orig_object_name)
|
||||||
|
return orig_obj.copy_to(new_container_name, new_object_name)
|
||||||
|
|
||||||
|
|
||||||
def swift_upload_object(container_name, object_name, object_data):
|
def swift_upload_object(container_name, object_name, object_data):
|
||||||
container = swift_api().get_container(container_name)
|
container = swift_api().get_container(container_name)
|
||||||
obj = container.create_object(object_name)
|
obj = container.create_object(object_name)
|
||||||
|
@ -52,6 +52,8 @@ urlpatterns += patterns('django_openstack.dash.views.containers',
|
|||||||
urlpatterns += patterns('django_openstack.dash.views.objects',
|
urlpatterns += patterns('django_openstack.dash.views.objects',
|
||||||
url(OBJECTS % '', 'index', name='dash_objects'),
|
url(OBJECTS % '', 'index', name='dash_objects'),
|
||||||
url(OBJECTS % 'upload', 'upload', name='dash_objects_upload'),
|
url(OBJECTS % 'upload', 'upload', name='dash_objects_upload'),
|
||||||
|
url(OBJECTS % '(?P<object_name>[^/]+)/copy',
|
||||||
|
'copy', name='dash_object_copy'),
|
||||||
url(OBJECTS % '(?P<object_name>[^/]+)/download',
|
url(OBJECTS % '(?P<object_name>[^/]+)/download',
|
||||||
'download', name='dash_objects_download'),
|
'download', name='dash_objects_download'),
|
||||||
)
|
)
|
||||||
|
@ -59,10 +59,40 @@ class UploadObject(forms.SelfHandlingForm):
|
|||||||
request.POST['container_name'],
|
request.POST['container_name'],
|
||||||
data['name'],
|
data['name'],
|
||||||
request.FILES['object_file'].read())
|
request.FILES['object_file'].read())
|
||||||
|
|
||||||
messages.success(request, "Object was successfully uploaded.")
|
messages.success(request, "Object was successfully uploaded.")
|
||||||
return shortcuts.redirect(request.build_absolute_uri())
|
return shortcuts.redirect(request.build_absolute_uri())
|
||||||
|
|
||||||
|
|
||||||
|
class CopyObject(forms.SelfHandlingForm):
|
||||||
|
container_choices = []
|
||||||
|
|
||||||
|
for idx, container in enumerate(api.swift_get_containers()):
|
||||||
|
container_choices.append((container['name'], container['name']))
|
||||||
|
|
||||||
|
new_container_name = forms.ChoiceField(
|
||||||
|
choices=container_choices,
|
||||||
|
label="Container to store object in")
|
||||||
|
|
||||||
|
new_object_name = forms.CharField(max_length="255",
|
||||||
|
label="New object name")
|
||||||
|
|
||||||
|
def handle(self, request, data):
|
||||||
|
orig_container_name = request.POST['orig_container_name']
|
||||||
|
orig_object_name = request.POST['orig_object_name']
|
||||||
|
new_container_name = request.POST['new_container_name']
|
||||||
|
new_object_name = data['new_object_name']
|
||||||
|
|
||||||
|
api.swift_copy_object(orig_container_name, orig_object_name,
|
||||||
|
new_container_name, new_object_name)
|
||||||
|
|
||||||
|
messages.success(request,
|
||||||
|
'Object was successfully copied to %s\%s' %
|
||||||
|
(new_container_name, new_object_name))
|
||||||
|
|
||||||
|
return shortcuts.redirect(request.build_absolute_uri())
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def index(request, tenant_id, container_name):
|
def index(request, tenant_id, container_name):
|
||||||
delete_form, handled = DeleteObject.maybe_handle(request)
|
delete_form, handled = DeleteObject.maybe_handle(request)
|
||||||
@ -101,3 +131,20 @@ def download(request, tenant_id, container_name, object_name):
|
|||||||
for data in object_data:
|
for data in object_data:
|
||||||
response.write(data)
|
response.write(data)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def copy(request, tenant_id, container_name, object_name):
|
||||||
|
form, handled = CopyObject.maybe_handle(request)
|
||||||
|
|
||||||
|
form.fields['new_container_name'].initial = container_name
|
||||||
|
|
||||||
|
if handled:
|
||||||
|
return handled
|
||||||
|
|
||||||
|
return render_to_response(
|
||||||
|
'dash_object_copy.html',
|
||||||
|
{'container_name': container_name,
|
||||||
|
'object_name': object_name,
|
||||||
|
'copy_form': form },
|
||||||
|
context_instance=template.RequestContext(request))
|
||||||
|
12
openstack-dashboard/dashboard/templates/_copy_object.html
Normal file
12
openstack-dashboard/dashboard/templates/_copy_object.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<form id="object_copy" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{% for hidden in form.hidden_fields %}{{ hidden }}{% endfor %}
|
||||||
|
{% for field in form.visible_fields %}
|
||||||
|
{{ field.label_tag }}
|
||||||
|
{{ field.errors }}
|
||||||
|
{{ field }}
|
||||||
|
{% endfor %}
|
||||||
|
<input type="hidden" name="orig_container_name" value="{{ container_name }}" />
|
||||||
|
<input type="hidden" name="orig_object_name" value="{{ object_name }}" />
|
||||||
|
<input type="submit" value="Copy Object" class="large-rounded" />
|
||||||
|
</form>
|
@ -8,6 +8,7 @@
|
|||||||
<td>{{ object.name }}</td>
|
<td>{{ object.name }}</td>
|
||||||
<td id="actions">
|
<td id="actions">
|
||||||
<ul>
|
<ul>
|
||||||
|
<li><a href="{% url dash_object_copy request.user.tenant container_name object.name %}">Copy</a></li>
|
||||||
<li>{% include "_delete_object.html" with form=delete_form %}</li>
|
<li>{% include "_delete_object.html" with form=delete_form %}</li>
|
||||||
<li><a href="{% url dash_objects_download request.user.tenant container_name object.name %}">Download</a>
|
<li><a href="{% url dash_objects_download request.user.tenant container_name object.name %}">Download</a>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
{% extends 'dash_base.html' %}
|
||||||
|
|
||||||
|
{% block sidebar %}
|
||||||
|
{% with current_sidebar="containers" %}
|
||||||
|
{{block.super}}
|
||||||
|
{% endwith %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block main %}
|
||||||
|
<div id='page_header'>
|
||||||
|
<h2><span>Object Store:</span> Objects</h2>
|
||||||
|
<p class='desc'><span>—</span> Copy an object.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% include "_messages.html" %}
|
||||||
|
|
||||||
|
<div class="container-label">Container:</div>
|
||||||
|
<div class="container-name">{{ container_name }}</div>
|
||||||
|
<div style="clear: both;"></div>
|
||||||
|
<div class="main_content">
|
||||||
|
<div class="dash_block wide form">
|
||||||
|
<div class='title_block'>
|
||||||
|
<h3>Copy {{ object_name }}</h3>
|
||||||
|
</div>
|
||||||
|
<div class="left">
|
||||||
|
{% include '_copy_object.html' with form=copy_form greeting="HI" %}
|
||||||
|
<h3><a href="{% url dash_objects request.user.tenant container_name %}"><< Return to objects list</a></h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="right">
|
||||||
|
<h3>Description:</h3>
|
||||||
|
<p>You may make a new copy of an existing object to store in this or another container.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user