Commit 1abc2a1f by cloud

apply szakdoga patch

parent 5d753e30
...@@ -6,9 +6,17 @@ ...@@ -6,9 +6,17 @@
{% block content %} {% block content %}
<div class="body-content"> <div class="body-content">
<div class="page-header"> <div class="page-header">
<div class="pull-right" style="padding-top: 15px;" id="ops"> <div class="pull-right" style="padding-top: 15px;" >
<form style="display: inline;" method="POST" action="{% url "dashboard.views.detail" pk=instance.pk %}">
{% csrf_token %}
<input type="hidden" name="deploy_local" />
<button title="{% trans "Deploy on Local PC" %}" class="btn btn-default
btn-xs" type="submit"><i class="icon-chevron-right"></i></button>
</form>
<div id="ops">
{% include "dashboard/vm-detail/_operations.html" %} {% include "dashboard/vm-detail/_operations.html" %}
</div> </div>
</div>
<h1> <h1>
<div id="vm-details-rename"> <div id="vm-details-rename">
<form action="" method="POST" id="vm-details-rename-form"> <form action="" method="POST" id="vm-details-rename-form">
...@@ -111,5 +119,6 @@ ...@@ -111,5 +119,6 @@
<script src="{{ STATIC_URL }}dashboard/vm-details.js"></script> <script src="{{ STATIC_URL }}dashboard/vm-details.js"></script>
<script src="{{ STATIC_URL }}dashboard/vm-common.js"></script> <script src="{{ STATIC_URL }}dashboard/vm-common.js"></script>
<script src="{{ STATIC_URL }}dashboard/vm-console.js"></script> <script src="{{ STATIC_URL }}dashboard/vm-console.js"></script>
<script src="{{ STATIC_URL }}dashboard/client-gui.js"></script>
<script src="{{ STATIC_URL }}dashboard/disk-list.js"></script> <script src="{{ STATIC_URL }}dashboard/disk-list.js"></script>
{% endblock %} {% endblock %}
...@@ -239,6 +239,7 @@ class VmDetailView(CheckedDetailView): ...@@ -239,6 +239,7 @@ class VmDetailView(CheckedDetailView):
'change_password': self.__change_password, 'change_password': self.__change_password,
'new_name': self.__set_name, 'new_name': self.__set_name,
'new_tag': self.__add_tag, 'new_tag': self.__add_tag,
'deploy_local': self.__deploy_local,
'to_remove': self.__remove_tag, 'to_remove': self.__remove_tag,
'port': self.__add_port, 'port': self.__add_port,
'new_network_vlan': self.__new_network, 'new_network_vlan': self.__new_network,
...@@ -247,6 +248,15 @@ class VmDetailView(CheckedDetailView): ...@@ -247,6 +248,15 @@ class VmDetailView(CheckedDetailView):
if request.POST.get(k) is not None: if request.POST.get(k) is not None:
return v(request) return v(request)
def __deploy_local(self, request):
self.object = self.get_object()
if not self.object.has_level(request.user, 'owner'):
raise PermissionDenied()
return HttpResponse(
json.dumps(self.object.deploy_local(request.user)),
content_type="application/json")
def __change_password(self, request): def __change_password(self, request):
self.object = self.get_object() self.object = self.get_object()
if not self.object.has_level(request.user, 'owner'): if not self.object.has_level(request.user, 'owner'):
......
...@@ -29,6 +29,10 @@ from .common import BaseResourceConfigModel, Lease ...@@ -29,6 +29,10 @@ from .common import BaseResourceConfigModel, Lease
from .network import Interface from .network import Interface
from .node import Node, Trait from .node import Node, Trait
import os
import random
import string
logger = getLogger(__name__) logger = getLogger(__name__)
pre_state_changed = Signal(providing_args=["new_state"]) pre_state_changed = Signal(providing_args=["new_state"])
post_state_changed = Signal(providing_args=["new_state"]) post_state_changed = Signal(providing_args=["new_state"])
...@@ -180,6 +184,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin, ...@@ -180,6 +184,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
('NOSTATE', _('no state')), ('NOSTATE', _('no state')),
('RUNNING', _('running')), ('RUNNING', _('running')),
('STOPPED', _('stopped')), ('STOPPED', _('stopped')),
('LOCAL_RUNNING', _('local_running')),
('SUSPENDED', _('suspended')), ('SUSPENDED', _('suspended')),
('ERROR', _('error')), ('ERROR', _('error')),
('PENDING', _('pending')), ('PENDING', _('pending')),
...@@ -788,6 +793,50 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin, ...@@ -788,6 +793,50 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
queue=queue_name queue=queue_name
).get(timeout=timeout) ).get(timeout=timeout)
def __deploy_local_vm(self, act, timeout=15):
"""Local deploy the virtual machine.
:param self: The virtual machine.
:param act: Parent activity.
"""
descriptor = self.get_vm_desc()
# create hardlink
hlinkname = ''.join(random.choice(string.ascii_uppercase +
string.digits) for _ in range(20))
remotedest = '/mnt/vmdisks/' + hlinkname
localdest = '/home/cloud/nfs/' + hlinkname
localsrc = '/home/cloud' + descriptor['disk_list'][0]['source']
os.link(localsrc, localdest)
descriptor['disk_list'][0]['source'] = remotedest
return descriptor
def deploy_local(self, user=None, task_uuid=None):
"""Deploy new virtual machine with network
:param self: The virtual machine to deploy.
:type self: vm.models.Instance
:param user: The user who's issuing the command.
:type user: django.contrib.auth.models.User
:param task_uuid: The task's UUID, if the command is being ex
ecuted
asynchronously.
:type task_uuid: str
"""
if self.destroyed_at:
raise self.InstanceDestroyedError(self)
def __on_commit(activity):
activity.resultant_state = 'LOCAL_RUNNING'
with instance_activity(code_suffix='local_deploy', instance=self,
on_commit=__on_commit, task_uuid=task_uuid,
user=user) as act:
return self.__deploy_local_vm(act)
def migrate_vm(self, to_node, timeout=120): def migrate_vm(self, to_node, timeout=120):
queue_name = self.get_remote_queue_name('vm') queue_name = self.get_remote_queue_name('vm')
return vm_tasks.migrate.apply_async(args=[self.vm_name, return vm_tasks.migrate.apply_async(args=[self.vm_name,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment