How to copy files between nodes¶
The following defines an scp-based remote-copy application, and a node prototype using it to copy an arbitrary file to a chosen remote destination.
1 defApplication('Scp', 'Scp') {|a|
2 a.name = "Scp"
3 a.version(0, 0, 1)
4 a.path = "/usr/bin/scp"
5 a.defProperty('source', "File to copy", nil, {:order => 1, :dynamic => false, :type => :string, :use_name => false})
6 a.defProperty('destination', "Destination to copy the source to", nil, {:order => 2, :dynamic => false, :type => :string, :use_name => false})
7 }
8 defPrototype('resultGetter', 'resultGetter'){|a|
9 a.defProperty('file', 'File to retrieve')
10 a.defProperty('server', 'Server to copy the file to')
11 a.addApplication("Scp", "getresults"){ |listener|
12 listener.bindProperty('source', 'file')
13 listener.bindProperty('destination','server')
14 }
15 }
The prototype can then be used for nodes (note the use of the Experiment ID to avoid collisions on the remote machine).
1 defGroup('SenderResults', property.src {|node|
2 node.prototype("resultGetter", { 'server' => "USER@SERVER:/tmp", 'file' => "/tmp/#{Experiment.ID}.Sender.pcap"})
3 }
4 defGroup('ReceiverResults', property.dst){|node|
5 node.prototype("resultGetter", { 'server' => "USER@SERVER:/tmp", 'file' => "/tmp/#{Experiment.ID}.Receiver.pcap"})
6 }
7 defGroup('ResultGetters', ["SenderResults","ReceiverResults"])
Finally, the files can be copied, e.g. at the end of the experiment.
1 whenAllInstalled() {|node|
2
3 #
4 # [Run the actual experiment here]
5 #
6
7 # Retrieve the results and wait to allow them to finish
8 group("ResultGetters").startApplications
9 wait 10
10
11 Experiment.done
12 }
You also need to have distributed SSH keys properly so scp doesn't need a password. This can be quiclky done, from the experimentation node as follows.
root@node9:~# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: d4:6c:c1:20:6d:a1:df:dd:44:a4:96:80:de:47:16:b8 root@node9 The key's randomart image is: +--[ RSA 2048]----+ | ..o=o..oo | | o+oooo+ | | .o..+++ . | | o.oEo.o | | S ... . | | | | | | | | | +-----------------+ root@node9:~# ssh-copy-id USER@SERVER: The authenticity of host 'SERVER (SERVER)' can't be established. RSA key fingerprint is 75:24:1d:06:ec:1a:e5:df:7a:34:f4:71:18:ce:2a:0a. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'SERVER' (RSA) to the list of known hosts. Error reading response length from authentication socket. USER@SERVER's password: Now try logging into the machine, with "ssh 'USER@1SERVER'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting.
Of course, the fingerprint of the generated key will vary.