Commit a44fc4c2 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Add --hypervisor option to backend cmds

Add '--hypervisor' option to 'backend-add' and 'backend-modify'
management commands.

Refs #3772
parent 8bcc0f5f
......@@ -105,6 +105,12 @@ class Backend(models.Model):
# Custom object manager to protect from cascade delete
objects = ProtectedDeleteManager()
HYPERVISORS = (
("kvm", "Linux KVM hypervisor"),
("xen-pvm", "Xen PVM hypervisor"),
("xen-hvm", "Xen KVM hypervisor"),
)
class Meta:
verbose_name = u'Backend'
ordering = ["clustername"]
......
......@@ -41,6 +41,9 @@ from synnefo.management.common import check_backend_credentials
from synnefo.webproject.management.utils import pprint_table
HYPERVISORS = [h[0] for h in Backend.HYPERVISORS]
class Command(BaseCommand):
can_import_settings = True
......@@ -54,6 +57,12 @@ class Command(BaseCommand):
'--no-check', action='store_false',
dest='check', default=True,
help="Do not perform credentials check and resources update"),
make_option('--hypervisor',
dest='hypervisor',
default=None,
choices=HYPERVISORS,
metavar="|".join(HYPERVISORS),
help="The hypervisor that the Ganeti backend uses"),
)
def handle(self, *args, **options):
......@@ -64,6 +73,7 @@ class Command(BaseCommand):
port = options['port']
username = options['username']
password = options['password']
hypervisor = options["hypervisor"]
if not (clustername and username and password):
raise CommandError("Clustername, user and pass must be supplied")
......@@ -72,13 +82,17 @@ class Command(BaseCommand):
if options['check']:
check_backend_credentials(clustername, port, username, password)
kw = {"clustername": clustername,
"port": port,
"username": username,
"password": password,
"drained": True}
if hypervisor:
kw["hypervisor"] = hypervisor
# Create the new backend in database
try:
backend = Backend.objects.create(clustername=clustername,
port=port,
username=username,
password=password,
drained=True)
backend = Backend.objects.create(**kw)
except IntegrityError as e:
raise CommandError("Cannot create backend: %s\n" % e)
......
......@@ -33,9 +33,12 @@
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from synnefo.db.models import Backend
from synnefo.webproject.management.utils import parse_bool
from synnefo.management.common import (get_backend, check_backend_credentials)
HYPERVISORS = [h[0] for h in Backend.HYPERVISORS]
class Command(BaseCommand):
output_transaction = True
......@@ -61,6 +64,12 @@ class Command(BaseCommand):
metavar="True|False",
help="Set the backend as drained to exclude from"
" allocation operations"),
make_option('--hypervisor',
dest='hypervisor',
default=None,
choices=HYPERVISORS,
metavar="|".join(HYPERVISORS),
help="The hypervisor that the Ganeti backend uses"),
make_option('--offline',
dest='offline',
choices=["True", "False"],
......@@ -92,5 +101,8 @@ class Command(BaseCommand):
backend.drained = parse_bool(options['drained'], strict=True)
if options['offline']:
backend.offline = parse_bool(options['offline'], strict=True)
hypervisor = options["hypervisor"]
if hypervisor:
backend.hypervisor = hypervisor
backend.save()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment