-
Notifications
You must be signed in to change notification settings - Fork 631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multipass clone #3264
base: main
Are you sure you want to change the base?
Multipass clone #3264
Changes from all commits
bb854f4
540bf4d
22d2fe5
9684262
932ba41
50c4be6
aa8e2a1
70a2c8c
ab4566c
dd8a725
e3aae14
91aa4c7
870030c
8125fe4
afdaf89
4c24fc5
4a83765
0f5e799
463220a
9216330
1df9c0f
660a2d7
3c107b5
d36ed1e
88ec4d5
dcbcc79
4598f9b
217a14b
a69e720
d43eaeb
2a3cfcc
72c1ec7
f28d6f5
e72f78e
c32e571
b9fdcba
4d96b5d
79348b1
1b9526c
eed8a10
50f8cb1
12c71c9
8daa47f
cebfd75
9ab0761
fc2276f
fd85513
8e88728
b6248b6
e357c69
ec0a58f
8ddfd13
3d6c2b9
f0cd182
ebe3d15
e6b3853
94a209d
5d43210
9c39ef9
3312963
c34cc7e
9b0ed71
489f729
04b1885
1aeb2cc
3e8c487
451b8be
2be5c64
816332e
6e64f88
c3adf14
6ad68c1
72494e8
9a7f03e
80fbb16
ce421a6
a86ee4c
0cf0e1b
81989ca
b967e05
0155bed
9a9e6ce
b417a14
e4d42b3
001c271
38264f5
07bbee2
cc852cb
3709a51
c01957c
1198623
3d96042
2b9388a
068edfd
626caad
27baf8e
828e191
86afbe8
95ed901
9026f42
7350433
9a81142
6c344cd
f978e60
ded0973
1006fd6
5c7efea
2dd7ed5
32acd01
9e7f913
9c978d0
889584a
7db5392
1289824
c6da907
6cdacec
1497b0a
96b8d55
fb3bc56
8bd9626
c1cd11e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright (C) Canonical, Ltd. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include "clone.h" | ||
|
||
#include "animated_spinner.h" | ||
#include "common_cli.h" | ||
|
||
#include <multipass/cli/argparser.h> | ||
|
||
namespace mp = multipass; | ||
namespace cmd = multipass::cmd; | ||
|
||
mp::ReturnCode cmd::Clone::run(ArgParser* parser) | ||
{ | ||
const auto parscode = parse_args(parser); | ||
if (parscode != ParseCode::Ok) | ||
{ | ||
return parser->returnCodeFrom(parscode); | ||
} | ||
|
||
AnimatedSpinner spinner{cout}; | ||
auto action_on_success = [this, &spinner](CloneReply& reply) -> ReturnCode { | ||
spinner.stop(); | ||
cout << reply.reply_message(); | ||
|
||
return ReturnCode::Ok; | ||
}; | ||
|
||
auto action_on_failure = [this, &spinner](grpc::Status& status, CloneReply& reply) -> ReturnCode { | ||
spinner.stop(); | ||
return standard_failure_handler_for(name(), cerr, status, reply.reply_message()); | ||
}; | ||
|
||
spinner.start("Cloning " + rpc_request.source_name()); | ||
return dispatch(&RpcMethod::clone, rpc_request, action_on_success, action_on_failure); | ||
} | ||
|
||
std::string cmd::Clone::name() const | ||
{ | ||
return "clone"; | ||
} | ||
|
||
QString cmd::Clone::short_help() const | ||
{ | ||
return QStringLiteral("Clone an Ubuntu instance"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we typical refer to them simply as an instance. See snapshot.cpp |
||
} | ||
|
||
QString cmd::Clone::description() const | ||
{ | ||
return QStringLiteral("A clone is a complete independent copy of a whole virtual machine instance"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should describe an action since it is a description of
WDYT |
||
} | ||
|
||
mp::ParseCode cmd::Clone::parse_args(ArgParser* parser) | ||
{ | ||
parser->addPositionalArgument("source_name", "The name of the source virtual machine instance", "<source_name>"); | ||
|
||
const QCommandLineOption destination_name_option{ | ||
{"n", "name"}, | ||
"An optional name for the destination instance, it obeys the same validity rules as instance names (see " | ||
"\"help launch\"). Default: \"<source_name>-cloneN\", where N is the Nth cloned instance of the original " | ||
"instance.", | ||
"destination-name"}; | ||
|
||
parser->addOption(destination_name_option); | ||
|
||
const auto status = parser->commandParse(this); | ||
if (status != ParseCode::Ok) | ||
{ | ||
return status; | ||
} | ||
|
||
const auto number_of_positional_arguments = parser->positionalArguments().count(); | ||
if (number_of_positional_arguments < 1) | ||
{ | ||
cerr << "Please provide the name of the source instance.\n"; | ||
return ParseCode::CommandLineError; | ||
} | ||
|
||
if (number_of_positional_arguments > 1) | ||
{ | ||
cerr << "Too many arguments.\n"; | ||
return ParseCode::CommandLineError; | ||
} | ||
|
||
const auto source_name = parser->positionalArguments()[0]; | ||
rpc_request.set_source_name(source_name.toStdString()); | ||
rpc_request.set_verbosity_level(parser->verbosityLevel()); | ||
if (parser->isSet(destination_name_option)) | ||
{ | ||
rpc_request.set_destination_name(parser->value(destination_name_option).toStdString()); | ||
} | ||
|
||
return ParseCode::Ok; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (C) Canonical, Ltd. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#ifndef MULTIPASS_CLONE_H | ||
#define MULTIPASS_CLONE_H | ||
|
||
#include <multipass/cli/command.h> | ||
|
||
namespace multipass | ||
{ | ||
namespace cmd | ||
{ | ||
class Clone final : public Command | ||
{ | ||
public: | ||
using Command::Command; | ||
ReturnCode run(ArgParser* parser) override; | ||
|
||
std::string name() const override; | ||
QString short_help() const override; | ||
QString description() const override; | ||
|
||
private: | ||
ParseCode parse_args(ArgParser* parser); | ||
|
||
CloneRequest rpc_request; | ||
}; | ||
} // namespace cmd | ||
} // namespace multipass | ||
#endif // MULTIPASS_CLONE_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vm_name
is a public member so you shouldn't need this accessor method, right?