Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
6b97b5c6
Commit
6b97b5c6
authored
Nov 09, 2012
by
Christos Stavrakakis
Browse files
Improve management commands
parent
317c3556
Changes
5
Hide whitespace changes
Inline
Side-by-side
snf-cyclades-app/synnefo/api/management/commands/flavor-create.py
View file @
6b97b5c6
...
...
@@ -37,32 +37,32 @@ from django.core.management.base import BaseCommand, CommandError
from
synnefo.db.models
import
Flavor
from
._common
import
format_bool
,
format_date
class
Command
(
BaseCommand
):
output_transaction
=
True
args
=
"<cpu>[,<cpu>,...] "
\
"<ram>[,<ram>,...] "
\
"<disk>[,<disk>,...] "
\
"<disk template>[,<disk template>,...]"
help
=
"Create one or more flavors"
help
=
"Create one or more flavors.
\n\n
The flavors that will be created are"
\
" those belonging to the cartesian product of the arguments"
\
def
handle
(
self
,
*
args
,
**
options
):
if
len
(
args
)
!=
4
:
raise
CommandError
(
"Invalid number of arguments"
)
cpus
=
args
[
0
].
split
(
','
)
rams
=
args
[
1
].
split
(
','
)
disks
=
args
[
2
].
split
(
','
)
templates
=
args
[
3
].
split
(
','
)
flavors
=
[]
for
cpu
,
ram
,
disk
,
template
in
product
(
cpus
,
rams
,
disks
,
templates
):
try
:
flavors
.
append
((
int
(
cpu
),
int
(
ram
),
int
(
disk
),
template
))
except
ValueError
:
raise
CommandError
(
"Invalid values"
)
for
cpu
,
ram
,
disk
,
template
in
flavors
:
flavor
=
Flavor
.
objects
.
create
(
cpu
=
cpu
,
ram
=
ram
,
disk
=
disk
,
disk_template
=
template
)
...
...
snf-cyclades-app/synnefo/api/management/commands/server-create.py
View file @
6b97b5c6
...
...
@@ -41,23 +41,36 @@ from synnefo.logic.backend_allocator import BackendAllocator
from
synnefo.api.util
import
get_image
,
allocate_public_address
from
synnefo.api.faults
import
ItemNotFound
HELP_MSG
=
"""
Create a new VM without authenticating the user or checking the resource
limits of the user. Also the allocator can be bypassed by specifing a
backend-id.
"""
class
Command
(
BaseCommand
):
help
=
"Create a new VM."
help
=
"Create a new VM."
+
HELP_MSG
output_transaction
=
True
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
"--backend-id"
,
dest
=
"backend_id"
,
help
=
"ID of the Ganeti backend"
),
help
=
"Unique identifier of the Ganeti backend."
" Use snf-manage backend-list to find out"
" available backends."
),
make_option
(
"--name"
,
dest
=
"name"
,
help
=
"
Name of
the server
.
"
),
help
=
"
An arbitrary string for naming
the server"
),
make_option
(
"--user-id"
,
dest
=
"user_id"
,
help
=
"
ID
of the
O
wner of the server
.
"
),
help
=
"
Unique identifier
of the
o
wner of the server"
),
make_option
(
"--image-id"
,
dest
=
"image_id"
,
help
=
"ID of the image."
),
help
=
"Unique identifier of the image."
" Use snf-manage image-list to find out"
" available images."
),
make_option
(
"--flavor-id"
,
dest
=
"flavor_id"
,
help
=
"ID of the flavor"
),
help
=
"Unique identifier of the flavor"
" Use snf-manage flavor-list to find out"
" available flavors."
),
make_option
(
"--password"
,
dest
=
"password"
,
help
=
"Password for the new server"
)
)
...
...
snf-cyclades-app/synnefo/api/management/commands/server-modify.py
View file @
6b97b5c6
...
...
@@ -37,13 +37,11 @@ from django.core.management.base import BaseCommand, CommandError
from
synnefo.db.models
import
VirtualMachine
from
._common
import
format_bool
,
format_date
class
Command
(
BaseCommand
):
args
=
"<server ID>"
help
=
"Modify a server"
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
'--name'
,
dest
=
'name'
,
...
...
@@ -74,25 +72,25 @@ class Command(BaseCommand):
dest
=
'unsuspended'
,
help
=
"Mark a server as not suspended"
)
)
def
handle
(
self
,
*
args
,
**
options
):
if
len
(
args
)
!=
1
:
raise
CommandError
(
"Please provide a server ID"
)
try
:
server_id
=
int
(
args
[
0
])
server
=
VirtualMachine
.
objects
.
get
(
id
=
server_id
)
except
(
ValueError
,
VirtualMachine
.
DoesNotExist
):
raise
CommandError
(
"Invalid server ID"
)
name
=
options
.
get
(
'name'
)
if
name
is
not
None
:
server
.
name
=
name
owner
=
options
.
get
(
'owner'
)
if
owner
is
not
None
:
server
.
userid
=
owner
state
=
options
.
get
(
'state'
)
if
state
is
not
None
:
allowed
=
[
x
[
0
]
for
x
in
VirtualMachine
.
OPER_STATES
]
...
...
@@ -100,15 +98,15 @@ class Command(BaseCommand):
msg
=
"Invalid state, must be one of %s"
%
', '
.
join
(
allowed
)
raise
CommandError
(
msg
)
server
.
operstate
=
state
if
options
.
get
(
'deleted'
):
server
.
deleted
=
True
elif
options
.
get
(
'undeleted'
):
server
.
deleted
=
False
if
options
.
get
(
'suspended'
):
server
.
suspended
=
True
elif
options
.
get
(
'unsuspended'
):
server
.
suspended
=
False
server
.
save
()
snf-cyclades-app/synnefo/logic/management/commands/backend-update-status.py
View file @
6b97b5c6
...
...
@@ -48,7 +48,11 @@ class Command(BaseCommand):
help
=
"Update statistics of only this backend"
),
make_option
(
'--older-than'
,
dest
=
'older_than'
,
metavar
=
"MINUTES"
,
help
=
"Update only backends that have not been updated for
\
MINUTES. Set to 0 to force update."
)
MINUTES. Set to 0 to force update."
),
make_option
(
'--include-drained'
,
dest
=
'drained'
,
default
=
False
,
action
=
'store_true'
,
help
=
"Also update statistics of drained backends"
)
)
def
handle
(
self
,
**
options
):
...
...
@@ -62,8 +66,10 @@ class Command(BaseCommand):
except
Backend
.
DoesNotExist
:
raise
CommandError
(
"Backend not found in DB"
)
else
:
# XXX:filter drained ?
backends
=
Backend
.
objects
.
all
()
backends
=
Backend
.
objects
.
filter
(
offline
=
False
)
if
not
options
[
'drained'
]:
backends
=
backends
.
filter
(
drained
=
False
)
now
=
datetime
.
datetime
.
now
()
if
options
[
'older_than'
]
is
not
None
:
...
...
snf-cyclades-app/synnefo/plankton/management/commands/image-show.py
View file @
6b97b5c6
...
...
@@ -36,6 +36,7 @@ from pprint import pprint
class
Command
(
BaseCommand
):
args
=
"<image_id>"
help
=
"Display available information about an image"
def
handle
(
self
,
*
args
,
**
options
):
...
...
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