Ejemplo n.º 1
0
def createResources(velo,
                    qty='',
                    startIndex='',
                    stopIndex='',
                    templateId='fea52e8b-8d75-455e-baa5-80751d9625c7'):
    BaseUrl = "https://" + velo + ".spirenteng.com" + getUrl('device')
    toDelete = {'deviceList': []}
    deviceName = 'Performance PC'
    ####Index Management#####
    startIndex, stopIndex = indexManagement(qty, startIndex, stopIndex)
    ####Create resources#####
    for i in range(startIndex, stopIndex):
        raw = {}
        raw['name'] = deviceName + str(i)
        raw['templateId'] = templateId
        body = json.dumps(raw.copy())
        rq = requests.post(BaseUrl,
                           data=body,
                           verify=False,
                           auth=('spirent', 'spirent'),
                           headers={'Content-type': 'application/json'})
        result = json.loads(rq.text)
        if 'errorId' in rq.text:
            print('Resource creation error. Message: ' + result['message'])
        else:
            toDelete['deviceList'].append(result['id'])
    testResult = outputNrOfElements(deviceName, stopIndex - startIndex,
                                    len(toDelete['deviceList']))
    return toDelete, testResult
Ejemplo n.º 2
0
def createAbstractResources(velo,
                            qty='',
                            startIndex='',
                            stopIndex='',
                            condition=''):
    BaseUrl = "https://" + velo + ".spirenteng.com" + getUrl(
        'abstract_resource')
    toDelete = {'abstractDeviceList': []}
    deviceName = 'Abstract Performance Device'
    ####Index Management#####
    startIndex, stopIndex = indexManagement(qty, startIndex, stopIndex)
    ####Create resources#####
    for i in range(startIndex, stopIndex):
        raw = {}
        raw['name'] = deviceName + str(i)
        raw['type'] = 'DEVICE'
        raw['condition'] = condition
        body = json.dumps(raw.copy())
        rq = requests.post(BaseUrl,
                           data=body,
                           verify=False,
                           auth=('spirent', 'spirent'),
                           headers={'Content-type': 'application/json'})
        result = json.loads(rq.text)
        if 'errorId' in rq.text:
            print('Resource creation error. Message: ' + result['message'])
        else:
            toDelete['abstractDeviceList'].append(result['id'])
    testResult = outputNrOfElements(deviceName, stopIndex - startIndex,
                                    len(toDelete['abstractDeviceList']))
    return toDelete, testResult
Ejemplo n.º 3
0
def reserveTopologies(velo, topologyIdList, start='', end='', duration='600'):
    postReservationUrl = "https://" + velo + ".spirenteng.com" + getUrl(
        'reservation')
    toDelete = {'reservationList': []}
    reservationName = 'Topology reservation test'
    for i, topId in enumerate(topologyIdList):
        raw = {}
        raw['name'] = reservationName + str(i + 1)
        if duration:
            raw['duration'] = duration
        if start:
            raw['start'] = start
        if end:
            raw['end'] = end
        raw['topologyId'] = topId
        rq = requests.post(postReservationUrl,
                           data=json.dumps(raw),
                           verify=False,
                           auth=('spirent', 'spirent'),
                           headers={'Content-type': 'application/json'})
        result = json.loads(rq.text)
        toDelete['reservationList'].append(result['id'])
    testResult = outputNrOfElements(reservationName, len(topologyIdList),
                                    len(toDelete['reservationList']))
    return toDelete, testResult
