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
654dbc54
authored
Oct 11, 2016
by
Szabolcs Gelencser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement deploy operation for Azure VM creation.
parent
b2ef4090
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
40 deletions
+79
-40
circle/vm/migrations/0008_instance_azure_id.py
+19
-0
circle/vm/migrations/0009_auto_20161011_1328.py
+19
-0
circle/vm/models/instance.py
+2
-1
circle/vm/operations.py
+39
-39
No files found.
circle/vm/migrations/0008_instance_azure_id.py
0 → 100644
View file @
654dbc54
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'vm'
,
'0007_interface_azure_id'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'instance'
,
name
=
'azure_id'
,
field
=
models
.
TextField
(
null
=
True
),
),
]
circle/vm/migrations/0009_auto_20161011_1328.py
0 → 100644
View file @
654dbc54
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'vm'
,
'0008_instance_azure_id'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'instance'
,
name
=
'azure_id'
,
field
=
models
.
TextField
(
blank
=
True
),
),
]
circle/vm/models/instance.py
View file @
654dbc54
...
...
@@ -228,6 +228,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
)
name
=
CharField
(
blank
=
True
,
max_length
=
100
,
verbose_name
=
_
(
'name'
),
help_text
=
_
(
"Human readable name of instance."
))
azure_id
=
TextField
(
blank
=
True
)
description
=
TextField
(
blank
=
True
,
verbose_name
=
_
(
'description'
))
template
=
ForeignKey
(
InstanceTemplate
,
blank
=
True
,
null
=
True
,
related_name
=
'instance_set'
,
on_delete
=
SET_NULL
,
...
...
@@ -645,7 +646,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
if
self
.
node
:
return
self
.
node
.
get_remote_queue_name
(
queue_id
,
priority
)
else
:
r
aise
Node
.
DoesNotExist
()
r
eturn
"localhost.vm.fast"
def
_is_notified_about_expiration
(
self
):
last_activity
=
self
.
activity_log
.
latest
(
'pk'
)
...
...
circle/vm/operations.py
View file @
654dbc54
...
...
@@ -51,6 +51,8 @@ from .models import (
Instance
,
InstanceActivity
,
InstanceTemplate
,
Interface
,
Node
,
NodeActivity
,
pwgen
)
#from storage.models import DataStore
from
.tasks
import
agent_tasks
,
vm_tasks
from
dashboard.store_api
import
Store
,
NoStoreException
...
...
@@ -377,32 +379,10 @@ class DeployOperation(InstanceOperation):
node
=
self
.
instance
.
node
)
def
_operation
(
self
,
activity
,
node
=
None
):
# Allocate VNC port and host node
self
.
instance
.
allocate_vnc_port
()
if
node
is
not
None
:
self
.
instance
.
node
=
node
self
.
instance
.
save
()
else
:
self
.
instance
.
allocate_node
()
# Deploy virtual images
try
:
self
.
instance
.
_deploy_disks
(
parent_activity
=
activity
)
except
:
self
.
instance
.
yield_node
()
self
.
instance
.
yield_vnc_port
()
raise
# Deploy VM on remote machine
if
self
.
instance
.
state
not
in
[
'PAUSED'
]:
# Deploy VM in Azure
if
self
.
instance
.
state
==
'PENDING'
:
self
.
instance
.
_deploy_vm
(
parent_activity
=
activity
)
# Establish network connection (vmdriver)
with
activity
.
sub_activity
(
'deploying_net'
,
readable_name
=
ugettext_noop
(
"deploy network"
)):
self
.
instance
.
deploy_net
()
try
:
self
.
instance
.
renew
(
parent_activity
=
activity
)
except
:
...
...
@@ -410,26 +390,46 @@ class DeployOperation(InstanceOperation):
self
.
instance
.
_resume_vm
(
parent_activity
=
activity
)
if
self
.
instance
.
has_agent
:
activity
.
sub_activity
(
'os_boot'
,
readable_name
=
ugettext_noop
(
"wait operating system loading"
),
interruptible
=
True
)
@register_operation
class
DeployVmOperation
(
SubOperationMixin
,
Remote
InstanceOperation
):
class
DeployVmOperation
(
SubOperationMixin
,
InstanceOperation
):
id
=
"_deploy_vm"
name
=
_
(
"deploy vm"
)
description
=
_
(
"Deploy virtual machine."
)
remote_queue
=
(
"vm"
,
"slow"
)
task
=
vm_tasks
.
deploy
def
_get_remote_args
(
self
,
**
kwargs
):
return
[
self
.
instance
.
get_vm_desc
()]
# intentionally not calling super
def
get_activity_name
(
self
,
kwargs
):
return
create_readable
(
ugettext_noop
(
"deploy virtual machine"
),
ugettext_noop
(
"deploy vm to
%(node)
s"
),
node
=
self
.
instance
.
node
)
def
_operation
(
self
):
nics
=
[
str
(
nic_id
)
for
nic_id
in
self
.
instance
.
interface_set
.
values_list
(
'azure_id'
,
flat
=
True
)]
#storage_name = DataStore.objects.get(pk=1).name
vm_size_version
=
self
.
instance
.
azure_template
vm_size_sku
=
vm_size_version
.
sku
vm_size_offer
=
vm_size_sku
.
offer
vm_size_publisher
=
vm_size_offer
.
publisher
args
=
[{
"name"
:
self
.
instance
.
name
,
"user"
:
"cloud"
,
"pw"
:
self
.
instance
.
pw
,
"vm_size"
:
self
.
instance
.
azure_vm_size
.
name
,
"nics"
:
nics
,
"datastore_name"
:
"mylittledatastore"
,
#storage_name,
"os_publisher"
:
vm_size_publisher
.
name
,
"os_offer"
:
vm_size_offer
.
name
,
"os_sku"
:
vm_size_sku
.
name
,
"os_version"
:
vm_size_version
.
name
,
}]
azure_id
=
vm_tasks
.
deploy
.
apply_async
(
args
=
args
,
queue
=
"localhost.vm.fast"
)
.
get
(
timeout
=
1200
)
if
azure_id
:
logger
.
info
(
"deployed '
%
s' vm in azure, with id '
%
s'"
%
(
self
.
instance
.
name
,
azure_id
))
self
.
instance
.
azure_id
=
azure_id
self
.
instance
.
save
()
else
:
logger
.
error
(
"failed to deploy '
%
s' vm in azure"
%
(
self
.
instance
.
name
))
@register_operation
class
DeployDisksOperation
(
SubOperationMixin
,
InstanceOperation
):
...
...
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