Index: /branches/amp_3_7_2/src/webui/webui/htdocs/new/src/cm/lib/task_scheduler.py
===================================================================
--- /branches/amp_3_7_2/src/webui/webui/htdocs/new/src/cm/lib/task_scheduler.py	(revision 2957)
+++ /branches/amp_3_7_2/src/webui/webui/htdocs/new/src/cm/lib/task_scheduler.py	(working copy)
@@ -1247,7 +1247,7 @@
     send_notification('success', 'Task <%s> has done.' % task_name, model='config')
 
 
-def config_backup(task_name, device_info, comment, file_num=0):
+def config_backup(task_name, device_info, comment, mgmt_ip_addr=None, file_num=0,):
     # device_info, virtual_file_path, cli_url, check_config_url, real_file_path, cli_cmd
     add_description(task_name, "The execution time: ")
     update_job_state(task_name, 'ongoing')
\ No newline at end of file
@@ -1262,26 +1262,16 @@
         cli_url = modify_url('/rest/device_type/cli_extend', device_info['type'])
         if device_info['type'].lower() in VPN_TYPE_LIST:
             uid = uuid.uuid1()
-            cm = __import__("cm")
-            reload(cm.conf)
-            network_card = cm.conf.NETWORK_CARD
-            # get config file from device
-            try:
-                local_ip = get_ip_address(network_card)
-            except Exception, e:
-                description = 'Local network settings are abnormal. Please configuare management interface by CLI "system management intertface <port_name>".'
-                config_failed(description, task_name)
-                return -1
 
             cli_cmd = {}
             virtual_file_path = DEFAULT_CONFIG_FILE_PATH + 'backup/' + '%s.all_cfg_tar' % uid
             real_file_name = device_info['name'] + '-' + datetime.datetime.now().strftime(
                 '%Y_%m_%d_%H:%M:%S') + '.all_cfg_tar'
             real_file_path = DEFAULT_CONFIG_FILE_PATH + 'backup/' + real_file_name
-            cli_cmd['export_config'] = 'config export all tftp %s %s' % (local_ip, uid)
+            cli_cmd['export_config'] = 'config export all tftp %s %s' % (mgmt_ip_addr, uid)
             cli_cmd['write_config'] = 'write file all %s' % uid
             cli_cmd['remove_config'] = 'no config %s \nYES' % (uid)
-            cli_cmd['net_config'] = 'write net all tftp %s %s.all_cfg_tar' % (local_ip, uid)
+            cli_cmd['net_config'] = 'write net all tftp %s %s.all_cfg_tar' % (mgmt_ip_addr, uid)
             check_config_url = modify_url('/rest/device_type/admintools/config_mgmt/SavedAllFile', device_info['type'])
             bu = Backup_AG(device_info, virtual_file_path, cli_url, check_config_url, real_file_path, cli_cmd)
             ret = bu.run()
\ No newline at end of file
@@ -1507,7 +1497,7 @@
     return ""
 
 
-def clone_ag(pk_list, file_name, comment, options):
+def clone_ag(pk_list, file_name, comment, options, mgmt_ip_addr):
     file_type = pk_list["file_type"]
     db = DB.get_connected_db()
     target_path = DEFAULT_CONFIG_FILE_PATH + 'system/' + file_name
\ No newline at end of file
@@ -1515,22 +1505,14 @@
     if file_type == 'device':
         # clone from run time config
         uid = uuid.uuid1()
-        cm = __import__("cm")
-        reload(cm.conf)
-        network_card = cm.conf.NETWORK_CARD
-        # get config file from device
-        try:
-            local_ip = get_ip_address(network_card)
-        except Exception, e:
-            return 'Local network settings are abnormal. Please configuare management interface by CLI "system management intertface <port_name>".'
         device_info = get_rest_info_from_device(pk_list['name'])[0]
         cli_url = modify_url('/rest/device_type/cli_extend', device_info['type'])
         cli_cmd = {}
         virtual_file_path = DEFAULT_CONFIG_FILE_PATH + 'backup/' + '%s.all_cfg_tar' % uid
-        cli_cmd['export_config'] = 'config export all tftp %s %s' % (local_ip, uid)
+        cli_cmd['export_config'] = 'config export all tftp %s %s' % (mgmt_ip_addr, uid)
         cli_cmd['write_config'] = 'write file all %s' % uid
         cli_cmd['remove_config'] = 'no config %s \nYES' % (uid)
