Ejemplo n.º 1
0
def main(ip1,ip2):
    a1 = FIMAPI(ip1)
    a2 = FIMAPI(ip2)
    remove_containers(a2)
    remove_net(a2,n2)
    remove_containers(a1)
    remove_net(a1,n1)
Ejemplo n.º 2
0
def main(nodeid):
    a = FIMAPI()

    fdus = {}
    nets = []

    input('Press enter to instantiate the demo')

    for d in net_desc:
        path_d = os.path.join(DESC_FOLDER, d)
        netd = json.loads(read(path_d))
        a.network.add_network(netd)
        nets.append(netd['uuid'])
        time.sleep(1)

    for d in descs:
        path_d = os.path.join(DESC_FOLDER, d)
        fdu_d = json.loads(read(path_d))
        fdu_id = a.fdu.onboard(fdu_d)
        iid = a.fdu.instantiate(fdu_id, nodeid)
        print('Instantiated: {}'.format(fdu_d['name']))
        fdus.update({fdu_id: iid})
        time.sleep(1)

    input('Press enter to terminate the demo')

    for k in fdus:
        iid = fdus[k]
        a.fdu.terminate(iid)
        a.fdu.offload(k)

    for n in nets:
        a.network.remove_network(n)

    print('Bye!')
Ejemplo n.º 3
0
    def __init__(self, uuid, name, tenant_id, tenant_name, url, url_admin=None, user=None, passwd=None, log_level=None,
                 config={}, persistent_info={}):
        """Constructor of VIM
        Params:
            'uuid': id asigned to this VIM
            'name': name assigned to this VIM, can be used for logging
            'tenant_id', 'tenant_name': (only one of them is mandatory) VIM tenant to be used
            'url_admin': (optional), url used for administrative tasks
            'user', 'passwd': credentials of the VIM user
            'log_level': provider if it should use a different log_level than the general one
            'config': dictionary with extra VIM information. This contains a consolidate version of general VIM config
                    at creation and particular VIM config at teh attachment
            'persistent_info': dict where the class can store information that will be available among class
                    destroy/creation cycles. This info is unique per VIM/credential. At first call it will contain an
                    empty dict. Useful to store login/tokens information for speed up communication

        Returns: Raise an exception is some needed parameter is missing, but it must not do any connectivity
            check against the VIM
        """

        vimconn.VimConnector.__init__(self, uuid, name, tenant_id, tenant_name, url, url_admin, user, passwd, log_level,
                                      config, persistent_info)

        self.logger.debug('vimconn_fos init with config: {}'.format(config))
        self.arch = config.get('arch', 'x86_64')
        self.hv = config.get('hypervisor', 'LXD')
        self.nodes = config.get('nodes', [])
        self.fdu_node_map = {}
        self.fos_api = FIMAPI(locator=self.url)
Ejemplo n.º 4
0
def deploy_admin1():
    a = FIMAPI(IP1)
    # Get the nodes from the domain
    print('Deploying on consumer nodes')
    nodes = a.node.list()
    if len(nodes) == 0:
        print('No nodes')
        exit(-1)
    # Print the nodes from the domain
    print('Nodes:')
    for n in nodes:
        print('UUID: {}'.format(n))
    measurement["domain"] = 'consumer'
    measure('start')
    time.sleep(1)
    net_deploy(net_desc, a, d1_n1)
    time.sleep(1)
    net_deploy(net_desc, a, d1_n2)
    time.sleep(1)
    container_deploy(descs_d1, a)
    path_d = os.path.join(DESC_FOLDER, net_desc[0])
    net_d = json.loads(read(path_d))
    time.sleep(1)
    net_info = get_net_info(a, net_d['uuid'])
    restartBrainMachine()
    print("Deployment finished")
Ejemplo n.º 5
0
def main(ip, fdufile, netfile):
    a = FIMAPI(ip)

    nodes = a.node.list()
    if len(nodes) == 0:
        print('No nodes')
        exit(-1)

    print('Nodes:')
    for n in nodes:
        print('UUID: {}'.format(n))

    fdu_d = FDU(json.loads(read_file(fdufile)))
    net_d = json.loads(read_file(netfile))

    n_uuid = net_d.get('uuid')

    n1 = '4a560914-1c3e-4966-9fa8-7f0acc903253'  #nuc

    input("Press enter to create network")
    a.network.add_network(net_d)
    a.network.add_network_to_node(net_d, n1)

    input('press enter to onboard descriptor')
    res = a.fdu.onboard(fdu_d)
    e_uuid = res.get_uuid()
    input('Press enter to define')
    inst_info = a.fdu.define(e_uuid)
    print(inst_info.to_json())
    instid = inst_info.get_uuid()

    input('Press enter to configure')
    a.fdu.configure(instid)

    input('Press enter to start')
    a.fdu.start(instid)

    # input('Press enter to stop')
    # a.entity.stop(e_uuid, n1, i_uuid)
    # input('Press enter to clean')
    # a.entity.clean(e_uuid, n1, i_uuid)
    # input('Press enter to undefine')
    # a.entity.undefine(e_uuid, n1)

    # input('Press enter to migrate')
    input('Press get info')
    info = a.fdu.instance_info(instid)
    print(info.to_json())

    #res = a.entity.migrate(e_uuid, i_uuid, n1, n2)
    #print('Res is: {}'.format(res))
    input('Press enter to terminate')

    a.fdu.terminate(instid)
    a.fdu.offload(e_uuid)
    input("Press enter to remove network")
    a.network.remove_network_from_node(n_uuid, n1)
    a.network.remove_network(n_uuid)

    exit(0)
