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>
32 from nepi.execution.ec import ExperimentController
34 from optparse import OptionParser, SUPPRESS_HELP
37 pl_slice = os.environ.get("PL_SLICE")
38 pl_user = os.environ.get("PL_USER")
39 pl_pass = os.environ.get("PL_PASS")
40 identity = os.environ.get("PL_SSHKEY")
42 usage = ("usage: %prog -H <hosts> -s <pl-slice> -u <pl-user> -p <pl-password> "
45 parser = OptionParser(usage = usage)
46 parser.add_option("-H", "--hosts", dest="hosts",
47 help="Comma separated list of PlanetLab host to update", type="str")
48 parser.add_option("-s", "--pl-slice", dest="pl_slice",
49 help="PlanetLab slicename", type="str", default=pl_slice)
50 parser.add_option("-u", "--pl-user", dest="pl_user",
51 help="PlanetLab web username", type="str", default=pl_user)
52 parser.add_option("-p", "--pl-password", dest="pl_password",
53 help="PlanetLab web password", type="str", default=pl_pass)
54 parser.add_option("-k", "--pl-ssh-key", dest="pl_ssh_key",
55 help="Path to private SSH key associated with the PL account",
56 type="str", default=identity)
58 (options, args) = parser.parse_args()
60 proceed = input ("Executing this script will modify the fedora yum repositories in the selected PlanetLab hosts. Are you sure to continue? [y/N] ")
61 if proceed.lower() not in ['yes', 'y']:
64 pl_slice = options.pl_slice
65 pl_ssh_key = options.pl_ssh_key
66 pl_user = options.pl_user
67 pl_password = options.pl_password
70 hosts = list(map(str.strip, hosts.split(",")))
73 ## Create the experiment controller
74 ec = ExperimentController(exp_id = "pl_update_fedora_repo")
76 for hostname in hosts:
77 # Register a Planetlab Node with no restrictions, it can be any node
78 node = ec.register_resource("planetlab::Node")
79 # The username in this case is the slice name, the one to use for login in
80 # via ssh into PlanetLab nodes. Replace with your own slice name.
82 ec.set(node, "hostname", hostname)
84 ec.set(node, "username", pl_slice)
85 ec.set(node, "identity", pl_ssh_key)
86 # The pluser and plpassword are the ones used to login in the PlanetLab web
87 # site. Replace with your own user and password account information.
89 ec.set(node, "pluser", pl_user)
91 ec.set(node, "plpassword", pl_password)
93 ec.set(node, "critical", False)
94 # Remove previous results
95 ec.set(node, "cleanExperiment", True)
96 ec.set(node, "cleanProcesses", True)
98 # Application to update fedora.repo
99 path_to_repo = os.path.join(
100 os.path.dirname(os.path.realpath(__file__)),
103 app = ec.register_resource("linux::Application")
104 ec.set(app, "files", path_to_repo)
105 ec.set(app, "sudo", True)
106 ec.set(app, "command",
107 "cp /etc/yum.repos.d/fedora.repo /etc/yum.repos.d/fedora.repo.old; "
108 "cp ${SHARE}/fedora.repo /etc/yum.repos.d/fedora.repo")
109 ec.set(app, "critical", False)
110 ec.register_connection(node, app)
114 # Application to update fedora.repo
115 path_to_repo = os.path.join(
116 os.path.dirname(os.path.realpath(__file__)),
117 "fedora-updates.repo")
119 app = ec.register_resource("linux::Application")
120 ec.set(app, "files", path_to_repo)
121 ec.set(app, "sudo", True)
122 ec.set(app, "command",
123 "cp /etc/yum.repos.d/fedora-updates.repo /etc/yum.repos.d/fedora-updates.repo.old; "
124 "cp ${SHARE}/fedora-updates.repo /etc/yum.repos.d/fedora-updates.repo")
125 ec.set(app, "critical", False)
126 ec.register_connection(node, app)
133 ec.wait_finished(apps)
137 print(ec.trace(app, "stderr"))