diff --git a/lib/ansible/modules/network/cloudengine/ce_file_copy.py b/lib/ansible/modules/network/cloudengine/ce_file_copy.py
index be535994cb0..414f6a2c648 100644
--- a/lib/ansible/modules/network/cloudengine/ce_file_copy.py
+++ b/lib/ansible/modules/network/cloudengine/ce_file_copy.py
@@ -113,6 +113,21 @@ try:
except ImportError:
HAS_SCP = False
+CE_NC_GET_DISK_INFO = """
+
+
+
+
+
+
+
+
+
+
+
+
+"""
+
CE_NC_GET_FILE_INFO = """
@@ -129,12 +144,13 @@ CE_NC_GET_FILE_INFO = """
CE_NC_GET_SCP_ENABLE = """
-
-
-
-
-
-
+
+
+
+
+
+
+
"""
@@ -215,7 +231,7 @@ class FileCopy(object):
# get file info
root = ElementTree.fromstring(xml_str)
- topo = root.find("data/vfm/dirs/dir")
+ topo = root.find("vfm/dirs/dir")
if topo is None:
return False, 0
@@ -233,16 +249,19 @@ class FileCopy(object):
def enough_space(self):
"""Whether device has enough space"""
- commands = list()
- cmd = 'dir %s' % self.file_system
- commands.append(cmd)
- output = run_commands(self.module, commands)
- if not output:
- return True
+ xml_str = CE_NC_GET_DISK_INFO
+ ret_xml = get_nc_config(self.module, xml_str)
+ if "" in ret_xml:
+ return
+
+ xml_str = ret_xml.replace('\r', '').replace('\n', '').\
+ replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\
+ replace('xmlns="http://www.huawei.com/netconf/vrp"', "")
+
+ root = ElementTree.fromstring(xml_str)
+ topo = root.find("vfm/dfs/df/freeSize")
+ kbytes_free = topo.text
- match = re.search(r'\((.*) KB free\)', output[0])
- kbytes_free = match.group(1)
- kbytes_free = kbytes_free.replace(',', '')
file_size = os.path.getsize(self.local_file)
if int(kbytes_free) * 1024 > file_size:
return True
@@ -284,7 +303,6 @@ class FileCopy(object):
self.module.fail_json(msg='Could not transfer file. There was an error '
'during transfer. Please make sure the format of '
'input parameters is right.')
-
scp.close()
return True
@@ -292,9 +310,10 @@ class FileCopy(object):
"""Get scp enable state"""
xml_str = CE_NC_GET_SCP_ENABLE
+ scp_enable = dict()
ret_xml = get_nc_config(self.module, xml_str)
if "" in ret_xml:
- return False
+ return scp_enable
xml_str = ret_xml.replace('\r', '').replace('\n', '').\
replace('xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', "").\
@@ -302,15 +321,14 @@ class FileCopy(object):
# get file info
root = ElementTree.fromstring(xml_str)
- topo = root.find("data/sshs/sshServer")
+ topo = root.find("sshs/sshServerEnable")
if topo is None:
- return False
+ return scp_enable
for eles in topo:
- if eles.tag in ["scpEnable"]:
- return True, eles.text
+ scp_enable[eles.tag] = eles.text
- return False
+ return scp_enable
def work(self):
"""Excute task """
@@ -331,10 +349,13 @@ class FileCopy(object):
self.module.fail_json(
msg="'Error: The maximum length of remote_file is 4096.'")
- retcode, cur_state = self.get_scp_enable()
- if retcode and cur_state == 'Disable':
+ cur_state = self.get_scp_enable()
+ if len(cur_state) > 0 and (cur_state.get('scpIpv4Enable').lower() == 'disable' or cur_state.get('scpIpv6Enable').lower() == 'disable'):
self.module.fail_json(
- msg="'Error: Please ensure SCP server is enabled.'")
+ msg="'Error: Please ensure ipv4 and ipv6 SCP server are enabled.'")
+ elif len(cur_state) == 0:
+ self.module.fail_json(
+ msg="'Error: Please ensure ipv4 and ipv6 SCP server are enabled.'")
if not os.path.isfile(self.local_file):
self.module.fail_json(