From b1394ed444f4cb94726276a2cdf0ec4e7b229581 Mon Sep 17 00:00:00 2001
From: Amey Bhide <abhide@vmware.com>
Date: Thu, 3 Dec 2015 12:47:04 -0800
Subject: [PATCH] [Admin Utility]: Add command for list-backup-edges

$ nsxadmin -r backup-edges -o list
NSX Plugin in use: nsxv
Notify callbacks for backup-edges, list
Calling callback
tools.python_nsxadmin.admin.plugins.common.utils.nsx_list_backup_edges
==== [NSX] List Backup Edges ====
backup-edges
+---------+
| id      |
+---------+
| edge-5  |
| edge-9  |
| edge-13 |
| edge-18 |
+---------+

Change-Id: Id4cba1240db71e581174a39c51c57f72012a9199
---
 .../admin/plugins/common/constants.py         |  1 +
 .../plugins/nsxv/resources/backup_edges.py    | 52 +++++++++++++++++++
 tools/python_nsxadmin/admin/shell.py          |  2 +
 3 files changed, 55 insertions(+)
 create mode 100644 tools/python_nsxadmin/admin/plugins/nsxv/resources/backup_edges.py

diff --git a/tools/python_nsxadmin/admin/plugins/common/constants.py b/tools/python_nsxadmin/admin/plugins/common/constants.py
index d85b443226..19aa573eb8 100644
--- a/tools/python_nsxadmin/admin/plugins/common/constants.py
+++ b/tools/python_nsxadmin/admin/plugins/common/constants.py
@@ -25,3 +25,4 @@ SECURITY_GROUPS = 'security-groups'
 EDGES = 'edges'
 SPOOFGUARD_POLICY = 'spoofguard-policy'
 DHCP_BINDING = 'dhcp-binding'
+BACKUP_EDGES = 'backup-edges'
diff --git a/tools/python_nsxadmin/admin/plugins/nsxv/resources/backup_edges.py b/tools/python_nsxadmin/admin/plugins/nsxv/resources/backup_edges.py
new file mode 100644
index 0000000000..1154a6fcc6
--- /dev/null
+++ b/tools/python_nsxadmin/admin/plugins/nsxv/resources/backup_edges.py
@@ -0,0 +1,52 @@
+# Copyright 2015 VMware, Inc.  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 logging
+
+from tools.python_nsxadmin.admin.plugins.common import constants
+from tools.python_nsxadmin.admin.plugins.common import formatters
+
+import tools.python_nsxadmin.admin.plugins.common.utils as admin_utils
+import tools.python_nsxadmin.admin.plugins.nsxv.resources.utils as utils
+import tools.python_nsxadmin.admin.shell as shell
+
+from neutron.callbacks import registry
+
+
+LOG = logging.getLogger(__name__)
+nsxv = utils.get_nsxv_client()
+
+
+def get_nsxv_backup_edges():
+    edges = nsxv.get_edges()[1]
+    edges = edges['edgePage'].get('data', [])
+    backup_edges = []
+    for edge in edges:
+        if edge['name'].startswith("backup-"):
+            backup_edges.append(edge)
+    return backup_edges
+
+
+@admin_utils.output_header
+def nsx_list_backup_edges(resource, event, trigger, **kwargs):
+    """List backup edges"""
+    backup_edges = get_nsxv_backup_edges()
+    LOG.info(formatters.output_formatter(constants.BACKUP_EDGES, backup_edges,
+                                         ['id']))
+
+
+registry.subscribe(nsx_list_backup_edges,
+                   constants.BACKUP_EDGES,
+                   shell.Operations.LIST.value)
diff --git a/tools/python_nsxadmin/admin/shell.py b/tools/python_nsxadmin/admin/shell.py
index 88726fba0e..88ac616dbc 100644
--- a/tools/python_nsxadmin/admin/shell.py
+++ b/tools/python_nsxadmin/admin/shell.py
@@ -87,6 +87,8 @@ nsxv_resources = {
     constants.DHCP_BINDING: Resource(constants.DHCP_BINDING,
                                      [Operations.LIST.value,
                                       Operations.NSX_UPDATE.value]),
+    constants.BACKUP_EDGES: Resource(constants.BACKUP_EDGES,
+                                     [Operations.LIST.value]),
 }
 
 nsxv3_resources_names = map(lambda res: res.name, nsxv3_resources.itervalues())