-        cli_cmd['net_config'] = 'write net all tftp %s %s.all_cfg_tar' % (local_ip, uid)
+        cli_cmd['net_config'] = 'write net all tftp %s %s.all_cfg_tar' % (mgmt_ip_addr, uid)
         check_config_url = modify_url('/rest/device_type/admintools/config_mgmt/SavedAllFile', device_info['type'])
         bu = Backup_AG(device_info, virtual_file_path, cli_url, check_config_url, target_all_path, cli_cmd)
         ret = bu.run()
\ No newline at end of file
@@ -1578,7 +1560,7 @@
     return ""
 
 
-def config_clone(task_name, options):
+def config_clone(task_name, options, mgmt_ip_addr):
     add_description(task_name, "The execution time: ")
     update_job_state(task_name, 'ongoing')
     mark_expire_all(get_model('cm', ['tasking', 'Tasks']))
\ No newline at end of file
@@ -1615,7 +1597,7 @@
                     config_failed(ret, task_name)
                     return
         elif device_type.lower() in VPN_TYPE_LIST:
-            ret = clone_ag(pk_list, file_name, comment, options)
+            ret = clone_ag(pk_list, file_name, comment, options, mgmt_ip_addr)
             if ret:
                 config_failed(ret, task_name)
                 return
\ No newline at end of file
@@ -1717,7 +1699,7 @@
     return res
 
 
-def config_recover(task_name, device_info, file_type, file_name, backup=False, device_name=None):
+def config_recover(task_name, device_info, file_type, file_name, backup=False, device_name=None, mgmt_ip_addr=None):
     add_description(task_name, "The execution time: ")
     update_job_state(task_name, 'ongoing')
     mark_expire_all(get_model('cm', ['tasking', 'Tasks']))
\ No newline at end of file
@@ -1744,18 +1726,9 @@
             rcv = Apply_AG(real_file_path, device_info, cli_url, xmlprc_status["status"])
         else:
             uid = uuid.uuid1()
-            cm = __import__("cm")
-            reload(cm.conf)
-            network_card = cm.conf.NETWORK_CARD
-            try:
-                local_ip = get_ip_address(network_card)
-            except Exception, e:
-                description = 'Local network settings are abnormal. Please configuare management interface by CLI "system management intertface <port_name>".'
-                config_failed(description, task_name)
-                return
             cli_cmd = {}
             virtual_file_path = DEFAULT_CONFIG_FILE_PATH + 'backup' + '/%s.all_cfg_tar' % uid
-            cli_cmd['import_config'] = 'config import all tftp %s "%s.all_cfg_tar"' % (local_ip, uid)
+            cli_cmd['import_config'] = 'config import all tftp %s "%s.all_cfg_tar"' % (mgmt_ip_addr, uid)
             cli_cmd['sync_config'] = "config file all %s" % uid
             cli_cmd['remove_config'] = 'no config %s \nYES' % (uid)
             check_config_url = '/rest/%s/global/admintools/config_mgmt/SavedAllFile' % _type
\ No newline at end of file
Index: /branches/amp_3_7_2/src/webui/webui/htdocs/new/src/cm/models/configuration/config_file/__init__.py
===================================================================
--- /branches/amp_3_7_2/src/webui/webui/htdocs/new/src/cm/models/configuration/config_file/__init__.py	(revision 2934)
+++ /branches/amp_3_7_2/src/webui/webui/htdocs/new/src/cm/models/configuration/config_file/__init__.py	(working copy)
@@ -1,3 +1,5 @@
+import re
+
 from hive.imports.model import *
 from django.utils.translation import ugettext_lazy as _
 #from cm.lib.sqlite_db import DB
@@ -58,6 +60,8 @@
                 self._model._meta.mark_delay_query(each)
             return QuerySet(self._model, result)
 """
+
+
 class ConfigFile(ANModel):
     name = CharField(verbose_name='File Name', primary_key=True, length='1..128')
     #asso_file_type = AssoField2(verbose_name='File Type', primary_key=True, tgt='configuration.config_file.FileType.asso',
@@ -87,7 +91,7 @@
         config_change = True
         instance_mul = '0'
         option_fields = (
-            DynamicMultiEnumField(name='device', verbose_name='devices', 
+            DynamicMultiEnumField(name='device', verbose_name='devices',
                 values=['__field:cm.device_mgmt.device.Device.name']),
         )
 
@@ -199,7 +203,7 @@
             )),
             DateTimeField(verbose_name='Expire Time', name='expire_time', condition=ValueCondition('option', ['deferred'])),
         )
-        
+
     class Refresh(Action):
         verbose_name = _('Refresh')
         action_name = _('Refresh')
@@ -301,6 +305,7 @@
         )
 
     class Manager(CLIManager):
+
         def _get_query_set(self):
             db = DB.get_connected_db()
             fetchall_sql = "SELECT name, create_time, modify_time, type, comment, device_type FROM file_list"
@@ -314,7 +319,7 @@
                 del each['type']
                 #self._model._meta.mark_delay_query(each)
             """