Ejemplo n.º 6
0
def main(ip):
    a = FIMAPI(ip)

    fdus = {}
    nets = []

    #input('Press enter to instantiate the demo')

    for d in net_desc:
        path_d = os.path.join(DESC_FOLDER,d)
        netd = json.loads(read(path_d))
        a.network.add_network(netd)
        nets.append(netd['uuid'])
        time.sleep(1)

    for d,n in descs:
        path_d = os.path.join(DESC_FOLDER,d)
        fdu_d = FDU(json.loads(read(path_d)))
        res = a.fdu.onboard(fdu_d)
        fdu_id = res.get_uuid()
        print ('fdu_id : {}'.format(fdu_id))
        inst_info = a.fdu.instantiate(fdu_id, n)
        iid = inst_info.get_uuid()
        print ('iid : {}'.format(iid))
        print('Instantiated: {}'.format(fdu_d.get_name()))
        fdus.update({fdu_id: iid})
        time.sleep(1)

    print('Bye!')
Ejemplo n.º 7
0
def main(ip):
    a = FIMAPI(locator=ip)

    nodes = a.node.list()
    print('Nodes: {}'.format(nodes))

    fdus = {}

    input('Press enter to instantiate the demo')

    for d in descs:
        df, n = d
        ds = json.loads(read(os.path.join(DESC_FOLDER, df)))
        fdu_id = a.fdu.onboard(ds)
        iid = a.fdu.instantiate(fdu_id, n)
        print('Instantiated: {}'.format(ds['name']))
        fdus.update({fdu_id: iid})
        time.sleep(1)

    input('Press enter to terminate the demo')

    for k in fdus:
        iid = fdus[k]
        a.fdu.terminate(iid)
        a.fdu.offload(k)

    print('Bye!')
Ejemplo n.º 8
0
def main(ip):
    a = FIMAPI(ip)

    fdus = {}

    nodes = a.node.list()
    if len(nodes) == 0:
        print('No nodes')
        exit(-1)

    print('Nodes:')
    for n in nodes:
        print('UUID: {}'.format(n))
        discs = a.fdu.list()
        for d_id in discs:
            info = a.fdu.instance_list(d_id)
            print('info : {}'.format(info))
            if n in info:
                time.sleep(1)
                i_ids = info[n]
                for iid in i_ids:
                    print('Terminating iid : {}'.format(iid))
                    a.fdu.terminate(iid)
                    a.fdu.offload(d_id)

    nets = a.network.list()
    if nets:
        print('networks : {}'.format(nets))
        for n in nets:
            net_uuid = n['uuid']
            print('net_id : {}'.format(net_uuid))
            a.network.remove_network(net_uuid)

    exit(0)
Ejemplo n.º 9
0
def main(ip, fdufile, netfile):
    a = FIMAPI(ip)

    nodes = a.node.list()
    if len(nodes) == 0:
        print('No nodes')
        exit(-1)

    print('Nodes:')
    for n in nodes:
        print('UUID: {}'.format(n))

    fdu_d = FDU(json.loads(read_file(fdufile)))
    net_d = json.loads(read_file(netfile))

    n_uuid = net_d.get('uuid')

    #n1 = 'a2d358aa-af2b-42cb-8d23-a89e88b97e5c' #fosmed
    n1 = '4a560914-1c3e-4966-9fa8-7f0acc903253'  #nuc
    # n1 = '53712df2-9649-4a21-be2e-80eed00ff9ce' #ubuntuvm1
    #n1 = 'a4589fae-0493-40cf-b976-2d03020d060d' #foskvm
    # n1 = '53712df2-9649-4a21-be2e-80eed00ff9ce' #ubuntuvm1
    # n1 = 'd07b095f-7948-4f9b-95cc-c61029f6c3c3' #fosdbg

    input("Press enter to create network")
    a.network.add_network(net_d)
    a.network.add_network_to_node(net_d, n1)

    input('press enter to onboard descriptor')
    res = a.fdu.onboard(fdu_d)
    e_uuid = res.get_uuid()
    input('Press enter to intantiate')
    inst_info = a.fdu.instantiate(e_uuid, n1)
    instid = inst_info.get_uuid()

    # input('Press enter to stop')
    # a.entity.stop(e_uuid, n1, i_uuid)
    # input('Press enter to clean')
    # a.entity.clean(e_uuid, n1, i_uuid)
    # input('Press enter to undefine')
    # a.entity.undefine(e_uuid, n1)

    # input('Press enter to migrate')
    input('Press get info')
    info = a.fdu.instance_info(instid)
    print(info.to_json())

    #res = a.entity.migrate(e_uuid, i_uuid, n1, n2)
    #print('Res is: {}'.format(res))
    input('Press enter to terminate')

    a.fdu.terminate(instid)
    a.fdu.offload(e_uuid)
    input("Press enter to remove network")
    a.network.remove_network_from_node(n_uuid, n1)
    a.network.remove_network(n_uuid)

    exit(0)
