mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
fix user/meta data: if data is empty, return a blank file, not 404
This commit is contained in:
parent
f919e0119e
commit
81475c256b
@ -229,19 +229,21 @@ public class VirtualRoutingResource implements Manager {
|
|||||||
} else {
|
} else {
|
||||||
dataBytes = data.getBytes();
|
dataBytes = data.getBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
tmpFile = File.createTempFile("vmdata_", null);
|
|
||||||
FileOutputStream outStream = new FileOutputStream(tmpFile);
|
|
||||||
outStream.write(dataBytes);
|
|
||||||
outStream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
String tmpDir = System.getProperty("java.io.tmpdir");
|
|
||||||
s_logger.warn("Failed to create temporary file: is " + tmpDir + " full?", e);
|
|
||||||
return new Answer(cmd, false, "Failed to create or write to temporary file: is " + tmpDir + " full? " + e.getMessage() );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
tmpFile = File.createTempFile("vmdata_", null);
|
||||||
|
FileOutputStream outStream = new FileOutputStream(tmpFile);
|
||||||
|
if (dataBytes != null)
|
||||||
|
outStream.write(dataBytes);
|
||||||
|
outStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
String tmpDir = System.getProperty("java.io.tmpdir");
|
||||||
|
s_logger.warn("Failed to create temporary file: is " + tmpDir + " full?", e);
|
||||||
|
return new Answer(cmd, false, "Failed to create or write to temporary file: is " + tmpDir + " full? " + e.getMessage() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
final Script command = new Script(_vmDataPath, _timeout, s_logger);
|
final Script command = new Script(_vmDataPath, _timeout, s_logger);
|
||||||
command.add("-r", cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP));
|
command.add("-r", cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP));
|
||||||
command.add("-v", cmd.getVmIpAddress());
|
command.add("-v", cmd.getVmIpAddress());
|
||||||
|
|||||||
@ -153,23 +153,25 @@ def vm_data(session, args):
|
|||||||
|
|
||||||
fd = None
|
fd = None
|
||||||
tmp_path = None
|
tmp_path = None
|
||||||
if (vmDataValue != "none"):
|
|
||||||
try:
|
try:
|
||||||
fd,tmp_path = tempfile.mkstemp()
|
fd,tmp_path = tempfile.mkstemp()
|
||||||
tmpfile = open(tmp_path, 'w')
|
tmpfile = open(tmp_path, 'w')
|
||||||
|
|
||||||
if (vmDataFolder == "userdata"):
|
if vmDataFolder == "userdata" and vmDataValue != "none":
|
||||||
vmDataValue = base64.urlsafe_b64decode(vmDataValue)
|
vmDataValue = base64.urlsafe_b64decode(vmDataValue)
|
||||||
|
|
||||||
|
if vmDataValue != "none":
|
||||||
tmpfile.write(vmDataValue)
|
tmpfile.write(vmDataValue)
|
||||||
tmpfile.close()
|
|
||||||
cmd.append("-d")
|
tmpfile.close()
|
||||||
cmd.append(tmp_path)
|
cmd.append("-d")
|
||||||
except:
|
cmd.append(tmp_path)
|
||||||
util.SMlog(" vmdata failed to write tempfile " )
|
except:
|
||||||
os.close(fd)
|
util.SMlog(" vmdata failed to write tempfile " )
|
||||||
os.remove(tmp_path)
|
os.close(fd)
|
||||||
return ''
|
os.remove(tmp_path)
|
||||||
|
return ''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
txt = util.pread2(cmd)
|
txt = util.pread2(cmd)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user