def intercloudGW_stop(intercloudGW):
    response = respAction("200", "ok")
    """Implement here your function"""
    print(
        '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
    print(
        '                Receiving action STOP intercloudGW                  ')
    #------------------------------------------------linkgw------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    """ Determine server which handle linkgw category """
    attributePUB = {'what': 'linkgw'}
    client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication',
                        attributePUB)
    publication = client.GetElement_pathuuid(client.Get()[0])
    client.host = publication['host']
    client.port = publication['port']
    publication = client.GetElement_pathuuid(
        client.GetElement(publication['uuid'])['occi.publication.why'])

    attribute = {
        'intercloudGW': intercloudGW.node,
        'state': '1',
    }
    conetsOCCI = OCCIclient(publication['host'], publication['port'],
                            'CO-NETS-PAAS', 'linkgw', attribute)
    listInstance = conetsOCCI.Get()

    for item in listInstance:
        linkgws = conetsOCCI.GetElement_pathuuid(item)
        conetsOCCI.host = linkgws['host']
        conetsOCCI.port = linkgws['port']
        conetsOCCI.category = linkgws['category']
        linkgws = conetsOCCI.GetElement(linkgws['uuid'])
        print('Sending STOP to linkgw')
        conetsOCCI.action(linkgws['occi.core.id'], 'stop')

    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    tempintercloudGW = {
        'name': intercloudGW.name,
        'node': intercloudGW.node,
        'account': intercloudGW.account,
        'price': intercloudGW.price,
        'state': intercloudGW.state,
    }
    attribute = {
        'state': '0',
    }
    conetsOCCI.category = 'intercloudGW'
    conetsOCCI.attributes = tempintercloudGW

    uuidintercloudGW = conetsOCCI.Get()
    conetsOCCI.attributes = attribute
    conetsOCCI.Put(conetsOCCI.GetElement_pathuuid(uuidintercloudGW[0])['uuid'])
    print('Changing the state of the intercloudGW to 0')

    return response
