Comment 6 for bug 1052561

Revision history for this message
Tomoe Sugihara (tomoe) wrote :

Hi Akihiro,

Just wanted to let you know that I tailored your patch for Folsom as follows and it fixed the problem.

diff --git a/horizon/dashboards/nova/access_and_security/floating_ips/tables.py b/horizon/dashboards/nova/access_and_security/floating_ips/tables.py
index e032e00..d12a38f 100644
--- a/horizon/dashboards/nova/access_and_security/floating_ips/tables.py
+++ b/horizon/dashboards/nova/access_and_security/floating_ips/tables.py
@@ -27,6 +27,7 @@ from horizon import exceptions
 from horizon import messages
 from horizon import tables

+from utils import get_int_or_uuid

 LOG = logging.getLogger(__name__)

@@ -82,7 +83,8 @@ class DisassociateIP(tables.Action):

     def single(self, table, request, obj_id):
         try:
- fip = table.get_object_by_id(int(obj_id))
+ fip = table.get_object_by_id(get_int_or_uuid(obj_id))
+
             api.server_remove_floating_ip(request, fip.instance_id, fip.id)
             LOG.info('Disassociating Floating IP "%s".' % obj_id)
             messages.success(request,
@@ -117,7 +119,7 @@ class FloatingIPsTable(tables.DataTable):
                          empty_value="-")

     def sanitize_id(self, obj_id):
- return int(obj_id)
+ return get_int_or_uuid(obj_id)

     def get_object_display(self, datum):
         return datum.ip
diff --git a/horizon/dashboards/nova/access_and_security/floating_ips/utils.py b/horizon/dashboards/nova/access_and_security/floating_ips/utils.py
new file mode 100644
index 0000000..b61b8b3
--- /dev/null
+++ b/horizon/dashboards/nova/access_and_security/floating_ips/utils.py
@@ -0,0 +1,32 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2012 NEC Corporation All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import uuid
+
+
+def get_int_or_uuid(value):
+ """Check if a value is valid as UUID or an integer.
+
+ This method is mainly used to convert floating IP id to the
+ appropriate type. For floating IP id, integer is used in Nova's
+ original implementation, but UUID is used in Quantum based one.
+ """
+ try:
+ uuid.UUID(value)
+ return value
+ except (ValueError, AttributeError):
+ return int(value)
+
diff --git a/horizon/dashboards/nova/access_and_security/floating_ips/workflows.py b/horizon/dashboards/nova/access_and_security/floating_ips/workflows.py
index 58dd989..dbec798 100644
--- a/horizon/dashboards/nova/access_and_security/floating_ips/workflows.py
+++ b/horizon/dashboards/nova/access_and_security/floating_ips/workflows.py
@@ -23,13 +23,15 @@ from horizon import exceptions
 from horizon import workflows
 from horizon import forms

+from utils import get_int_or_uuid
+

 ALLOCATE_URL = "horizon:nova:access_and_security:floating_ips:allocate"

 class AssociateIPAction(workflows.Action):
     ip_id = forms.DynamicTypedChoiceField(label=_("IP Address"),
- coerce=int,
+ coerce=get_int_or_uuid,
                                           empty_value=None,
                                           add_item_link=ALLOCATE_URL)
     instance_id = forms.ChoiceField(label=_("Instance"))