Commit d675c34c authored by Romain Olivo's avatar Romain Olivo
Browse files

add example

parent 9c3a7f33
Pipeline #85971 passed with stages
in 1 minute and 54 seconds
......@@ -29,7 +29,7 @@ class Distem():
if opts is None:
opts = []
self.post_json('/vnetworks', data={'name': name, 'address': address})
return self.post_json('/vnetworks', data={'name': name, 'address': address})
def vnetwork_remove(self, vnetname):
......@@ -47,7 +47,7 @@ class Distem():
see {file:files/resources_desc.md#Virtual_Networks Resource Description - VNetworks}
"""
self.delete_json('/vnetworks/%s' %(str(vnetname)), data={'type': "remove"})
return self.delete_json('/vnetworks/%s' %(str(vnetname)), data={'type': "remove"})
def vnetwork_info(self, vnetname):
......@@ -63,7 +63,7 @@ class Distem():
see {file:files/resources_desc.md#Virtual_Networks Resource Description - VNetworks}
"""
self.get_json('/vnetworks/%s' %(str(vnetname)))
return self.get_json('/vnetworks/%s' %(str(vnetname)))
def vnode_info(self, vnodename):
......@@ -78,7 +78,7 @@ class Distem():
{Dictionnary} The virtual node description
see {file:files/resources_desc.md#Virtual_Nodes Resource Description - VNodes}
"""
self.get_json('/vnodes/%s' %(str(vnodename)))
return self.get_json('/vnodes/%s' %(str(vnodename)))
def vnode_create(self, name, desc=None, ssh_key=None):
......@@ -125,7 +125,7 @@ class Distem():
'async': False
}
self.post_json('/vnodes/%s' %(name), data=data)
return self.post_json('/vnodes/%s' %(name), data=data)
def vnode_start(self, vnodename):
......@@ -156,7 +156,7 @@ class Distem():
'async': False
}
self.put_json('/vnodes/%s' % (str(vnodename)), data=desc)
return self.put_json('/vnodes/%s' % (str(vnodename)), data=desc)
def vnode_stop(self, vnodename):
......@@ -184,7 +184,7 @@ class Distem():
'async': False
}
self.put_json('/vnodes/%s' %(vnodename), data=desc)
return self.put_json('/vnodes/%s' %(vnodename), data=desc)
def vnode_remove(self, vnodename):
......@@ -202,7 +202,7 @@ class Distem():
see {file:files/resources_desc.md#Virtual_Nodes Resource Description - VNodes}
"""
self.put_json('/vnodes/%s' %(vnodename), data={'type': "remove"})
return self.put_json('/vnodes/%s' %(vnodename), data={'type': "remove"})
def vnode_freeze(self, vnodename):
......@@ -221,7 +221,7 @@ class Distem():
see {file:files/resources_desc.md#Virtual_Nodes Resource Description - VNodes}
"""
self.put_json('/vnodes/%s' %(str(vnodename)), {'async': False, 'type': 'freeze'})
return self.put_json('/vnodes/%s' %(str(vnodename)), {'async': False, 'type': 'freeze'})
def vnode_unfreeze(self, vnodename):
......@@ -240,7 +240,7 @@ class Distem():
see {file:files/resources_desc.md#Virtual_Nodes Resource Description - VNodes}
"""
self.put_json('/vnodes/%s' %(str(vnodename)), {'async': False, 'type': 'unfreeze'})
return self.put_json('/vnodes/%s' %(str(vnodename)), {'async': False, 'type': 'unfreeze'})
def vnode_execute(self, vnodename, command):
......@@ -257,7 +257,7 @@ class Distem():
[String] The result of the command (Array of string if multilines)
"""
self.post_json('/vnodes/%s/commands/' %(str(vnodename)), data={'command': str(command)})
return self.post_json('/vnodes/%s/commands/' %(str(vnodename)), data={'command': str(command)})
def vnodes_info(self):
......@@ -271,7 +271,7 @@ class Distem():
see {file:files/resources_desc.md#Virtual_Nodes Resource Description - VNodes}
"""
self.get_json("/vnodes")
return self.get_json("/vnodes")
def vnodes_create(self, names, desc=None, ssh_key=None):
......@@ -311,7 +311,7 @@ class Distem():
'async': False
}
self.post_json('/vnodes/', data=data)
return self.post_json('/vnodes/', data=data)
def vnodes_remove(self, names=None):
......@@ -327,7 +327,7 @@ class Distem():
if names is None:
names = []
self.put_json("/vnodes", data={'names': names, 'type': 'delete', 'async': False})
return self.put_json("/vnodes", data={'names': names, 'type': 'delete', 'async': False})
def vnodes_start(self, names):
......@@ -353,7 +353,7 @@ class Distem():
"""
desc = {'status': 'RUNNING'}
self.put_json('/vnodes', {'names': names, 'desc': desc, 'async': False, 'type': 'update'})
return self.put_json('/vnodes', {'names': names, 'desc': desc, 'async': False, 'type': 'update'})
def vnodes_stop(self, names=None):
......@@ -373,7 +373,7 @@ class Distem():
if names is None:
names = []
self.put_json("/vnodes", {'names': names, 'async': False, 'type': 'stop'})
return self.put_json("/vnodes", {'names': names, 'async': False, 'type': 'stop'})
def vnodes_freeze(self, names=None):
......@@ -395,7 +395,7 @@ class Distem():
if names is None:
names = []
self.put_json("/vnodes", {'names': names, 'async': False, 'type': 'freeze'})
return self.put_json("/vnodes", {'names': names, 'async': False, 'type': 'freeze'})
def vnodes_unfreeze(self, names=None):
......@@ -417,7 +417,7 @@ class Distem():
if names is None:
names = []
self.put_json("/vnodes", {'names': names, 'async': False, 'type': 'unfreeze'})
return self.put_json("/vnodes", {'names': names, 'async': False, 'type': 'unfreeze'})
def vnodes_execute(self, names, command):
......@@ -434,7 +434,7 @@ class Distem():
{Dictionnary} The result of the command (one entry by vnode)
"""
self.post_json("/commands", {'names': names, 'command': command})
return self.post_json("/commands", {'names': names, 'command': command})
def vfilesystem_info(self, vnodename):
......@@ -450,7 +450,7 @@ class Distem():
{Dictionnary} The virtual node filesystem informations
"""
self.get_json('/vnodes/%s/filesystem/' %(str(vnodename)))
return self.get_json('/vnodes/%s/filesystem/' %(str(vnodename)))
def vfilesystem_create(self, vnodename, desc):
......@@ -469,7 +469,7 @@ class Distem():
see {file:files/resources_desc.md#File_System0 Resource Description - VFilesystem}
"""
self.post_json('/vnodes/%s/filesystem/' %(str(vnodename)), {"desc": desc})
return self.post_json('/vnodes/%s/filesystem/' %(str(vnodename)), {"desc": desc})
def vfilesystem_update(self, vnodename, desc):
......@@ -488,7 +488,7 @@ class Distem():
see {file:files/resources_desc.md#File_System0 Resource Description - VFilesystem}
"""
self.put_json('/vnodes/%s/filesystem/' %(str(vnodename)), data=desc)
return self.put_json('/vnodes/%s/filesystem/' %(str(vnodename)), data=desc)
def viface_info(self, vnodename, vifacename):
......@@ -506,7 +506,7 @@ class Distem():
see {file:files/resources_desc.md#Network_Interfaces Resource Description - VIfaces}
"""
self.get_json('/vnodes/%s/ifaces/%s' %(str(vnodename), str(vifacename)))
return self.get_json('/vnodes/%s/ifaces/%s' %(str(vnodename), str(vifacename)))
def viface_create(self, vnodename, name, desc):
......@@ -527,7 +527,7 @@ class Distem():
see {file:files/resources_desc.md#Network_Interfaces Resource Description - VIfaces}
"""
self.post_json('/vnodes/%s/ifaces/' %(str(vnodename)), {'name': name, 'desc': desc})
return self.post_json('/vnodes/%s/ifaces/' %(str(vnodename)), {'name': name, 'desc': desc})
def viface_remove(self, vnodename, vifacename):
......@@ -545,7 +545,7 @@ class Distem():
see {file:files/resources_desc.md#Network_Interfaces Resource Description - VIfaces}
"""
self.delete_json('/vnodes/%s/ifaces/%s/' %(str(vnodename), str(vifacename)), data={})
return self.delete_json('/vnodes/%s/ifaces/%s/' %(str(vnodename), str(vifacename)), data={})
def vcpu_create(self, vnodename, val, unit='mhz', corenb=1):
......@@ -568,7 +568,7 @@ class Distem():
"""
desc = {'corenb': corenb, 'val': val, 'unit': unit}
self.post_json("/vnodes/%s/cpu" %(vnodename), data={'desc': desc})
return self.post_json("/vnodes/%s/cpu" %(vnodename), data={'desc': desc})
def vcpu_update(self, vnodename, val, unit='mhz'):
......@@ -589,7 +589,7 @@ class Distem():
"""
desc = {'val': val, 'unit': unit}
self.put_json("/vnodes/%s/cpu" %(vnodename), {'desc': desc})
return self.put_json("/vnodes/%s/cpu" %(vnodename), {'desc': desc})
def vcpu_remove(self, vnodename):
......@@ -606,7 +606,7 @@ class Distem():
see {file:files/resources_desc.md#CPU0 Resource Description - VCPU}
"""
self.delete_json("/vnodes/%s/cpu" %(vnodename), data={})
return self.delete_json("/vnodes/%s/cpu" %(vnodename), data={})
def vcpu_info(self, vnodename):
......@@ -620,7 +620,7 @@ class Distem():
see {file:files/resources_desc.md#CPU0 Resource Description - VCPU}
"""
self.get_json("/vnodes/%s/cpu" %(vnodename))
return self.get_json("/vnodes/%s/cpu" %(vnodename))
def vinput_update(self, vnodename, vifacename, desc=None):
......@@ -645,7 +645,7 @@ class Distem():
if desc is None:
desc = {}
self.put_json("/vnodes/%s/ifaces/%s/input/" %(vnodename, vifacename),
return self.put_json("/vnodes/%s/ifaces/%s/input/" %(vnodename, vifacename),
{'desc': desc})
......@@ -664,7 +664,7 @@ class Distem():
see {file:files/resources_desc.md#Traffic Resource Description - VTraffic}
"""
self.get_json("/vnodes/%s/ifaces/%s/input" %(vnodename, vifacename))
return self.get_json("/vnodes/%s/ifaces/%s/input" %(vnodename, vifacename))
def voutput_update(self, vnodename, vifacename, desc=None):
......@@ -689,7 +689,7 @@ class Distem():
if desc is None:
desc = {}
self.put_json("/vnodes/%s/ifaces/%s/output" %(vnodename, vifacename), {'desc': desc})
return self.put_json("/vnodes/%s/ifaces/%s/output" %(vnodename, vifacename), {'desc': desc})
def voutput_info(self, vnodename, vifacename):
......@@ -707,7 +707,7 @@ class Distem():
see {file:files/resources_desc.md#Traffic Resource Description - VTraffic})
"""
self.get_json("/vnodes/%s/ifaces/%s/output" %(vnodename, vifacename))
return self.get_json("/vnodes/%s/ifaces/%s/output" %(vnodename, vifacename))
def vmem_create(self, vnodename, mem, swap=None, hierarchy='v1'):
......@@ -729,7 +729,7 @@ class Distem():
swap = []
desc = {'mem': mem, 'swap': swap, 'hierarchy': hierarchy}
self.post_json("/vnodes/%s/vmem" %(vnodename), {'desc': desc})
return self.post_json("/vnodes/%s/vmem" %(vnodename), {'desc': desc})
def vmem_update(self, vnodename, desc):
......@@ -742,7 +742,7 @@ class Distem():
desc(dict) The memory limitation description
"""
self.put_json("/vnodes/%s/vmem" %(vnodename), {'desc': desc})
return self.put_json("/vnodes/%s/vmem" %(vnodename), {'desc': desc})
def get_json(self, route):
......@@ -778,7 +778,7 @@ class Distem():
req = requests.Request(method, route, data=_data)
prepped = req.prepare()
response = self.client.send(prepped)
response = return self.client.send(prepped)
if 200 <= response.status_code < 300:
try:
......
import requests
import os
import json
import copy
from statistics import mean
from statistics import stdev
from math import sqrt
if __name__ == "__main__":
# The path to the compressed filesystem image
# We can point to local file since our homedir is available from NFS
FSIMG="file:///home/rolivo/distem_img/distem-fs-jessie.tar.gz"
# Put the physical machines that have been assigned to you
# You can get that by executing: cat $OAR_NODE_FILE | uniq
PNODES=["econome-21.nantes.grid5000.fr","econome-5.nantes.grid5000.fr"]
# The first argument of the script is the address (in CIDR format)
# of the virtual network to set-up in our platform
# This ruby hash table describes our virtual network
vnet = {
'name': 'lol',
'address': "10.176.0.0/22"
}
nodelist = ['node-1','node-2']
# Read SSH keys
PRIV_KEY = os.path.join(os.environ["HOME"], ".ssh", "id_rsa")
PUB_KEY = "%s.pub" % PRIV_KEY
private_key = open(os.path.expanduser(PRIV_KEY)).read()
public_key = open(os.path.expanduser(PUB_KEY)).read()
sshkeys = {
"public" : public_key,
"private" : private_key
}
latencies = ['0ms', '20ms', '40ms', '60ms']
results = {
'scp': {},
'rsync': {}
}
node1 = {
'name': 'node-1',
'address': []
}
node2 = {
'name': 'node-2',
'address': []
}
ifname = 'if0'
iteration = 5
def average(values, length_values):
sum_values = 0.0
for i in range(length_values):
sum_values += values[i]
return sum_values / length_values
def stddev(values, iteration):
return sqrt(values / iteration)
# Connect to the Distem server (on http://localhost:4567 by default)
distem = Distem()
# Start by creating the virtual network
print("Network created")
distem.vnetwork_create(vnet['name'],
vnet['address'])
# Creating one virtual node per physical one
# Create the first virtual node and set it to be hosted on
# the first physical machine
print("Node %s created" %nodelist[0])
distem.vnode_create(nodelist[0],
{'host': PNODES[0]}, sshkeys)
# Specify the path to the compressed filesystem image
# of this virtual node
distem.vfilesystem_create(nodelist[0],
{'image': FSIMG})
# Create a virtual network interface and connect it to vnet
print("Interface created")
distem.viface_create(nodelist[0],
'if0',
{'vnetwork': vnet['name'], 'default': 'true' })
# Create the first virtual node and set it to be hosted on
# the second physical machine
print("Node %s created" %nodelist[1])
distem.vnode_create(nodelist[1],
{'host': PNODES[1] },
sshkeys)
distem.vfilesystem_create(nodelist[1],
{'image': FSIMG })
# Create a virtual network interface and connect it to vnet
print("Interface created")
distem.viface_create(nodelist[1],
'if0',
{ 'vnetwork': vnet['name'] }
)
# Starting the virtual nodes using the synchronous method
distem.vnodes_start(nodelist)
print("Nodes started")
# Getting the -automatically affected- address of each virtual nodes
# virtual network interfaces
node1['address'] = distem.viface_info(node1['name'],ifname)['address'].split("/")[0]
node2['address'] = distem.viface_info(node2['name'],ifname)['address'].split("/")[0]
# Creating the files we will use in our experimentation
distem.vnode_execute(node1['name'],
'mkdir -p /tmp/src ; cd /tmp/src ; \
for i in `seq 1 100`; do \
dd if=/dev/zero of=$i bs=1K count=50; \
done'
)
# Printing the current latency
start_time = float(time.time())
distem.vnode_execute(node1['name'], 'hostname')
print("Latency without any limitations # %s" %(str(time.time() - start_time)))
desc = {
'output': {
'latency': {
'delay': []
}
}
}
# Starting our experiment for each specified latencies
print('Starting tests')
for latency in latencies:
sum_rsync = 0.0
sum_scp = 0.0
deviation_scp = 0.0
deviation_rsync = 0.0
print("Latency #%s" %str(latency))
# Update the latency description on virtual nodes
desc['output']['latency']['delay'] = latency
distem.viface_update(node1['name'],ifname,desc)
distem.viface_update(node2['name'],ifname,desc)
for i in range(iteration):
print("\tIteration ## %s" %i)
# Launch SCP test
# Cleaning target directory on node2
distem.vnode_execute(node2['name'], 'rm -rf /tmp/dst')
# Starting the copy from node1 to node2
start_time = round(time.time(), 5)
distem.vnode_execute(node1['name'],
"scp -rq /tmp/src #{node2['address']}:/tmp/dst"
)
values_scp = round(time.time() - start_time, 5)
sum_scp += values_scp
# Launch RSYNC test
# Cleaning target directory on node2
distem.vnode_execute(node2['name'], 'rm -rf /tmp/dst')
# Starting the copy from node1 to node2
start_time = time.time()
distem.vnode_execute('node-1',
"rsync -r /tmp/src #{node2['address']}:/tmp/dst"
)
values_rsync = round(time.time() - start_time, 5)
sum_rsync += values_rsync
deviation_scp += (values_scp-sum_scp) * (values_scp-sum_scp)
deviation_rsync += (values_rsync-sum_rsync) * (values_rsync-sum_rsync)
print("SCP results:")
print("%s: [average=%s,standard_deviation=%s]"
%(str(latency), str(sum_scp/iteration), stddev(deviation_scp, iteration)))
print("RSYNC results:")
print("%s: [average=%s,standard_deviation=%s]"
%(str(latency), str(sum_rsync/iteration), stddev(deviation_rsync, iteration)))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment