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 {
|
||||
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);
|
||||
command.add("-r", cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP));
|
||||
command.add("-v", cmd.getVmIpAddress());
|
||||
|
||||
@ -153,23 +153,25 @@ def vm_data(session, args):
|
||||
|
||||
fd = None
|
||||
tmp_path = None
|
||||
if (vmDataValue != "none"):
|
||||
try:
|
||||
fd,tmp_path = tempfile.mkstemp()
|
||||
tmpfile = open(tmp_path, 'w')
|
||||
|
||||
try:
|
||||
fd,tmp_path = tempfile.mkstemp()
|
||||
tmpfile = open(tmp_path, 'w')
|
||||
|
||||
if (vmDataFolder == "userdata"):
|
||||
vmDataValue = base64.urlsafe_b64decode(vmDataValue)
|
||||
|
||||
if vmDataFolder == "userdata" and vmDataValue != "none":
|
||||
vmDataValue = base64.urlsafe_b64decode(vmDataValue)
|
||||
|
||||
if vmDataValue != "none":
|
||||
tmpfile.write(vmDataValue)
|
||||
tmpfile.close()
|
||||
cmd.append("-d")
|
||||
cmd.append(tmp_path)
|
||||
except:
|
||||
util.SMlog(" vmdata failed to write tempfile " )
|
||||
os.close(fd)
|
||||
os.remove(tmp_path)
|
||||
return ''
|
||||
|
||||
tmpfile.close()
|
||||
cmd.append("-d")
|
||||
cmd.append(tmp_path)
|
||||
except:
|
||||
util.SMlog(" vmdata failed to write tempfile " )
|
||||
os.close(fd)
|
||||
os.remove(tmp_path)
|
||||
return ''
|
||||
|
||||
try:
|
||||
txt = util.pread2(cmd)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user