#!/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 version 2 as # published by the Free Software Foundation; # # 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 __future__ import print_function from six.moves import input 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 = 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 = [host.strip() for host in 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. if hostname != "any": 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. if pl_user: ec.set(node, "pluser", pl_user) if pl_password: ec.set(node, "plpassword", pl_password) ec.set(node, "critical", False) # 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, "files", 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 ${SHARE}/fedora.repo /etc/yum.repos.d/fedora.repo") ec.set(app, "critical", False) 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, "files", 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 ${SHARE}/fedora-updates.repo /etc/yum.repos.d/fedora-updates.repo") ec.set(app, "critical", False) ec.register_connection(node, app) apps.append(app) ec.deploy() ec.wait_finished(apps) for app in apps: try: print(ec.trace(app, "stderr")) except: print("NO stderr") ec.shutdown()