예제 #2
0
def linkgw_start(linkgw):
    response = respAction("200", "ok")
    """Implement here your function"""
    print(
        '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
    print(
        '                 Receiving action START linkgw                      ')

    #---------------------------------------------------gw-------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    """ Determine server which handle gw category """
    attributePUB = {'what': 'gw'}

    client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication',
                        attributePUB)
    publication = client.GetElement_pathuuid(client.Get()[0])
    client.host = publication['host']
    client.port = publication['port']
    publication = client.GetElement_pathuuid(
        client.GetElement(publication['uuid'])['occi.publication.why'])

    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    attribute = {}
    conetsOCCI = OCCIclient(publication['host'], publication['port'],
                            'CO-NETS-PAAS', 'gw', attribute)

    #--------------------------------------------uuid gw src-----------------------------------------------------------#
    gwsrc = conetsOCCI.GetElement_pathuuid(linkgw.gwsrc)
    addressgwsrc = conetsOCCI.GetElement(gwsrc['uuid'])
    publicaddrgwsrc = addressgwsrc['occi.gw.publicaddr']
    privateaddrgwsrc = addressgwsrc['occi.gw.privateaddr']
    ethernamegwsrc = addressgwsrc['occi.gw.ethername']

    #--------------------------------------------uuid gw dst-----------------------------------------------------------#
    gwdst = conetsOCCI.GetElement_pathuuid(linkgw.gwdst)
    addressgwdst = conetsOCCI.GetElement(gwdst['uuid'])
    publicaddrgwdst = addressgwdst['occi.gw.publicaddr']
    privateaddrgwdst = addressgwdst['occi.gw.privateaddr']
    ethernamegwdst = addressgwdst['occi.gw.ethername']
    #-----------------------------start gateway source and gateway destination-----------------------------------------#

    print('Sending START to gateway source')
    conetsOCCI.action(gwsrc['uuid'], 'start')
    print('Sending START to gateway destination')
    conetsOCCI.action(gwdst['uuid'], 'start')

    #-------------------------------------------------contract---------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    """ Determine server which handle contract category """
    attributePUB = {'what': 'contract'}

    client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication',
                        attributePUB)
    publication = client.GetElement_pathuuid(client.Get()[0])
    client.host = publication['host']
    client.port = publication['port']
    publication = client.GetElement_pathuuid(
        client.GetElement(publication['uuid'])['occi.publication.why'])

    attribute = {}
    client = OCCIclient(publication['host'], publication['port'], 'CO-PARSER',
                        'contract', attribute)

    endpointsrc = client.GetElement(
        client.GetElement_pathuuid(linkgw.endpointsrc)['uuid'])
    endpointdst = client.GetElement(
        client.GetElement_pathuuid(linkgw.endpointdst)['uuid'])

    #-------------------------------------------------provider gwsrc---------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    """ Determine server which handle procci provider category """
    attributePUB = {'what': endpointsrc['occi.contract.profile']}

    client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication',
                        attributePUB)
    publication = client.GetElement_pathuuid(client.Get()[0])
    client.host = publication['host']
    client.port = publication['port']
    publication = client.GetElement_pathuuid(
        client.GetElement(publication['uuid'])['occi.publication.why'])

    attribute = {}
    client = OCCIclient(publication['host'], publication['port'], 'CO-PARSER',
                        endpointsrc['occi.contract.profile'], attribute)

    #print endpointsrc['occi.contract.provider']
    privateaddrvmsrc = client.GetElement(
        client.GetElement_pathuuid(
            endpointsrc['occi.contract.provider'])['uuid'])
    privateaddrvmsrc = privateaddrvmsrc['occi.' +
                                        endpointsrc['occi.contract.profile'] +
                                        '.privateaddr']

    #-------------------------------------------------provider gwdst---------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    """ Determine server which handle procci provider category """
    attributePUB = {'what': endpointdst['occi.contract.profile']}

    client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication',
                        attributePUB)
    publication = client.GetElement_pathuuid(client.Get()[0])
    client.host = publication['host']
    client.port = publication['port']
    publication = client.GetElement_pathuuid(
        client.GetElement(publication['uuid'])['occi.publication.why'])

    attribute = {}
    client = OCCIclient(publication['host'], publication['port'], 'CO-PARSER',
                        endpointdst['occi.contract.profile'], attribute)

    #print endpointdst['occi.contract.provider']
    privateaddrvmdst = client.GetElement(
        client.GetElement_pathuuid(
            endpointdst['occi.contract.provider'])['uuid'])
    privateaddrvmdst = privateaddrvmdst['occi.' +
                                        endpointdst['occi.contract.profile'] +
                                        '.privateaddr']

    gwsrc = gwProcci()
    gwdst = gwProcci()

    templist = privateaddrvmsrc.split('.')
    templist[3] = '0/24'
    privateaddrvmsrc = '.'.join(templist)
    #print privateaddrvmsrc

    templist = privateaddrvmdst.split('.')
    templist[3] = '0/24'
    privateaddrvmdst = '.'.join(templist)
    #print privateaddrvmdst
    ''' Configuration des gateways'''
    gwsrc.configure_protocol_IPSEC(gwsrc, publicaddrgwsrc, ethernamegwsrc,
                                   'IKEgwsrc', 'ESPgwsrc')
    gwdst.configure_protocol_IPSEC(gwdst, publicaddrgwdst, ethernamegwdst,
                                   'IKEgwdst', 'ESPgwdst')
    ''' Connecte les deux gateways'''
    gwsrc.connect_gw(gwsrc, linkgw.addressgresrc, linkgw.prefix,
                     linkgw.tunnelproto, publicaddrgwsrc, publicaddrgwdst,
                     linkgw.authenticationkey, linkgw.addressgredst,
                     privateaddrvmdst)
    gwsrc.connect_gw(gwsrc, linkgw.addressgredst, linkgw.prefix,
                     linkgw.tunnelproto, publicaddrgwdst, publicaddrgwsrc,
                     linkgw.authenticationkey, linkgw.addressgresrc,
                     privateaddrvmsrc)

    return response
