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 as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
21 # THIS IS A MAINTAINANCE SCRIPT!
22 # Use this script only if you are getting the following error when using yum:
24 # Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again
26 # Example of how to run this experiment (replace with your information):
29 # python examples/planetlab/update_fedora_repo.py -H <host1,host2,..> -s <pl-slice> -u <pl-user> -p <pl-password> -k <pl-ssh-key>
31 from nepi.execution.ec import ExperimentController
33 from optparse import OptionParser, SUPPRESS_HELP
36 pl_slice = os.environ.get("PL_SLICE")
37 pl_user = os.environ.get("PL_USER")
38 pl_pass = os.environ.get("PL_PASS")
39 identity = os.environ.get("PL_SSHKEY")
41 usage = ("usage: %prog -H <hosts> -s <pl-slice> -u <pl-user> -p <pl-password> "
44 parser = OptionParser(usage = usage)
45 parser.add_option("-H", "--hosts", dest="hosts",
46 help="Comma separated list of PlanetLab host to update", type="str")
47 parser.add_option("-s", "--pl-slice", dest="pl_slice",
48 help="PlanetLab slicename", type="str", default=pl_slice)
49 parser.add_option("-u", "--pl-user", dest="pl_user",
50 help="PlanetLab web username", type="str", default=pl_user)
51 parser.add_option("-p", "--pl-password", dest="pl_password",
52 help="PlanetLab web password", type="str", default=pl_pass)
53 parser.add_option("-k", "--pl-ssh-key", dest="pl_ssh_key",
54 help="Path to private SSH key associated with the PL account",
55 type="str", default=identity)
57 (options, args) = parser.parse_args()
59 proceed = raw_input ("Executing this script will modify the fedora yum repositories in the selected PlanetLab hosts. Are you sure to continue? [y/N] ")
60 if proceed.lower() not in ['yes', 'y']:
63 pl_slice = options.pl_slice
64 pl_ssh_key = options.pl_ssh_key
65 pl_user = options.pl_user
66 pl_password = options.pl_password
69 hosts = map(str.strip, hosts.split(","))
72 ## Create the experiment controller
73 ec = ExperimentController(exp_id = "pl_update_fedora_repo")
75 for hostname in hosts:
76 # Register a Planetlab Node with no restrictions, it can be any node
77 node = ec.register_resource("planetlab::Node")
78 # The username in this case is the slice name, the one to use for login in
79 # via ssh into PlanetLab nodes. Replace with your own slice name.
81 ec.set(node, "hostname", hostname)
83 ec.set(node, "username", pl_slice)
84 ec.set(node, "identity", pl_ssh_key)
85 # The pluser and plpassword are the ones used to login in the PlanetLab web
86 # site. Replace with your own user and password account information.
87 ec.set(node, "pluser", pl_user)
88 ec.set(node, "plpassword", pl_password)
89 ec.set(node, "critical", False)
90 # Remove previous results
91 ec.set(node, "cleanExperiment", True)
92 ec.set(node, "cleanProcesses", True)
94 # Application to update fedora.repo
95 path_to_repo = os.path.join(
96 os.path.dirname(os.path.realpath(__file__)),
99 app = ec.register_resource("linux::Application")
100 ec.set(app, "files", path_to_repo)
101 ec.set(app, "sudo", True)
102 ec.set(app, "command",
103 "cp /etc/yum.repos.d/fedora.repo /etc/yum.repos.d/fedora.repo.old; "
104 "cp ${SHARE}/fedora.repo /etc/yum.repos.d/fedora.repo")
105 ec.set(app, "critical", False)
106 ec.register_connection(node, app)
110 # Application to update fedora.repo
111 path_to_repo = os.path.join(
112 os.path.dirname(os.path.realpath(__file__)),
113 "fedora-updates.repo")
115 app = ec.register_resource("linux::Application")
116 ec.set(app, "files", path_to_repo)
117 ec.set(app, "sudo", True)
118 ec.set(app, "command",
119 "cp /etc/yum.repos.d/fedora-updates.repo /etc/yum.repos.d/fedora-updates.repo.old; "
120 "cp ${SHARE}/fedora-updates.repo /etc/yum.repos.d/fedora-updates.repo")
121 ec.set(app, "critical", False)
122 ec.register_connection(node, app)
129 ec.wait_finished(apps)
133 print ec.trace(app, "stderr")