Ejemplo n.º 4
0
def createVsphereClouds(velo,
                        qty='',
                        startIndex='',
                        stopIndex='',
                        cloudName='Performance vSphere Cloud',
                        username='******',
                        password='******',
                        endpoint='https://vcenter-apt-dut.spirenteng.com/sdk'):
    BaseUrl = "https://" + velo + ".spirenteng.com" + getUrl('cloud')
    toDelete = {'cloudList': []}
    ####Index Management###
    startIndex, stopIndex = indexManagement(qty, startIndex, stopIndex)
    ####Create Clouds####
    for i in range(startIndex, stopIndex):
        body = {}
        body['providerType'] = 'VMWARE'
        body['name'] = cloudName + str(i)
        body[
            'description'] = 'vSferaIndex Testing <-> Agrama teritory. Beware of clickbaits'
        body['endpoint'] = endpoint
        body['credentials'] = {'username': username, 'password': password}
        body = json.dumps(body)
        rq = requests.post(BaseUrl,
                           data=body,
                           verify=False,
                           auth=('spirent', 'spirent'),
                           headers={'Content-type': 'application/json'})
        result = json.loads(rq.text)
        if 'errorId' in rq.text:
            print('Resource creation error. Message: ' + result['message'])
        else:
            toDelete['cloudList'].append(result['id'])
    testResult = outputNrOfElements(cloudName, stopIndex - startIndex,
                                    len(toDelete['cloudList']))
    return toDelete, testResult
Ejemplo n.º 5
0
def createOpenStackClouds(velo,
                          qty='',
                          startIndex='',
                          stopIndex='',
                          cloudName='Performance OpenStack Cloud',
                          username='******',
                          password='******',
                          endpoint='http://10.140.71.22:5000/v3'):
    BaseUrl = "https://" + velo + ".spirenteng.com" + getUrl('cloud')
    toDelete = {'cloudList': []}
    ####Index Management###
    startIndex, stopIndex = indexManagement(qty, startIndex, stopIndex)
    ####Create Clouds####
    for i in range(startIndex, stopIndex):
        body = {}
        body['providerType'] = 'OPEN_STACK'
        body['name'] = cloudName + str(i)
        body[
            'description'] = 'OpixStiva <-> Agrama teritory. Beware of clickbaits'
        body['endpoint'] = endpoint
        body['credentials'] = {'username': username, 'password': password}
        body['properties'] = [{
            'id': 'domain',
            'value': 'gimi_test'
        }, {
            'id': 'region',
            'value': 'RegionOne'
        }, {
            'id': 'tenant',
            'value': 'admin_gimi'
        }]
        body = json.dumps(body)
        rq = requests.post(BaseUrl,
                           data=body,
                           verify=False,
                           auth=('spirent', 'spirent'),
                           headers={'Content-type': 'application/json'})
        result = json.loads(rq.text)
        if 'errorId' in rq.text:
            print('Resource creation error. Message: ' + result['message'])
        else:
            toDelete['cloudList'].append(result['id'])
    testResult = outputNrOfElements(cloudName, stopIndex - startIndex,
                                    len(toDelete['cloudList']))
    return toDelete, testResult
Ejemplo n.º 6
0
def createPortGroups(velo,
                     deviceTemplateId='fea52e8b-8d75-455e-baa5-80751d9625c7',
                     portTemplateId='a5266606-f35b-482b-8c3f-a4317c1ccbb9',
                     qty='',
                     startIndex='',
                     stopIndex='',
                     portsPerGroup=5,
                     deviceName='Performance Port Group Test'):
    devicePostUrl = "https://" + velo + ".spirenteng.com" + getUrl('device')
    toDelete = {'deviceList': []}
    previousGroupId = ''
    ####Create ports json#################
    portsBody = {}
    portsBody['ports'] = []
    port = {}
    for i in range(1, portsPerGroup + 1):
        port['groupId'] = 'Some Id'
        port['name'] = 'Port ' + str(i)
        port['templateId'] = portTemplateId
        portsBody['ports'].append(port.copy())
    ####Index management##########################
    startIndex, stopIndex = indexManagement(qty, startIndex, stopIndex)
    ########Device handling######################
    for i in range(startIndex, stopIndex):
        deviceBody = {}
        deviceBody['name'] = deviceName + str(i)
        deviceBody['templateId'] = deviceTemplateId
        deviceBody = json.dumps(deviceBody)
        rq = requests.post(devicePostUrl,
                           data=deviceBody,
                           verify=False,
                           auth=('spirent', 'spirent'),
                           headers={'Content-type': 'application/json'})
        deviceResult = json.loads(rq.text)
        if 'errorId' in rq.text:
            print('Topology publishing error. Message: ' +
                  deviceResult['message'])
        else:
            toDelete['deviceList'].append(deviceResult['id'])
        ########Port Group handling##############
        portGroupPostUrl = "https://" + velo + ".spirenteng.com/velocity/api/inventory/v8/device/" + deviceResult[
            'id'] + "/port_group"
        groupBody = {}
        groupBody['name'] = 'Port Group ' + str(i)
        manualAssociations = {}
        manualAssociations['id'] = previousGroupId
        groupBody['manualAssociations'] = [manualAssociations]
        groupBody = json.dumps(groupBody)
        rq = requests.post(portGroupPostUrl,
                           data=groupBody,
                           verify=False,
                           auth=('spirent', 'spirent'),
                           headers={'Content-type': 'application/json'})
        portGroupResult = json.loads(rq.text)
        ########Save group id as previous to link device port group to the next#####
        previousGroupId = portGroupResult['id']
        # ########Ports handling####################
        portPostUrl = "https://" + velo + ".spirenteng.com/velocity/api/inventory/v8/device/" + deviceResult[
            'id'] + "/ports"
        for d in portsBody['ports']:
            d.update({'groupId': portGroupResult['id']})
        portsBodyResult = json.dumps(portsBody.copy())
        rq = requests.post(portPostUrl,
                           data=portsBodyResult,
                           verify=False,
                           auth=('spirent', 'spirent'),
                           headers={'Content-type': 'application/json'})
    testResult = outputNrOfElements(deviceName, stopIndex - startIndex,
                                    len(toDelete["deviceList"]))
    return toDelete, testResult