예제 #3
0
def linkgw_stop(linkgw):
    response = respAction("200", "ok")
    """Implement here your function"""
    print(
        '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
    print(
        '                   Receiving action STOP linkgw                     ')

    #---------------------------------------------------gw-------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    """ Determine server which handle gw category """
    attributePUB = {'what': 'gw'}

    client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication',
                        attributePUB)
    publication = client.GetElement_pathuuid(client.Get()[0])
    client.host = publication['host']
    client.port = publication['port']
    publication = client.GetElement_pathuuid(
        client.GetElement(publication['uuid'])['occi.publication.why'])

    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    attribute = {}
    gwOCCI = OCCIclient(publication['host'], publication['port'], 'CO-PARSER',
                        'gw', attribute)

    #--------------------------------------------uuid gw src-----------------------------------------------------------#
    gwsrc = gwOCCI.GetElement_pathuuid(linkgw.gwsrc)
    #--------------------------------------------uuid gw dst-----------------------------------------------------------#
    gwdst = gwOCCI.GetElement_pathuuid(linkgw.gwdst)
    #------------------------------stop gateway source and gateway destination-----------------------------------------#
    print('Sending STOP to gateway source')
    gwOCCI.action(gwsrc['uuid'], 'stop')
    print('Sending STOP to gateway destination')
    gwOCCI.action(gwdst['uuid'], 'stop')

    templinkgw = {
        'name': linkgw.name,
        'intercloudGW': linkgw.intercloudGW,
        'account': linkgw.account,
        'gwsrc': linkgw.gwsrc,
        'gwdst': linkgw.gwdst,
        'tunnelproto': linkgw.tunnelproto,
        'addressgresrc': linkgw.addressgresrc,
        'addressgredst': linkgw.addressgredst,
        'prefix': linkgw.prefix,
        'authenticationkey': linkgw.authenticationkey,
        'endpointsrc': linkgw.endpointsrc,
        'endpointdst': linkgw.endpointdst,
        'state': linkgw.state,
    }

    gwOCCI.category = 'linkgw'
    gwOCCI.attributes = templinkgw

    uuidlinkgw = gwOCCI.Get()
    uuidlinkgw = gwOCCI.GetElement_pathuuid(uuidlinkgw[0])['uuid']

    attribute = {
        'state': '0',
    }

    gwOCCI.attributes = attribute
    gwOCCI.Put(uuidlinkgw)
    print('Changing the state of the link gateway to 0')

    return response
def intercloudGW_start(intercloudGW):
    response = respAction("200", "ok")
    """Implement here your function"""
    print(
        '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
    print(
        '                Receiving action START intercloudGW                 ')

    #---------------------------------------------------intercloudGW---------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    """ Determine server which handle intercloudGW category """
    attributePUB = {'what': 'intercloudGW'}

    client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication',
                        attributePUB)
    publication = client.GetElement_pathuuid(client.Get()[0])
    client.host = publication['host']
    client.port = publication['port']
    publication = client.GetElement_pathuuid(
        client.GetElement(publication['uuid'])['occi.publication.why'])

    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#

    tempintercloudGW = {
        'name': intercloudGW.name,
        'node': intercloudGW.node,
        'account': intercloudGW.account,
        'price': intercloudGW.price,
        'state': intercloudGW.state,
    }

    gwOCCI = OCCIclient(publication['host'], publication['port'],
                        'CO-NETS-PAAS', 'intercloudGW', tempintercloudGW)

    uuidintercloudGW = gwOCCI.Get()[0].replace(' ', '')

    #-------------------------------------------------contract---------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    """ Determine server which handle contract category """
    attributePUB = {'what': 'contract'}

    client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication',
                        attributePUB)
    publication = client.GetElement_pathuuid(client.Get()[0])
    client.host = publication['host']
    client.port = publication['port']
    publication = client.GetElement_pathuuid(
        client.GetElement(publication['uuid'])['occi.publication.why'])

    attribute = {
        'provider': uuidintercloudGW,
        'profile': 'intercloudGW',
        'node': intercloudGW.node,
    }
    client = OCCIclient(publication['host'], publication['port'], 'CO-PARSER',
                        'contract', attribute)
    listinstruction = client.GetLinks(
        client.GetElement_pathuuid(client.Get()[0])['uuid'])
    #print listinstruction

    #------------------------------------------------Instruction-------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    """ Determine server which handle instruction category """
    attributePUB = {'what': 'instruction'}

    client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication',
                        attributePUB)
    publication = client.GetElement_pathuuid(client.Get()[0])
    client.host = publication['host']
    client.port = publication['port']
    publication = client.GetElement_pathuuid(
        client.GetElement(publication['uuid'])['occi.publication.why'])

    attribute = {}
    client = OCCIclient(publication['host'], publication['port'], 'CO-PARSER',
                        'instruction', attribute)

    listNodeToConnect = []
    for item in listinstruction:
        nodetoConnect = client.GetElement_pathuuid(item)
        client.host = nodetoConnect['host']
        client.port = nodetoConnect['port']
        client.category = nodetoConnect['category']
        listNodeToConnect.append(
            client.GetElement(
                nodetoConnect['uuid'])['occi.instruction.source'])

    listlinkgw = []
    for i in range(len(listNodeToConnect)):
        for j in range(i + 1, len(listNodeToConnect)):
            listlinkgw.append({
                'name': intercloudGW.name,
                'intercloudGW': intercloudGW.node,
                'account': intercloudGW.account,
                'gwsrc': '',
                'gwdst': '',
                'tunnelproto': 'gre',
                'addressgresrc': '10.3.3.1',
                'addressgredst': '10.3.3.2',
                'prefix': '30',
                'authenticationkey': 'test_key_1',
                'endpointsrc': listNodeToConnect[i],
                'endpointdst': listNodeToConnect[j],
                'state': '0',
            })

    #------------------------------------------------linkgw------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    """ Determine server which handle linkgw category """
    attributePUB = {'what': 'linkgw'}
    client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication',
                        attributePUB)
    publication = client.GetElement_pathuuid(client.Get()[0])
    client.host = publication['host']
    client.port = publication['port']
    publication = client.GetElement_pathuuid(
        client.GetElement(publication['uuid'])['occi.publication.why'])

    listuuidlinkgw = []
    for i in listlinkgw:
        conetsOCCI = OCCIclient(publication['host'], publication['port'],
                                'CO-NETS-PAAS', 'linkgw', i)
        uuidlinkgw = conetsOCCI.GetElement_pathuuid(conetsOCCI.Post())['uuid']
        listuuidlinkgw.append(uuidlinkgw)
        print('Sending Post to linkgw')

    for item in listuuidlinkgw:
        print('Sending START to linkgw')
        conetsOCCI.action(item, 'start')

    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    tempintercloudGW = {
        'name': intercloudGW.name,
        'node': intercloudGW.node,
        'account': intercloudGW.account,
        'price': intercloudGW.price,
        'state': intercloudGW.state,
    }
    attribute = {
        'state': '1',
    }
    conetsOCCI.category = 'intercloudGW'
    conetsOCCI.attributes = tempintercloudGW

    uuidintercloudGW = conetsOCCI.Get()
    conetsOCCI.attributes = attribute
    conetsOCCI.Put(conetsOCCI.GetElement_pathuuid(uuidintercloudGW[0])['uuid'])
    print('Changing the state of the intercloudGW to 1')

    return response
