Revision 2333a2c4

b/snf-cyclades-app/synnefo/logic/management/commands/backend-add.py
37 37
                                   update_resources,
38 38
                                   create_network_synced,
39 39
                                   connect_network_synced)
40
from synnefo.logic.rapi import GanetiApiError, GanetiRapiClient
40
from synnefo.management.common import check_backend_credentials
41 41

  
42 42

  
43 43
class Command(BaseCommand):
......
74 74

  
75 75
        # Ensure correctness of credentials
76 76
        if options['check']:
77
            self.stdout.write('Checking connectivity and credentials.\n')
78
            try:
79
                client = GanetiRapiClient(clustername, port, username, password)
80
                # This command will raise an exception if there is no
81
                # write-access
82
                client.ModifyCluster()
83
            except GanetiApiError as e:
84
                self.stdout.write('Check failed:\n%s\n' % e)
85
                return
86
            else:
87
                self.stdout.write('Check passed.\n')
88

  
89
        info = client.GetInfo()
90
        info_name = info['name']
91
        if info_name != clustername:
92
            raise CommandError("Invalid clustername value. Please use the"
93
                               " Ganeti Cluster name: %s" % info_name)
77
            check_backend_credentials(clustername, port, username, password)
94 78

  
95 79
        # Create the new backend in database
96 80
        try:
b/snf-cyclades-app/synnefo/logic/management/commands/backend-modify.py
33 33

  
34 34
from optparse import make_option
35 35
from django.core.management.base import BaseCommand, CommandError
36
from synnefo.management.common import get_backend
36
from synnefo.management.common import get_backend, check_backend_credentials
37 37

  
38 38

  
39 39
class Command(BaseCommand):
40
    output_transaction = True
40 41
    args = "<backend ID>"
41 42
    help = "Modify a backend"
42 43

  
......
87 88
            if value is not None:
88 89
                backend.__setattr__(field, value)
89 90

  
91
        credentials = ('clustername', 'port', 'username', 'password')
92
        for field in credentials:
93
            if options.get(field):
94
                # check credentials, if any of them changed!
95
                check_backend_credentials(backend.clustername, backend.port,
96
                                          backend.username, backend.password)
97
                return
98

  
90 99
        backend.save()
b/snf-cyclades-app/synnefo/management/common.py
43 43
from synnefo.api.faults import ItemNotFound
44 44
from django.core.exceptions import FieldError
45 45

  
46

  
47 46
from synnefo.api.util import validate_network_size
48 47
from synnefo.settings import MAX_CIDR_BLOCK
48
from synnefo.logic.rapi import GanetiApiError, GanetiRapiClient
49 49

  
50 50

  
51 51
def format_bool(b):
......
201 201
        return objects.exclude(**exclude_dict)
202 202
    except FieldError as e:
203 203
        raise CommandError(e)
204

  
205

  
206
def check_backend_credentials(clustername, port, username, password):
207
    try:
208
        client = GanetiRapiClient(clustername, port, username, password)
209
        # This command will raise an exception if there is no
210
        # write-access
211
        client.ModifyCluster()
212
    except GanetiApiError as e:
213
        raise CommandError(e)
214

  
215
    info = client.GetInfo()
216
    info_name = info['name']
217
    if info_name != clustername:
218
        raise CommandError("Invalid clustername value. Please use the"
219
                           " Ganeti Cluster name: %s" % info_name)

Also available in: Unified diff