From: Richard W.M. Jones Date: Mon, 16 Mar 2015 13:46:38 +0000 (+0000) Subject: Start mclu version 2. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=7b25fd838a71991bf5b2ca5e6efeb607dfe439ea;p=mclu.git Start mclu version 2. --- diff --git a/.gitignore b/.gitignore index 19c78cf..13c72d6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ *~ -*.pyc Makefile Makefile.in @@ -8,13 +7,10 @@ Makefile.in /autom4te.cache /configure /config.log -/config.py /config.status /local* /install-sh /mclu-*.tar.gz /mclu -/mclu.spec /missing /run -/xmls/*.xml diff --git a/CONFIGURATION b/CONFIGURATION deleted file mode 100644 index 90aa19c..0000000 --- a/CONFIGURATION +++ /dev/null @@ -1,113 +0,0 @@ -Configuring mclu ----------------- - -Introduction ------------- - -mclu is based around the idea that you have a small collection of -fairly similar "nodes". Ideally they would be identical nodes, if you -want live migration to work seamlessly, but they don't have to be. - -Here is a picture of the cluster that I run mclu on: -http://rwmj.wordpress.com/2014/04/28/caseless-virtualization-cluster-part-5/#content - -Nodes, control node, NFS server -------------------------------- - -There is also one "control" node, which could be your laptop or could -be one of the cluster nodes. This is where you run the 'mclu' -command, and also where the single configuration file is located -(mclu.conf, usually located in /etc/mclu). - -Each node must be accessible from the control node over ssh. Each -node must be running the libvirt daemon (libvirtd). - -mclu uses a mix of ssh commands and remote libvirt to manage the -nodes. You should configure ssh so it can access the nodes without -needing passwords (eg. using ssh-agent). If you use the default -libvirt URI (see config file) then you also need to set up -passwordless root ssh access to the nodes; there are other ways to -configure this, eg. opening the libvirtd port on each node, but they -are probably not as secure. - -Each node, including the control node, must have access to shared -storage where the guest disk images are stored. The easiest way to do -this is to export /var/lib/libvirt/images from one machine and -NFS-mount it on all the nodes (and also to have a nice fast network). -Cluster filesystems are another possibility. mclu does NOT support -non-shared storage nor storage migration. - -Wake-on-LAN ------------ - -The nodes can be up or down. mclu deals transparently with nodes -being switched off. If you configure wake-on-LAN (usually a BIOS -setting) then mclu will be able to wake up nodes. - -Running guests --------------- - -The guest libvirt XML files are also stored on the control node -(usually /etc/mclu/xmls). Guests are created as transient, which -means the libvirt daemon running on each node does not have a -persistent configuration of any guest. - -Guests run on a single node at a time. You can list/start/stop/ -migrate them using mclu. The requirement for a guest to be running on -a single node may be enforced if you run libvirt sanlock or virtlockd. -This requires further configuration, see: -http://libvirt.org/locking.html -https://rwmj.wordpress.com/2014/05/08/setting-up-virtlockd-on-nfs/#content - -If sanlock/virtlockd is not running then mclu will try its best not to -have the guest running in two places at once (if it happens, this will -cause permanent disk corruption in the guest). - -Migration ---------- - -For guest live migration to work transparently, you will probably want -to configure libvirt bridged networking and open firewall ports -49152-49215 on every node. - -Bridged networking means that each guest appears as a local machine on -your network, and if it migrates then network connections will not be -interrupted. See: -http://wiki.libvirt.org/page/Networking#Bridged_networking_.28aka_.22shared_physical_device.22.29 - -The firewall ports have to be opened because libvirt cannot (yet?) do -fully managed migration over two SSH connections (even though the -documentation says it can). Hopefully they will fix this soon. - -Editing guest configuration or disk images ------------------------------------------- - -The guest configuration (libvirt XML) is stored in the xmls directory -(usually /etc/mclu/xmls). You can edit this file directly if you want. -Changes will not take effect until the guest is restarted. - -The guest disk images are located in the images directory (usually -/var/lib/libvirt/images). You can use libguestfs against these in -read-only mode (or read-write mode PROVIDED the guest is not running). - -You can also create or import guests by dropping an XML file and an -image into those directories. (But it might be easier to use the -'mclu build' and 'mclu import' subcommands). - -SELinux -------- - -I have SELinux enabled on all nodes of my cluster. However it wasn't -easy to get this far. In particular you need to enable one or -probably both of these booleans: - - setsebool -P virt_use_nfs on - setsebool -P use_nfs_home_dirs on - -Other tips ----------- - -Install ntp on all the nodes so that the date is kept in synch. - -Install lm_sensors on all nodes so you can monitor temperature, fan -speed and so on. diff --git a/COPYING b/COPYING deleted file mode 100644 index d159169..0000000 --- a/COPYING +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - 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. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index e5fd98f..0000000 --- a/Makefile.am +++ /dev/null @@ -1,66 +0,0 @@ -# mclu (mini cluster) -# 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. - -ACLOCAL_AMFLAGS = -I m4 - -# Why doesn't automake include _SCRIPTS and _DATA ...? -EXTRA_DIST = CONFIGURATION mclu.spec $(pkgdata_SCRIPTS) $(conf_DATA) - -# This rule just ensures that the wrapper binary and Python files get -# installed when we do 'make install'. - -bin_SCRIPTS = mclu - -pkgdata_SCRIPTS = \ - config.py \ - lib.py \ - libvirt_xml.py \ - mclu.py \ - mclu_build.py \ - mclu_console.py \ - mclu_import.py \ - mclu_info.py \ - mclu_list.py \ - mclu_migrate.py \ - mclu_off.py \ - mclu_on.py \ - mclu_reboot.py \ - mclu_start.py \ - mclu_status.py \ - mclu_stop.py \ - mclu_viewer.py \ - node.py - -# Configuration file. - -confdir = $(sysconfdir)/$(PACKAGE_NAME) -conf_DATA = mclu.conf - -install-data-hook: - mkdir -p $(DESTDIR)/$(sysconfdir)/$(PACKAGE_NAME)/xmls - -CLEANFILES = \ - *~ \ - *.pyc \ - config.py \ - mclu \ - mclu.spec - -# Run pylint. - -lint: - pylint -E $(pkgdata_SCRIPTS) diff --git a/README b/README deleted file mode 100644 index 8e958f4..0000000 --- a/README +++ /dev/null @@ -1,99 +0,0 @@ -mclu (mini cluster) is a virtualization cluster manager. - -The key features: - - - Entirely command line driven. - - - No required dependencies except ansible (on the client only), - libvirt and ssh. - - - Nothing to install on the nodes except libvirtd and sshd. - - - Only designed for small clusters (up to around 10-20 hosts). - - - Simple configuration. - -Example commands ----------------------------------------------------------------------- - - mclu status Display status of the cluster - mclu list List all virtual machines on the cluster - mclu on ham0 Switch on (wake-on-LAN) node 'ham0' - mclu off ham0 Power off node 'ham0' in the cluster - mclu start ham0:vm Start vm on node 'ham0' - mclu stop ham0:* Stop all VMs on node 'ham0' - mclu migrate *:* ham2: Live migrate all VMs to 'ham2' - mclu build ham3:vm fedora-20 Build and run a new Fedora 20 VM on node 'ham3' - mclu console ham3:fedora-20 Show me the serial console of a VM - mclu viewer ham3:fedora-20 Show me the graphical console of a VM - mclu info Print general configuration information - mclu --help Print help on all commands - -Since the mclu cluster is based on an ansible "hosts group", you can -also issue ansible commands, eg: - - ansible cluster -u root -a "yum -y update" Update all nodes in the cluster - ansible cluster -m ping Ping all nodes - -Configuration notes ----------------------------------------------------------------------- - -See `CONFIGURATION'. - -Dependencies ----------------------------------------------------------------------- - -To get a full list of the required and optional dependencies, look at: - - - configure.ac - - mclu.spec.in - -Building it ----------------------------------------------------------------------- - -If building straight from git, then do: - - autoreconf -i - -To build: - - ./configure --prefix /usr --sysconfdir /etc - make - -To run without installing: - - - Edit the configuration file (mclu.conf). - - - Add the hosts group (usually called '[cluster]') to /etc/ansible/hosts. - You can set $ANSIBLE_HOSTS to change the location of this file. - - - Run commands such as: - - ./run status - ./run list - -To install: - - - sudo make install - - - Edit the configuration file (/etc/mclu/mclu.conf). - - - Add the hosts group (usually called '[cluster]') to /etc/ansible/hosts. - - - Run commands such as: - - mclu status - mclu list - -Developer information ----------------------------------------------------------------------- - -The license is GPLv2+. - -The git repo is: - - http://git.annexia.org/?p=mclu.git;a=summary - -There is no mclu mailing list. Send patches to the virt-tools mailing list: - - http://www.redhat.com/mailman/listinfo/virt-tools-list diff --git a/config.py.in b/config.py.in deleted file mode 100644 index d340d32..0000000 --- a/config.py.in +++ /dev/null @@ -1,30 +0,0 @@ -# mclu (mini cluster) -# @configure_input@ -# 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. - -PACKAGE_NAME="@PACKAGE_NAME@" -PACKAGE_VERSION="@PACKAGE_VERSION@" - -prefix="@prefix@" -sysconfdir="@sysconfdir@" -# Avoid stupid crap with datarootdir: -pkgdatadir="@prefix@/share/@PACKAGE_NAME@" - -SSH="@SSH@" -WOL="@WOL@" -VIRT_BUILDER="@VIRT_BUILDER@" -VIRT_VIEWER="@VIRT_VIEWER@" diff --git a/configure.ac b/configure.ac deleted file mode 100644 index de668bc..0000000 --- a/configure.ac +++ /dev/null @@ -1,62 +0,0 @@ -# mclu (mini cluster) -# 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. - -AC_INIT([mclu],1.0) -AM_INIT_AUTOMAKE([foreign]) -AC_CONFIG_MACRO_DIR([m4]) - -dnl Python 2.x (required). -AC_PATH_PROG([PYTHON],[python]) -if test "x$PYTHON" = "xno"; then - AC_MSG_ERROR([Python 2.x is required]) -fi - -AC_MSG_CHECKING([Python version]) -PYTHON_VERSION_MAJOR=`$PYTHON -c "import sys; print (sys.version_info@<:@0@:>@)"` -PYTHON_VERSION_MINOR=`$PYTHON -c "import sys; print (sys.version_info@<:@1@:>@)"` -AC_MSG_RESULT([$PYTHON_VERSION_MAJOR.$PYTHON_VERSION_MINOR]) - -if test $PYTHON_VERSION_MAJOR -ne 2; then - AC_MSG_ERROR([Python version 2 is required, found $PYTHON_VERSION_MAJOR]) -fi - -dnl SSH client (required). -AC_PATH_PROG([SSH],[ssh],[no]) -if test "x$SSH" = "xno"; then - AC_MSG_ERROR([SSH client is required]) -fi - -dnl Ansible client (required). -dnl Actually the ansible command line tool is not used, but we do use -dnl the Python library. XXX Should check for that instead. -AC_PATH_PROG([ANSIBLE],[ansible],[no]) -if test "x$ANSIBLE" = "xno"; then - AC_MSG_ERROR([ansible is required]) -fi - -dnl Wake-on-LAN client (optional). -AC_PATH_PROG([WOL],[wol],[no]) - -dnl virt-builder (optional). -AC_PATH_PROG([VIRT_BUILDER],[virt-builder],[no]) - -dnl virt-viewer (optional). -AC_PATH_PROG([VIRT_VIEWER],[virt-viewer],[no]) - -AC_CONFIG_FILES([run], [chmod +x,-w run]) -AC_CONFIG_FILES([Makefile config.py mclu mclu.spec]) -AC_OUTPUT diff --git a/lib.py b/lib.py deleted file mode 100644 index 1430f14..0000000 --- a/lib.py +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/python -# mclu (mini cluster) -# 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. - -import sys -import os -import re - -import libvirt -import ansible.runner -import ansible.inventory - -# Get separate list of running and inactive guests. -def get_all_guests (c): - running = {} - inactive = {} - - # Find running guests. - runner = ansible.runner.Runner ( - remote_user = 'root', - module_name = 'virt', - module_args = 'command=list_vms', # XXX ignore state=shutdown - pattern = c['nodes_group'], - ) - data = runner.run () - - for node in data['contacted'].keys(): - # Get the flat list of guests from this node: - vms = data['contacted'][node]['list_vms'] - # Store which node the guest is running on, and turn list into a map. - for vm in vms: - if node in running: - sys.exit ("error: virtual machine %s is running on two nodes!" % node) - running[vm] = { 'vm' : vm, 'node' : node } - - # Find inactive guests (XML configuration files). - for name in get_guest_configs (c): - if name not in running: - inactive[name] = name - - return running, inactive - -# Get the names of guests from the XML configuration files in xmls_dir. -def get_guest_configs (c): - names = [] - for filename in sorted (os.listdir (c['xmls_dir'])): - m = re.search (r'^(.*)\.xml$', filename) - if m: - names.append (m.group (1)) - return names - -# Start a guest running on a given node. The node must not be -# running anywhere already. -def start_guest (c, node_name, guest_name): - fp = open ("%s/%s.xml" % (c['xmls_dir'], guest_name), "r") - xml = fp.read () - fp.close () - - conn = libvirt.open (uri_of_node (node_name)) - if conn == None: - sys.exit ("error: could not open a libvirt connection to %s" % - node_name) - conn.createXML (xml) - -def pick_any_node_which_is_up (c): - inventory = ansible.inventory.Inventory () - runner = ansible.runner.Runner ( - remote_user = 'root', - module_name = 'ping', - inventory = inventory, - pattern = c['nodes_group'], - ) - data = runner.run () - if len (data['contacted']) == 0: - sys.exit ("error: no nodes are up, use mclu on") - return data['contacted'].keys()[0] - -# XXX Make this configurable. -def uri_of_node (node_name): - return "qemu+ssh://root@%s/system" % node_name diff --git a/libvirt_xml.py b/libvirt_xml.py deleted file mode 100644 index ceb5ab7..0000000 --- a/libvirt_xml.py +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/python -# mclu (mini cluster) -# 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. - -import os -import random -import sys - -# Generate libvirt XML. Would be nice to use virt-install here, but -# it doesn't work: RHBZ#1095789 -def generate_libvirt_xml (vm_name, memory, vcpus, virtio, output): - network_model = "virtio" - if not virtio: - network_model = "e1000" - - # Give the network a fixed MAC address, otherwise libvirt will - # generate a random one on every guest restart. - network_mac = "52:54:00:%02x:%02x:%02x" % (random.randint (0, 0xff), - random.randint (0, 0xff), - random.randint (0, 0xff)) - - # XXX Quoting, and we should use a real XML generator. - xml = """ - - %s - %d - %d - %d - - hvm - - - - - - - - - - - - - - destroy - restart - restart - - - - - - - - - - - - - - -""" % (vm_name, memory, memory, vcpus, network_mac, network_model) - - # virtio-scsi or IDE disk: - if virtio: - xml += """ - - - - - - -""" % output - else: - xml += """ - - - - - -""" % output - - xml += """ - - -""" - - return xml diff --git a/m4/.exists b/m4/.exists deleted file mode 100644 index e69de29..0000000 diff --git a/mclu.conf b/mclu.conf deleted file mode 100644 index 300b79e..0000000 --- a/mclu.conf +++ /dev/null @@ -1,43 +0,0 @@ -# mclu (mini cluster) configuration file. -# -# This file is parsed by Python's ConfigParser. -# -# This is the real configuration file I use to control my -# virtualization cluster. For a picture of it see: -# http://rwmj.wordpress.com/2014/04/28/caseless-virtualization-cluster-part-5/#content - -# Some defaults are provided: -# %(home)s expands to $HOME -# %(config_dir)s expands to the directory containing mclu.conf -# Note that in the Python '%(...)s' syntax, 's' means 'string'. It is -# not part of the expanded output. - -# The global section has general configuration. -[global] - -# The location of guest disk images. This location MUST be shared -# between all nodes including the machine running mclu (eg. using NFS -# or some sort of clustered storage). -images_dir = /var/lib/libvirt/images - -# The location of libvirt XML configuration files for guests. -# -# Note: This does NOT need to be shared or even visible on the cluster -# nodes. But it must be available on the machine running 'mclu'. -xmls_dir = %(config_dir)s/xmls/ - -# The name of the ansible group which contains the list of nodes -# in the cluster. You have to edit /etc/ansible/hosts and add a -# section: -# -# [cluster] -# ham0 mac=74:d4:35:55:85:3f -# ham1 mac=74:d4:35:51:ab:86 -# ham2 mac=74:d4:35:55:82:96 -# ham3 mac=74:d4:35:55:84:b4 -# -# The mac=... (MAC addresses) are optional, to support wake-on-LAN. -# -# If you don't want to edit /etc/ansible/hosts then you can export -# $ANSIBLE_HOSTS to name another file instead. -nodes_group = cluster diff --git a/mclu.in b/mclu.in deleted file mode 100644 index 10376db..0000000 --- a/mclu.in +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - -# mclu (mini cluster) -# @configure_input@ -# 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. - -pkgdatadir="@prefix@/share/@PACKAGE_NAME@" - -if [ ! -x "$pkgdatadir/mclu.py" ]; then - echo "mclu: wrapper script cannot find installed mclu.py" - echo "Did you forget to run 'make install'?" - echo "OR if you want to run without installing, use:" - echo " ./run [args...]" - exit 1 -fi -"$pkgdatadir/mclu.py" "$@" diff --git a/mclu.py b/mclu.py deleted file mode 100755 index 0a439ec..0000000 --- a/mclu.py +++ /dev/null @@ -1,109 +0,0 @@ -#!/usr/bin/python -# mclu (mini cluster) -# 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. - -import argparse -import ConfigParser -import os -import re -import sys - -import config -import mclu_build -import mclu_console -import mclu_import -import mclu_info -import mclu_list -import mclu_migrate -import mclu_off -import mclu_on -import mclu_reboot -import mclu_start -import mclu_status -import mclu_stop -import mclu_viewer - -parser = argparse.ArgumentParser ( - prog='mclu', - description='Mini virtualization cluster management tool', -) -parser.add_argument ( - '-f', - type=file, - help='specify location of the configuration file', - metavar='MCLU.CONF', -) - -# Add subcommands. -subparsers = parser.add_subparsers () -mclu_build.cmdline (subparsers) -mclu_console.cmdline (subparsers) -mclu_import.cmdline (subparsers) -mclu_info.cmdline (subparsers) -mclu_list.cmdline (subparsers) -mclu_migrate.cmdline (subparsers) -mclu_off.cmdline (subparsers) -mclu_on.cmdline (subparsers) -mclu_reboot.cmdline (subparsers) -mclu_start.cmdline (subparsers) -mclu_status.cmdline (subparsers) -mclu_stop.cmdline (subparsers) -mclu_viewer.cmdline (subparsers) - -args = parser.parse_args() - -# Default location of the config file if not defined on the command line: -if not args.f: - config_dir = config.sysconfdir + "/" + config.PACKAGE_NAME - args.f = open (config_dir + "/" + "mclu.conf") -else: - # config_dir is the directory containing mclu.conf - config_dir = os.path.dirname (args.f.name) - -# Configuration file default settings. You cannot set defaults per -# section, so we have to rely on setting names not overlapping. -conf_defaults = { - "home" : os.getenv ("HOME"), - "config_dir" : config_dir, -} - -# Read the configuration file. -conf = ConfigParser.SafeConfigParser (conf_defaults) -conf.readfp (args.f) - -# Global configuration. -images_dir = conf.get ("global", "images_dir") -if not os.path.isdir (images_dir): - sys.exit ("configuration error: [globals] 'images_dir' (%s) directory does not exist" % images_dir) -xmls_dir = conf.get ("global", "xmls_dir") -if not os.path.isdir (xmls_dir): - sys.exit ("configuration error: [globals] 'xmls_dir' (%s) directory does not exist", xmls_dir) -nodes_group = conf.get ("global", "nodes_group") - -# A config dict with less-used configuration settings. -c = { - "config_file" : args.f.name, - "config_dir" : config_dir, - "images_dir" : images_dir, - "nodes_group" : nodes_group, - "xmls_dir" : xmls_dir, - - "conf" : conf, -} - -# Run the subcommand. -args.run (c, args) diff --git a/mclu.spec.in b/mclu.spec.in deleted file mode 100644 index 244658b..0000000 --- a/mclu.spec.in +++ /dev/null @@ -1,58 +0,0 @@ -Name: @PACKAGE_NAME@ -Version: @PACKAGE_VERSION@ -Release: 1%{?dist} -Summary: Mini cluster, a virtualization cluster manager - -BuildArch: noarch - -License: GPLv2+ -URL: http://git.annexia.org/?p=mclu.git;a=summary -Source0: @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz - -BuildRequires: python-devel -BuildRequires: libvirt-python -BuildRequires: /usr/bin/ssh -BuildRequires: ansible - -Requires: libvirt-python -Requires: /usr/bin/ssh -Requires: ansible - -# These are optional: comment them out to get a less functional mclu. -BuildRequires: /usr/bin/wol -BuildRequires: /usr/bin/virt-builder -BuildRequires: /usr/bin/virt-viewer -Requires: /usr/bin/wol -Requires: /usr/bin/virt-builder -Requires: /usr/bin/virt-viewer - - -%description -mclu (mini cluster) is a virtualization cluster manager. - - -%prep -%setup -q - - -%build -%configure -make %{?_smp_mflags} - - -%install -make DESTDIR=$RPM_BUILD_ROOT install - - -%files -%doc CONFIGURATION COPYING README -%dir %{_sysconfdir}/mclu/ -%dir %{_sysconfdir}/mclu/xmls/ -%config(noreplace) %{_sysconfdir}/mclu/mclu.conf -%{_bindir}/mclu -%{_datadir}/%{name}/ - - -%changelog -* Thu May 8 2014 Richard W.M. Jones - @PACKAGE_VERSION@-1 -- Initial release. diff --git a/mclu_build.py b/mclu_build.py deleted file mode 100644 index a7de55c..0000000 --- a/mclu_build.py +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/python -# mclu (mini cluster) -# 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. - -import argparse -import os -import re -import subprocess -import sys -import libvirt - -import config -import lib -import libvirt_xml - -def cmdline (subparsers): - p = subparsers.add_parser ( - 'build', - help='build and run a new virtual machine', - ) - p.add_argument ( - '--memory', default=1024, type=int, - help='RAM to give to guest (default unit is megabytes)' - ) - p.add_argument ( - '--vcpus', default=4, type=int, - help='virtual CPUs to give to guest' - ) - p.add_argument ( - '--virtio', action='store_const', const=True, - help='use virtio disks and network' - ) - p.add_argument ( - '--no-start', action='store_const', const=True, - help='do not start the guest after building' - ) - p.add_argument ( - '--size', required=True, - help='size of disk' - ) - p.add_argument ( - 'name', - help='name of the new VM (or use "vm:name")' - ) - p.add_argument ( - 'os_version', - help='OS & version of guest (see virt-builder docs)' - ) - p.add_argument ( - 'vbargs', nargs='*', - help='virt-builder arguments (after "--")' - ) - p.set_defaults (run=run) - -def run (c, args): - # Did the user request a particular node? If not, we'll run it - # on any node which is up. - m = re.match (r'^(.*):(.*)$', args.name) - if m: - node_name = m.group (1) - vm_name = m.group (2) - else: - node_name = lib.pick_any_node_which_is_up (c) - vm_name = args.name - - # Get all the guests, so we can tell if the name is a duplicate. - running, inactive = lib.get_all_guests (c) - - if vm_name in running or vm_name in inactive: - sys.exit ("error: VM name (%s) already exists" % vm_name) - - output = '%s/%s.img' % (c['images_dir'], vm_name) - - # Call out to virt-builder to build the disk image. - vbargs = [ - config.VIRT_BUILDER, - args.os_version, - '--output', output, - '--format', 'qcow2', - ] - if args.size: - vbargs.extend (['--size', args.size]) - if args.vbargs: - vbargs.extend (args.vbargs) - subprocess.check_call (vbargs) - - # XXX Unfortunately this is necessary so qemu can access the disk. - os.chmod (output, 0666) - - # Generate the XML. Would be nice to use virt-install here, but - # it doesn't work: RHBZ#1095789 - xml = libvirt_xml.generate_libvirt_xml (vm_name, - args.memory, - args.vcpus, - args.virtio, - output) - - # Write the XML to the xmls_dir. - fp = open ("%s/%s.xml" % (c['xmls_dir'], vm_name), "w") - fp.write (xml) - fp.close () - - if not args.no_start: - # Start the guest. - lib.start_guest (c, node_name, vm_name) - print "guest started on node %s" % node_name diff --git a/mclu_console.py b/mclu_console.py deleted file mode 100644 index b4299cd..0000000 --- a/mclu_console.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/python -# mclu (mini cluster) -# 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. - -import argparse -import re -import sys -import subprocess - -import lib - -def cmdline (subparsers): - p = subparsers.add_parser ( - 'console', - help='connect to console of named VM', - ) - p.add_argument ( - 'vm', - help='vm (or node:vm) to connect to' - ) - p.set_defaults (run=run) - -def run (c, args): - running, _ = lib.get_all_guests (c) - - m = re.match (r'^(.*):(.*)$', args.vm) - if m: - # We don't actually care about the node, but we check it - # is the expected one below. - node_name_check = m.group (1) - vm_name = m.group (2) - else: - node_name_check = None - vm_name = args.vm - - if vm_name not in running: - sys.exit ("error: vm %s not found or not running" % vm_name) - - vm = running[vm_name]['vm'] - node_name = running[vm_name]['node'] - - if node_name_check and node_name != node_name_check: - sys.exit ("error: vm %s is not running on node %s, did you mean %s:%s ?" % - (vm_name, node_name_check, node_name, vm_name)) - - # Run the virsh console command. - subprocess.call (["virsh", - "-c", lib.uri_of_node (node_name), - "console", - vm_name]) diff --git a/mclu_import.py b/mclu_import.py deleted file mode 100644 index 7a019ba..0000000 --- a/mclu_import.py +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/python -# mclu (mini cluster) -# 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. - -import argparse -import os -import re -import sys -import subprocess - -import config -import lib -import libvirt_xml - -def cmdline (subparsers): - p = subparsers.add_parser ( - 'import', - help='import and existing virtual machine', - ) - p.add_argument ( - '--memory', default=1024, type=int, - help='RAM to give to guest (default unit is megabytes)' - ) - p.add_argument ( - '--vcpus', default=4, type=int, - help='virtual CPUs to give to guest' - ) - p.add_argument ( - '--virtio', action='store_const', const=True, - help='use virtio disks and network' - ) - p.add_argument ( - '--no-start', action='store_const', const=True, - help='do not start the guest after importing' - ) - p.add_argument ( - 'name', - help='name of the new VM (or use "vm:name")' - ) - p.add_argument ( - 'disk', - help='disk image to import' - ) - p.set_defaults (run=run) - -def run (c, args): - # Did the user request a particular node? If not, we'll run it - # on any node which is up. - m = re.match (r'^(.*):(.*)$', args.name) - if m: - node_name = m.group (1) - vm_name = m.group (2) - else: - node_name = lib.pick_any_node_which_is_up (c) - vm_name = args.name - - # Get all the guests, so we can tell if the name is a duplicate. - running, inactive = lib.get_all_guests (c) - - if vm_name in running or vm_name in inactive: - sys.exit ("error: VM name (%s) already exists" % vm_name) - - output = '%s/%s.img' % (c['images_dir'], vm_name) - - # Use qemu-img to convert the input format (whatever it is) to qcow2, - # and also to copy it. - subprocess.check_call ([ - "qemu-img", - "convert", - args.disk, - "-O", "qcow2", - output - ]) - - # XXX Unfortunately this is necessary so qemu can access the disk. - os.chmod (output, 0666) - - # Generate the XML. Would be nice to use virt-install here, but - # it doesn't work: RHBZ#1095789 - xml = libvirt_xml.generate_libvirt_xml (vm_name, - args.memory, - args.vcpus, - args.virtio, - output) - - # Write the XML to the xmls_dir. - fp = open ("%s/%s.xml" % (c['xmls_dir'], vm_name), "w") - fp.write (xml) - fp.close () - - if not args.no_start: - # Start the guest. - lib.start_guest (c, node_name, vm_name) - print "guest started on node %s" % node_name diff --git a/mclu_info.py b/mclu_info.py deleted file mode 100644 index b800e5b..0000000 --- a/mclu_info.py +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/python -# mclu (mini cluster) -# 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. - -import argparse - -def cmdline (subparsers): - p = subparsers.add_parser ( - 'info', - help='print general configuration information', - ) - p.set_defaults (run=run) - -def run (c, args, nodes): - print "config_dir=%s" % c['config_dir'] - print "config_file=%s" % c['config_file'] - print "images_dir=%s" % c['images_dir'] - print "node_names=%s" % c['node_names'] - print "xmls_dir=%s" % c['xmls_dir'] diff --git a/mclu_list.py b/mclu_list.py deleted file mode 100644 index ace59a4..0000000 --- a/mclu_list.py +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/python -# mclu (mini cluster) -# 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. - -import argparse -import libvirt - -import lib - -def cmdline (subparsers): - p = subparsers.add_parser ( - 'list', - help='list virtual machines', - ) - p.add_argument ( - '--running', action='store_const', const=True, - help='list only running VMs' - ) - p.add_argument ( - '--inactive', action='store_const', const=True, - help='list only inactive VMs' - ) - p.set_defaults (run=run) - -def run (c, args): - show_running = True - show_inactive = True - if not args.running or not args.inactive: - if args.running: - show_running = True - show_inactive = False - if args.inactive: - show_running = False - show_inactive = True - - running, inactive = lib.get_all_guests (c) - - if show_running: - for guest in sorted (running.values()): - node_name = guest['node'] - dom_name = guest['vm'] - full_name = "%s:%s" % (node_name, dom_name) - print "%-40s running" % full_name - - if show_inactive: - for name in sorted (inactive.values()): - print "%-40s inactive" % name diff --git a/mclu_migrate.py b/mclu_migrate.py deleted file mode 100644 index 36ba398..0000000 --- a/mclu_migrate.py +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/python -# mclu (mini cluster) -# 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. - -import argparse -import fnmatch -import re -import sys -import libvirt - -import lib - -def cmdline (subparsers): - p = subparsers.add_parser ( - 'migrate', - help='live migrate virtual machine(s)', - ) - p.add_argument ( - 'wildcards', nargs='+', - help='virtual machine(s) to be migrated' - ) - p.add_argument ( - 'dest', - help='destination node' - ) - p.set_defaults (run=run) - -def run (c, args): - running, _ = lib.get_all_guests (c) - - # Identify the VMs to be migrated. - migrate_vms = [] - for vm in running.values(): - node_name = vm['node'] - vm_name = vm['vm'] - # Form the name of this VM (eg. "ham0:vm") so we can match it - # against the wildcards (eg. "ham0:*") - name = node_name + ":" + vm_name - for wc in args.wildcards: - if fnmatch.fnmatch (name, wc) or fnmatch.fnmatch (vm_name, wc): - migrate_vms.append (vm) - - if not migrate_vms: - sys.exit ("error: no VMs are going to be migrated") - - # Get destination node. It can be written either 'dest' or 'dest:' - m = re.match (r'(.*):$', args.dest) - if m: - dest = m.group (1) - else: - dest = args.dest - - dconn = libvirt.open (lib.uri_of_node (dest)) - if dconn == None: - sys.exit ("error: could not open a libvirt connection to %s" % dest) - - for vm in migrate_vms: - sconn = libvirt.open (lib.uri_of_node (vm['node'])) - if sconn == None: - sys.exit ("error: could not open a libvirt connection to %s" % - vm['node']) - dom = sconn.lookupByName (vm['vm']) - dom.migrate (dconn, libvirt.VIR_MIGRATE_LIVE) diff --git a/mclu_off.py b/mclu_off.py deleted file mode 100644 index 3851545..0000000 --- a/mclu_off.py +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/python -# mclu (mini cluster) -# 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. - -import argparse -import os -import subprocess -import sys -import time - -import ansible.inventory -import ansible.runner - -import lib - -def cmdline (subparsers): - p = subparsers.add_parser ( - 'off', - help='power off a node (or nodes)' - ) - p.add_argument ( - 'wildcard', - help='node name(s) to be powered off (wildcard may be used)' - ) - p.set_defaults (run=run) - -def run (c, args): - inventory = ansible.inventory.Inventory () - inventory.subset (subset_pattern = args.wildcard) - nodes = inventory.get_hosts (c['nodes_group']) - - # Check the nodes have no guests. - running, _ = lib.get_all_guests (c) - for node in nodes: - for vm in running.values(): - if vm['node'] == node.name: - sys.exit ("error: node %s has running guests, migrate them off or stop them first" % node.name) - - # Power them off. - runner = ansible.runner.Runner ( - remote_user = 'root', - module_name = 'command', - module_args = '/sbin/poweroff', - inventory = inventory, - pattern = c['nodes_group'], - ) - data = runner.run () - - # Wait for them to power off. - pings = 60 - runner = ansible.runner.Runner ( - remote_user = 'root', - module_name = 'ping', - inventory = inventory, - pattern = c['nodes_group'], - ) - while pings > 0: - data = runner.run () - if len (data['contacted']) == 0: - break - pings -= 1 - time.sleep (1) - - if pings == 0: - sys.exit ('warning: some nodes did not power off') diff --git a/mclu_on.py b/mclu_on.py deleted file mode 100644 index 7183f93..0000000 --- a/mclu_on.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/python -# mclu (mini cluster) -# 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. - -import argparse -import os -import sys -import time -import subprocess - -import ansible.inventory -import ansible.runner - -import config -import lib - -def cmdline (subparsers): - p = subparsers.add_parser ( - 'on', - help='power on a node (or nodes)' - ) - p.add_argument ( - 'wildcard', - help='node name(s) to be woken up (wildcard may be used)' - ) - p.set_defaults (run=run) - -def run (c, args): - inventory = ansible.inventory.Inventory () - inventory.subset (subset_pattern = args.wildcard) - nodes = inventory.get_hosts (c['nodes_group']) - - # Wake them up. - for node in nodes: - vars = node.get_variables() - if 'mac' in vars: - devnull = open (os.devnull, "w") - subprocess.check_call ([config.WOL, vars['mac']], - stdout = devnull, stderr = devnull) - else: - print "warning: no mac= line in ansible hosts file for %s (ignored)" % node.name - - # Wait for them to come up. - pings = 30 - runner = ansible.runner.Runner ( - remote_user = 'root', - module_name = 'ping', - inventory = inventory, - pattern = c['nodes_group'], - ) - while pings > 0: - data = runner.run () - if len (data['dark']) == 0: - break - pings -= 1 - time.sleep (1) - - if pings == 0: - sys.exit ('warning: some nodes did not wake up') diff --git a/mclu_reboot.py b/mclu_reboot.py deleted file mode 100644 index 07917d1..0000000 --- a/mclu_reboot.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/python -# mclu (mini cluster) -# 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. - -import argparse -import fnmatch -import subprocess - -import libvirt - -import lib - -def cmdline (subparsers): - p = subparsers.add_parser ( - 'reboot', - help='reboot virtual machine(s)', - ) - p.add_argument ( - '--force', action='store_const', const=True, - help='reset the virtual machine(s) forcibly' - ) - p.add_argument ( - 'wildcards', nargs='+', - help='virtual machine(s) to be rebooted' - ) - p.set_defaults (run=run) - -def run (c, args): - running, _ = lib.get_all_guests (c) - - for vm in running.values(): - node_name = vm['node'] - vm_name = vm['vm'] - # Form the name of this VM (eg. "ham0:vm") so we can match it - # against the wildcards (eg. "ham0:*") - name = node_name + ":" + vm_name - for wc in args.wildcards: - if fnmatch.fnmatch (name, wc) or fnmatch.fnmatch (vm_name, wc): - if args.force: - subprocess.check_call (["virsh", - "-c", lib.uri_of_node (node_name), - "reset", vm_name]) - else: - subprocess.check_call (["virsh", - "-c", lib.uri_of_node (node_name), - "reboot", vm_name]) diff --git a/mclu_start.py b/mclu_start.py deleted file mode 100644 index 01a2f1a..0000000 --- a/mclu_start.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/python -# mclu (mini cluster) -# 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. - -import argparse -import fnmatch -import re -import subprocess -import sys -import libvirt - -import config -import lib - -def cmdline (subparsers): - p = subparsers.add_parser ( - 'start', - help='start virtual machine(s)', - ) - p.add_argument ( - '--viewer', action='store_const', const=True, - help='start virt-viewer to show the graphical console' - ) - p.add_argument ( - 'vms', nargs='+', - help='virtual machine(s) to be started' - ) - p.set_defaults (run=run) - -def run (c, args): - _, inactive = lib.get_all_guests (c) - - # User supplied a list of node:VMs. - for a in args.vms: - m = re.match (r'^(.*):(.*)$', a) - if m: - node_name = m.group (1) - wc = m.group (2) - else: - wc = a - node_name = lib.pick_any_node_which_is_up (c) - started = [] - for vm_name in inactive: - if fnmatch.fnmatch (vm_name, wc): - if args.viewer: - subprocess.Popen ([config.VIRT_VIEWER, - "-c", lib.uri_of_node (node_name), - vm_name], - close_fds=True) - lib.start_guest (c, node_name, vm_name) - started.append (vm_name) - - if not started: - sys.exit ("error: no VMs matched pattern %s" % a) - - # Make sure we don't start the same VMs again the next - # time around the loop: - for vm_name in started: - del inactive[vm_name] diff --git a/mclu_status.py b/mclu_status.py deleted file mode 100644 index add55ab..0000000 --- a/mclu_status.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/python -# mclu (mini cluster) -# 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. - -import argparse - -import ansible.runner - -import lib - -def cmdline (subparsers): - p = subparsers.add_parser ( - 'status', - help='display cluster status' - ) - p.set_defaults (run=run) - -def run (c, args): - runner = ansible.runner.Runner ( - remote_user = 'root', - module_name = 'ping', - pattern = c['nodes_group'], - ) - data = runner.run () - for name in sorted (data['contacted']): - print "%s\tup" % name - for name in sorted (data['dark']): - print "%s\tdown" % name diff --git a/mclu_stop.py b/mclu_stop.py deleted file mode 100644 index 883b67a..0000000 --- a/mclu_stop.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/python -# mclu (mini cluster) -# 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. - -import argparse -import fnmatch -import subprocess - -import libvirt - -import lib - -def cmdline (subparsers): - p = subparsers.add_parser ( - 'stop', - help='stop virtual machine(s)', - ) - p.add_argument ( - '--force', action='store_const', const=True, - help='power off the virtual machine(s) forcibly' - ) - p.add_argument ( - 'wildcards', nargs='+', - help='virtual machine(s) to be stopped' - ) - p.set_defaults (run=run) - -def run (c, args): - running, _ = lib.get_all_guests (c) - - for vm in running.values(): - node_name = vm['node'] - vm_name = vm['vm'] - # Form the name of this VM (eg. "ham0:vm") so we can match it - # against the wildcards (eg. "ham0:*") - name = node_name + ":" + vm_name - for wc in args.wildcards: - if fnmatch.fnmatch (name, wc) or fnmatch.fnmatch (vm_name, wc): - if args.force: - subprocess.check_call (["virsh", - "-c", lib.uri_of_node (node_name), - "destroy", vm_name]) - else: - subprocess.check_call (["virsh", - "-c", lib.uri_of_node (node_name), - "shutdown", vm_name]) diff --git a/mclu_viewer.py b/mclu_viewer.py deleted file mode 100644 index 7c4018b..0000000 --- a/mclu_viewer.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/python -# mclu (mini cluster) -# 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. - -import argparse -import re -import sys -import subprocess - -import config -import lib - -def cmdline (subparsers): - p = subparsers.add_parser ( - 'viewer', - help='connect to graphical console of named VM', - ) - p.add_argument ( - 'vm', - help='vm (or node:vm) to connect to' - ) - p.set_defaults (run=run) - -def run (c, args): - running, _ = lib.get_all_guests (c) - - m = re.match (r'^(.*):(.*)$', args.vm) - if m: - # We don't actually care about the node, but we check it - # is the expected one below. - node_name_check = m.group (1) - vm_name = m.group (2) - else: - node_name_check = None - vm_name = args.vm - - if vm_name not in running: - sys.exit ("error: vm %s not found or not running" % vm_name) - - vm = running[vm_name]['vm'] - node_name = running[vm_name]['node'] - - if node_name_check and node_name != node_name_check: - sys.exit ("error: vm %s is not running on node %s, did you mean %s:%s ?" % - (vm_name, node_name_check, node_name, vm_name)) - - # Run the virsh console command. - subprocess.call ([config.VIRT_VIEWER, - "-c", lib.uri_of_node (node_name), - vm_name]) diff --git a/node.py b/node.py deleted file mode 100644 index 613a456..0000000 --- a/node.py +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/python -# mclu (mini cluster) -# 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. - -import os -import sys -import subprocess -import libvirt - -import config - -class Node: - def __init__ (self, name, host, mac, uri): - self.name = name - self.host = host - self.mac = mac - self.uri = uri - self.conn = None - self.up = None - - def ping (self, force = False): - """Test if node is up.""" - if not force: - if self.up is not None: - return self.up - - devnull = open (os.devnull, "w") - r = subprocess.call (["ping", "-c", "1", self.host], - stdout = devnull, stderr = devnull) - self.up = r == 0 - return self.up - - def ssh_ping (self): - """Test if we can open an SSH connection""" - if self.ping (): - devnull = open (os.devnull, "w") - r = subprocess.call ([config.SSH, "-l", "root", self.host, ":"], - stdout = devnull, stderr = devnull) - return r == 0 - else: - return False - - def libvirt_ping (self): - """Test if we can open a libvirt connection""" - if self.ping(): - conn = libvirt.openReadOnly (self.uri) - return conn != None - else: - return False - - def wake (self): - if not self.ping (): - devnull = open (os.devnull, "w") - subprocess.check_call ([config.WOL, self.mac], - stdout = devnull, stderr = devnull) - - def shutdown (self): - if self.ping (): - devnull = open (os.devnull, "w") - r = subprocess.call ([config.SSH, "-l", "root", self.host, - "/sbin/poweroff"], - stdout = devnull, stderr = devnull) - # returns a non-zero exit status, for unknown reasons - - def guests (self): - """Return the list of VMs running on this node""" - guests = [] - if self.ping (): - conn = self.get_connection () - for id in conn.listDomainsID(): - try: - dom = conn.lookupByID (id) - except: - continue - guests.append (dom) - return guests - - def get_connection (self): - """Return cached libvirt connection, fail if not possible.""" - if not self.ping (): - sys.exit ("error: node %s is not awake" % self.name) - if self.conn is not None: - return self.conn - conn = libvirt.open (self.uri) - if conn == None: - sys.exit ("error: could not open a libvirt connection to %s (URI: %s)" % - (self.host, self.uri)) - self.conn = conn - return self.conn diff --git a/run.in b/run.in deleted file mode 100644 index 6394ac1..0000000 --- a/run.in +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -# mclu (mini cluster) -# 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. - -b=@abs_top_builddir@ - -#echo $b/mclu.py -f $b/mclu.conf "$@" -exec $b/mclu.py -f $b/mclu.conf "$@" diff --git a/xmls/.exists b/xmls/.exists deleted file mode 100644 index e69de29..0000000