예제 #5
0
def linkgw_create(linkgw):
    """Implement here your function"""
    print(
        '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
    print(
        '                       Receiving POST linkgw                        ')

    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    attribute = {}
    client = OCCIclient(' ', ' ', ' ', ' ', attribute)
    parametersrc = client.GetElement_pathuuid(linkgw.endpointsrc)
    client.host = parametersrc['host']
    client.port = parametersrc['port']
    client.category = parametersrc['category']
    client.GetElement(parametersrc['uuid'])
    providergwsrc = client.GetElement(
        parametersrc['uuid'])['occi.contract.profile']
    print('The gw source provider is: ' + providergwsrc)

    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    parameterdst = client.GetElement_pathuuid(linkgw.endpointdst)
    client.host = parameterdst['host']
    client.port = parameterdst['port']
    client.category = parameterdst['category']
    client.GetElement(parameterdst['uuid'])
    providergwdst = client.GetElement(
        parameterdst['uuid'])['occi.contract.profile']
    print('The gw destination provider is: ' + providergwdst)
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#

    #----------------------------------------------------gw------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    """ Determine server which handle linkgw category """
    attributePUB = {'what': 'gw'}
    client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication',
                        attributePUB)
    publication = client.GetElement_pathuuid(client.Get()[0])
    client.host = publication['host']
    client.port = publication['port']
    publication = client.GetElement_pathuuid(
        client.GetElement(publication['uuid'])['occi.publication.why'])

    attribute = {'provider_type': providergwsrc}
    client = OCCIclient(publication['host'], publication['port'],
                        'CO-NET-PAAS', 'gw', attribute)
    listInstance = client.Get()
    if len(listInstance) == 0:
        gw = {
            'name': linkgw.name,
            'publicaddr': '',
            'privateaddr': '',
            'ethername': 'eth0',
            'intercloudGW': linkgw.intercloudGW,
            'contract': '',
            'provider_type': providergwsrc,
            'provider_platform': '',
            'connection': '1',
            'account': linkgw.account,
            'state': '0',
        }
        client.attributes = gw
        print('Creating the first gateway in the ' + providergwsrc +
              ' provider')
        linkgw.gwsrc = client.Post()
    else:
        #---------------------------Incremente the number of connection in gwsrc-------------------------------------------#
        #------------------------------------------------------------------------------------------------------------------#
        linkgw.gwsrc = listInstance[0]
        gwsrc = client.GetElement_pathuuid(listInstance[0])
        client.host = gwsrc['host']
        client.port = gwsrc['port']
        client.category = gwsrc['category']
        client.GetElement(gwsrc['uuid'])
        nbconnection = client.GetElement(gwsrc['uuid'])['occi.gw.connection']
        print('The number of connection in gateway source is: ' +
              str(int(nbconnection) + 1))
        attributes = {'connection': str(int(nbconnection) + 1)}
        client.attributes = attributes
        client.Put(gwsrc['uuid'])
        print('Incrementing the number of connection in gateway source')
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    attribute = {'provider_type': providergwdst}
    client = OCCIclient(publication['host'], publication['port'],
                        'CO-NET-PAAS', 'gw', attribute)
    listInstance = client.Get()
    if len(listInstance) == 0:
        gw = {
            'name': linkgw.name,
            'publicaddr': '',
            'privateaddr': '',
            'ethername': 'eth0',
            'intercloudGW': linkgw.intercloudGW,
            'contract': '',
            'provider_type': providergwdst,
            'provider_platform': '',
            'connection': '1',
            'account': linkgw.account,
            'state': '0',
        }
        client.attributes = gw
        linkgw.gwdst = client.Post()
        print('Creating the first gateway in the ' + providergwdst +
              ' provider')

    else:
        #---------------------------Incremente the number of connection in gwdst-------------------------------------------#
        #------------------------------------------------------------------------------------------------------------------#
        linkgw.gwdst = listInstance[0]
        gwdst = client.GetElement_pathuuid(listInstance[0])
        client.host = gwdst['host']
        client.port = gwdst['port']
        client.category = gwdst['category']
        client.GetElement(gwdst['uuid'])
        nbconnection = client.GetElement(gwdst['uuid'])['occi.gw.connection']
        print('The number of connection in gateway destination is: ' +
              str(int(nbconnection) + 1))
        attributes = {'connection': str(int(nbconnection) + 1)}
        client.attributes = attributes
        client.Put(gwdst['uuid'])
        print('Incrementing the number of connection in gateway destination')
    linkgw.state = '1'

    return linkgw
