3 # NEPI, a framework to manage network experiments
4 # Copyright (C) 2013 INRIA
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 2 as
8 # published by the Free Software Foundation;
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20 # THIS IS A MAINTAINANCE SCRIPT!
21 # Use this script only if you are getting the following error when using yum:
23 # Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again
25 # Example of how to run this experiment (replace with your information):
28 # python examples/planetlab/update_fedora_repo.py -H <host1,host2,..> -s <pl-slice> -u <pl-user> -p <pl-password> -k <pl-ssh-key>
30 from __future__ import print_function
32 from six.moves import input
34 from nepi.execution.ec import ExperimentController
36 from optparse import OptionParser, SUPPRESS_HELP
39 pl_slice = os.environ.get("PL_SLICE")
40 pl_user = os.environ.get("PL_USER")
41 pl_pass = os.environ.get("PL_PASS")
42 identity = os.environ.get("PL_SSHKEY")
44 usage = ("usage: %prog -H <hosts> -s <pl-slice> -u <pl-user> -p <pl-password> "
47 parser = OptionParser(usage = usage)
48 parser.add_option("-H", "--hosts", dest="hosts",
49 help="Comma separated list of PlanetLab host to update", type="str")
50 parser.add_option("-s", "--pl-slice", dest="pl_slice",
51 help="PlanetLab slicename", type="str", default=pl_slice)
52 parser.add_option("-u", "--pl-user", dest="pl_user",
53 help="PlanetLab web username", type="str", default=pl_user)
54 parser.add_option("-p", "--pl-password", dest="pl_password",
55 help="PlanetLab web password", type="str", default=pl_pass)
56 parser.add_option("-k", "--pl-ssh-key", dest="pl_ssh_key",
57 help="Path to private SSH key associated with the PL account",
58 type="str", default=identity)
60 (options, args) = parser.parse_args()
62 proceed = input ("Executing this script will modify the fedora yum repositories in the selected PlanetLab hosts. Are you sure to continue? [y/N] ")
63 if proceed.lower() not in ['yes', 'y']:
66 pl_slice = options.pl_slice
67 pl_ssh_key = options.pl_ssh_key
68 pl_user = options.pl_user
69 pl_password = options.pl_password
72 hosts = [host.strip() for host in hosts.split(",")]
75 ## Create the experiment controller
76 ec = ExperimentController(exp_id = "pl_update_fedora_repo")
78 for hostname in hosts:
79 # Register a Planetlab Node with no restrictions, it can be any node
80 node = ec.register_resource("planetlab::Node")
81 # The username in this case is the slice name, the one to use for login in
82 # via ssh into PlanetLab nodes. Replace with your own slice name.
84 ec.set(node, "hostname", hostname)
86 ec.set(node, "username", pl_slice)
87 ec.set(node, "identity", pl_ssh_key)
88 # The pluser and plpassword are the ones used to login in the PlanetLab web
89 # site. Replace with your own user and password account information.
91 ec.set(node, "pluser", pl_user)
93 ec.set(node, "plpassword", pl_password)
95 ec.set(node, "critical", False)
96 # Remove previous results
97 ec.set(node, "cleanExperiment", True)
98 ec.set(node, "cleanProcesses", True)
100 # Application to update fedora.repo
101 path_to_repo = os.path.join(
102 os.path.dirname(os.path.realpath(__file__)),
105 app = ec.register_resource("linux::Application")
106 ec.set(app, "files", path_to_repo)
107 ec.set(app, "sudo", True)
108 ec.set(app, "command",
109 "cp /etc/yum.repos.d/fedora.repo /etc/yum.repos.d/fedora.repo.old; "
110 "cp ${SHARE}/fedora.repo /etc/yum.repos.d/fedora.repo")
111 ec.set(app, "critical", False)
112 ec.register_connection(node, app)
116 # Application to update fedora.repo
117 path_to_repo = os.path.join(
118 os.path.dirname(os.path.realpath(__file__)),
119 "fedora-updates.repo")
121 app = ec.register_resource("linux::Application")
122 ec.set(app, "files", path_to_repo)
123 ec.set(app, "sudo", True)
124 ec.set(app, "command",
125 "cp /etc/yum.repos.d/fedora-updates.repo /etc/yum.repos.d/fedora-updates.repo.old; "
126 "cp ${SHARE}/fedora-updates.repo /etc/yum.repos.d/fedora-updates.repo")
127 ec.set(app, "critical", False)
128 ec.register_connection(node, app)
135 ec.wait_finished(apps)
139 print(ec.trace(app, "stderr"))