Ejemplo n.º 10
0
def main(ip, fdufile, netfile):
    a = FIMAPI(ip)
    nodes = a.node.list()
    if len(nodes) == 0:
        print('No nodes')
        exit(-1)

    print('Nodes:')
    for n in nodes:
        print('UUID: {}'.format(n))

    fdu_d = FDU(json.loads(read_file(fdufile)))

    net_d = json.loads(read_file(netfile))

    n_uuid = net_d.get('uuid')

    n1 = '1e03d6b9-908e-44e6-9fc2-3282e38c442d'  #fog01
    n2 = 'dc02633d-491b-40b3-83be-072748142fc4'  #fog02

    input("Press enter to create network")
    a.network.add_network(net_d)
    net_info = get_net_info(a, net_d['uuid'])
    print('Net info {}'.format(net_info))

    input('press enter to network creation')
    a.network.add_network_to_node(net_info['uuid'], n1)

    input('press enter to onboard descriptor')
    res = a.fdu.onboard(fdu_d)
    e_uuid = res.get_uuid()
    input('Press enter to define')
    inst_info = a.fdu.define(e_uuid)
    print(inst_info.to_json())
    instid = inst_info.get_uuid()

    input('Press enter to configure')
    a.fdu.configure(instid)

    input('Press enter to start')
    a.fdu.start(instid)

    input('Press get info')
    info = a.fdu.instance_info(instid)
    print(info.to_json())

    #res = a.entity.migrate(e_uuid, i_uuid, n1, n2)
    #print('Res is: {}'.format(res))
    input('Press enter to terminate')

    a.fdu.terminate(instid)
    a.fdu.offload(e_uuid)
    input("Press enter to remove network")
    a.network.remove_network_from_node(n_uuid, n1)
    a.network.remove_network(n_uuid)

    exit(0)
Ejemplo n.º 11
0
def SetFog05(ip_addr):
    a = FIMAPI(ip_addr)
    nodes = a.node.list()
    failed_fog05 = False
    if len(nodes) == 0:
        print('No nodes, Fog05 failed')
        failed_fog05 = True
        # exit(-1)
    # Print the nodes from the domain
    return a, failed_fog05
Ejemplo n.º 12
0
def main(ip, ip2):
    a = FIMAPI(ip)

    a2 = FIMAPI(ip2)

    nodes = a.node.list()
    if len(nodes) == 0:
        print('No nodes')
        exit(-1)

    print('Nodes:')
    for n in nodes:
        print('UUID: {}'.format(n))

    input('Press to deploy net on consumer domain')
    net_deploy(net_desc, a, d1_n1)
    net_deploy(net_desc, a, d1_n2)
    input('Press to deploy containers on consumer domain')
    container_deploy(descs_d1, a)

    input('Press to move client to second domain')
    for d in net_desc:
        path_d = os.path.join(DESC_FOLDER, d)
        net_d = json.loads(read(path_d))
        net_info = get_net_info(a, net_d['uuid'])
        print(net_info)
        print(a2)
        input('Press to create federated vxlan to second domain')
        a2.network.add_network(net_info)
        net_info2 = get_net_info(a2, net_info['uuid'])
        print(net_info2)
        print('Net info {}'.format(net_info2))
        a2.network.add_network_to_node(net_info2['uuid'], d2_n1)

    input('press enter to onboard on provider domain')

    container_deploy(descs_d2, a2)

    print("bye")

    exit(0)
Ejemplo n.º 13
0
def main(ip, fdufile):
    a = FIMAPI(ip)

    nodes = a.node.list()
    if len(nodes) == 0:
        print('No nodes')
        exit(-1)

    print('Nodes:')
    for n in nodes:
        print('UUID: {}'.format(n))

    fdu_d = FDU(json.loads(read_file(fdufile)))

    input('press enter to onboard descriptor')
    res = a.fdu.onboard(fdu_d)
    print(res.to_json())
    e_uuid = res.get_uuid()
    # code.interact(local=locals())

    # display choice
    print('Choose at which node you want to define the fdu:')
    for idx, n in enumerate(nodes):
        print('{}: {}'.format(idx, n))
    index = input('')

    inst_info = a.fdu.define(e_uuid, nodes[int(index)])
    print(inst_info.to_json())
    instid = inst_info.get_uuid()

    input('Press enter to configure')
    a.fdu.configure(instid)

    input('Press enter to start')
    a.fdu.start(instid)

    input('Press get info')
    info = a.fdu.instance_info(instid)
    print(info.to_json())

    input('Press enter to stop')
    a.fdu.stop(instid)

    input('Press enter to clean')
    a.fdu.clean(instid)

    input('Press enter to remove')

    a.fdu.undefine(instid)
    a.fdu.offload(e_uuid)

    exit(0)
Ejemplo n.º 14
0
def deploy_provider(net_d, provider_domain):
    print(net_d)
    net_info = net_d
    if net_d['privacy'] == "trusty":
        print("Trusty federation")
        # a2 = FIMAPI(net_d["net_type"])
        measure('trusty_info_get')
        consumer_domain = FIMAPI(net_d["net_type"])
        net_info = get_net_info(consumer_domain, net_d['uuid'])
        print(consumer_domain.network.list())
        print('Net info {}'.format(net_info))
    else:
        measure('untrusty_info_get')
        print("Untrusty federation")
        # net_info = json.loads(net_d)

    consumer_domain = FIMAPI(net_d["net_type"])
    net_info = get_net_info(consumer_domain, net_d['uuid'])
    print(consumer_domain.network.list())
    print('Net info {}'.format(net_info))
    # Create network based on the descriptor
    # Get info if the network is created
    print(net_d['uuid'], net_d['net_type'])

    measure('net_deploy')
    print("net_info 1 = ", net_info)
    provider_domain.network.add_network(net_info)
    # net_info = get_net_info(provider_domain,net_info['uuid'])
    print("net_info 2 = ", net_info)
    # Add the created network to the node (n1)
    # input('press enter to network creation')
    measure('net_add')
    time.sleep(1)
    provider_domain.network.add_network_to_node(net_info['uuid'], d2_n1)

    measure('container_deploy')
    time.sleep(1)
    container_deploy(descs_d2, provider_domain)
    return provider_domain
