Fix vmunbundle to allow 'vmadm receive' to have raw JSON parsed to it #487
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
According to https://github.com/joyent/smartos-live/blob/master/src/vm/README.migration, it should be possible to pipe the JSON output of vmadm get into vmadm receive (once the ZFS datasets are moved across) to re-install the zone. In practice, when attempted on joyent_20150903T073920Z (and seemingly since inception as the logic hasn't changed) vmadm receive will fail with 'Failed to get JSON!'.
This is because the condition in VM.js receiveStdinChunk requires a chunk name and size to be provided by vmunbundle. When raw JSON is passed into vmunbundle, it fails to find the 'magic header' that vmadm send generates so it dumps the raw JSON and exits prior to printing the chunk_name and chunk_size. These two parameters don't actually get calculated as they are pulled from the header.
This change simply provides the data expected by VM.js in the case of raw JSON being used. Looking at the comments in vmunbundle the intention seems to have been there.