vsm_array_string_free(ids);
}
+void buildNetdevList(const std::string& zone,std::vector<std::string>& list)
+{
+ using namespace std::placeholders;
+ VsmArrayString ids;
+
+ CommandLineInterface::executeCallback(bind(vsm_zone_get_netdevs, _1, zone.c_str(), &ids));
+ for (VsmString* id = ids; *id; ++id) {
+ list.push_back(*id);
+ }
+ vsm_array_string_free(ids);
+}
+
} // namespace
const std::vector<std::string> CommandLineInterface::buildCompletionList(const Args& a) const
buildZoneList(v);
}
else if (ss == "{NETDEV}") {
- //TODO: get list of available interfaces
- v.push_back("lo");
- v.push_back("eth0");
+ buildNetdevList(a[a.size()-2],v); // zone name must precede netdev
}
else if (ss.length() > 0) {
v.push_back(ss);
void CommandLineInterface::printUsage(std::ostream& out) const
{
- out << mName;
+ out << "Syntax\n";
+ out << "\t" << mName;
for (const auto& args : mArgsSpec) {
out << " " << args.name;
}
out << "\n\n"
- << "\tDescription\n"
- << "\t\t" << mDescription << "\n";
+ "Description\n"
+ "\t" << mDescription << "\n";
if (!mArgsSpec.empty()) {
- out << "\n\tOptions\n";
+ out << "\n"
+ "Options\n";
for (const auto& args : mArgsSpec) {
- out << "\t\t" << args.name << " -- " << args.description << "\n";
+ out << "\t" << args.name << " -- ";
+ const std::string& d=args.description;
+ std::stringstream ss(d);
+ std::string item;
+ std::getline(ss, item);
+ out << item << std::endl;
+ while (std::getline(ss, item))
+ out << "\t\t" << item << std::endl;
}
}
out << "\n";
{
using namespace std::placeholders;
- if (argv.size() < 2) {
+ if (argv.size() < 3) {
throw runtime_error("Not enough parameters");
}
{
create_netdev,
"net-create",
- "Create network interface in zone",
+ "Create network virtualization for the zone",
MODE_COMMAND_LINE | MODE_INTERACTIVE,
{
{"zone_id", "zone name", "{ZONE}"},
- {"netdevtype", "interface type", "macvlan|phys|veth"},
+ {"netdevtype", "interface type (veth, macvlan, phys)\n"
+ " veth - create new zone iface and bridge to host\n"
+ "macvlan - create new zone slave iface briged to master with specified mode\n"
+ " phys - move existing iface from host to zone (no way to move it back)",
+ "veth|macvlan|phys"
+ },
{"zone_netdev", "interface name (eth0)", "eth0|eth1"},
{"host_netdev", "bridge name (virbr0)", "virbr0|virbr1"},
- {"mode", "macvlan mode (private, vepa, bridge, passthru)", "private|vepa|bridge|passthru"}}
+ {"mode", "macvlan mode (private, vepa, bridge, passthru)\n"
+ " private - bridge but no comunicate with otheri vlan\n"
+ " vepa - ethernet switch\n"
+ " bridge - light weight to other vlan\n"
+ "passthru - only one vlan device",
+ "private|vepa|bridge|passthru"}}
},
{
destroy_netdev,
n = name + " ";
}
+ out << "Usage: " << n << "[-h|help|-f <filename>|[<command> [-h|help|<args>]]]\n\n";
if (mode == MODE_COMMAND_LINE) {
- out << "Usage: " << n << "[-h|-f <filename>|[<command> [-h|<args>]]\n"
- << "Called without parameters enters interactive mode.\n"
+ out << "Description:\n"
+ << "\tCommand line tool to manage vasum containers.\n"
+ << "\tCalled without parameters enters interactive mode.\n"
<< "Options:\n"
- << "-h print help\n"
- << "-f <filename> read and execute commands from file\n\n";
- } else {
- out << "Usage: [-h|<command> [-h|<args>]]\n\n";
+ << "\t-h,help print this help\n"
+ << "\t-f <filename> read and execute commands from file\n\n";
}
out << "command can be one of the following:\n";
if (std::find(addLineBefore.begin(), addLineBefore.end(), command.getName()) != addLineBefore.end()) {
out << std::endl;
}
- out << " " << std::setw(25) << std::left << command.getName()
- << command.getDescription() << std::endl;
+ out << " " << std::setw(20) << std::left << command.getName();
+ const std::string& d = command.getDescription();
+ std::stringstream ss(d);
+ std::string item;
+ std::getline(ss, item);
+ out << item << std::endl;
}
}
- out << "\nSee " << n << "command -h to read about a specific one.\n";
+ out << "\nType '" << n << "command help' to read about a specific one.\n";
}
int connect()
return EXIT_FAILURE;
}
- auto it = std::find(argv.begin(), argv.end(), std::string("-h"));
- if (it != argv.end()) {
+ if (argv.size() > 1 && (argv[1] == "-h" || argv[1] == "help")) {
command.printUsage(std::cout);
return EXIT_SUCCESS;
}
int cliMode(const int argc, const char** argv)
{
- if (std::string(argv[1]) == "-h") {
+ if (std::string(argv[1]) == "-h" || std::string(argv[1]) == "help") {
printUsage(std::cout, argv[0], MODE_COMMAND_LINE);
return EXIT_SUCCESS;
}