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
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
6e8e3ebb
authored
Sep 03, 2013
by
tarokkk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
typo and formatting
parent
af334a69
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
28 deletions
+16
-28
vm/models.py
+16
-28
No files found.
vm/models.py
100644 → 100755
View file @
6e8e3ebb
#!/usr/bin/env python
from
datetime
import
timedelta
import
logging
import
manager.manager
from
.
import
tasks
from
django.conf.settings
import
CLOUD_URL
#
from django.conf.settings import CLOUD_URL
from
django.contrib.auth.models
import
User
# from django.core import signing
from
django.db
import
models
from
django.db.models.signals
import
pre_delete
from
django.dispatch
import
receiver
from
django.template.defaultfilters
import
escape
#
from django.template.defaultfilters import escape
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
...
...
@@ -29,6 +34,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.
"""
...
...
@@ -38,12 +44,15 @@ class BaseResourceConfigModel(models.Model):
'for balloning.'
))
arch
=
models
.
CharField
(
max_length
=
10
,
verbose_name
=
_
(
'architecture'
))
priority
=
models
.
IntegerField
(
help_text
=
_
(
'instance priority'
))
boot_menu
=
models
.
BooleanField
()
raw_data
=
models
.
TextField
()
class
Meta
:
abstract
=
True
class
NamedBaseResourceConfig
(
BaseResourceConfigModel
,
TimeStampedModel
):
"""Pre-created, named base resource configurations.
"""
name
=
models
.
CharField
(
max_length
=
50
,
unique
=
True
,
...
...
@@ -75,6 +84,7 @@ class Node(TimeStampedModel):
class
Lease
(
models
.
Model
):
"""Lease times for VM instances.
Specifies a time duration until suspension and deletion of a VM
...
...
@@ -103,6 +113,7 @@ class Lease(models.Model):
class
InstanceTemplate
(
BaseResourceConfigModel
,
TimeStampedModel
):
"""Virtual machine template.
Every template has:
...
...
@@ -165,6 +176,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.
...
...
@@ -180,32 +192,8 @@ class InterfaceTemplate(models.Model):
verbose_name_plural
=
_
(
'interface templates'
)
def
create_context
(
pw
,
hostname
,
smb_password
,
ssh_private_key
,
owner
,
token
,
extra
):
"""Return XML context configuration with given parameters.
"""
return
u'''
<SOURCE>web</SOURCE>
<HOSTNAME>
%(hostname)
s</HOSTNAME>
<NEPTUN>
%(neptun)
s</NEPTUN>
<USERPW>
%(pw)
s</USERPW>
<SMBPW>
%(smbpw)
s</SMBPW>
<SSHPRIV>
%(sshkey)
s</SSHPRIV>
<BOOTURL>
%(booturl)
s</BOOTURL>
<SERVER>store.cloud.ik.bme.hu</SERVER>
%(extra)
s
'''
%
{
"pw"
:
escape
(
pw
),
"hostname"
:
escape
(
hostname
),
"smbpw"
:
escape
(
smb_password
),
"sshkey"
:
escape
(
ssh_private_key
),
"neptun"
:
escape
(
owner
),
"booturl"
:
"
%
sb/
%
s/"
%
(
CLOUD_URL
,
token
),
"extra"
:
extra
}
class
Instance
(
BaseResourceConfigModel
,
TimeStampedModel
):
"""Virtual machine instance.
Every instance has:
...
...
@@ -289,7 +277,7 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
# create instance and do additional setup
inst
=
cls
(
**
kwargs
)
for
disk
in
template
.
disks
:
inst
.
disks
.
add
(
disk
.
get_exc
ul
sive
())
inst
.
disks
.
add
(
disk
.
get_exc
lu
sive
())
# save instance
inst
.
save
()
# create related entities
...
...
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