Ejemplo n.º 7
0
def createCopyTopologies(velo,
                         topologyBodyPath,
                         qty='',
                         startIndex='',
                         stopIndex='',
                         topologyName='Performance Topology Test'):
    initPostUrl = "https://" + velo + ".spirenteng.com" + getUrl('topology')
    toDelete = {'topologyList': []}
    ####Open initial topology#####
    with open(topologyBodyPath, 'r') as stream:
        try:
            topologyBody = yaml.load(stream)
        except yaml.YAMLError as exc:
            print(exc)
            sys.exit(1)
    ####Post initial topology###
    data = yaml.dump(topologyBody, default_flow_style=False)
    rq = requests.post(
        initPostUrl,
        data=data,
        verify=False,
        auth=('spirent', 'spirent'),
        headers={
            'Content-type':
            'application/vnd.spirent-velocity.topology.tosca+yaml'
        })
    initial = json.loads(rq.text)
    if 'errorId' in rq.text:
        print('Topology creation error. Message: ' + initial['message'])
    copyPostUrl = initPostUrl + '?copyFrom=' + initial['id']
    ####Index Management###########
    startIndex, stopIndex = indexManagement(qty, startIndex, stopIndex)
    ####Copy the topology and publish it########
    for i in range(startIndex, stopIndex):
        raw = {}
        raw['name'] = topologyName + ' ' + str(i)
        raw['isAbstract'] = 'true'
        raw = json.dumps(raw)
        rq = requests.post(copyPostUrl,
                           data=raw,
                           verify=False,
                           auth=('spirent', 'spirent'),
                           headers={'Content-type': 'application/json'})
        result = json.loads(rq.text)
        BaseUrlPUT = "https://" + velo + ".spirenteng.com" + getUrl(
            'topology') + '/' + result['id']
        body = {}
        body['isDraft'] = 'false'
        body = json.dumps(body)
        rq = requests.put(BaseUrlPUT,
                          data=body,
                          verify=False,
                          auth=('spirent', 'spirent'),
                          headers={'Content-type': 'application/json'})
        topology = json.loads(rq.text)
        if 'errorId' in rq.text:
            print('Topology publishing error. Message: ' + topology['message'])
        else:
            toDelete['topologyList'].append(topology['id'])
    testResult = outputNrOfElements(topologyName, stopIndex - startIndex,
                                    len(toDelete["topologyList"]))
    ####Delete initial topology####
    rq = requests.delete(initPostUrl + '/' + initial['id'],
                         verify=False,
                         auth=('spirent', 'spirent'))
    return toDelete, testResult