1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267
|
(* libguestfs
* Copyright (C) 2014 Red Hat Inc.
*
* 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; either version 2 of the License, or
* (at your option) any later version.
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*)
(* Please read generator/README first. *)
open Printf
open Std_utils
open Docstrings
open Pr
let generate_header = generate_header ~inputs:["generator/customize.ml"]
(* Command-line arguments used by virt-customize, virt-builder,
* virt-sysprep and (some for) virt-v2v.
*)
type op = {
op_name : string; (* argument name, without "--" *)
op_type : op_type; (* argument value type *)
op_discrim : string; (* argument discriminator in OCaml code *)
op_exclude_v2v : bool; (* if true, don't include for virt-v2v *)
op_shortdesc : string; (* single-line description *)
op_pod_longdesc : string; (* multi-line description *)
}
and op_type =
| Unit (* no argument *)
| String of string (* string *)
| StringPair of string (* string:string *)
| StringTriplet of string (* string:string:string *)
| StringList of string (* string,string,... *)
| TargetLinks of string (* target:link[:link...] *)
| PasswordSelector of string (* password selector *)
| UserPasswordSelector of string (* user:selector *)
| SSHKeySelector of string (* user:selector *)
| StringFn of (string * string) (* string, function name *)
| SMPoolSelector of string (* pool selector *)
let ops = [
{ op_name = "append-line";
op_type = StringPair "FILE:LINE";
op_discrim = "`AppendLine";
op_exclude_v2v = false;
op_shortdesc = "Append line(s) to the file";
op_pod_longdesc = "\
Append a single line of text to the C<FILE>. If the file does not already
end with a newline, then one is added before the appended
line. Also a newline is added to the end of the C<LINE> string
automatically.
For example (assuming ordinary shell quoting) this command:
--append-line '/etc/hosts:10.0.0.1 foo'
will add either C<10.0.0.1 foo⏎> or C<⏎10.0.0.1 foo⏎> to
the file, the latter only if the existing file does not
already end with a newline.
C<⏎> represents a newline character, which is guessed by
looking at the existing content of the file, so this command
does the right thing for files using Unix or Windows line endings.
It also works for empty or non-existent files.
To insert several lines, use the same option several times:
--append-line '/etc/hosts:10.0.0.1 foo'
--append-line '/etc/hosts:10.0.0.2 bar'
To insert a blank line before the appended line, do:
--append-line '/etc/hosts:'
--append-line '/etc/hosts:10.0.0.1 foo'";
};
{ op_name = "chmod";
op_type = StringPair "PERMISSIONS:FILE";
op_discrim = "`Chmod";
op_exclude_v2v = false;
op_shortdesc = "Change the permissions of a file";
op_pod_longdesc = "\
Change the permissions of C<FILE> to C<PERMISSIONS>.
I<Note>: C<PERMISSIONS> by default would be decimal, unless you prefix
it with C<0> to get octal, ie. use C<0700> not C<700>.";
};
{ op_name = "chown";
op_type = StringTriplet "UID:GID:PATH";
op_discrim = "`Chown";
op_exclude_v2v = false;
op_shortdesc = "Change the owner user and group ID of a file or directory";
op_pod_longdesc = "\
Change the owner user and group ID of a file or directory in the guest.
Note:
=over 4
=item *
Only numeric UIDs and GIDs will work, and these may not be the same
inside the guest as on the host.
=item *
This will not work with Windows guests.
=back
For example:
virt-customize --chown '0:0:/var/log/audit.log'
See also: I<--upload>.";
};
{ op_name = "commands-from-file";
op_type = StringFn ("FILENAME", "customize_read_from_file");
op_discrim = "`CommandsFromFile";
op_exclude_v2v = false;
op_shortdesc = "Read customize commands from file";
op_pod_longdesc = "\
Read the customize commands from a file, one (and its arguments)
each line.
Each line contains a single customization command and its arguments,
for example:
delete /some/file
install some-package
password some-user:password:its-new-password
Empty lines are ignored, and lines starting with C<#> are comments
and are ignored as well. Furthermore, arguments can be spread across
multiple lines, by adding a C<\\> (continuation character) at the of
a line, for example
edit /some/file:\\
s/^OPT=.*/OPT=ok/
The commands are handled in the same order as they are in the file,
as if they were specified as I<--delete /some/file> on the command
line.";
};
{ op_name = "copy";
op_type = StringPair "SOURCE:DEST";
op_discrim = "`Copy";
op_exclude_v2v = false;
op_shortdesc = "Copy files in disk image";
op_pod_longdesc = "\
Copy files or directories recursively inside the guest.
Wildcards cannot be used.";
};
{ op_name = "copy-in";
op_type = StringPair "LOCALPATH:REMOTEDIR";
op_discrim = "`CopyIn";
op_exclude_v2v = false;
op_shortdesc = "Copy local files or directories into image";
op_pod_longdesc = "\
Copy local files or directories recursively into the disk image,
placing them in the directory C<REMOTEDIR> (which must exist).
Wildcards cannot be used.";
};
{ op_name = "delete";
op_type = String "PATH";
op_discrim = "`Delete";
op_exclude_v2v = false;
op_shortdesc = "Delete a file or directory";
op_pod_longdesc = "\
Delete a file from the guest. Or delete a directory (and all its
contents, recursively).
You can use shell glob characters in the specified path. Be careful
to escape glob characters from the host shell, if that is required.
For example:
virt-customize --delete '/var/log/*.log'.
See also: I<--upload>, I<--scrub>.";
};
{ op_name = "edit";
op_type = StringPair "FILE:EXPR";
op_discrim = "`Edit";
op_exclude_v2v = false;
op_shortdesc = "Edit file using Perl expression";
op_pod_longdesc = "\
Edit C<FILE> using the Perl expression C<EXPR>.
Be careful to properly quote the expression to prevent it from
being altered by the shell.
Note that this option is only available when Perl 5 is installed.
See L<virt-edit(1)/NON-INTERACTIVE EDITING>.";
};
{ op_name = "firstboot";
op_type = String "SCRIPT";
op_discrim = "`FirstbootScript";
op_exclude_v2v = false;
op_shortdesc = "Run script at first guest boot";
op_pod_longdesc = "\
Install C<SCRIPT> inside the guest, so that when the guest first boots
up, the script runs (as root, late in the boot process).
The script is automatically chmod +x after installation in the guest.
The alternative version I<--firstboot-command> is the same, but it
conveniently wraps the command up in a single line script for you.
You can have multiple I<--firstboot> options. They run in the same
order that they appear on the command line.
Please take a look at L<virt-builder(1)/FIRST BOOT SCRIPTS> for more
information and caveats about the first boot scripts.
See also I<--run>.";
};
{ op_name = "firstboot-command";
op_type = String "'CMD+ARGS'";
op_discrim = "`FirstbootCommand";
op_exclude_v2v = false;
op_shortdesc = "Run command at first guest boot";
op_pod_longdesc = "\
Run command (and arguments) inside the guest when the guest first
boots up (as root, late in the boot process).
You can have multiple I<--firstboot> options. They run in the same
order that they appear on the command line.
Please take a look at L<virt-builder(1)/FIRST BOOT SCRIPTS> for more
information and caveats about the first boot scripts.
See also I<--run>.";
};
{ op_name = "firstboot-install";
op_type = StringList "PKG,PKG..";
op_discrim = "`FirstbootPackages";
op_exclude_v2v = false;
op_shortdesc = "Add package(s) to install at first boot";
op_pod_longdesc = "\
Install the named packages (a comma-separated list). These are
installed when the guest first boots using the guest’s package manager
(eg. apt, yum, etc.) and the guest’s network connection.
For an overview on the different ways to install packages, see
L<virt-builder(1)/INSTALLING PACKAGES>.";
};
{ op_name = "hostname";
op_type = String "HOSTNAME";
op_discrim = "`Hostname";
op_exclude_v2v = false;
op_shortdesc = "Set the hostname";
op_pod_longdesc = "\
Set the hostname of the guest to C<HOSTNAME>. You can use a
dotted hostname.domainname (FQDN) if you want.";
};
{ op_name = "inject-blnsvr";
op_type = String "METHOD";
op_discrim = "`InjectBalloonServer";
op_exclude_v2v = true;
op_shortdesc = "Inject the Balloon Server into a Windows guest";
op_pod_longdesc = "\
Inject the Balloon Server (F<blnsvr.exe>) into a Windows guest.
This operation also injects a firstboot script so that the Balloon
Server is installed when the guest boots.
The parameter is the same as used by the I<--inject-virtio-win> operation.
Note that to do a full conversion of a Windows guest from a
foreign hypervisor like VMware (which involves many other operations)
you should use the L<virt-v2v(1)> tool instead of this.";
};
{ op_name = "inject-qemu-ga";
op_type = String "METHOD";
op_discrim = "`InjectQemuGA";
op_exclude_v2v = true;
op_shortdesc = "Inject the QEMU Guest Agent into a Windows guest";
op_pod_longdesc = "\
Inject the QEMU Guest Agent into a Windows guest. The guest
agent communicates with qemu through a socket in order to
provide enhanced features (see L<qemu-ga(8)>). This operation
also injects a firstboot script so that the Guest Agent is
installed when the guest boots.
The parameter is the same as used by the I<--inject-virtio-win> operation.
Note that to do a full conversion of a Windows guest from a
foreign hypervisor like VMware (which involves many other operations)
you should use the L<virt-v2v(1)> tool instead of this.";
};
{ op_name = "inject-virtio-win";
op_type = String "METHOD";
op_discrim = "`InjectVirtioWin";
op_exclude_v2v = true;
op_shortdesc = "Inject virtio-win drivers into a Windows guest";
op_pod_longdesc = "\
Inject virtio-win drivers into a Windows guest. These drivers
add virtio accelerated drivers suitable when running on top of
a hypervisor that supports virtio (such as qemu/KVM). The
operation also adjusts the Windows Registry so that the drivers
are installed when the guest boots.
The parameter can be one of:
=over 4
=item ISO
The path to the ISO image containing the virtio-win drivers
(eg. F</usr/share/virtio-win/virtio-win.iso>).
=item DIR
The directory containing the unpacked virtio-win drivers
(eg. F</usr/share/virtio-win>).
=item B<\"osinfo\">
The literal string C<\"osinfo\"> means to use the
libosinfo database to locate the drivers. (See
L<osinfo-query(1)>.
=back
Note that to do a full conversion of a Windows guest from a
foreign hypervisor like VMware (which involves many other operations)
you should use the L<virt-v2v(1)> tool instead of this.";
};
{ op_name = "install";
op_type = StringList "PKG,PKG..";
op_discrim = "`InstallPackages";
op_exclude_v2v = false;
op_shortdesc = "Add package(s) to install";
op_pod_longdesc = "\
Install the named packages (a comma-separated list). These are
installed during the image build using the guest’s package manager
(eg. apt, yum, etc.) and the host’s network connection.
For an overview on the different ways to install packages, see
L<virt-builder(1)/INSTALLING PACKAGES>.
See also I<--update>, I<--uninstall>.";
};
{ op_name = "link";
op_type = TargetLinks "TARGET:LINK[:LINK..]";
op_discrim = "`Link";
op_exclude_v2v = false;
op_shortdesc = "Create symbolic links";
op_pod_longdesc = "\
Create symbolic link(s) in the guest, starting at C<LINK> and
pointing at C<TARGET>.";
};
{ op_name = "mkdir";
op_type = String "DIR";
op_discrim = "`Mkdir";
op_exclude_v2v = false;
op_shortdesc = "Create a directory";
op_pod_longdesc = "\
Create a directory in the guest.
This uses S<C<mkdir -p>> so any intermediate directories are created,
and it also works if the directory already exists.";
};
{ op_name = "move";
op_type = StringPair "SOURCE:DEST";
op_discrim = "`Move";
op_exclude_v2v = false;
op_shortdesc = "Move files in disk image";
op_pod_longdesc = "\
Move files or directories inside the guest.
Wildcards cannot be used.";
};
{ op_name = "password";
op_type = UserPasswordSelector "USER:SELECTOR";
op_discrim = "`Password";
op_exclude_v2v = false;
op_shortdesc = "Set user password";
op_pod_longdesc = "\
Set the password for C<USER>. (Note this option does I<not>
create the user account).
See L<virt-builder(1)/USERS AND PASSWORDS> for the format of
the C<SELECTOR> field, and also how to set up user accounts.";
};
{ op_name = "root-password";
op_type = PasswordSelector "SELECTOR";
op_discrim = "`RootPassword";
op_exclude_v2v = false;
op_shortdesc = "Set root password";
op_pod_longdesc = "\
Set the root password.
See L<virt-builder(1)/USERS AND PASSWORDS> for the format of
the C<SELECTOR> field, and also how to set up user accounts.
Note: In virt-builder, if you I<don't> set I<--root-password>
then the guest is given a I<random> root password.";
};
{ op_name = "run";
op_type = String "SCRIPT";
op_discrim = "`Script";
op_exclude_v2v = false;
op_shortdesc = "Run script in disk image";
op_pod_longdesc = "\
Run the shell script (or any program) called C<SCRIPT> on the disk
image. The script runs virtualized inside a small appliance, chrooted
into the guest filesystem.
The script is automatically chmod +x.
If libguestfs supports it then a limited network connection is
available but it only allows outgoing network connections. You can
also attach data disks (eg. ISO files) as another way to provide data
(eg. software packages) to the script without needing a network
connection (I<--attach>). You can also upload data files (I<--upload>).
You can have multiple I<--run> options. They run
in the same order that they appear on the command line.
See also: I<--firstboot>, I<--attach>, I<--upload>.";
};
{ op_name = "run-command";
op_type = String "'CMD+ARGS'";
op_discrim = "`Command";
op_exclude_v2v = false;
op_shortdesc = "Run command in disk image";
op_pod_longdesc = "\
Run the command and arguments on the disk image. The command runs
virtualized inside a small appliance, chrooted into the guest filesystem.
If libguestfs supports it then a limited network connection is
available but it only allows outgoing network connections. You can
also attach data disks (eg. ISO files) as another way to provide data
(eg. software packages) to the script without needing a network
connection (I<--attach>). You can also upload data files (I<--upload>).
You can have multiple I<--run-command> options. They run
in the same order that they appear on the command line.
See also: I<--firstboot>, I<--attach>, I<--upload>.";
};
{ op_name = "scrub";
op_type = String "FILE";
op_discrim = "`Scrub";
op_exclude_v2v = false;
op_shortdesc = "Scrub a file";
op_pod_longdesc = "\
Scrub a file from the guest. This is like I<--delete> except that:
=over 4
=item *
It scrubs the data so a guest could not recover it.
=item *
It cannot delete directories, only regular files.
=back";
};
{ op_name = "sm-attach";
op_type = SMPoolSelector "SELECTOR";
op_discrim = "`SMAttach";
op_exclude_v2v = false;
op_shortdesc = "Attach to a subscription-manager pool";
op_pod_longdesc = "\
Attach to a pool using C<subscription-manager>.
See L<virt-builder(1)/SUBSCRIPTION-MANAGER> for the format of
the C<SELECTOR> field.";
};
{ op_name = "sm-register";
op_type = Unit;
op_discrim = "`SMRegister";
op_exclude_v2v = false;
op_shortdesc = "Register using subscription-manager";
op_pod_longdesc = "\
Register the guest using C<subscription-manager>.
This requires credentials being set using I<--sm-credentials>.";
};
{ op_name = "sm-remove";
op_type = Unit;
op_discrim = "`SMRemove";
op_exclude_v2v = false;
op_shortdesc = "Remove all the subscriptions";
op_pod_longdesc = "\
Remove all the subscriptions from the guest using
C<subscription-manager>.";
};
{ op_name = "sm-unregister";
op_type = Unit;
op_discrim = "`SMUnregister";
op_exclude_v2v = false;
op_shortdesc = "Unregister using subscription-manager";
op_pod_longdesc = "\
Unregister the guest using C<subscription-manager>.";
};
{ op_name = "ssh-inject";
op_type = SSHKeySelector "USER[:SELECTOR]";
op_discrim = "`SSHInject";
op_exclude_v2v = false;
op_shortdesc = "Inject a public key into the guest";
op_pod_longdesc = "\
Inject an ssh key so the given C<USER> will be able to log in over
ssh without supplying a password. The C<USER> must exist already
in the guest.
See L<virt-builder(1)/SSH KEYS> for the format of
the C<SELECTOR> field.
You can have multiple I<--ssh-inject> options, for different users
and also for more keys for each user."
};
{ op_name = "tar-in";
op_type = StringPair "TARFILE:REMOTEDIR";
op_discrim = "`TarIn";
op_exclude_v2v = false;
op_shortdesc = "Copy local files or directories from a tarball into image";
op_pod_longdesc = "\
Copy local files or directories from a local tar file
called C<TARFILE> into the disk image, placing them in the
directory C<REMOTEDIR> (which must exist). Note that
the tar file must be uncompressed (F<.tar.gz> files will not work
here)";
};
{ op_name = "timezone";
op_type = String "TIMEZONE";
op_discrim = "`Timezone";
op_exclude_v2v = false;
op_shortdesc = "Set the default timezone";
op_pod_longdesc = "\
Set the default timezone of the guest to C<TIMEZONE>. Use a location
string like C<Europe/London>";
};
{ op_name = "touch";
op_type = String "FILE";
op_discrim = "`Touch";
op_exclude_v2v = false;
op_shortdesc = "Run touch on a file";
op_pod_longdesc = "\
This command performs a L<touch(1)>-like operation on C<FILE>.";
};
{ op_name = "truncate";
op_type = String "FILE";
op_discrim = "`Truncate";
op_exclude_v2v = false;
op_shortdesc = "Truncate a file to zero size";
op_pod_longdesc = "\
This command truncates C<FILE> to a zero-length file. The file must exist
already.";
};
{ op_name = "truncate-recursive";
op_type = String "PATH";
op_discrim = "`TruncateRecursive";
op_exclude_v2v = false;
op_shortdesc = "Recursively truncate all files in directory";
op_pod_longdesc = "\
This command recursively truncates all files under C<PATH> to zero-length.";
};
{ op_name = "uninstall";
op_type = StringList "PKG,PKG..";
op_discrim = "`UninstallPackages";
op_exclude_v2v = false;
op_shortdesc = "Uninstall package(s)";
op_pod_longdesc = "\
Uninstall the named packages (a comma-separated list). These are
removed during the image build using the guest’s package manager
(eg. apt, yum, etc.). Dependent packages may also need to be
uninstalled to satisfy the request.
See also I<--install>, I<--update>.";
};
{ op_name = "update";
op_type = Unit;
op_discrim = "`Update";
op_exclude_v2v = false;
op_shortdesc = "Update packages";
op_pod_longdesc = "\
Do the equivalent of C<yum update>, C<apt-get upgrade>, or whatever
command is required to update the packages already installed in the
template to their latest versions.
See also I<--install>, I<--uninstall>.";
};
{ op_name = "upload";
op_type = StringPair "FILE:DEST";
op_discrim = "`Upload";
op_exclude_v2v = false;
op_shortdesc = "Upload local file to destination";
op_pod_longdesc = "\
Upload local file C<FILE> to destination C<DEST> in the disk image.
File owner and permissions from the original are preserved, so you
should set them to what you want them to be in the disk image.
C<DEST> could be the final filename. This can be used to rename
the file on upload.
If C<DEST> is a directory name (which must already exist in the guest)
then the file is uploaded into that directory, and it keeps the same
name as on the local filesystem.
See also: I<--mkdir>, I<--delete>, I<--scrub>.";
};
{ op_name = "write";
op_type = StringPair "FILE:CONTENT";
op_discrim = "`Write";
op_exclude_v2v = false;
op_shortdesc = "Write file";
op_pod_longdesc = "\
Write C<CONTENT> to C<FILE>.";
};
]
(* Flags. *)
type flag = {
flag_name : string; (* argument name, without "--" *)
flag_type : flag_type; (* argument value type *)
flag_ml_var : string; (* variable name in OCaml code *)
flag_shortdesc : string; (* single-line description *)
flag_pod_longdesc : string; (* multi-line description *)
}
and flag_type =
| FlagBool of bool (* boolean is the default value *)
| FlagPasswordCrypto of string
| FlagSMCredentials of string
let flags = [
{ flag_name = "no-logfile";
flag_type = FlagBool false;
flag_ml_var = "scrub_logfile";
flag_shortdesc = "Scrub build log file";
flag_pod_longdesc = "\
Scrub C<builder.log> (log file from build commands) from the image
after building is complete. If you don't want to reveal precisely how
the image was built, use this option.
See also: L</LOG FILE>.";
};
{ flag_name = "password-crypto";
flag_type = FlagPasswordCrypto "md5|sha256|sha512";
flag_ml_var = "password_crypto";
flag_shortdesc = "Set password crypto";
flag_pod_longdesc = "\
When the virt tools change or set a password in the guest, this
option sets the password encryption of that password to
C<md5>, C<sha256> or C<sha512>.
C<sha256> and C<sha512> require glibc E<ge> 2.7 (check crypt(3) inside
the guest).
C<md5> will work with relatively old Linux guests (eg. RHEL 3), but
is not secure against modern attacks.
The default is C<sha512> unless libguestfs detects an old guest that
didn't have support for SHA-512, in which case it will use C<md5>.
You can override libguestfs by specifying this option.
Note this does not change the default password encryption used
by the guest when you create new user accounts inside the guest.
If you want to do that, then you should use the I<--edit> option
to modify C</etc/sysconfig/authconfig> (Fedora, RHEL) or
C</etc/pam.d/common-password> (Debian, Ubuntu).";
};
{ flag_name = "no-selinux-relabel";
flag_type = FlagBool false (* XXX - the default in virt-builder *);
flag_ml_var = "no_selinux_relabel";
flag_shortdesc = "Do not relabel files with correct SELinux labels";
flag_pod_longdesc = "\
Do not attempt to correct the SELinux labels of files in the guest.
In such guests that support SELinux, customization automatically
relabels files so that they have the correct SELinux label. (The
relabeling is performed immediately, but if the operation fails,
customization will instead touch F</.autorelabel> on the image to
schedule a relabel operation for the next time the image boots.) This
option disables the automatic relabeling.
The option is a no-op for guests that do not support SELinux.";
};
{ flag_name = "selinux-relabel";
flag_type = FlagBool false;
flag_ml_var = "selinux_relabel_ignored";
flag_shortdesc = "Compatibility option doing nothing";
flag_pod_longdesc = "This is a compatibility option that does nothing.";
};
{ flag_name = "sm-credentials";
flag_type = FlagSMCredentials "SELECTOR";
flag_ml_var = "sm_credentials";
flag_shortdesc = "Credentials for subscription-manager";
flag_pod_longdesc = "\
Set the credentials for C<subscription-manager>.
See L<virt-builder(1)/SUBSCRIPTION-MANAGER> for the format of
the C<SELECTOR> field.";
};
]
let rec generate_customize_cmdline_mli () =
generate_header OCamlStyle GPLv2plus;
pr "\
(** Command line argument parsing, both for the virt-customize binary
and for the other tools that share the same code. *)
";
generate_ops_struct_decl ();
pr "\n";
pr "\
type argspec = Getopt.keys * Getopt.spec * Getopt.doc
val argspec : ?v2v:bool -> unit -> (argspec * string option * string) list * (unit -> ops)
(** This returns a pair [(list, get_ops)].
[list] is a list of the command line arguments, plus some extra data.
[get_ops] is a function you can call {i after} command line parsing
which will return the actual operations specified by the user on the
command line.
If the parameter [~v2v] is true then this excludes parameters
that should be excluded from virt-v2v. *)"
and generate_customize_cmdline_ml () =
generate_header OCamlStyle GPLv2plus;
pr "\
(* Command line argument parsing, both for the virt-customize binary
* and for the other tools that share the same code.
*)
open Printf
open Std_utils
open Tools_utils
open Common_gettext.Gettext
open Getopt.OptionName
";
generate_ops_struct_decl ();
pr "\n";
pr "\
type argspec = Getopt.keys * Getopt.spec * Getopt.doc
let rec argspec ?(v2v = false) () =
let ops = ref [] in
";
List.iter (
function
| { flag_type = FlagBool default; flag_ml_var = var } ->
pr " let %s = ref %b in\n" var default
| { flag_type = FlagPasswordCrypto _; flag_ml_var = var } ->
pr " let %s = ref None in\n" var
| { flag_type = FlagSMCredentials _; flag_ml_var = var } ->
pr " let %s = ref None in\n" var
) flags;
pr "\
let rec get_ops () = {
ops = List.rev !ops;
flags = get_flags ();
}
and get_flags () = {
";
List.iter (fun { flag_ml_var = var } -> pr " %s = !%s;\n" var var) flags;
pr " }
in
let split_string_pair option_name arg =
let i =
try String.index arg ':'
with Not_found ->
error (f_\"invalid format for '--%%s' parameter, see the man page\")
option_name in
let len = String.length arg in
String.sub arg 0 i, String.sub arg (i+1) (len-(i+1))
and split_string_triplet option_name arg =
match String.nsplit ~max:3 \":\" arg with
| [a; b; c] -> a, b, c
| _ ->
error (f_\"invalid format for '--%%s' parameter, see the man page\")
option_name
and split_string_list arg =
String.nsplit \",\" arg
in
let split_links_list option_name arg =
match String.nsplit \":\" arg with
| [] | [_] ->
error (f_\"invalid format for '--%%s' parameter, see the man page\")
option_name
| target :: lns -> target, lns
in
let rec argspec = [
";
List.iter (
function
| { op_type = Unit; op_name = name; op_discrim = discrim;
op_exclude_v2v = exclude_v2v;
op_shortdesc = shortdesc; op_pod_longdesc = longdesc } ->
pr " (\n";
pr " [ L\"%s\" ],\n" name;
pr " Getopt.Unit (fun () -> List.push_front %s ops),\n" discrim;
pr " s_\"%s\"\n" shortdesc;
pr " ),\n";
pr " None, %S, %b;\n" longdesc exclude_v2v
| { op_type = String v; op_name = name; op_discrim = discrim;
op_exclude_v2v = exclude_v2v;
op_shortdesc = shortdesc; op_pod_longdesc = longdesc } ->
pr " (\n";
pr " [ L\"%s\" ],\n" name;
pr " Getopt.String (s_\"%s\", fun s -> List.push_front (%s s) ops),\n" v discrim;
pr " s_\"%s\"\n" shortdesc;
pr " ),\n";
pr " Some %S, %S, %b;\n" v longdesc exclude_v2v
| { op_type = StringPair v; op_name = name; op_discrim = discrim;
op_exclude_v2v = exclude_v2v;
op_shortdesc = shortdesc; op_pod_longdesc = longdesc } ->
pr " (\n";
pr " [ L\"%s\" ],\n" name;
pr " Getopt.String (\n";
pr " s_\"%s\",\n" v;
pr " fun s ->\n";
pr " let p = split_string_pair \"%s\" s in\n" name;
pr " List.push_front (%s p) ops\n" discrim;
pr " ),\n";
pr " s_\"%s\"\n" shortdesc;
pr " ),\n";
pr " Some %S, %S, %b;\n" v longdesc exclude_v2v
| { op_type = StringTriplet v; op_name = name; op_discrim = discrim;
op_exclude_v2v = exclude_v2v;
op_shortdesc = shortdesc; op_pod_longdesc = longdesc } ->
pr " (\n";
pr " [ L\"%s\" ],\n" name;
pr " Getopt.String (\n";
pr " s_\"%s\",\n" v;
pr " fun s ->\n";
pr " let p = split_string_triplet \"%s\" s in\n" name;
pr " List.push_front (%s p) ops\n" discrim;
pr " ),\n";
pr " s_\"%s\"\n" shortdesc;
pr " ),\n";
pr " Some %S, %S, %b;\n" v longdesc exclude_v2v
| { op_type = StringList v; op_name = name; op_discrim = discrim;
op_exclude_v2v = exclude_v2v;
op_shortdesc = shortdesc; op_pod_longdesc = longdesc } ->
pr " (\n";
pr " [ L\"%s\" ],\n" name;
pr " Getopt.String (\n";
pr " s_\"%s\",\n" v;
pr " fun s ->\n";
pr " let ss = split_string_list s in\n";
pr " List.push_front (%s ss) ops\n" discrim;
pr " ),\n";
pr " s_\"%s\"\n" shortdesc;
pr " ),\n";
pr " Some %S, %S, %b;\n" v longdesc exclude_v2v
| { op_type = TargetLinks v; op_name = name; op_discrim = discrim;
op_exclude_v2v = exclude_v2v;
op_shortdesc = shortdesc; op_pod_longdesc = longdesc } ->
pr " (\n";
pr " [ L\"%s\" ],\n" name;
pr " Getopt.String (\n";
pr " s_\"%s\",\n" v;
pr " fun s ->\n";
pr " let ss = split_links_list \"%s\" s in\n" name;
pr " List.push_front (%s ss) ops\n" discrim;
pr " ),\n";
pr " s_\"%s\"\n" shortdesc;
pr " ),\n";
pr " Some %S, %S, %b;\n" v longdesc exclude_v2v
| { op_type = PasswordSelector v; op_name = name; op_discrim = discrim;
op_exclude_v2v = exclude_v2v;
op_shortdesc = shortdesc; op_pod_longdesc = longdesc } ->
pr " (\n";
pr " [ L\"%s\" ],\n" name;
pr " Getopt.String (\n";
pr " s_\"%s\",\n" v;
pr " fun s ->\n";
pr " let sel = Password.parse_selector s in\n";
pr " List.push_front (%s sel) ops\n" discrim;
pr " ),\n";
pr " s_\"%s\"\n" shortdesc;
pr " ),\n";
pr " Some %S, %S, %b;\n" v longdesc exclude_v2v
| { op_type = UserPasswordSelector v; op_name = name; op_discrim = discrim;
op_exclude_v2v = exclude_v2v;
op_shortdesc = shortdesc; op_pod_longdesc = longdesc } ->
pr " (\n";
pr " [ L\"%s\" ],\n" name;
pr " Getopt.String (\n";
pr " s_\"%s\",\n" v;
pr " fun s ->\n";
pr " let user, sel = split_string_pair \"%s\" s in\n" name;
pr " let sel = Password.parse_selector sel in\n";
pr " List.push_front (%s (user, sel)) ops\n" discrim;
pr " ),\n";
pr " s_\"%s\"\n" shortdesc;
pr " ),\n";
pr " Some %S, %S, %b;\n" v longdesc exclude_v2v
| { op_type = SSHKeySelector v; op_name = name; op_discrim = discrim;
op_exclude_v2v = exclude_v2v;
op_shortdesc = shortdesc; op_pod_longdesc = longdesc } ->
pr " (\n";
pr " [ L\"%s\" ],\n" name;
pr " Getopt.String (\n";
pr " s_\"%s\",\n" v;
pr " fun s ->\n";
pr " let user, selstr = String.split \":\" s in\n";
pr " let sel = Ssh_key.parse_selector selstr in\n";
pr " List.push_front (%s (user, sel)) ops\n" discrim;
pr " ),\n";
pr " s_\"%s\"\n" shortdesc;
pr " ),\n";
pr " Some %S, %S, %b;\n" v longdesc exclude_v2v
| { op_type = StringFn (v, fn); op_name = name; op_discrim = discrim;
op_exclude_v2v = exclude_v2v;
op_shortdesc = shortdesc; op_pod_longdesc = longdesc } ->
pr " (\n";
pr " [ L\"%s\" ],\n" name;
pr " Getopt.String (\n";
pr " s_\"%s\",\n" v;
pr " fun s ->\n";
pr " %s s;\n" fn;
pr " List.push_front (%s s) ops\n" discrim;
pr " ),\n";
pr " s_\"%s\"\n" shortdesc;
pr " ),\n";
pr " Some %S, %S, %b;\n" v longdesc exclude_v2v
| { op_type = SMPoolSelector v; op_name = name; op_discrim = discrim;
op_exclude_v2v = exclude_v2v;
op_shortdesc = shortdesc; op_pod_longdesc = longdesc } ->
pr " (\n";
pr " [ L\"%s\" ],\n" name;
pr " Getopt.String (\n";
pr " s_\"%s\",\n" v;
pr " fun s ->\n";
pr " let sel = Subscription_manager.parse_pool_selector s in\n";
pr " List.push_front (%s sel) ops\n" discrim;
pr " ),\n";
pr " s_\"%s\"\n" shortdesc;
pr " ),\n";
pr " Some %S, %S, %b;\n" v longdesc exclude_v2v
) ops;
List.iter (
function
| { flag_type = FlagBool default; flag_ml_var = var; flag_name = name;
flag_shortdesc = shortdesc; flag_pod_longdesc = longdesc } ->
pr " (\n";
pr " [ L\"%s\" ],\n" name;
if default (* is true *) then
pr " Getopt.Clear %s,\n" var
else
pr " Getopt.Set %s,\n" var;
pr " s_\"%s\"\n" shortdesc;
pr " ),\n";
pr " None, %S, false;\n" longdesc
| { flag_type = FlagPasswordCrypto v; flag_ml_var = var;
flag_name = name; flag_shortdesc = shortdesc;
flag_pod_longdesc = longdesc } ->
pr " (\n";
pr " [ L\"%s\" ],\n" name;
pr " Getopt.String (\n";
pr " s_\"%s\",\n" v;
pr " fun s ->\n";
pr " %s := Some (Password.password_crypto_of_string s)\n" var;
pr " ),\n";
pr " s_\"%s\"\n" shortdesc;
pr " ),\n";
pr " Some %S, %S, false;\n" v longdesc
| { flag_type = FlagSMCredentials v; flag_ml_var = var;
flag_name = name; flag_shortdesc = shortdesc;
flag_pod_longdesc = longdesc } ->
pr " (\n";
pr " [ L\"%s\" ],\n" name;
pr " Getopt.String (\n";
pr " s_\"%s\",\n" v;
pr " fun s ->\n";
pr " %s := Some (Subscription_manager.parse_credentials_selector s)\n"
var;
pr " ),\n";
pr " s_\"%s\"\n" shortdesc;
pr " ),\n";
pr " Some %S, %S, false;\n" v longdesc
) flags;
pr " ]
and customize_read_from_file filename =
let forbidden_commands = [
";
List.iter (
function
| { op_type = StringFn (_, _); op_name = name; } ->
pr " \"%s\";\n" name
| { op_type = Unit; }
| { op_type = String _; }
| { op_type = StringPair _; }
| { op_type = StringTriplet _; }
| { op_type = StringList _; }
| { op_type = TargetLinks _; }
| { op_type = PasswordSelector _; }
| { op_type = UserPasswordSelector _; }
| { op_type = SSHKeySelector _; }
| { op_type = SMPoolSelector _; } -> ()
) ops;
pr " ] in
let lines = read_whole_file filename in
let lines = String.lines_split lines in
let lines = List.map String.triml lines in
let lines = List.filter (
fun line ->
String.length line > 0 && line.[0] <> '#'
) lines in
let cmds = List.map (fun line -> String.split \" \" line) lines in
(* Check for commands not allowed in files containing commands. *)
List.iter (
fun (cmd, _) ->
if List.mem cmd forbidden_commands then
error (f_\"command '%%s' cannot be used in command files, see the man page\")
cmd
) cmds;
List.iter (
fun (cmd, arg) ->
try
let ((_, spec, _), _, _, _) = List.find (
fun ((keys, _, _), _, _, _) ->
List.mem (L cmd) keys
) argspec in
(match spec with
| Getopt.Unit fn -> fn ()
| Getopt.String (_, fn) -> fn arg
| Getopt.Set varref -> varref := true
| _ -> error \"INTERNAL error: spec not handled for %%s\" cmd
)
with Not_found ->
error (f_\"command '%%s' not valid, see the man page\")
cmd
) cmds
in
(* If we're in virt-v2v, drop the excluded from virt-v2v args. *)
let argspec =
List.filter_map (
fun (keys, spec, doc, exclude_v2v) ->
if v2v && exclude_v2v then None
else Some (keys, spec, doc)
) argspec in
argspec, get_ops
"
and generate_ops_struct_decl () =
pr "\
type ops = {
ops : op list;
flags : flags;
}
";
(* Operations. *)
pr "and op = [\n";
List.iter (
function
| { op_type = Unit; op_discrim = discrim; op_name = name } ->
pr " | %s\n (* --%s *)\n" discrim name
| { op_type = String v; op_discrim = discrim; op_name = name } ->
pr " | %s of string\n (* --%s %s *)\n" discrim name v
| { op_type = StringPair v; op_discrim = discrim;
op_name = name } ->
pr " | %s of string * string\n (* --%s %s *)\n" discrim name v
| { op_type = StringTriplet v; op_discrim = discrim;
op_name = name } ->
pr " | %s of string * string * string\n (* --%s %s *)\n"
discrim name v
| { op_type = StringList v; op_discrim = discrim;
op_name = name } ->
pr " | %s of string list\n (* --%s %s *)\n" discrim name v
| { op_type = TargetLinks v; op_discrim = discrim;
op_name = name } ->
pr " | %s of string * string list\n (* --%s %s *)\n" discrim name v
| { op_type = PasswordSelector v; op_discrim = discrim;
op_name = name } ->
pr " | %s of Password.password_selector\n (* --%s %s *)\n"
discrim name v
| { op_type = UserPasswordSelector v; op_discrim = discrim;
op_name = name } ->
pr " | %s of string * Password.password_selector\n (* --%s %s *)\n"
discrim name v
| { op_type = SSHKeySelector v; op_discrim = discrim;
op_name = name } ->
pr " | %s of string * Ssh_key.ssh_key_selector\n (* --%s %s *)\n"
discrim name v
| { op_type = StringFn (v, _); op_discrim = discrim; op_name = name } ->
pr " | %s of string\n (* --%s %s *)\n" discrim name v
| { op_type = SMPoolSelector v; op_discrim = discrim;
op_name = name } ->
pr " | %s of Subscription_manager.sm_pool\n (* --%s %s *)\n"
discrim name v
) ops;
pr "]\n";
(* Flags. *)
pr "and flags = {\n";
List.iter (
function
| { flag_type = FlagBool _; flag_ml_var = var; flag_name = name } ->
pr " %s : bool;\n (* --%s *)\n" var name
| { flag_type = FlagPasswordCrypto v; flag_ml_var = var;
flag_name = name } ->
pr " %s : Password.password_crypto option;\n (* --%s %s *)\n"
var name v
| { flag_type = FlagSMCredentials v; flag_ml_var = var;
flag_name = name } ->
pr " %s : Subscription_manager.sm_credentials option;\n (* --%s %s *)\n"
var name v
) flags;
pr "}\n"
let generate_customize_synopsis_pod ?(v2v = false) () =
(* generate_header PODStyle GPLv2plus; - NOT POSSIBLE *)
let options =
List.filter_map (
function
| { op_exclude_v2v = true } when v2v -> None
| { op_type = Unit; op_name = n } ->
Some (n, sprintf "[--%s]" n)
| { op_type = String v | StringPair v | StringTriplet v | StringList v
| TargetLinks v | PasswordSelector v | UserPasswordSelector v
| SSHKeySelector v | StringFn (v, _) | SMPoolSelector v;
op_name = n } ->
Some (n, sprintf "[--%s %s]" n v)
) ops @
List.map (
function
| { flag_type = FlagBool _; flag_name = n } ->
n, sprintf "[--%s]" n
| { flag_type = FlagPasswordCrypto v; flag_name = n } ->
n, sprintf "[--%s %s]" n v
| { flag_type = FlagSMCredentials v; flag_name = n } ->
n, sprintf "[--%s %s]" n v
) flags in
(* Print the option names in the synopsis, line-wrapped. *)
let col = ref 4 in
pr " ";
List.iter (
fun (_, str) ->
let len = String.length str + 1 in
col := !col + len;
if !col >= 72 then (
col := 4 + len;
pr "\n "
);
pr " %s" str
) options;
if !col > 4 then
pr "\n"
let generate_customize_options_pod ?(v2v = false) () =
generate_header PODStyle GPLv2plus;
pr "=over 4\n\n";
let pod =
List.filter_map (
function
| { op_exclude_v2v = true } when v2v ->
None
| { op_type = Unit; op_name = n; op_pod_longdesc = ld } ->
Some (n, sprintf "B<--%s>" n, ld)
| { op_type = String v | StringPair v | StringTriplet v | StringList v
| TargetLinks v | PasswordSelector v | UserPasswordSelector v
| SSHKeySelector v | StringFn (v, _) | SMPoolSelector v;
op_name = n; op_pod_longdesc = ld } ->
Some (n, sprintf "B<--%s> %s" n v, ld)
) ops @
List.map (
function
| { flag_type = FlagBool _; flag_name = n; flag_pod_longdesc = ld } ->
n, sprintf "B<--%s>" n, ld
| { flag_type = FlagPasswordCrypto v;
flag_name = n; flag_pod_longdesc = ld } ->
n, sprintf "B<--%s> %s" n v, ld
| { flag_type = FlagSMCredentials v;
flag_name = n; flag_pod_longdesc = ld } ->
n, sprintf "B<--%s> %s" n v, ld
) flags in
let cmp (arg1, _, _) (arg2, _, _) =
compare (String.lowercase_ascii arg1) (String.lowercase_ascii arg2)
in
let pod = List.sort cmp pod in
List.iter (
fun (_, item, longdesc) ->
pr "\
=item %s
%s
" item longdesc
) pod;
pr "=back\n\n"
|