Ejemplo n.º 15
0
def main(ip, fdufile):
    a = FIMAPI(ip)

    nodes = a.node.list()
    if len(nodes) == 0:
        print('No nodes')
        exit(-1)

    print('Nodes:')
    for n in nodes:
        print('UUID: {}'.format(n))

    fdu_d = FDU(json.loads(read_file(fdufile)))

    n1 = '4a560914-1c3e-4966-9fa8-7f0acc903253'  #nuc

    input('press enter to onboard descriptor')
    res = a.fdu.onboard(fdu_d)
    print(res.to_json())
    e_uuid = res.get_uuid()
    # code.interact(local=locals())

    input('Press enter to define')
    inst_info = a.fdu.define(e_uuid, n1)
    print(inst_info.to_json())
    instid = inst_info.get_uuid()

    input('Press enter to configure')
    a.fdu.configure(instid)

    input('Press enter to start')
    a.fdu.start(instid)

    input('Press get info')
    info = a.fdu.instance_info(instid)
    print(info.to_json())

    input('Press enter to stop')
    a.fdu.stop(instid)

    input('Press enter to clean')
    a.fdu.clean(instid)

    input('Press enter to remove')

    a.fdu.undefine(instid)
    a.fdu.offload(e_uuid)

    exit(0)
Ejemplo n.º 16
0
def main(ip):
    a = FIMAPI(ip)

    fdus = {}
    nets = []

    print('Current Eclipse fog05 Infrastrucutre:')

    nodes = a.node.list()
    for nid in nodes:
        info = a.node.info(nid)
        print('ID: {} Hostname: {}'.format(nid, info['name']))


    input('Press enter to instantiate the demo')

    for d in net_desc:
        path_d = os.path.join(DESC_FOLDER,d)
        netd = json.loads(read(path_d))
        a.network.add_network(netd)
        nets.append(netd['uuid'])
        time.sleep(1)

    for d in descs:
        nid = descs[d]
        print('Instantiating {} to {}'.format(d, nid))
        path_d = os.path.join(DESC_FOLDER,d)
        data = json.loads(read(path_d))
        fdu_d = FDU(data)
        fduinfo = a.fdu.onboard(fdu_d)
        fdu_id = fduinfo.uuid
        print ('fdu_id : {}'.format(fdu_id))
        inst_info = a.fdu.define(fdu_id, nid)
        iid = inst_info.uuid
        time.sleep(1)
        a.fdu.configure(iid)
        time.sleep(1)
        a.fdu.start(iid)
        print ('iid : {}'.format(iid))
        print('Instantiated: {}'.format(fdu_d.name))
        fdus.update({fdu_id: iid})
        time.sleep(2)

    print('Instantiated:')
    print(json.dumps(fdus, indent=2))
    print('Bye!')
Ejemplo n.º 17
0
def deploy_provider(winning_ip_address, net_uuid, provider_domain):

    consumer_domain = FIMAPI(winning_ip_address)
    net_info = get_net_info(consumer_domain, net_uuid)
    # Create network based on the descriptor
    # Get info if the network is created
    # print(net_d['uuid'], net_d['net_type'])

    measure('net_deploy')
    provider_domain.network.add_network(net_info)
    # Add the created network to the node (n1)
    # input('press enter to network creation')
    measure('net_add')
    time.sleep(1)
    provider_domain.network.add_network_to_node(net_info['uuid'], d2_n1)

    measure('container_deploy')
    time.sleep(1)
    container_deploy(descs_d2, provider_domain)
    return provider_domain
Ejemplo n.º 18
0
def dashboard(yaks_ip=''):
    if yaks_ip == '':
        if 'yaksIp' in session:
            return render_template('dashboard.html')
        else:
            return render_template('connect.html')
    else:
        session['yaksIp'] = escape(yaks_ip)
        # fog05 initialization goes here
        global a
        a = FIMAPI(session['yaksIp'])
        nodes = a.node.list()
        if len(nodes) == 0:
            app.logger.error('No nodes at {}'.format(session['yaksIp']))
            return redirect(url_for('close'))

        session['nodes'] = nodes
        # session['instances'] = dict()
        session['instances'] = {'node_id': 'instance_id'}
        app.logger.debug('Nodes: {}'.format(nodes))
        return render_template('dashboard.html')
Ejemplo n.º 19
0
if __name__ == '__main__':
    ip_addr = getIPaddress()
    print("NODE IP address:", ip_addr)
    host_id = str(ip_addr).split(".")[3]
    # setBlockchainNodeIP(host_id)

    fog_05, failed_fog05 = SetFog05(ip_addr)
    ip2 = "163.117.140.237"
    path_d = os.path.join(DESC_FOLDER, net_desc[0])
    net_d = json.loads(read(path_d))
    # time.sleep(1)
    net_info = get_net_info(fog_05, net_d['uuid'])

    print("DEPLOYING NET:", net_info, "\n on node: ", ip2)
    provider_domain = FIMAPI(ip2)

    provider_domain.network.add_network(net_info)
    # net_info = get_net_info(provider_domain,net_info['uuid'])
    print("net_info 2 = ", net_info)
    # Add the created network to the node (n1)
    # input('press enter to network creation')
    time.sleep(1)
    provider_domain.network.add_network_to_node(net_info['uuid'], d2_n1)

    # measure('container_deploy')
    time.sleep(1)
    container_deploy(descs_d2, provider_domain)

    question = input("Terminate the service? PRESS ENTER TO TERMINATE")
    if question != "no":
Ejemplo n.º 20
0
    fos_api.flavor.remove(flv_id)
    return json.dumps({'result': True})


# MAIN and UTILS


def read_file(file_path):
    data = ''
    with open(file_path, 'r') as f:
        data = f.read()
    return data


