예제 #1
0
    def execute_many_cmd_Cosacs(self, address, cmds):
        for item in cmds:

            attributes = {
                'name': '',
                'syntax': item,
                'nature': 'system',
                'status': '',
                'identifier': ''
            }
            cl = OCCIclient(address, '8286', 'COSACS', 'script', attributes)
            cl.Post()

        cosacsStart = {'name': 'cosacs:start'}

        startcmd = OCCIclient(address, '8286', 'COSACS', 'script', cosacsStart)
        startcmd.Post()
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
예제 #3
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
예제 #4
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