def _provision(roles): nodes = [] for value in roles.values(): nodes.extend(value) # remove duplicate hosts # Note(jrbalderrama): do we have to implement hash/equals in Host? nodes = set([node.address for node in nodes]) # Provision nodes so we can run Ansible on it remote.exec_command_on_nodes( nodes, 'apt-get update && apt-get -y --force-yes install python', 'Installing python...') # Bind volumes of docker in /tmp (free storage location on G5k) remote.exec_command_on_nodes(nodes, ('mkdir -p /tmp/docker/volumes; ' 'mkdir -p /var/lib/docker/volumes'), 'Creating docker volumes directory in /tmp') remote.exec_command_on_nodes( nodes, ('(mount | grep /tmp/docker/volumes) || ' 'mount --bind /tmp/docker/volumes /var/lib/docker/volumes'), 'Bind mount') # Bind nova local storage in /tmp remote.exec_command_on_nodes( nodes, 'mkdir -p /tmp/nova ; mkdir -p /var/lib/nova', 'Creating nova directory in /tmp') remote.exec_command_on_nodes(nodes, ('(mount | grep /tmp/nova) || ' 'mount --bind /tmp/nova /var/lib/nova'), 'Bind mount')
def dhcp_interfaces(c_resources): # TODO(msimonin) add a filter machines = c_resources["machines"] for desc in machines: nics = desc.get("_c_nics", []) nics_list = [nic for nic, _ in nics] ifconfig = ["ip link set %s up" % nic for nic in nics_list] cmd = "%s ; dhclient %s" % (";".join(ifconfig), " ".join(nics_list)) remote.exec_command_on_nodes(desc["_c_ssh_nodes"], cmd, cmd)
def grant_root_access(c_resources): machines = c_resources["machines"] for desc in machines: cmd = ["cat ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys"] cmd.append("sudo-g5k tee -a /root/.ssh/authorized_keys") cmd = "|".join(cmd) remote.exec_command_on_nodes(desc["_c_nodes"], cmd, cmd, conn_params={})
def exec_command_on_nodes(nodes, cmd, label, conn_params=None): """Execute a command on a node (id or hostname) or on a set of nodes. Args: nodes (list): list of targets of the command cmd. Each must be an execo.Host. cmd (str): string representing the command to run on the remote nodes. label (str): string for debugging purpose. conn_params (dict): connection parameters passed to the execo.Remote function. """ remote.exec_command_on_nodes(nodes, cmd, label, conn_params)