if __name__ == '__main__':
    if len(sys.argv) < 2:
        exit(-1)
    print('ARGS {}'.format(sys.argv))
    file_dir = os.path.dirname(__file__)
    cfg = json.loads(read_file(sys.argv[1]))
    global conf
    conf = cfg
    global fos_api
    fos_api = FIMAPI(locator=conf.get('yaks'),
                     sysid=conf.get('sysid'),
                     tenantid=conf.get('tenantid'))
    global img_dict
    img_dict = {}
    app.run(host=conf.get('host'),
            port=conf.get('port'),
            debug=conf.get('debug'))
Ejemplo n.º 21
0
from fog05 import FIMAPI
import sys

api = FIMAPI(sys.argv[1])
nodes=api.node.list()
print("\n{0} nodes found".format(len(nodes)))
for node in nodes:
	print('\n\n---------NODE-------------\n')
	print(node)
	print('\n\n--------PLUGINS-----------\n')
	print(api.node.plugins(node))
def main(ip, fdufile):
    t1 = time.time()
    a = FIMAPI(ip)
    t2 = time.time()
    t_conn = t2 - t1

    nodes = a.node.list()
    if len(nodes) == 0:
        print('No nodes')
        exit(-1)

    print('Nodes:')
    for n in nodes:
        print('UUID: {}'.format(n))

    fdu_d = FDU(json.loads(read_file(fdufile)))

    input('press enter to onboard descriptor')
    t1 = time.time()
    res = a.fdu.onboard(fdu_d)
    t2 = time.time()
    t_fdu = t2 - t1
    print(res.to_json())
    e_uuid = res.get_uuid()
    # code.interact(local=locals())

    # display choice
    print('Choose at which node you want to define the fdu:')
    for idx, n in enumerate(nodes):
        print('{}: {}'.format(idx, n))
    index = input('')

    t1 = time.time()
    inst_info = a.fdu.define(e_uuid, nodes[int(index)])
    t2 = time.time()
    t_define = t2 - t1
    print(inst_info.to_json())
    instid = inst_info.get_uuid()

    input('Press enter to configure')
    t1 = time.time()
    a.fdu.configure(instid)
    t2 = time.time()
    t_config = t2 - t1

    input('Press enter to start')
    # cl = pylxd.Client(endpoint='https://192.168.56.112:8443', verify=False)
    cl = pylxd.Client()
    inst = cl.instances.get("c{}".format(instid))
    t1 = time.time()
    a.fdu.start(instid)

    while inst.state().status != 'Running':
        time.sleep(0.01)
    t2 = time.time()
    t_start = t2 - t1

    input('Press get info')
    info = a.fdu.instance_info(instid)
    print(info.to_json())

    input('Press enter to stop')
    t1 = time.time()
    a.fdu.stop(instid)
    t2 = time.time()
    t_stop = t2 - t1

    input('Press enter to clean')
    t1 = time.time()
    a.fdu.clean(instid)
    t2 = time.time()
    t_clean = t2 - t1

    input('Press enter to remove')
    t1 = time.time()
    a.fdu.undefine(instid)
    t2 = time.time()
    t_undef = t2 - t1
    t1 = time.time()
    a.fdu.offload(e_uuid)
    t2 = time.time()
    t_delfdu = t2 - t1

    print(
        "connection: {} \n Fdu: {} \n Define: {} \n Config: {} \n Start: {} \n Stop: {} \n Clean: {} \n Undef: {} \n DelFdu: {}"
        .format(t_conn, t_fdu, t_define, t_config, t_start, t_stop, t_clean,
                t_undef, t_delfdu))

    exit(0)
Ejemplo n.º 23
0

# MAIN and UTILS


def read_file(file_path):
    data = ''
    with open(file_path, 'r') as f:
        data = f.read()
    return data


if __name__ == '__main__':
    if len(sys.argv) < 2:
        exit(-1)
    print('ARGS {}'.format(sys.argv))
    file_dir = os.path.dirname(__file__)
    cfg = json.loads(read_file(sys.argv[1]))
    global conf
    conf = cfg
    global fos_api

    yendpoint = conf.get('yaks', os.environ['YAKS_HOST'])
    fos_api = FIMAPI(locator=yendpoint,
                     sysid=conf.get('sysid'),
                     tenantid=conf.get('tenantid'))
    global img_dict
    img_dict = {}
    app.run(host=conf.get('host'),
            port=conf.get('port'),
            debug=conf.get('debug'))
Ejemplo n.º 24
0
def main(ip, fdufile, netfile, routerfile):
    a = FIMAPI(ip)

    nodes = a.node.list()
    if len(nodes) == 0:
        print('No nodes')
        exit(-1)

    print('Nodes:')
    for n in nodes:
        print('UUID: {}'.format(n))

    fdu_d = FDU(json.loads(read_file(fdufile)))
    net_d = json.loads(read_file(netfile))
    router_d = json.loads(read_file(routerfile))

    # e_uuid = fdu_d.get('uuid')
    n_uuid = net_d.get('uuid')
    r_uuid = router_d.get('uuid')

    input("Press enter to create network")
    a.network.add_network(net_d)

    n1 = '4a560914-1c3e-4966-9fa8-7f0acc903253'  #nuc

    input('press enter to onboard descriptor')
    desc = a.fdu.onboard(fdu_d)
    e_uuid = desc.get_uuid()
    input('Press enter to instantiate')
    rec = a.fdu.instantiate(e_uuid, n1)
    intsid = rec.get_uuid()
    input('Press enter to create router')
    a.network.add_router(n1, router_d)

    # input("press enter to add router port")
    # res = a.network.add_router_port(n1, r_uuid, "INTERNAL", "6cc2aa30-1dcf-4c93-a57e-433fd0bd498e", "192.168.234.1/24")
    # print(res)

    # input("press enter to remove router port")
    # res = a.network.remove_router_port(n1, r_uuid, "6cc2aa30-1dcf-4c93-a57e-433fd0bd498e")
    # print(res)

    # input('Press enter to stop')
    # a.entity.stop(e_uuid, n1, i_uuid)
    # input('Press enter to clean')
    # a.entity.clean(e_uuid, n1, i_uuid)
    # input('Press enter to undefine')
    # a.entity.undefine(e_uuid, n1)

    # input('Press enter to migrate')

    #res = a.entity.migrate(e_uuid, i_uuid, n1, n2)
    #print('Res is: {}'.format(res))
    input('Press enter to remove')

    a.fdu.terminate(intsid)
    a.fdu.offload(e_uuid)
    input('Press enter to remove router')
    a.network.remove_router(n1, r_uuid)
    input("Press enter to remove network")
    a.network.remove_network(n_uuid)

    exit(0)