-            res = sorted(result, key=lambda x: x["create_time"], reverse=True) 
+            res = sorted(result, key=lambda x: x["create_time"], reverse=True)
             return QuerySet(self._model, res)
 
         def _update_comment(self, instance):
@@ -339,7 +344,7 @@
                 db.close()
                 raise ModelQueryException(CLICmdError(__('The file name has existed!')))
             db.close()
-            
+
             if not os.path.exists(file_path):
                 os.makedirs(file_path)
             if file_type == "customize" or file_type == "template":
@@ -375,15 +380,9 @@
 
                     shutil.move(data["upload_path"], per_config_path)
 
-                    cm = __import__("cm")
-                    reload(cm.conf)
-                    network_card = cm.conf.NETWORK_CARD
-                    try:
-                        local_ip = get_ip_address(network_card)
-                    except Exception, e:
-                        raise ModelQueryException(CLICmdError(__('Local network settings are abnormal. Please configuare management interface by CLI "system management intertface <port_name>".')))
+                    mgmt_ip_addr = self.get_amp_mgmt_ip()
 
-                    cli_url = '"ftp://array:admin@%s:9993/upload/%s/%s"' % (local_ip, task_name, filename)
+                    cli_url = '"ftp://array:admin@%s:9993/upload/%s/%s"' % (mgmt_ip_addr, task_name, filename)
 
                     cli_content = cli_content.replace('"'+replace_str+'"', cli_url)
                     cli_content = cli_content.replace(replace_str, cli_url)
@@ -490,10 +489,12 @@
             if GLOBAL_TASK.get_schedule(task_name):
                 GLOBAL_TASK.remove(task_name)
             remove_job_from_database(task_name)
+            mgmt_ip_addr = self.get_amp_mgmt_ip()
+
             new_schedule = {}
             description = " Backup config create time: " + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + '\n'
             new_schedule['func'] = 'config_backup'
-            new_schedule['args'] = [task_name, device_info, options['comment']]
+            new_schedule['args'] = [task_name, device_info, options['comment'], mgmt_ip_addr]
             new_schedule_str = json.dumps(new_schedule)
             add_job_into_database(task_name, 'config_backup', description, 'date', 'waiting', date.strftime('%Y-%m-%d %H:%M:%S'), new_schedule_str, device_list=device_name)
 
@@ -576,8 +577,8 @@
                 else:
                     sched.add_job(config_backup, trigger, next_run_time=date, args=new_schedule['args'], id=task_name)
                 GLOBAL_TASK.add(task_name, sched)
-                mark_expire_all(get_model('cm', ['tasking', 'Tasks'])) 
-            return              
+                mark_expire_all(get_model('cm', ['tasking', 'Tasks']))
+            return
 
         def _perform_Recover(self, options):
             pk_list = options['__pk_list'][0]
@@ -604,10 +605,12 @@
             if GLOBAL_TASK.get_schedule(task_name):
                 GLOBAL_TASK.remove(task_name)
             remove_job_from_database(task_name)
+            mgmt_ip_addr = self.get_amp_mgmt_ip()
+
             new_schedule = {}
             description = " Recover config create time: " + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + '\n'
             new_schedule['func'] = 'config_recover'
-            new_schedule['args'] = [task_name, device_info, file_type, pk_list['name'], backup, device_name]
+            new_schedule['args'] = [task_name, device_info, file_type, pk_list['name'], backup, device_name, mgmt_ip_addr]
             new_schedule_str = json.dumps(new_schedule)
             add_job_into_database(task_name, 'config_recover', description, 'date', 'waiting', date.strftime('%Y-%m-%d %H:%M:%S'), new_schedule_str, device_list=device_name)
 
@@ -643,7 +646,7 @@
             return
 
         def _perform_Sync_from_device(self, options):
-            #sync from device  {u'device': [u'\u5a01\u9707\u5929', u'\u64ce\u5929\u67f1'], 
+            #sync from device  {u'device': [u'\u5a01\u9707\u5929', u'\u64ce\u5929\u67f1'],
             #perform sync from device {u'device': [u'\u64ce\u5929\u67f1'], u'__pk_list': []}
             #print "perform sync from device", options
             for device in options['device']:
@@ -659,7 +662,7 @@
                     data = {'cmd' : 'show running'}
                     new_url = '/rest/%s/cli_extend' % _type
                 running_params = json.dumps(data)
