VBoxManageImport.cpp revision d4f7483a46e1c44ae5fcc4195be291545ae720a4
/* $Id$ */
/** @file
* VBoxManage - The appliance-related commands.
*/
/*
* Copyright (C) 2009 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#ifndef VBOX_ONLY_DOCS
/*******************************************************************************
* Header Files *
*******************************************************************************/
#ifndef VBOX_ONLY_DOCS
#include <list>
#include <map>
#endif /* !VBOX_ONLY_DOCS */
#include "VBoxManage.h"
using namespace com;
// funcs
///////////////////////////////////////////////////////////////////////////////
typedef std::map<uint32_t, ArgsMap> ArgsMapsMap; // map of maps, one for each virtual system, sorted by index
typedef std::map<uint32_t, IgnoresMap> IgnoresMapsMap; // map of maps, one for each virtual system, sorted by index
{
if (pmapArgs)
{
{
return true;
}
}
return false;
}
int handleImportAppliance(HandlerArg *a)
{
bool fExecute = true; // if true, then we actually do the import
// for each -vsys X command, maintain a map of command line items
// (we'll parse them later after interpreting the OVF, when we can
// actually check whether they make sense semantically)
for (int i = 0;
i < a->argc;
++i)
{
bool fIsIgnore = false;
if ( (strThisArg == "--dry-run")
|| (strThisArg == "-dry-run")
|| (strThisArg == "-n")
)
fExecute = false;
else if (strThisArg == "-vsys")
{
if (++i < a->argc)
{
if (VINF_SUCCESS != (rc = Utf8Str(a->argv[i]).toInt(ulVsys))) // don't use SUCCESS() macro, fail even on warnings
return errorSyntax(USAGE_IMPORTAPPLIANCE, "Argument to -vsys option must be a non-negative number.");
}
else
}
else if ( (strThisArg == "-ostype")
|| (strThisArg == "-vmname")
|| (strThisArg == "-memory")
)
{
return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding -vsys argument.", strThisArg.c_str());
if (++i < a->argc)
if (fIsIgnore)
{
return errorSyntax(USAGE_IMPORTAPPLIANCE, "Argument to -vsys option must be a non-negative number.");
}
else
{
// store both this arg and the next one in the strings map for later parsing
}
else
return errorSyntax(USAGE_IMPORTAPPLIANCE, "Missing argument to \"%s\" option.", strThisArg.c_str());
}
else if (strThisArg[0] == '-')
else if (!strOvfFilename)
else
}
if (!strOvfFilename)
do
{
// call interpret(); this can yield both warnings and errors, so we need
// to tinker with the error info a bit
{
for (unsigned i = 0; i < cWarnings; ++i)
{
}
}
{
break;
}
RTPrintf("OK.\n");
// fetch all disks
{
RTPrintf("Disks:");
RTPrintf("\n");
}
// fetch virtual system descriptions
// match command line arguments with virtual system descriptions;
// this is only to sort out invalid indices at this time
++it)
{
if (ulVsys >= cVirtualSystemDescriptions)
return errorSyntax(USAGE_IMPORTAPPLIANCE,
"Invalid index %RI32 with -vsys option; the OVF contains only %RI32 virtual system(s).",
}
// dump virtual system descriptions and match command-line arguments
if (cVirtualSystemDescriptions > 0)
{
for (unsigned i = 0; i < cVirtualSystemDescriptions; ++i)
{
RTPrintf("Virtual system %i:\n", i);
// look up the corresponding command line options, if any
// this collects the final values for setFinalValues()
{
bool fIgnoreThis = mapIgnoresMapsPerVsys[i][a];
aEnabled[a] = true;
switch (t)
{
{
RTPrintf("%2d: VM name specified with -vmname: \"%ls\"\n",
a, bstrFinalValue.raw());
}
else
RTPrintf("%2d: Suggested VM name \"%ls\""
"\n (change with \"-vsys %d -vmname <name>\")\n",
a, bstrFinalValue.raw(), i);
break;
{
RTPrintf("%2d: OS type specified with -ostype: \"%ls\"\n",
a, bstrFinalValue.raw());
}
else
RTPrintf("%2d: Suggested OS type: \"%ls\""
"\n (change with \"-vsys %d -ostype <type>\"; use \"list ostypes\" to list all)\n",
a, bstrFinalValue.raw(), i);
break;
RTPrintf("%2d: Number of CPUs (ignored): %ls\n",
a, aVboxValues[a]);
break;
{
{
{
RTPrintf("%2d: Guest memory specified with -memory: %ls MB\n",
a, bstrFinalValue.raw());
}
else
return errorSyntax(USAGE_IMPORTAPPLIANCE,
"Argument to -memory option must be a non-negative number.");
}
else
RTPrintf("%2d: Guest memory: %ls MB\n (change with \"-vsys %d -memory <MB>\")\n",
a, bstrFinalValue.raw(), i);
}
break;
if (fIgnoreThis)
{
RTPrintf("%2d: IDE controller, type %ls -- disabled\n",
a,
aVboxValues[a]);
aEnabled[a] = false;
}
else
RTPrintf("%2d: IDE controller, type %ls"
"\n (disable with \"-vsys %d -ignore %d\")\n",
a,
aVboxValues[a],
i, a);
break;
if (fIgnoreThis)
{
RTPrintf("%2d: SATA controller, type %ls -- disabled\n",
a,
aVboxValues[a]);
aEnabled[a] = false;
}
else
RTPrintf("%2d: SATA controller, type %ls"
"\n (disable with \"-vsys %d -ignore %d\")\n",
a,
aVboxValues[a],
i, a);
break;
if (fIgnoreThis)
{
RTPrintf("%2d: SCSI controller, type %ls -- disabled\n",
a,
aVboxValues[a]);
aEnabled[a] = false;
}
else
{
{
RTPrintf("%2d: SCSI controller, type set with -type%d: %ls\n",
a,
a,
bstrFinalValue.raw());
}
else
RTPrintf("%2d: SCSI controller, type %ls"
"\n (change with \"-vsys %d -type%d {BusLogic|LsiLogic}\";"
"\n disable with \"-vsys %d -ignore %d\")\n",
a,
aVboxValues[a],
i, a, i, a);
}
break;
if (fIgnoreThis)
{
RTPrintf("%2d: Hard disk image: source image=%ls -- disabled\n",
a,
aOvfValues[a]);
aEnabled[a] = false;
}
else
{
{
// strOverride now has the controller index as a number, but we
// need a "controller=X" format string
RTPrintf("%2d: Hard disk image: source image=%ls, target path=%ls, %ls\n",
a,
aOvfValues[a],
aVboxValues[a],
aExtraConfigValues[a]);
}
else
RTPrintf("%2d: Hard disk image: source image=%ls, target path=%ls, %ls"
"\n (change controller with \"-vsys %d -controller%d <id>\";"
"\n disable with \"-vsys %d -ignore %d\")\n",
a,
aOvfValues[a],
aVboxValues[a],
i, a, i, a);
}
break;
if (fIgnoreThis)
{
RTPrintf("%2d: CD-ROM -- disabled\n",
a);
aEnabled[a] = false;
}
else
RTPrintf("%2d: CD-ROM"
"\n (disable with \"-vsys %d -ignore %d\")\n",
a, i, a);
break;
if (fIgnoreThis)
{
RTPrintf("%2d: Floppy -- disabled\n",
a);
aEnabled[a] = false;
}
else
RTPrintf("%2d: Floppy"
"\n (disable with \"-vsys %d -ignore %d\")\n",
a, i, a);
break;
RTPrintf("%2d: Network adapter: orig %ls, config %ls, extra %ls\n", // @todo implement once we have a plan for the back-end
a,
aOvfValues[a],
aVboxValues[a],
aExtraConfigValues[a]);
break;
if (fIgnoreThis)
{
RTPrintf("%2d: USB controller -- disabled\n",
a);
aEnabled[a] = false;
}
else
RTPrintf("%2d: USB controller"
"\n (disable with \"-vsys %d -ignore %d\")\n",
a, i, a);
break;
if (fIgnoreThis)
{
RTPrintf("%2d: Sound card \"%ls\" -- disabled\n",
a,
aOvfValues[a]);
aEnabled[a] = false;
}
else
RTPrintf("%2d: Sound card (appliance expects \"%ls\", can change on import)"
"\n (disable with \"-vsys %d -ignore %d\")\n",
a,
aOvfValues[a],
i,
a);
break;
}
}
if (fExecute)
} // for (unsigned i = 0; i < cVirtualSystemDescriptions; ++i)
if (fExecute)
{
// go!
{
}
else
RTPrintf("Successfully imported the appliance.\n");
}
} // end if (aVirtualSystemDescriptions.size() > 0)
} while (0);
}
static const RTGETOPTDEF g_aExportOptions[]
= {
};
int handleExportAppliance(HandlerArg *a)
{
do
{
int c;
// start at 0 because main() has hacked both the argc and argv given to us
{
switch (c)
{
case 'o': // --output
if (strOutputFile.length())
else
break;
case VINF_GETOPT_NOT_OPTION:
{
// must be machine: try UUID or name
/* assume it's a UUID */
{
/* must be a name */
}
if (machine)
}
break;
default:
if (c > 0)
{
if (RT_C_IS_GRAPH(c))
else
}
else if (c == VERR_GETOPT_UNKNOWN_OPTION)
else if (ValueUnion.pDef)
else
}
break;
}
break;
if (llMachines.size() == 0)
return errorSyntax(USAGE_EXPORTAPPLIANCE, "At least one machine must be specified with the export command.");
if (!strOutputFile.length())
++itM)
{
}
break;
{
}
else
} while (0);
}
#endif /* !VBOX_ONLY_DOCS */