Ejemplo n.º 25
0
def consumer(ip, fdufile, netfile):
    # Access the fog05 domain web socket
    a = FIMAPI(ip)
    # Get the nodes from the domain
    nodes = a.node.list()
    if len(nodes) == 0:
        print('No nodes')
        exit(-1)
    # Print the nodes from the domain
    print('Nodes:')
    for n in nodes:
        print('UUID: {}'.format(n))

    # Load the FDU (descriptors)
    fdu_d = FDU(json.loads(read_file(fdufile)))
    # Load the network descriptor
    net_d = json.loads(read_file(netfile))
    n_uuid = net_d.get('uuid')

    # Create network based on the descriptor
    input("Press enter to create network")
    a.network.add_network(net_d)
    # Get info if the network is created
    net_info = get_net_info(a, net_d['uuid'])
    print('Net info {}'.format(net_info))

    # Add the created network to the node (n1)
    input('press enter to network creation')
    a.network.add_network_to_node(net_info['uuid'], n1)

    #  On-board the FDU
    input('press enter to onboard descriptor')
    res = a.fdu.onboard(fdu_d)
    # Get the identifier of the on-boarded FDU
    e_uuid = res.get_uuid()
    # Define an instance of the on-boarded FDU
    input('Press enter to define')
    inst_info = a.fdu.define(e_uuid)
    # Get the ID of the defined FDU instance
    print(inst_info.to_json())
    instid = inst_info.get_uuid()

    # Configure the defined FDU instance
    input('Press enter to configure')
    a.fdu.configure(instid)

    # Start the configured FDU instance
    input('Press enter to start')
    a.fdu.start(instid)
    # Get the info of the started FDU instance
    input('Press get info')
    info = a.fdu.instance_info(instid)
    print(info.to_json())

    ########## FEDERATION STARTS HERE ###########################################################
    debug_txt = input("\nUse service_id:")
    service_id = debug_txt
    print(net_d)
    # net_d = {"uuid": "6cc2aa30-1dcf-4c93-a57e-433fd0bd498e",\
    #         "name": "net1",\
    #         "net_type": "ELAN",\
    #         "is_mgmt": False
    #         }

    print("\nSERVICE_ID:", service_id)
    debug_txt = input("\nCreate Service anouncement....(ENTER)")
    start = time.time()
    bids_event = AnnounceService(net_d, service_id)
    bidderArrived = False
    while bidderArrived == False:
        new_events = bids_event.get_all_entries()
        for event in new_events:
            event_id = str(web3.toText(event['args']['_id']))
            print(service_id, web3.toText(event['args']['_id']),
                  event['args']['max_bid_index'])
            #if event_id == web3.toText(text= service_id):
            bid_index = int(event['args']['max_bid_index'])
            bidderArrived = True
            if int(bid_index) < 2:
                bid_info = GetBidInfo(int(bid_index - 1), service_id)
                print(bid_info)
                ChooseProvider(int(bid_index) - 1, service_id)
                break
    serviceDeployed = False
    while serviceDeployed == False:
        serviceDeployed = True if GetServiceState(service_id) == 2 else False
    serviceDeployedInfo = GetServiceInfo(service_id, False)
    end = time.time()
    print(serviceDeployedInfo)
    print("SERVICE FEDERATED!")
    print("Time it took:", int(end - start))
    ########## FEDERATION FINISH HERE ###########################################################

    input('Press enter to terminate')
    a.fdu.terminate(instid)
    a.fdu.offload(e_uuid)
    input("Press enter to remove network")
    a.network.remove_network_from_node(n_uuid, n1)
    a.network.remove_network(n_uuid)

    exit(0)
import json
import time
from fog05 import FIMAPI
from fog05_sdk.interfaces.FDU import FDU

BROKER_IP = '192.168.31.232'


def read_file(filepath):
    with open(filepath, 'r') as f:
        data = f.read()
    return data


api = FIMAPI(BROKER_IP)
uuid_fisso = '01369aac-9965-4277-96c0-280cf007e953'
uuid_portatile = '9806ff42-cecc-48c1-9f44-da51955d4732'

desc = json.loads(read_file('./fdu_migra_rel.json'))

fdu_descriptor = FDU(desc)
fduD = api.fdu.onboard(fdu_descriptor)
fdu_id = fduD.get_uuid()
print('fdu_id: {}'.format(fdu_id))

# local-node specific section
inst_info = api.fdu.define(fdu_id, '01369aac-9965-4277-96c0-280cf007e953')
api.fdu.configure(inst_info.get_uuid())
api.fdu.start(inst_info.get_uuid(),
              "sleep_period=10,iterations=60,env_output=state_test_f")