-                
+
                 try:
                     rest_response_data = send_https_rest_request('POST', new_url, running_params, device_info[0]['ip_address'], device_info[0]['restapi_port'], device_info[0]['restapi_username'], device_info[0]['restapi_password'])
                 except:
@@ -668,7 +671,7 @@
                     config_result = json.loads(rest_response_data['body'])['contents']
                 else:
                     raise ModelQueryException(CLICmdError(__("The request is not found!")))
-                
+
                 device_path = os.path.join(DEFAULT_CONFIG_FILE_PATH, 'device')
                 if not os.path.isdir(device_path):
                     os.makedirs(device_path)
@@ -698,7 +701,7 @@
             fetchall_sql = "SELECT name FROM file_list where type='backup' and name like '%" + device_name + "%'"
             data = db.fetchall(fetchall_sql)
             key = ['name',]
-            backup_list = [dict(zip(key, each)) for each in data]   
+            backup_list = [dict(zip(key, each)) for each in data]
             db.close()
 
             device_backup_list = []
@@ -719,10 +722,12 @@
             if GLOBAL_TASK.get_schedule(task_name):
                 GLOBAL_TASK.remove(task_name)
             remove_job_from_database(task_name)
+            mgmt_ip_addr = self.get_amp_mgmt_ip()
+
             new_schedule = {}
             description = " Clone config create time: " + date_now.strftime('%Y-%m-%d %H:%M:%S') + '\n'
             new_schedule['func'] = 'config_clone'
-            new_schedule['args'] = [task_name, options]
+            new_schedule['args'] = [task_name, options, mgmt_ip_addr]
             new_schedule_str = json.dumps(new_schedule)
             add_job_into_database(task_name, 'config_clone', description, 'date', 'waiting', date.strftime('%Y-%m-%d %H:%M:%S'), new_schedule_str, device_list=pk_list['name'][:-4] if pk_list['name'][-4:] == '.cfg' else pk_list['name'])
 
@@ -732,6 +737,30 @@
             mark_expire_all(get_model('cm', ['tasking', 'Tasks']))
             return
 
+        def get_amp_mgmt_ip(self):
+            try:
+                self.cli.set_enable()
+                cli_output = self.cli.cmd('show ip address')
+
+                match = re.search(r'ip address\s+"[^"]+"\s+(\d+\.\d+\.\d+\.\d+)', cli_output)
+
+                if not match:
+                    raise ModelQueryException(
+                        CLICmdError(__(
+                            "Management IP is not set."
+                            " Please configure management interface by CLI: system management interface <port_name>"
+                        ))
+                    )
+                return match.group(1)
+
+            except Exception:
+                raise ModelQueryException(
+                    CLICmdError(__(
+                        "Local network settings are abnormal. Please configure "
+                        "management interface by CLI: system management interface <port_name>"
+                    ))
+                )
+
         def _perform_Init_device(self, options):
             pk_list = options['__pk_list'][0]
             device_list = []
Index: /branches/amp_3_7_2/src/webui/webui/htdocs/new/src/cm/models/configuration/update/__init__.py
===================================================================
--- /branches/amp_3_7_2/src/webui/webui/htdocs/new/src/cm/models/configuration/update/__init__.py	(revision 2957)
+++ /branches/amp_3_7_2/src/webui/webui/htdocs/new/src/cm/models/configuration/update/__init__.py	(working copy)
@@ -278,6 +278,10 @@
                 self.cli.set_enable()
                 result = self.cli.cmd('show ip address')
                 mgmt_ip_addr = extract_mgmt_ip(result)
+                if mgmt_ip_addr is None:
+                    return ('Management IP is not set.'
+                            'Please configure management interface by CLI "system management interface <port_name>".')
+
                 description = " UPDATE create time: " + data_now.strftime('%Y-%m-%d %H:%M:%S') + '\n'
                 new_schedule['func'] = 'upload_to_device'
                 new_schedule['args'] = [int(pk_list['id']), task_name, device_info['ip_address'],
\ No newline at end of file
@@ -287,8 +291,6 @@
                 new_schedule_str = json.dumps(new_schedule)
                 add_job_into_database(task_name, 'update', description, 'date', 'waiting',
                                       date.strftime('%Y-%m-%d %H:%M:%S'), new_schedule_str, device_list=device)
-                self.cli.set_enable()
-                reslt = self.cli.cmd('show ip address')
 
                 sched = BackgroundScheduler()
                 sched.add_job(upload_to_device, 'date', next_run_time=date, args=new_schedule['args'], id=task_name)
\ No newline at end of file
