From: Alina Quereilhac Date: Mon, 19 Jan 2015 20:02:39 +0000 (+0100) Subject: Adding scripts to update yum repos in PL nodes X-Git-Tag: nepi-3.2.0~18 X-Git-Url: http://git.onelab.eu/?p=nepi.git;a=commitdiff_plain;h=6b5d5c46b4d6c3c8bba46d3c84efab12be4e32bd Adding scripts to update yum repos in PL nodes --- diff --git a/examples/planetlab/fedora-updates.repo b/examples/planetlab/fedora-updates.repo new file mode 100644 index 00000000..246f71f0 --- /dev/null +++ b/examples/planetlab/fedora-updates.repo @@ -0,0 +1,28 @@ +[updates] +name=Fedora $releasever - $basearch - Updates +failovermethod=priority +#baseurl=http://download.fedoraproject.org/pub/fedora/linux/updates/$releasever/$basearch/ +#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=updates-released-f$releasever&arch=$basearch +baseurl=http://archives.fedoraproject.org/pub/archive/fedora/linux/updates/$releasever/$basearch/ +enabled=1 +gpgcheck=1 +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch + +[updates-debuginfo] +name=Fedora $releasever - $basearch - Updates - Debug +failovermethod=priority +#baseurl=http://download.fedoraproject.org/pub/fedora/linux/updates/$releasever/$basearch/debug/ +mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=updates-released-debug-f$releasever&arch=$basearch +enabled=0 +gpgcheck=1 +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch + +[updates-source] +name=Fedora $releasever - Updates Source +failovermethod=priority +#baseurl=http://download.fedoraproject.org/pub/fedora/linux/updates/$releasever/SRPMS/ +#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=updates-released-source-f$releasever&arch=$basearch +baseurl=http://archives.fedoraproject.org/pub/archive/fedora/linux/updates/$releasever/SRPMS +enabled=0 +gpgcheck=1 +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch diff --git a/examples/planetlab/fedora.repo b/examples/planetlab/fedora.repo new file mode 100644 index 00000000..8b5ed011 --- /dev/null +++ b/examples/planetlab/fedora.repo @@ -0,0 +1,31 @@ +[fedora] +name=Fedora $releasever - $basearch +failovermethod=priority +#baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/ +#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch +baseurl=http://archives.fedoraproject.org/pub/archive/fedora/linux/releases/$releasever/Fedora/$basearch/os/ +enabled=1 +metadata_expire=7d +gpgcheck=1 +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch + +[fedora-debuginfo] +name=Fedora $releasever - $basearch - Debug +failovermethod=priority +#baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/debug/ +mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=fedora-debug-$releasever&arch=$basearch +enabled=0 +metadata_expire=7d +gpgcheck=1 +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch + +[fedora-source] +name=Fedora $releasever - Source +failovermethod=priority +#baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/source/SRPMS/ +#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=fedora-source-$releasever&arch=$basearch +baseurl=http://archives.fedoraproject.org/pub/archive/fedora/linux/releases/$releasever/Fedora/source/SRPMS/ +enabled=0 +metadata_expire=7d +gpgcheck=1 +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch diff --git a/examples/planetlab/update_fedora_repo.py b/examples/planetlab/update_fedora_repo.py new file mode 100644 index 00000000..8d4b6047 --- /dev/null +++ b/examples/planetlab/update_fedora_repo.py @@ -0,0 +1,130 @@ +#!/usr/bin/env python +# +# NEPI, a framework to manage network experiments +# Copyright (C) 2013 INRIA +# +# 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 3 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, see . +# +# Author: Alina Quereilhac + +# THIS IS A MAINTAINANCE SCRIPT! +# Use this script only if you are getting the following error when using yum: +# +# Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again + +# Example of how to run this experiment (replace with your information): +# +# $ cd +# python examples/planetlab/update_fedora_repo.py -H -s -u -p -k + +from nepi.execution.ec import ExperimentController + +from optparse import OptionParser, SUPPRESS_HELP +import os + +pl_slice = os.environ.get("PL_SLICE") +pl_user = os.environ.get("PL_USER") +pl_pass = os.environ.get("PL_PASS") +identity = os.environ.get("PL_SSHKEY") + +usage = ("usage: %prog -H -s -u -p " + "-k ") + +parser = OptionParser(usage = usage) +parser.add_option("-H", "--hosts", dest="hosts", + help="Comma separated list of PlanetLab host to update", type="str") +parser.add_option("-s", "--pl-slice", dest="pl_slice", + help="PlanetLab slicename", type="str", default=pl_slice) +parser.add_option("-u", "--pl-user", dest="pl_user", + help="PlanetLab web username", type="str", default=pl_user) +parser.add_option("-p", "--pl-password", dest="pl_password", + help="PlanetLab web password", type="str", default=pl_pass) +parser.add_option("-k", "--pl-ssh-key", dest="pl_ssh_key", + help="Path to private SSH key associated with the PL account", + type="str", default=identity) + +(options, args) = parser.parse_args() + +proceed = raw_input ("Executing this script will modify the fedora yum repositories in the selected PlanetLab hosts. Are you sure to continue? [y/N] ") +if proceed.lower() not in ['yes', 'y']: + os._exit(1) + +pl_slice = options.pl_slice +pl_ssh_key = options.pl_ssh_key +pl_user = options.pl_user +pl_password = options.pl_password +hosts = options.hosts + +hosts = map(str.strip, hosts.split(",")) +apps = [] + +## Create the experiment controller +ec = ExperimentController(exp_id = "pl_update_fedora_repo") + +for hostname in hosts: + # Register a Planetlab Node with no restrictions, it can be any node + node = ec.register_resource("planetlab::Node") + # The username in this case is the slice name, the one to use for login in + # via ssh into PlanetLab nodes. Replace with your own slice name. + ec.set(node, "hostname", hostname) + ec.set(node, "username", pl_slice) + ec.set(node, "identity", pl_ssh_key) + # The pluser and plpassword are the ones used to login in the PlanetLab web + # site. Replace with your own user and password account information. + ec.set(node, "pluser", pl_user) + ec.set(node, "plpassword", pl_password) + # Remove previous results + ec.set(node, "cleanExperiment", True) + ec.set(node, "cleanProcesses", True) + + # Application to update fedora.repo + path_to_repo = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + "fedora.repo") + + app = ec.register_resource("linux::Application") + ec.set(app, "sources", path_to_repo) + ec.set(app, "sudo", True) + ec.set(app, "command", + "cp /etc/yum.repos.d/fedora.repo /etc/yum.repos.d/fedora.repo.old; " + "cp ${SRC}/fedora.repo /etc/yum.repos.d/fedora.repo") + ec.register_connection(node, app) + + apps.append(app) + + # Application to update fedora.repo + path_to_repo = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + "fedora-updates.repo") + + app = ec.register_resource("linux::Application") + ec.set(app, "sources", path_to_repo) + ec.set(app, "sudo", True) + ec.set(app, "command", + "cp /etc/yum.repos.d/fedora-updates.repo /etc/yum.repos.d/fedora-updates.repo.old; " + "cp ${SRC}/fedora-updates.repo /etc/yum.repos.d/fedora-updates.repo") + ec.register_connection(node, app) + + apps.append(app) + + +ec.deploy() + +ec.wait_finished(apps) + +for app in apps: + print ec.trace(app, "stderr") + +ec.shutdown() +