Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
942db813
authored
Sep 04, 2013
by
tarokkk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor deploy()
parent
42fb490c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
39 deletions
+64
-39
circle/manager/manager.py
+1
-26
circle/vm/models.py
+63
-13
No files found.
circle/manager/manager.py
View file @
942db813
#!/usr/bin/env python
from
mancelery
import
celery
from
celery
import
current_task
import
scheduler
@celery.task
def
deploy
(
instance
):
'''Create new virtual machine from VM class.
'''
# Get info from scheduler (free space, node with enough cpu and ram)
current_task
.
update_state
(
state
=
'PENDING'
)
instance
.
node
=
scheduler
.
get_node
()
# Create hard drives (storage)
current_task
.
update_state
(
state
=
'PREPARE'
)
for
disk
in
instance
.
disks
:
disk
.
deploy
()
# Create context
instance
.
create_context
()
# Create machine (vmdriver)
current_task
.
update_state
(
state
=
'DEPLOY VM'
)
instance
.
deploy_task
()
# Estabilish network connection (vmdriver)
current_task
.
update_state
(
state
=
'DEPLOY NET'
)
instance
.
deploy_net
()
# Resume machine (vmdriver)
current_task
.
update_state
(
state
=
'BOOT'
)
instance
.
resume
()
pass
instance
.
deploy
(
task_uuid
=
deploy
.
request
.
id
)
def
delete
():
...
...
circle/vm/models.py
View file @
942db813
...
...
@@ -5,6 +5,8 @@ import logging
from
.
import
tasks
from
manager
import
manager
,
scheduler
from
django.contrib.auth.models
import
User
from
django.db
import
models
from
django.db.models.signals
import
pre_delete
...
...
@@ -16,7 +18,6 @@ from model_utils.models import TimeStampedModel
from
firewall.models
import
Vlan
,
Host
from
storage.models
import
Disk
import
manager
logger
=
logging
.
getLogger
(
__name__
)
pwgen
=
User
.
objects
.
make_random_password
...
...
@@ -31,6 +32,7 @@ ACCESS_METHODS = [(k, ap[0]) for k, ap in ACCESS_PROTOCOLS.iteritems()]
class
BaseResourceConfigModel
(
models
.
Model
):
"""Abstract base class for models with base resource configuration
parameters.
"""
...
...
@@ -48,6 +50,7 @@ class BaseResourceConfigModel(models.Model):
class
NamedBaseResourceConfig
(
BaseResourceConfigModel
,
TimeStampedModel
):
"""Pre-created, named base resource configurations.
"""
name
=
models
.
CharField
(
max_length
=
50
,
unique
=
True
,
...
...
@@ -58,6 +61,7 @@ class NamedBaseResourceConfig(BaseResourceConfigModel, TimeStampedModel):
class
Node
(
TimeStampedModel
):
"""A VM host machine.
"""
name
=
models
.
CharField
(
max_length
=
50
,
unique
=
True
,
...
...
@@ -82,7 +86,8 @@ class Node(TimeStampedModel):
class
NodeActivity
(
TimeStampedModel
):
activity_code
=
models
.
CharField
(
max_length
=
100
)
task_uuid
=
models
.
CharField
(
max_length
=
50
,
unique
=
True
)
task_uuid
=
models
.
CharField
(
max_length
=
50
,
unique
=
True
,
null
=
True
,
blank
=
True
)
node
=
models
.
ForeignKey
(
Node
,
related_name
=
'activity_log'
)
user
=
models
.
ForeignKey
(
User
,
blank
=
True
,
null
=
True
)
started
=
models
.
DateTimeField
(
blank
=
True
,
null
=
True
)
...
...
@@ -92,6 +97,7 @@ class NodeActivity(TimeStampedModel):
class
Lease
(
models
.
Model
):
"""Lease times for VM instances.
Specifies a time duration until suspension and deletion of a VM
...
...
@@ -123,6 +129,7 @@ class Lease(models.Model):
class
InstanceTemplate
(
BaseResourceConfigModel
,
TimeStampedModel
):
"""Virtual machine template.
Every template has:
...
...
@@ -184,6 +191,7 @@ class InstanceTemplate(BaseResourceConfigModel, TimeStampedModel):
class
InterfaceTemplate
(
models
.
Model
):
"""Network interface template for an instance template.
If the interface is managed, a host will be created for it.
...
...
@@ -200,6 +208,7 @@ class InterfaceTemplate(models.Model):
class
Instance
(
BaseResourceConfigModel
,
TimeStampedModel
):
"""Virtual machine instance.
Every instance has:
...
...
@@ -388,15 +397,8 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
except
:
return
def
deploy
(
self
):
''' Launch celery task to handle asyncron jobs.
'''
manager
.
deploy
.
apply_async
(
self
)
def
deploy_task
(
self
):
''' Deploy virtual machine on remote node
'''
instance
=
{
def
get_vm_desc
(
self
):
return
{
'name'
:
'cloud-'
+
self
.
id
,
'vcpu'
:
self
.
num_cores
,
'memory'
:
self
.
ram_size
,
...
...
@@ -413,7 +415,42 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
'port'
:
self
.
get_vnc_port
()},
'raw_data'
:
self
.
raw_data
}
tasks
.
create
.
apply_async
(
instance
,
queue
=
self
.
node
+
".vm"
)
.
get
()
def
deploy_async
(
self
):
''' Launch celery task to handle asyncron jobs.
'''
manager
.
deploy
.
apply_async
(
self
)
def
deploy
(
self
,
user
,
task_uuid
=
None
):
''' Deploy new virtual machine with network
1. Schedule
'''
act
=
InstanceActivity
(
user
=
user
,
task_uuid
=
task_uuid
)
# Schedule
act
.
update_state
(
"PENDING"
)
self
.
node
=
scheduler
.
get_node
()
# Create virtual images
act
.
update_state
(
"PREPARING DISKS"
)
for
disk
in
self
.
disks
:
disk
.
deploy
()
# Deploy VM on remote machine
act
.
update_state
(
"DEPLOYING VM"
)
tasks
.
create
.
apply_async
(
self
.
get_vm_desc
,
queue
=
self
.
node
+
".vm"
)
.
get
()
# Estabilish network connection (vmdriver)
act
.
update_state
(
"DEPLOYING NET"
)
for
net
in
self
.
interface_set
.
all
():
net
.
deploy
()
# Resume vm
act
.
update_state
(
"BOOTING"
)
tasks
.
resume
.
apply_async
(
"cloud-"
+
self
.
id
,
queue
=
self
.
node
+
".vm"
)
.
get
()
act
.
finish
()
def
stop
(
self
):
# TODO implement
...
...
@@ -476,7 +513,8 @@ def delete_instance_pre(sender, instance, using, **kwargs):
class
InstanceActivity
(
TimeStampedModel
):
activity_code
=
models
.
CharField
(
max_length
=
100
)
task_uuid
=
models
.
CharField
(
max_length
=
50
,
unique
=
True
)
task_uuid
=
models
.
CharField
(
max_length
=
50
,
unique
=
True
,
null
=
True
,
blank
=
True
)
instance
=
models
.
ForeignKey
(
Instance
,
related_name
=
'activity_log'
)
user
=
models
.
ForeignKey
(
User
,
blank
=
True
,
null
=
True
)
started
=
models
.
DateTimeField
(
blank
=
True
,
null
=
True
)
...
...
@@ -484,6 +522,18 @@ class InstanceActivity(TimeStampedModel):
result
=
models
.
TextField
(
blank
=
True
,
null
=
True
)
status
=
models
.
CharField
(
default
=
'PENDING'
,
max_length
=
50
)
def
__init__
(
self
):
# TODO
pass
def
update_state
(
self
):
# TODO
pass
def
finish
(
self
):
# TODO
pass
class
Interface
(
models
.
Model
):
...
...
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