Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
870ef308
authored
Apr 09, 2020
by
Máhonfai Bálint
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add import disk operation
parent
5f4df6e6
Pipeline
#1063
passed with stage
in 0 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
37 deletions
+43
-37
circle/vm/operations.py
+43
-37
No files found.
circle/vm/operations.py
View file @
870ef308
...
...
@@ -16,47 +16,46 @@
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from
__future__
import
absolute_import
,
unicode_literals
from
StringIO
import
StringIO
from
base64
import
encodestring
from
hashlib
import
md5
from
logging
import
getLogger
import
os
from
re
import
search
from
string
import
ascii_lowercase
from
StringIO
import
StringIO
from
tarfile
import
TarFile
,
TarInfo
import
time
from
urlparse
import
urlsplit
import
os
import
time
from
celery.contrib.abortable
import
AbortableAsyncResult
from
celery.exceptions
import
TimeLimitExceeded
,
TimeoutError
from
django.conf
import
settings
from
django.core.exceptions
import
PermissionDenied
,
SuspiciousOperation
from
django.core.urlresolvers
import
reverse
from
django.db.models
import
Q
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
,
ugettext_noop
from
django.conf
import
settings
from
django.db.models
import
Q
from
re
import
search
from
sizefield.utils
import
filesizeformat
from
celery.contrib.abortable
import
AbortableAsyncResult
from
celery.exceptions
import
TimeLimitExceeded
,
TimeoutError
from
common.models
import
(
create_readable
,
humanize_exception
,
HumanReadableException
)
from
common.operations
import
Operation
,
register_operation
,
SubOperationMixin
from
dashboard.store_api
import
Store
,
NoStoreException
from
firewall.models
import
Host
from
manager.scheduler
import
SchedulerError
from
.tasks.local_tasks
import
(
abortable_async_instance_operation
,
abortable_async_node_operation
,
)
from
monitor.client
import
Client
from
storage.models
import
Disk
from
storage.tasks
import
storage_tasks
from
.models
import
(
Instance
,
InstanceActivity
,
InstanceTemplate
,
Interface
,
Node
,
NodeActivity
,
pwgen
)
from
.tasks
import
agent_tasks
,
vm_tasks
from
dashboard.store_api
import
Store
,
NoStoreException
from
firewall.models
import
Host
from
monitor.client
import
Client
from
storage.tasks
import
storage_tasks
from
.tasks.local_tasks
import
(
abortable_async_instance_operation
,
abortable_async_node_operation
,
)
logger
=
getLogger
(
__name__
)
...
...
@@ -325,8 +324,6 @@ class DownloadDiskOperation(InstanceOperation):
async_queue
=
"localhost.man.slow"
def
_operation
(
self
,
user
,
url
,
task
,
activity
,
name
=
None
):
from
storage.models
import
Disk
disk
=
Disk
.
download
(
url
=
url
,
name
=
name
,
task
=
task
)
devnums
=
list
(
ascii_lowercase
)
for
d
in
self
.
instance
.
disks
.
all
():
...
...
@@ -348,6 +345,31 @@ class DownloadDiskOperation(InstanceOperation):
@register_operation
class
ImportDiskOperation
(
InstanceOperation
):
id
=
'import_disk'
name
=
_
(
'import disk'
)
description
=
_
(
'Import and attach a disk image to the virtual machine '
'from the user store. The disk image has to be in the '
'root directory of the store.'
)
required_perms
=
(
'storage.import_disk'
,)
accept_states
=
(
'STOPPED'
,
'PENDING'
,
'RUNNING'
)
async_queue
=
'localhost.man.slow'
def
check_auth
(
self
,
user
):
super
(
ImportDiskOperation
,
self
)
.
check_auth
(
user
)
try
:
Store
(
user
)
except
NoStoreException
:
raise
PermissionDenied
def
_operation
(
self
,
user
,
name
,
disk_path
):
store
=
Store
(
user
)
download_link
=
store
.
request_download
(
disk_path
)
disk
=
Disk
.
import_disk
(
user
,
name
,
download_link
)
self
.
instance
.
disks
.
add
(
disk
)
@register_operation
class
ExportDiskOperation
(
InstanceOperation
):
id
=
'export_disk'
name
=
_
(
'export disk'
)
...
...
@@ -365,27 +387,11 @@ class ExportDiskOperation(InstanceOperation):
def
_operation
(
self
,
user
,
disk
,
format
):
store
=
Store
(
user
)
store
.
new_folder
(
'/export'
)
upload_link
=
store
.
request_upload
(
'/export'
)
upload_link
=
store
.
request_upload
(
'/'
)
disk
.
export
(
format
,
upload_link
)
@register_operation
class
ImportDiskOperation
(
InstanceOperation
):
id
=
'import_disk'
name
=
_
(
'import disk'
)
description
=
_
(
'Import and attach a disk image to the virtual machine.'
)
abortable
=
True
has_percentage
=
True
required_perms
=
(
'storage.import_disk'
,)
accept_states
=
(
'STOPPED'
,
'PENDING'
,
'RUNNING'
)
async_queue
=
'localhost.man.slow'
def
_operation
(
self
,
activity
):
pass
@register_operation
class
DeployOperation
(
InstanceOperation
):
id
=
'deploy'
name
=
_
(
"deploy"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment