Revision ba8ff608

b/snf-cyclades-app/synnefo/helpdesk/templates/helpdesk/account.html
75 75
</div>
76 76
{% else %}
77 77

  
78
<p>{% if is_ip %}User with IP {% else %}Account {% endif %}<em>{{ account }}</em> does not exist in cyclades database</p>
78
<p>{% if is_ip %}User with IP {% else %}{% if is_vm %}User with Virtual Machine
79
{% else %}Account {% endif %}{% endif %}<em>{{ search_query }}</em> does not exist in cyclades database</p>
79 80
{% endif %}
80 81
{% endblock %}
b/snf-cyclades-app/synnefo/helpdesk/urls.py
7 7
    url(r'^suspend_release/(?P<vm_id>[0-9]+)$',
8 8
        'synnefo.helpdesk.views.suspend_vm_release',
9 9
        name='helpdesk-suspend-vm-release'),
10
    url(r'^(?P<account_or_ip>.*)$', 'synnefo.helpdesk.views.account',
10
    url(r'^(?P<search_query>.*)$', 'synnefo.helpdesk.views.account',
11 11
        name='helpdesk-details'),
12 12
)
13 13

  
b/snf-cyclades-app/synnefo/helpdesk/views.py
51 51

  
52 52
IP_SEARCH_REGEX = re.compile('([0-9]+)(?:\.[0-9]+){3}')
53 53
UUID_SEARCH_REGEX = re.compile('([0-9a-z]{8}-([0-9a-z]{4}-){3}[0-9a-z]{12})')
54
VM_SEARCH_REGEX = re.compile('vm(-){0,}(?P<vmid>[0-9]+)')
54 55

  
55
USER_CATALOG_URL = settings.CYCLADES_USER_CATALOG_URL
56 56

  
57 57

  
58 58
def get_token_from_cookie(request, cookiename):
......
77 77
PERMITTED_GROUPS = getattr(settings, 'HELPDESK_PERMITTED_GROUPS', ['helpdesk'])
78 78
SHOW_DELETED_VMS = getattr(settings, 'HELPDESK_SHOW_DELETED_VMS', False)
79 79

  
80
# guess cyclades setting too
81
USER_CATALOG_URL = getattr(settings, 'CYCLADES_USER_CATALOG_URL', None)
82
USER_CATALOG_URL = getattr(settings, 'HELPDESK_USER_CATALOG_URL',
83
                           USER_CATALOG_URL)
84

  
80 85

  
81 86
def token_check(func):
82 87
    """
......
139 144
    account = request.GET.get('account', None)
140 145
    if account:
141 146
        return redirect('synnefo.helpdesk.views.account',
142
                        account_or_ip=account)
147
                        search_query=account)
143 148

  
144 149
    # show index template
145 150
    return direct_to_template(request, "helpdesk/index.html")
146 151

  
147 152

  
148 153
@helpdesk_user_required
149
def account(request, account_or_ip):
154
def account(request, search_query):
150 155
    """
151 156
    Account details view.
152 157
    """
......
156 161
    account_exists = True
157 162
    vms = []
158 163
    networks = []
159
    is_ip = IP_SEARCH_REGEX.match(account_or_ip)
160
    is_uuid = UUID_SEARCH_REGEX.match(account_or_ip)
161
    account_name = account_or_ip
164
    is_ip = IP_SEARCH_REGEX.match(search_query)
165
    is_uuid = UUID_SEARCH_REGEX.match(search_query)
166
    is_vm = VM_SEARCH_REGEX.match(search_query)
167
    account_name = search_query
162 168
    auth_token = request.user.get('auth_token')
163 169

  
164 170
    if is_ip:
165 171
        try:
166
            nic = NetworkInterface.objects.get(ipv4=account_or_ip)
167
            account_or_ip = nic.machine.userid
172
            nic = NetworkInterface.objects.get(ipv4=search_query)
173
            search_query = nic.machine.userid
168 174
            is_uuid = True
169 175
        except NetworkInterface.DoesNotExist:
170 176
            account_exists = False
177
            account = None
178

  
179
    if is_vm:
180
        vmid = is_vm.groupdict().get('vmid')
181
        try:
182
            vm = VirtualMachine.objects.get(pk=int(vmid))
183
            search_query = vm.userid
184
            is_uuid = True
185
        except VirtualMachine.DoesNotExist:
186
            account_exists = False
187
            account = None
188
            search_query = vmid
171 189

  
172 190
    if is_uuid:
173
        account = account_or_ip
191
        account = search_query
174 192
        account_name = astakos.get_displayname(auth_token, account,
175 193
                                               USER_CATALOG_URL)
176
    else:
177
        account_name = account_or_ip
194

  
195
    if account_exists and not is_uuid:
196
        account_name = search_query
178 197
        account = astakos.get_user_uuid(auth_token, account_name,
179 198
                                        USER_CATALOG_URL)
180 199

  
200
    if not account:
201
        account_exists = False
202

  
181 203
    filter_extra = {}
182 204
    if not show_deleted:
183 205
        filter_extra['deleted'] = False
......
200 222
    user_context = {
201 223
        'account_exists': account_exists,
202 224
        'is_ip': is_ip,
225
        'is_vm': is_vm,
226
        'is_uuid': is_uuid,
203 227
        'account': account,
228
        'search_query': search_query,
204 229
        'vms': vms,
205 230
        'show_deleted': show_deleted,
206 231
        'account_name': account_name,

Also available in: Unified diff