Revision 4c9ac139 snf-cyclades-app/synnefo/logic/management/commands/backend-add.py
b/snf-cyclades-app/synnefo/logic/management/commands/backend-add.py | ||
---|---|---|
41 | 41 |
from synnefo.webproject.management.utils import pprint_table |
42 | 42 |
|
43 | 43 |
|
44 |
HYPERVISORS = [h[0] for h in Backend.HYPERVISORS] |
|
45 |
|
|
46 |
|
|
44 | 47 |
class Command(BaseCommand): |
45 | 48 |
can_import_settings = True |
46 | 49 |
|
... | ... | |
54 | 57 |
'--no-check', action='store_false', |
55 | 58 |
dest='check', default=True, |
56 | 59 |
help="Do not perform credentials check and resources update"), |
60 |
make_option('--hypervisor', |
|
61 |
dest='hypervisor', |
|
62 |
default=None, |
|
63 |
choices=HYPERVISORS, |
|
64 |
metavar="|".join(HYPERVISORS), |
|
65 |
help="The hypervisor that the Ganeti backend uses"), |
|
57 | 66 |
) |
58 | 67 |
|
59 | 68 |
def handle(self, *args, **options): |
... | ... | |
64 | 73 |
port = options['port'] |
65 | 74 |
username = options['username'] |
66 | 75 |
password = options['password'] |
76 |
hypervisor = options["hypervisor"] |
|
67 | 77 |
|
68 | 78 |
if not (clustername and username and password): |
69 | 79 |
raise CommandError("Clustername, user and pass must be supplied") |
... | ... | |
72 | 82 |
if options['check']: |
73 | 83 |
check_backend_credentials(clustername, port, username, password) |
74 | 84 |
|
85 |
kw = {"clustername": clustername, |
|
86 |
"port": port, |
|
87 |
"username": username, |
|
88 |
"password": password, |
|
89 |
"drained": True} |
|
90 |
|
|
91 |
if hypervisor: |
|
92 |
kw["hypervisor"] = hypervisor |
|
75 | 93 |
# Create the new backend in database |
76 | 94 |
try: |
77 |
backend = Backend.objects.create(clustername=clustername, |
|
78 |
port=port, |
|
79 |
username=username, |
|
80 |
password=password, |
|
81 |
drained=True) |
|
95 |
backend = Backend.objects.create(**kw) |
|
82 | 96 |
except IntegrityError as e: |
83 | 97 |
raise CommandError("Cannot create backend: %s\n" % e) |
84 | 98 |
|
Also available in: Unified diff