예제 #6
0
def gw_create(gw):
    """Implement here your function"""
    """Implement here your function"""
    print(
        '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
    print(
        '                         Receiving POST gw                          ')

    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    attribute = {}
    client = OCCIclient('', '', 'CO-PROCCI', '', attribute)
    node = client.GetElement_pathuuid(gw.intercloudGW)
    client.host = node['host']
    client.port = node['port']
    client.category = node['category']
    node = client.GetElement(node['uuid'])
    infrastructure = node['occi.node.infrastructure']
    image = node['occi.node.image']
    firewall = node['occi.node.firewall']
    accsessnode = node['occi.node.access']
    scopenode = node['occi.node.scope']
    typenode = node['occi.node.type']

    infra = client.GetElement_pathuuid(infrastructure)
    client.host = infra['host']
    client.port = infra['port']
    client.category = infra['category']
    infra = client.GetElement(infra['uuid'])

    img = client.GetElement_pathuuid(image)
    client.host = img['host']
    client.port = img['port']
    client.category = img['category']
    img = client.GetElement(img['uuid'])

    fire = client.GetElement_pathuuid(firewall)
    client.host = fire['host']
    client.port = fire['port']
    client.category = fire['category']
    fire = client.GetElement(fire['uuid'])

    #-------------------------------------------Infrastructure---------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    compute = infra['occi.infrastructure.compute']
    compute = client.GetElement_pathuuid(compute)
    client.host = compute['host']
    client.port = compute['port']
    client.category = compute['category']
    compute = client.GetElement(compute['uuid'])
    #------------------------------------------------------------------------------------------------------------------#
    """ Determine server which handle compute category """
    attributePUB = {'what': 'compute'}
    client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication',
                        attributePUB)
    publication = client.GetElement_pathuuid(client.Get()[0])
    client.host = publication['host']
    client.port = publication['port']
    publication = client.GetElement_pathuuid(
        client.GetElement(publication['uuid'])['occi.publication.why'])

    archi = compute['occi.compute.architecture']
    tempdict = {
        'name': gw.name,
        'architecture': archi,
        'cores': compute['occi.compute.cores'],
        'speed': compute['occi.compute.speed'],
        'memory': compute['occi.compute.memory']
    }
    testPost = OCCIclient(publication['host'], publication['port'],
                          'CO-PROCCI', 'compute', tempdict)
    compute = testPost.Post()
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    network = infra['occi.infrastructure.network']
    network = client.GetElement_pathuuid(network)
    client.host = network['host']
    client.port = network['port']
    client.category = network['category']
    network = client.GetElement(network['uuid'])
    #------------------------------------------------------------------------------------------------------------------#
    """ Determine server which handle network category """
    attributePUB = {'what': 'network'}
    client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication',
                        attributePUB)
    publication = client.GetElement_pathuuid(client.Get()[0])
    client.host = publication['host']
    client.port = publication['port']
    publication = client.GetElement_pathuuid(
        client.GetElement(publication['uuid'])['occi.publication.why'])

    tempdict = {
        'name': network['occi.network.name'],
        'label': network['occi.network.label'],
        'vlan': network['occi.network.vlan']
    }
    testPost = OCCIclient(publication['host'], publication['port'], 'CO-NETS',
                          'network', tempdict)
    network = testPost.Post()
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    storage = infra['occi.infrastructure.storage']
    storage = client.GetElement_pathuuid(storage)
    client.host = storage['host']
    client.port = storage['port']
    client.category = storage['category']
    storage = client.GetElement(storage['uuid'])
    #------------------------------------------------------------------------------------------------------------------#
    """ Determine server which handle storage category """
    attributePUB = {'what': 'storage'}
    client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication',
                        attributePUB)
    publication = client.GetElement_pathuuid(client.Get()[0])
    client.host = publication['host']
    client.port = publication['port']
    publication = client.GetElement_pathuuid(
        client.GetElement(publication['uuid'])['occi.publication.why'])

    tempdict = {'name': gw.name, 'size': storage['occi.storage.size']}
    testPost = OCCIclient(publication['host'], publication['port'],
                          'CO-PROCCI', 'storage', tempdict)
    storage = testPost.Post()
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    """ Determine server which handle infrastructure category """
    attributePUB = {'what': 'infrastructure'}
    client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication',
                        attributePUB)
    publication = client.GetElement_pathuuid(client.Get()[0])
    client.host = publication['host']
    client.port = publication['port']
    publication = client.GetElement_pathuuid(
        client.GetElement(publication['uuid'])['occi.publication.why'])

    tempdict = {
        'name': gw.name,
        'compute': compute,
        'network': network,
        'storage': storage
    }
    testPost = OCCIclient(publication['host'], publication['port'],
                          'CO-PROCCI', 'infrastructure', tempdict)
    infrastructure = testPost.Post()

    #--------------------------------------------------Image-----------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    system = img['occi.image.system']
    system = client.GetElement_pathuuid(system)
    client.host = system['host']
    client.port = system['port']
    client.category = system['category']
    system = client.GetElement(system['uuid'])
    #------------------------------------------------------------------------------------------------------------------#
    """ Determine server which handle system category """
    attributePUB = {'what': 'system'}
    client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication',
                        attributePUB)
    publication = client.GetElement_pathuuid(client.Get()[0])
    client.host = publication['host']
    client.port = publication['port']
    publication = client.GetElement_pathuuid(
        client.GetElement(publication['uuid'])['occi.publication.why'])
    """ Post a system category """
    tempdict = {'name': system['occi.system.name']}
    testPost = OCCIclient(publication['host'], publication['port'], 'CO-EZVM',
                          'system', tempdict)
    system = testPost.Post()
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    """ Determine server which handle image category """
    attributePUB = {'what': 'image'}
    client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication',
                        attributePUB)
    publication = client.GetElement_pathuuid(client.Get()[0])
    client.host = publication['host']
    client.port = publication['port']
    publication = client.GetElement_pathuuid(
        client.GetElement(publication['uuid'])['occi.publication.why'])
    """ Post a image category """
    tempdict = {'name': gw.name, 'system': system}
    testPost = OCCIclient(publication['host'], publication['port'], 'CO-EZVM',
                          'image', tempdict)
    image = testPost.Post()

    #-------------------------------------------------Firewall---------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    """ Determine server which handle firewall category """
    attributePUB = {'what': 'firewall'}
    client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication',
                        attributePUB)
    publication = client.GetElement_pathuuid(client.Get()[0])
    client.host = publication['host']
    client.port = publication['port']
    publication = client.GetElement_pathuuid(
        client.GetElement(publication['uuid'])['occi.publication.why'])
    """ Post a firewall category """
    tempdict = {}
    OCCIfirewall = OCCIclient(publication['host'], publication['port'],
                              'CO-NETS', 'firewall', tempdict)
    firewall = OCCIfirewall.Post()

    #---------------------------------------------------node-----------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    """ Determine server which handle node category """
    attributePUB = {'what': 'node'}
    client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication',
                        attributePUB)
    publication = client.GetElement_pathuuid(client.Get()[0])
    client.host = publication['host']
    client.port = publication['port']
    publication = client.GetElement_pathuuid(
        client.GetElement(publication['uuid'])['occi.publication.why'])

    tempdict = {
        'name': gw.name,
        'provider': gw.provider_type,
        'infrastructure': infrastructure,
        'image': image,
        'access': accsessnode,
        'scope': scopenode,
        'type': typenode,
        'firewall': firewall
    }
    testPost = OCCIclient(publication['host'], publication['port'],
                          'CO-PROCCI', 'node', tempdict)
    node = testPost.Post()
    """ Update firewall """
    OCCIfirewall.attributes = {'node': node}
    OCCIfirewall.Put(OCCIfirewall.GetElement_pathuuid(firewall)['uuid'])

    #------------------------------------------------Provisionning-----------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    """ Determine server which handle opennebula category """
    attributePUB = {'what': gw.provider_type}
    client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication',
                        attributePUB)
    publication = client.GetElement_pathuuid(client.Get()[0])
    client.host = publication['host']
    client.port = publication['port']
    publication = client.GetElement_pathuuid(
        client.GetElement(publication['uuid'])['occi.publication.why'])

    profile = client.GetElement_pathuuid(gw.account)
    client.host = profile['host']
    client.port = profile['port']
    client.category = profile['category']
    profile = client.GetElement(profile['uuid'])['occi.account.name']
    tempdict = {
        'name': gw.name,
        'flavor': 'small',
        'architecture': archi,
        'node': node,
        'account': gw.account,
        'profile': profile
    }
    testPost = OCCIclient(publication['host'], publication['port'],
                          'CO-PROCCI', gw.provider_type, tempdict)
    provider = testPost.Post()

    #--------------------------------------------------Contract--------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    #------------------------------------------------------------------------------------------------------------------#
    """ Determine server which handle contract category """
    attributePUB = {'what': 'contract'}
    client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication',
                        attributePUB)
    publication = client.GetElement_pathuuid(client.Get()[0])
    client.host = publication['host']
    client.port = publication['port']
    publication = client.GetElement_pathuuid(
        client.GetElement(publication['uuid'])['occi.publication.why'])

    tempdict = {
        'name': gw.name,
        'node': node,
        'provider': provider,
        'profile': gw.provider_type,
        'access': accsessnode,
        'scope': scopenode,
        'type': typenode
    }
    testPost = OCCIclient(publication['host'], publication['port'],
                          'CO-PROCCI', 'contract', tempdict)
    contract = testPost.Post()
    gw.contract = contract
    print('Creating a contract for this gateway')

    return gw