Ejemplo n.º 27
0
def main(ip, ip2, fdufile, fdu2, netfile):
    a = FIMAPI(ip)

    a2 = FIMAPI(ip2)

    nodes = a.node.list()
    if len(nodes) == 0:
        print('No nodes')
        exit(-1)

    print('Nodes:')
    for n in nodes:
        print('UUID: {}'.format(n))

    fdu_d = FDU(json.loads(read_file(fdufile)))
    second_fdu_d = FDU(json.loads(read_file(fdu2)))

    net_d = json.loads(read_file(netfile))

    n_uuid = net_d.get('uuid')

    n1 = 'dc02633d-491b-40b3-83be-072748142fc4'  #fog02
    n2 = '1e03d6b9-908e-44e6-9fc2-3282e38c442d'  #fog01

    input("Press enter to create network")
    a.network.add_network(net_d)
    net_info = get_net_info(a, net_d['uuid'])
    print('Net info {}'.format(net_info))

    input('press enter to network creation')
    a.network.add_network_to_node(net_info['uuid'], n1)

    input('press enter to onboard descriptor')
    res = a.fdu.onboard(fdu_d)
    e_uuid = res.get_uuid()
    input('Press enter to define')
    inst_info = a.fdu.define(e_uuid)
    print(inst_info.to_json())
    instid = inst_info.get_uuid()

    input('Press enter to configure')
    a.fdu.configure(instid)

    input('Press enter to start')
    a.fdu.start(instid)

    # input('press enter to onboard second descriptor')
    # res = a.fdu.onboard(second_fdu_d)
    # s_e_uuid = res.get_uuid()
    # input('Press enter to define')
    # s_inst_info = a.fdu.define(s_e_uuid)
    # print(s_inst_info.to_json())
    # s_instid = s_inst_info.get_uuid()

    # input('Press enter to configure')
    # a.fdu.configure(s_instid)

    # input('Press enter to start')
    # a.fdu.start(s_instid)

    # input('Press enter to stop')
    # a.entity.stop(e_uuid, n1, i_uuid)
    # input('Press enter to clean')
    # a.entity.clean(e_uuid, n1, i_uuid)
    # input('Press enter to undefine')
    # a.entity.undefine(e_uuid, n1)

    # input('Press enter to migrate')
    input('Press get info')
    info = a.fdu.instance_info(instid)
    print(info.to_json())

    # input('Press get info')
    # info = a.fdu.instance_info(s_instid)
    # print(info.to_json())

    input('Press to move client to second domain')
    net_info = get_net_info(a, net_d['uuid'])
    input('Press to create federated vxlan to second domain')
    a2.network.add_network(net_info)

    net_info2 = get_net_info(a2, net_info['uuid'])
    print('Net info {}'.format(net_info2))
    a2.network.add_network_to_node(net_info2['uuid'], n2)

    # input('remove client from first domain')
    # a.fdu.terminate(s_instid)
    # a.fdu.offload(s_e_uuid)

    input('press enter to onboard second descriptor')
    res = a2.fdu.onboard(second_fdu_d)
    s_e_uuid = res.get_uuid()
    input('Press enter to define')
    s_inst_info = a2.fdu.define(s_e_uuid)
    print(s_inst_info.to_json())
    s_instid = s_inst_info.get_uuid()

    input('Press enter to configure')
    a2.fdu.configure(s_instid)

    input('Press enter to start')
    a2.fdu.start(s_instid)

    input('Press get info')
    info = a2.fdu.instance_info(s_instid)
    print(info.to_json())

    #res = a.entity.migrate(e_uuid, i_uuid, n1, n2)
    #print('Res is: {}'.format(res))
    input('Press enter to terminate')

    a.fdu.terminate(instid)
    a.fdu.offload(e_uuid)
    a2.fdu.terminate(s_instid)
    a2.fdu.offload(s_e_uuid)
    input("Press enter to remove network")
    a.network.remove_network_from_node(n_uuid, n1)
    a.network.remove_network(n_uuid)

    exit(0)
Ejemplo n.º 28
0
def provider(ip, fdufile, netfile):
    a = FIMAPI(ip)
    a2 = FIMAPI('163.117.139.226')
    # Get the nodes from the domain
    nodes = a.node.list()
    if len(nodes) == 0:
        print('No nodes')
        exit(-1)
    # Print the nodes from the domain
    print('Nodes:')
    for n in nodes:
        print('UUID: {}'.format(n))

    # Load the FDU (descriptors)
    fdu_d = FDU(json.loads(read_file(fdufile)))

    debug_txt = input("\nBegin listening?")
    service_id = ''
    print("\nSERVICE_ID:", service_id)
    debug_txt = input("\nStart listening for federation events....(ENTER)")
    newService_event = ServiceAnnouncementEvent()
    newService = False
    open_services = []
    print("Waiting for federation event....")
    while newService == False:
        new_events = newService_event.get_all_entries()
        for event in new_events:
            service_id = web3.toText(event['args']['id'])
            if GetServiceState(service_id) == 0:
                open_services.append(service_id)
        if len(open_services) > 0:
            print("OPEN = ", len(open_services))
            newService = True
    service_id = open_services[-1]
    winnerChosen_event = PlaceBid(service_id)
    winnerChosen = False
    while winnerChosen == False:
        new_events = winnerChosen_event.get_all_entries()
        for event in new_events:
            event_serviceid = web3.toText(event['args']['_id'])
            if event_serviceid == service_id:
                winnerChosen = True
                break
    am_i_winner = CheckWinner(service_id)
    if am_i_winner == True:
        net_d = GetServiceInfo(service_id, True)
        ########## FEDERATED SERVICE DEPLOYEMENT HERE ###########################################################
        print(net_d)
        if net_d['uuid'] == "6cc2aa30-1dcf-4c93-a57e-433fd0bd498e":
            print("UUID match")
        else:
            print("UUID does not match")

        # Create network based on the descriptor
        # input("Press enter to create network")
        # Get info if the network is created
        print(net_d['uuid'])
        print(a2.network.list())
        net_info = get_net_info(a2, net_d['uuid'])
        print('Net info {}'.format(net_info))

        a.network.add_network(net_info)
        # Add the created network to the node (n1)
        input('press enter to network creation')
        a.network.add_network_to_node(net_info['uuid'], n2)

        #  On-board the FDU
        input('press enter to onboard descriptor')
        res = a.fdu.onboard(fdu_d)
        # Get the identifier of the on-boarded FDU
        e_uuid = res.get_uuid()
        # Define an instance of the on-boarded FDU
        input('Press enter to define')
        inst_info = a.fdu.define(e_uuid)
        # Get the ID of the defined FDU instance
        print(inst_info.to_json())
        instid = inst_info.get_uuid()

        # Configure the defined FDU instance
        input('Press enter to configure')
        a.fdu.configure(instid)

        # Start the configured FDU instance
        input('Press enter to start')
        a.fdu.start(instid)
        # Get the info of the started FDU instance
        input('Press get info')
        info = a.fdu.instance_info(instid)
        print(info.to_json())

        ######################### UNTIL HERE ####################################################################
        ServiceDeployed(service_id)
    else:
        print("I am not a Winner")

    input('Press enter to terminate')

    a.fdu.terminate(instid)
    a.fdu.offload(e_uuid)
    exit(0)
