Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f40dd11d
authored
Oct 01, 2013
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: refactoring task fixing EUI
parent
3585f29a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
28 deletions
+54
-28
circle/vm/models.py
+43
-28
circle/vm/tasks/net_tasks.py
+11
-0
circle/vm/tasks/vm_tasks.py
+0
-0
No files found.
circle/vm/models.py
View file @
f40dd11d
...
@@ -10,9 +10,9 @@ from django.db.models import (Model, ForeignKey, ManyToManyField, IntegerField,
...
@@ -10,9 +10,9 @@ from django.db.models import (Model, ForeignKey, ManyToManyField, IntegerField,
from
django.utils
import
timezone
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
from
model_utils.models
import
TimeStampedModel
from
model_utils.models
import
TimeStampedModel
from
netaddr
import
EUI
from
netaddr
import
EUI
,
mac_unix
from
.tasks
import
local_tasks
,
remote
_tasks
from
.tasks
import
local_tasks
,
vm_tasks
,
net
_tasks
from
firewall.models
import
Vlan
,
Host
from
firewall.models
import
Vlan
,
Host
from
storage.models
import
Disk
from
storage.models
import
Disk
...
@@ -247,7 +247,8 @@ class InterfaceTemplate(Model):
...
@@ -247,7 +247,8 @@ class InterfaceTemplate(Model):
'association) should be generated.'
))
'association) should be generated.'
))
template
=
ForeignKey
(
InstanceTemplate
,
verbose_name
=
_
(
'template'
),
template
=
ForeignKey
(
InstanceTemplate
,
verbose_name
=
_
(
'template'
),
related_name
=
'interface_set'
,
related_name
=
'interface_set'
,
help_text
=
_
())
help_text
=
_
(
'Template the interface '
'template belongs to.'
))
class
Meta
:
class
Meta
:
permissions
=
()
permissions
=
()
...
@@ -351,10 +352,10 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
...
@@ -351,10 +352,10 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
kwargs
.
setdefault
(
'access_method'
,
template
.
access_method
)
kwargs
.
setdefault
(
'access_method'
,
template
.
access_method
)
# create instance and do additional setup
# create instance and do additional setup
inst
=
cls
(
**
kwargs
)
inst
=
cls
(
**
kwargs
)
for
disk
in
template
.
disks
:
inst
.
disks
.
add
(
disk
.
get_exclusive
())
# save instance
# save instance
inst
.
save
()
inst
.
save
()
for
disk
in
template
.
disks
.
all
():
inst
.
disks
.
add
(
disk
.
get_exclusive
())
# create related entities
# create related entities
for
iftmpl
in
template
.
interface_set
.
all
():
for
iftmpl
in
template
.
interface_set
.
all
():
i
=
Interface
.
create_from_template
(
instance
=
inst
,
template
=
iftmpl
)
i
=
Interface
.
create_from_template
(
instance
=
inst
,
template
=
iftmpl
)
...
@@ -511,8 +512,8 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
...
@@ -511,8 +512,8 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
# Deploy VM on remote machine
# Deploy VM on remote machine
act
.
update_state
(
'DEPLOYING VM'
)
act
.
update_state
(
'DEPLOYING VM'
)
queue_name
=
self
.
node
.
host
.
hostname
+
".vm"
queue_name
=
self
.
node
.
host
.
hostname
+
".vm"
remote
_tasks
.
create
.
apply_async
(
args
=
[
self
.
get_vm_desc
()],
vm
_tasks
.
create
.
apply_async
(
args
=
[
self
.
get_vm_desc
()],
queue
=
queue_name
)
.
get
()
queue
=
queue_name
)
.
get
()
# Estabilish network connection (vmdriver)
# Estabilish network connection (vmdriver)
act
.
update_state
(
'DEPLOYING NET'
)
act
.
update_state
(
'DEPLOYING NET'
)
...
@@ -521,8 +522,8 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
...
@@ -521,8 +522,8 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
# Resume vm
# Resume vm
act
.
update_state
(
'BOOTING'
)
act
.
update_state
(
'BOOTING'
)
remote
_tasks
.
resume
.
apply_async
(
args
=
[
self
.
vm_name
],
vm
_tasks
.
resume
.
apply_async
(
args
=
[
self
.
vm_name
],
queue
=
queue_name
)
.
get
()
queue
=
queue_name
)
.
get
()
act
.
finish
(
result
=
'SUCCESS'
)
act
.
finish
(
result
=
'SUCCESS'
)
...
@@ -540,8 +541,8 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
...
@@ -540,8 +541,8 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
act
.
task_uuid
=
task_uuid
act
.
task_uuid
=
task_uuid
act
.
save
()
act
.
save
()
queue_name
=
self
.
node
.
host
.
hostname
+
".vm"
queue_name
=
self
.
node
.
host
.
hostname
+
".vm"
remote
_tasks
.
stop
.
apply_async
(
args
=
[
self
.
get_vm_desc
()],
vm
_tasks
.
stop
.
apply_async
(
args
=
[
self
.
get_vm_desc
()],
queue
=
queue_name
)
.
get
()
queue
=
queue_name
)
.
get
()
def
stop_async
(
self
,
user
=
None
):
def
stop_async
(
self
,
user
=
None
):
"""Execute stop asynchronously.
"""Execute stop asynchronously.
...
@@ -556,8 +557,8 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
...
@@ -556,8 +557,8 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
act
.
task_uuid
=
task_uuid
act
.
task_uuid
=
task_uuid
act
.
save
()
act
.
save
()
queue_name
=
self
.
node
.
host
.
hostname
+
".vm"
queue_name
=
self
.
node
.
host
.
hostname
+
".vm"
remote
_tasks
.
resume
.
apply_async
(
args
=
[
self
.
vm_name
],
vm
_tasks
.
resume
.
apply_async
(
args
=
[
self
.
vm_name
],
queue
=
queue_name
)
.
get
()
queue
=
queue_name
)
.
get
()
def
resume_async
(
self
,
user
=
None
):
def
resume_async
(
self
,
user
=
None
):
"""Execute resume asynchronously.
"""Execute resume asynchronously.
...
@@ -573,8 +574,8 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
...
@@ -573,8 +574,8 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
act
.
task_uuid
=
task_uuid
act
.
task_uuid
=
task_uuid
act
.
save
()
act
.
save
()
queue_name
=
self
.
node
.
host
.
hostname
+
".vm"
queue_name
=
self
.
node
.
host
.
hostname
+
".vm"
remote
_tasks
.
power_off
.
apply_async
(
args
=
[
self
.
get_vm_desc
()],
vm
_tasks
.
power_off
.
apply_async
(
args
=
[
self
.
get_vm_desc
()],
queue
=
queue_name
)
.
get
()
queue
=
queue_name
)
.
get
()
def
poweroff_async
(
self
,
user
=
None
):
def
poweroff_async
(
self
,
user
=
None
):
"""Execute poweroff asynchronously.
"""Execute poweroff asynchronously.
...
@@ -590,8 +591,8 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
...
@@ -590,8 +591,8 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
act
.
task_uuid
=
task_uuid
act
.
task_uuid
=
task_uuid
act
.
save
()
act
.
save
()
queue_name
=
self
.
node
.
host
.
hostname
+
".vm"
queue_name
=
self
.
node
.
host
.
hostname
+
".vm"
remote
_tasks
.
restart
.
apply_async
(
args
=
[
self
.
get_vm_desc
()],
vm
_tasks
.
restart
.
apply_async
(
args
=
[
self
.
get_vm_desc
()],
queue
=
queue_name
)
.
get
()
queue
=
queue_name
)
.
get
()
def
restart_async
(
self
,
user
=
None
):
def
restart_async
(
self
,
user
=
None
):
"""Execute restart asynchronously.
"""Execute restart asynchronously.
...
@@ -607,8 +608,8 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
...
@@ -607,8 +608,8 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
act
.
task_uuid
=
task_uuid
act
.
task_uuid
=
task_uuid
act
.
save
()
act
.
save
()
queue_name
=
self
.
node
.
host
.
hostname
+
".vm"
queue_name
=
self
.
node
.
host
.
hostname
+
".vm"
remote
_tasks
.
save_as
.
apply_async
(
args
=
[
self
.
get_vm_desc
()],
vm
_tasks
.
save_as
.
apply_async
(
args
=
[
self
.
get_vm_desc
()],
queue
=
queue_name
)
.
get
()
queue
=
queue_name
)
.
get
()
def
save_as_async
(
self
,
user
=
None
):
def
save_as_async
(
self
,
user
=
None
):
"""Execute save_as asynchronously.
"""Execute save_as asynchronously.
...
@@ -663,6 +664,9 @@ class Interface(Model):
...
@@ -663,6 +664,9 @@ class Interface(Model):
instance
=
ForeignKey
(
Instance
,
verbose_name
=
_
(
'instance'
),
instance
=
ForeignKey
(
Instance
,
verbose_name
=
_
(
'instance'
),
related_name
=
'interface_set'
)
related_name
=
'interface_set'
)
def
__unicode__
(
self
):
return
'cloud-'
+
str
(
self
.
instance
.
id
)
+
'-'
+
str
(
self
.
vlan
.
vid
)
@property
@property
def
mac
(
self
):
def
mac
(
self
):
try
:
try
:
...
@@ -680,31 +684,42 @@ class Interface(Model):
...
@@ -680,31 +684,42 @@ class Interface(Model):
i
=
instance
.
id
&
0xfffffff
i
=
instance
.
id
&
0xfffffff
v
=
vlan
.
vid
&
0xfff
v
=
vlan
.
vid
&
0xfff
m
=
(
0x02
<<
40
)
|
(
i
<<
12
)
|
v
m
=
(
0x02
<<
40
)
|
(
i
<<
12
)
|
v
return
EUI
(
m
)
return
EUI
(
m
,
dialect
=
mac_unix
)
def
get_vmnetwork_desc
(
self
):
def
get_vmnetwork_desc
(
self
):
return
{
return
{
'name'
:
'cloud-'
+
self
.
instance
.
id
+
'-'
+
self
.
vlan
.
vid
,
'name'
:
'cloud-'
+
str
(
self
.
instance
.
id
)
+
'-'
+
str
(
self
.
vlan
.
vid
),
'bridge'
:
'cloud'
,
'bridge'
:
'cloud'
,
'mac'
:
s
elf
.
mac
,
'mac'
:
s
tr
(
self
.
mac
)
,
'ipv4'
:
self
.
host
.
ipv4
if
self
.
host
is
not
None
else
None
,
'ipv4'
:
self
.
host
.
ipv4
if
self
.
host
is
not
None
else
None
,
'ipv6'
:
self
.
host
.
ipv6
if
self
.
host
is
not
None
else
None
,
'ipv6'
:
self
.
host
.
ipv6
if
self
.
host
is
not
None
else
None
,
'vlan'
:
self
.
vlan
.
vid
,
'vlan'
:
self
.
vlan
.
vid
,
'managed'
:
self
.
host
is
not
None
'managed'
:
self
.
host
is
not
None
}
}
def
deploy
(
self
):
def
deploy
(
self
,
user
=
None
,
task_uuid
=
None
):
#TODO
net_tasks
.
create
.
apply_async
(
pass
args
=
[
self
.
get_vmnetwork_desc
()],
queue
=
self
.
instance
.
node
.
host
.
hostname
+
'.net'
)
def
remove
(
self
,
user
=
None
,
task_uuid
=
None
):
net_tasks
.
delete
.
apply_async
(
args
=
[
self
.
get_vmnetwork_desc
()],
queue
=
self
.
instance
.
node
.
host
.
hostname
+
'.net'
)
@classmethod
@classmethod
def
create_from_template
(
cls
,
instance
,
template
):
def
create_from_template
(
cls
,
instance
,
template
):
"""Create a new interface for an instance based on an
"""Create a new interface for an instance based on an
InterfaceTemplate.
InterfaceTemplate.
"""
"""
host
=
(
Host
(
vlan
=
template
.
vlan
,
mac
=
cls
.
generate_mac
(
instance
,
if
template
.
managed
:
template
.
vlan
))
host
=
Host
(
vlan
=
template
.
vlan
,
if
template
.
managed
else
None
)
mac
=
str
(
cls
.
generate_mac
(
instance
,
template
.
vlan
)))
# TODO Fix at firewall EUI
host
.
save
()
else
:
host
=
None
iface
=
cls
(
vlan
=
template
.
vlan
,
host
=
host
,
instance
=
instance
)
iface
=
cls
(
vlan
=
template
.
vlan
,
host
=
host
,
instance
=
instance
)
iface
.
save
()
iface
.
save
()
return
iface
return
iface
circle/vm/tasks/net_tasks.py
0 → 100644
View file @
f40dd11d
from
manager.mancelery
import
celery
@celery.task
(
name
=
'netdriver.create'
)
def
create
(
params
):
pass
@celery.task
(
name
=
'netdriver.delete'
)
def
delete
(
params
):
pass
circle/vm/tasks/
remote
_tasks.py
→
circle/vm/tasks/
vm
_tasks.py
View file @
f40dd11d
File moved
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