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
c462cc6d
authored
Oct 27, 2016
by
Szabolcs Gelencser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor deploy vm operation, add diagnostics extension deploy
parent
bac9f005
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
16 deletions
+39
-16
circle/vm/operations.py
+32
-16
circle/vm/tasks/net_tasks.py
+3
-0
circle/vm/tasks/vm_tasks.py
+4
-0
No files found.
circle/vm/operations.py
View file @
c462cc6d
...
@@ -52,7 +52,7 @@ from .models import (
...
@@ -52,7 +52,7 @@ from .models import (
NodeActivity
,
pwgen
NodeActivity
,
pwgen
)
)
from
.tasks
import
agent_tasks
,
vm_tasks
from
.tasks
import
agent_tasks
,
vm_tasks
,
net_tasks
from
dashboard.store_api
import
Store
,
NoStoreException
from
dashboard.store_api
import
Store
,
NoStoreException
from
firewall.models
import
Host
from
firewall.models
import
Host
...
@@ -372,28 +372,25 @@ class DeployOperation(InstanceOperation):
...
@@ -372,28 +372,25 @@ class DeployOperation(InstanceOperation):
def
on_commit
(
self
,
activity
):
def
on_commit
(
self
,
activity
):
activity
.
resultant_state
=
'RUNNING'
activity
.
resultant_state
=
'RUNNING'
activity
.
result
=
create_readable
(
ugettext_noop
(
"virtual machine successfully "
"deployed to node:
%(node)
s"
),
node
=
self
.
instance
.
node
)
def
_operation
(
self
,
activity
,
node
=
None
):
def
_operation
(
self
,
activity
,
node
=
None
):
# Deploy VM in Azure
if
not
self
.
instance
.
azure_id
:
if
self
.
instance
.
state
==
'PENDING'
:
self
.
instance
.
_deploy_vm
(
parent_activity
=
activity
)
self
.
instance
.
_deploy_vm
(
parent_activity
=
activity
)
self
.
instance
.
_start_diagnostics
(
parent_activity
=
activity
)
else
:
self
.
instance
.
_resume_vm
(
parent_activity
=
activity
)
self
.
instance
.
_collect_public_ips
(
parent_activity
=
activity
)
try
:
try
:
self
.
instance
.
renew
(
parent_activity
=
activity
)
self
.
instance
.
renew
(
parent_activity
=
activity
)
except
:
except
:
pass
pass
self
.
instance
.
_resume_vm
(
parent_activity
=
activity
)
@register_operation
@register_operation
class
DeployVmOperation
(
SubOperationMixin
,
InstanceOperation
):
class
DeployVmOperation
(
SubOperationMixin
,
InstanceOperation
):
id
=
"_deploy_vm"
id
=
"_deploy_vm"
name
=
_
(
"deploy vm"
)
name
=
_
(
"Create and start virtual machine in Azure"
)
description
=
_
(
"Deploy virtual machine."
)
def
_operation
(
self
):
def
_operation
(
self
):
nics
=
[
str
(
nic_id
)
for
nic_id
in
nics
=
[
str
(
nic_id
)
for
nic_id
in
...
@@ -419,7 +416,7 @@ class DeployOperation(InstanceOperation):
...
@@ -419,7 +416,7 @@ class DeployOperation(InstanceOperation):
}]
}]
azure_id
=
vm_tasks
.
deploy
.
apply_async
(
azure_id
=
vm_tasks
.
deploy
.
apply_async
(
args
=
args
,
queue
=
"localhost.vm.
fast
"
args
=
args
,
queue
=
"localhost.vm.
slow
"
)
.
get
(
timeout
=
1200
)
)
.
get
(
timeout
=
1200
)
if
azure_id
:
if
azure_id
:
...
@@ -434,17 +431,26 @@ class DeployOperation(InstanceOperation):
...
@@ -434,17 +431,26 @@ class DeployOperation(InstanceOperation):
@register_operation
@register_operation
class
ResumeVmOperation
(
SubOperationMixin
,
InstanceOperation
):
class
ResumeVmOperation
(
SubOperationMixin
,
InstanceOperation
):
id
=
"_resume_vm"
id
=
"_resume_vm"
name
=
_
(
"boot virtual machine"
)
name
=
_
(
"Start existing virtual machine"
)
def
_operation
(
self
):
vm_tasks
.
resume
.
apply_async
(
args
=
[
self
.
instance
.
name
],
queue
=
"localhost.vm.slow"
)
.
get
(
timeout
=
1200
)
@register_operation
class
CollectPublicIPsOperation
(
SubOperationMixin
,
InstanceOperation
):
id
=
"_collect_public_ips"
name
=
_
(
"Collect public IPs of virtual machine"
)
def
_operation
(
self
):
def
_operation
(
self
):
#TODO: implement resume functionality too
nics
=
[{
nics
=
[{
"id"
:
nic
.
id
,
"id"
:
nic
.
id
,
"public_ip_name"
:
nic
.
public_ip_name
,
"public_ip_name"
:
nic
.
public_ip_name
,
}
for
nic
in
self
.
instance
.
interface_set
.
all
()]
}
for
nic
in
self
.
instance
.
interface_set
.
all
()]
result
=
vm_tasks
.
resume
.
apply_async
(
result
=
net_tasks
.
collect_public_ips
.
apply_async
(
args
=
[
nics
],
queue
=
"localhost.
vm
.fast"
args
=
[
nics
],
queue
=
"localhost.
net
.fast"
)
.
get
(
timeout
=
1200
)
)
.
get
(
timeout
=
1200
)
for
nic
in
result
:
for
nic
in
result
:
...
@@ -452,6 +458,16 @@ class DeployOperation(InstanceOperation):
...
@@ -452,6 +458,16 @@ class DeployOperation(InstanceOperation):
nic_obj
.
public_ip
=
nic
[
"public_ip"
]
nic_obj
.
public_ip
=
nic
[
"public_ip"
]
nic_obj
.
save
()
nic_obj
.
save
()
@register_operation
class
StartDiagnosticsOperation
(
SubOperationMixin
,
InstanceOperation
):
id
=
"_start_diagnostics"
name
=
_
(
"Start diagnostics on virtual machine"
)
def
_operation
(
self
):
vm_tasks
.
install_diagnostics_extension
.
apply_async
(
args
=
[
self
.
instance
.
name
],
queue
=
"localhost.vm.fast"
)
.
get
(
timeout
=
1200
)
@register_operation
@register_operation
class
DestroyOperation
(
InstanceOperation
):
class
DestroyOperation
(
InstanceOperation
):
id
=
'destroy'
id
=
'destroy'
...
...
circle/vm/tasks/net_tasks.py
View file @
c462cc6d
...
@@ -17,6 +17,9 @@
...
@@ -17,6 +17,9 @@
from
manager.mancelery
import
celery
from
manager.mancelery
import
celery
@celery.task
(
name
=
'netdriver.collect_public_ips'
)
def
collect_public_ips
(
nics
):
pass
@celery.task
(
name
=
'netdriver.create_azure_interface'
)
@celery.task
(
name
=
'netdriver.create_azure_interface'
)
def
create_azure_interface
(
ifacepk
,
vlan_name
):
def
create_azure_interface
(
ifacepk
,
vlan_name
):
...
...
circle/vm/tasks/vm_tasks.py
View file @
c462cc6d
...
@@ -61,6 +61,10 @@ def get_queues():
...
@@ -61,6 +61,10 @@ def get_queues():
cache
.
set
(
key
,
result
,
10
)
cache
.
set
(
key
,
result
,
10
)
return
result
return
result
@celery.task
(
name
=
'vmdriver.install_diagnostics_extension'
)
def
install_diagnostics_extension
(
vm_name
):
pass
@celery.task
(
name
=
'vmdriver.save_as_template'
)
@celery.task
(
name
=
'vmdriver.save_as_template'
)
def
save_as_template
(
vm_name
,
vm_pk
):
def
save_as_template
(
vm_name
,
vm_pk
):
pass
pass
...
...
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