Ejemplo n.º 29
0
import json
import time
from fog05 import FIMAPI
from fog05_sdk.interfaces.FDU import FDU


def read_file(filepath):
    with open(filepath, 'r') as f:
        data = f.read()
    return data


api = FIMAPI('192.168.31.232')
uuid_fisso = '01369aac-9965-4277-96c0-280cf007e953'
uuid_portatile = '9806ff42-cecc-48c1-9f44-da51955d4732'

descs = json.loads(read_file("./system.json"))
for label in descs["devices"]:
    print(label)
    print(descs["devices"][label])
    desc = json.loads(read_file("./" + descs["devices"][label]["desc"]))
    fdu_descriptor = FDU(desc)
    fduD = api.fdu.onboard(fdu_descriptor)
    fdu_id = fduD.get_uuid()
    inst_info = api.fdu.define(fdu_id, '9806ff42-cecc-48c1-9f44-da51955d4732')
    descs["devices"][label]["nuuid"] = uuid_portatile
    descs["devices"][label]["fuuid"] = fdu_id
    descs["devices"][label]["iuuid"] = inst_info.get_uuid()
    api.fdu.configure(inst_info.get_uuid())
    # env = "nuuid=" + uuid_portatile + \
    #       "fuuid=" + fdu_id + \
Ejemplo n.º 30
0
def main(ip, fdufile, netfile, routerfile):
    a = FIMAPI(ip)

    nodes = a.node.list()
    if len(nodes) == 0:
        print('No nodes')
        exit(-1)

    print('Nodes:')
    for n in nodes:
        print('UUID: {}'.format(n))

    fdu_d = FDU(json.loads(read_file(fdufile)))
    net_d = json.loads(read_file(netfile))
    router_d = json.loads(read_file(routerfile))

    # e_uuid = fdu_d.get('uuid')
    n_uuid = net_d.get('uuid')
    r_uuid = router_d.get('uuid')

    input("Press enter to create network")
    a.network.add_network(net_d)


    #n1 = 'a2d358aa-af2b-42cb-8d23-a89e88b97e5c' #fosmed
    n1 = '4a560914-1c3e-4966-9fa8-7f0acc903253' #nuc
    #n1 = 'a4589fae-0493-40cf-b976-2d03020d060d' #foskvm
    # n1 = '53712df2-9649-4a21-be2e-80eed00ff9ce' #ubuntuvm1
    # n1 = 'de8c2f1c-9414-48ec-8400-a324cb1e6612' #ubuntuvm2
    # n1 = 'd07b095f-7948-4f9b-95cc-c61029f6c3c3' #fosdbg

    input('press enter to onboard descriptor')
    desc = a.fdu.onboard(fdu_d)
    e_uuid = desc.get_uuid()
    input('Press enter to instantiate')
    rec = a.fdu.instantiate(e_uuid, n1)
    intsid = rec.get_uuid()
    input('Press enter to create router')
    a.network.add_router(n1, router_d)


    # input("press enter to add router port")
    # res = a.network.add_router_port(n1, r_uuid, "INTERNAL", "6cc2aa30-1dcf-4c93-a57e-433fd0bd498e", "192.168.234.1/24")
    # print(res)

    # input("press enter to remove router port")
    # res = a.network.remove_router_port(n1, r_uuid, "6cc2aa30-1dcf-4c93-a57e-433fd0bd498e")
    # print(res)

    # input('Press enter to stop')
    # a.entity.stop(e_uuid, n1, i_uuid)
    # input('Press enter to clean')
    # a.entity.clean(e_uuid, n1, i_uuid)
    # input('Press enter to undefine')
    # a.entity.undefine(e_uuid, n1)

    # input('Press enter to migrate')

    #res = a.entity.migrate(e_uuid, i_uuid, n1, n2)
    #print('Res is: {}'.format(res))
    input('Press enter to remove')

    a.fdu.terminate(intsid)
    a.fdu.offload(e_uuid)
    input('Press enter to remove router')
    a.network.remove_router(n1, r_uuid)
    input("Press enter to remove network")
    a.network.remove_network(n_uuid)

    exit(0)