예제 #7
0
def gw_start(gw):
	response=respAction("200","ok")
	"""Implement here your function"""
	print('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
	print('                     Receiving action START gw                      ')

	#-------------------------------------------------contract---------------------------------------------------------#
	#------------------------------------------------------------------------------------------------------------------#
	#------------------------------------------------------------------------------------------------------------------#
	""" Determine server which handle contract category """
	attributePUB= {
		'what': 'contract'
	}

	client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication', attributePUB)
	publication = client.GetElement_pathuuid(client.Get()[0])
	client.host = publication['host']
	client.port = publication['port']
	publication = client.GetElement_pathuuid(client.GetElement(publication['uuid'])['occi.publication.why'])


	attribute = {}
	client = OCCIclient(publication['host'], publication['port'], 'CO-PARSER', 'contract', attribute)

	#----------------------------------------------start Node----------------------------------------------------------#
	gwcontract = client.GetElement_pathuuid(gw.contract)
	print('Sending START to the contract of the gateway source')
	client.action(gwcontract['uuid'], 'start')
	gwcontract = client.GetElement(gwcontract['uuid'])

	#-------------------------------------------------provider gw------------------------------------------------------#
	#------------------------------------------------------------------------------------------------------------------#
	#------------------------------------------------------------------------------------------------------------------#
	""" Determine server which handle procci provider category """
	attributePUB= {
		'what': gwcontract['occi.contract.profile']
	}

	client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication', attributePUB)
	publication = client.GetElement_pathuuid(client.Get()[0])
	client.host = publication['host']
	client.port = publication['port']
	publication = client.GetElement_pathuuid(client.GetElement(publication['uuid'])['occi.publication.why'])


	attribute = {}
	client = OCCIclient(publication['host'], publication['port'], 'CO-PARSER', gwcontract['occi.contract.profile'], attribute)

	addressgw = client.GetElement(client.GetElement_pathuuid(gwcontract['occi.contract.provider'])['uuid'])
	gwprivateaddr = addressgw['occi.'+ gwcontract['occi.contract.profile'] +'.privateaddr']
	gwpublicaddr = addressgw['occi.'+ gwcontract['occi.contract.profile'] +'.publicaddr']

	print('The private address of the gateway is: '+gwprivateaddr)
	print('The public address of the gateway is: '+gwpublicaddr)

	#---------------------------------------------------gw-------------------------------------------------------------#
	#------------------------------------------------------------------------------------------------------------------#
	#------------------------------------------------------------------------------------------------------------------#
	""" Determine server which handle gw category """
	attributePUB= {
		'what': 'gw'
	}

	client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication', attributePUB)
	publication = client.GetElement_pathuuid(client.Get()[0])
	client.host = publication['host']
	client.port = publication['port']
	publication = client.GetElement_pathuuid(client.GetElement(publication['uuid'])['occi.publication.why'])

	#------------------------------------------------------------------------------------------------------------------#
	#------------------------------------------------------------------------------------------------------------------#
	tempgw={
		'name':gw.name,
		'publicaddr':gw.publicaddr,
		'privateaddr':gw.privateaddr,
		'ethername':gw.ethername,
		'intercloudGW': gw.intercloudGW,
		'contract':gw.contract,
		'provider_type':gw.provider_type,
		'provider_platform':gw.provider_platform,
		'connection':gw.connection,
		'account':gw.account,
		'state':gw.state,
	}
	attribute = {
		'publicaddr': gwpublicaddr,
		'privateaddr': gwprivateaddr,
		'state': '1',
	}
	gwOCCI = OCCIclient(publication['host'], publication['port'], 'CO-PARSER', 'gw', tempgw)

	uuidgw=gwOCCI.Get()
	gwOCCI.attributes=attribute
	gwOCCI.Put(gwOCCI.GetElement_pathuuid(uuidgw[0])['uuid'])
	print('updating the gateway category with the public and private address')


	return response
예제 #8
0
def gw_stop(gw):
	response=respAction("200","ok")
	"""Implement here your function"""
	print('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
	print('                     Receiving action STOP gw                       ')

	#---------------------------------------------------gw-------------------------------------------------------------#
	#------------------------------------------------------------------------------------------------------------------#
	#------------------------------------------------------------------------------------------------------------------#
	""" Determine server which handle gw category """
	attributePUB= {
		'what': 'gw'
	}

	client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication', attributePUB)
	publication = client.GetElement_pathuuid(client.Get()[0])
	client.host = publication['host']
	client.port = publication['port']
	publication = client.GetElement_pathuuid(client.GetElement(publication['uuid'])['occi.publication.why'])
	#------------------------------------------------------------------------------------------------------------------#
	#------------------------------------------------------------------------------------------------------------------#

	tempgw={
		'name':gw.name,
		'publicaddr':gw.publicaddr,
		'privateaddr':gw.privateaddr,
		'ethername':gw.ethername,
		'intercloudGW': gw.intercloudGW,
		'contract':gw.contract,
		'provider_type':gw.provider_type,
		'provider_platform':gw.provider_platform,
		'connection':gw.connection,
		'account':gw.account,
		'state':gw.state,
	}

	gwOCCI = OCCIclient(publication['host'], publication['port'], 'CO-PARSER', 'gw', tempgw)
	uuidgw=gwOCCI.Get()
	uuidgw=gwOCCI.GetElement_pathuuid(uuidgw[0])['uuid']
	nbconnection = gwOCCI.GetElement(uuidgw)['occi.gw.connection']

	if int(nbconnection) > 0:
		attributes = {
			'connection': str(int(nbconnection)-1)
		}
		gwOCCI.attributes = attributes
		gwOCCI.Put(uuidgw)
		print('decrement the number of connection to :'+attributes['connection'])


	if int(nbconnection) == 1:
		#-------------------------------------------------contract---------------------------------------------------------#
		#------------------------------------------------------------------------------------------------------------------#
		#------------------------------------------------------------------------------------------------------------------#
		""" Determine server which handle contract category """
		attributePUB= {
			'what': 'contract'
		}
		client = OCCIclient('127.0.0.1', '8086', 'CO-PUB', 'publication', attributePUB)
		publication = client.GetElement_pathuuid(client.Get()[0])
		client.host = publication['host']
		client.port = publication['port']
		publication = client.GetElement_pathuuid(client.GetElement(publication['uuid'])['occi.publication.why'])


		attribute = {}
		client = OCCIclient(publication['host'], publication['port'], 'CO-PARSER', 'contract', attribute)

		#----------------------------------------------stop Node----------------------------------------------------------#
		gwcontract = client.GetElement_pathuuid(gw.contract)
		print('the number of connection = 0 ==> stopping the gateway  ')

		client.action(gwcontract['uuid'], 'stop')
		gwcontract = client.GetElement(gwcontract['uuid'])


		attribute = {
			'publicaddr': '',
			'privateaddr': '',
			'state': '0',
		}

		gwOCCI.attributes=attribute
		gwOCCI.Put(uuidgw)
		print('Changing the state of the gateway to 0')

	return response