Commit 5f69de67 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Check clustername when modifying backend

parent 877bdecf
......@@ -37,7 +37,7 @@ from synnefo.logic.backend import (get_physical_resources,
update_resources,
create_network_synced,
connect_network_synced)
from synnefo.logic.rapi import GanetiApiError, GanetiRapiClient
from synnefo.management.common import check_backend_credentials
class Command(BaseCommand):
......@@ -74,23 +74,7 @@ class Command(BaseCommand):
# Ensure correctness of credentials
if options['check']:
self.stdout.write('Checking connectivity and credentials.\n')
try:
client = GanetiRapiClient(clustername, port, username, password)
# This command will raise an exception if there is no
# write-access
client.ModifyCluster()
except GanetiApiError as e:
self.stdout.write('Check failed:\n%s\n' % e)
return
else:
self.stdout.write('Check passed.\n')
info = client.GetInfo()
info_name = info['name']
if info_name != clustername:
raise CommandError("Invalid clustername value. Please use the"
" Ganeti Cluster name: %s" % info_name)
check_backend_credentials(clustername, port, username, password)
# Create the new backend in database
try:
......
......@@ -33,10 +33,11 @@
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from synnefo.management.common import get_backend
from synnefo.management.common import get_backend, check_backend_credentials
class Command(BaseCommand):
output_transaction = True
args = "<backend ID>"
help = "Modify a backend"
......@@ -87,4 +88,12 @@ class Command(BaseCommand):
if value is not None:
backend.__setattr__(field, value)
credentials = ('clustername', 'port', 'username', 'password')
for field in credentials:
if options.get(field):
# check credentials, if any of them changed!
check_backend_credentials(backend.clustername, backend.port,
backend.username, backend.password)
return
backend.save()
......@@ -43,9 +43,9 @@ from synnefo.api.util import get_image as backend_get_image
from synnefo.api.faults import ItemNotFound
from django.core.exceptions import FieldError
from synnefo.api.util import validate_network_size
from synnefo.settings import MAX_CIDR_BLOCK
from synnefo.logic.rapi import GanetiApiError, GanetiRapiClient
def format_bool(b):
......@@ -201,3 +201,19 @@ def filter_results(objects, filter_by):
return objects.exclude(**exclude_dict)
except FieldError as e:
raise CommandError(e)
def check_backend_credentials(clustername, port, username, password):
try:
client = GanetiRapiClient(clustername, port, username, password)
# This command will raise an exception if there is no
# write-access
client.ModifyCluster()
except GanetiApiError as e:
raise CommandError(e)
info = client.GetInfo()
info_name = info['name']
if info_name != clustername:
raise CommandError("Invalid clustername value. Please use the"
" Ganeti Cluster name: %s" % info_name)
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