Exemple #1
0
def create_psservice(node_id, name, access_point, type, description):
    # Check if the service already exists
    services = Service.objects.filter(properties_bag__psserviceproperties__accessPoint=access_point)
    if len(services) > 0:
        return services[0]
    
    # See if we can find node by id, but not necessary
    node = None
    try:
        node = Node.objects.get(unis_id=node_id)
    except Node.DoesNotExist:
        pass
    
    service = Service.objects.create(parent=node, unis_id=node_id+':service=snmpma')
    
    props = psServiceProperties()
    props.serviceName = name
    props.accessPoint = access_point
    props.serviceType = type
    props.serviceDescription = description
    
    service.properties_bag.add(props)
    service.save()
    
    return service
Exemple #2
0
def create_psservice(node_id, name, access_point, type, description):
    # Check if the service already exists
    services = Service.objects.filter(
        properties_bag__psserviceproperties__accessPoint=access_point)
    if len(services) > 0:
        return services[0]

    # See if we can find node by id, but not necessary
    node = None
    try:
        node = Node.objects.get(unis_id=node_id)
    except Node.DoesNotExist:
        pass

    service = Service.objects.create(parent=node,
                                     unis_id=node_id + ':service=snmpma')

    props = psServiceProperties()
    props.serviceName = name
    props.accessPoint = access_point
    props.serviceType = type
    props.serviceDescription = description

    service.properties_bag.add(props)
    service.save()

    return service
Exemple #3
0
def create_psservice(serviceName, accessPoint, serviceType, serviceDescription, eventTypes):
    """Create new service object in the topology model.
    If a service with the same accessPoint exists, this method will
    return a reference to the existing object.
    
    Arguments:
        serviceName: string name of the service
        accessPoint: string accessPoint of the service, must start with http: or https://
        serviceDescription:
        serviceType: e.g gLS, hLS, MA, MP
        eventTypes: dict or list of supported event types by the service
    """
    
    # Check if the service already exists
    services = Service.objects.filter(properties_bag__psserviceproperties__accessPoint=accessPoint)
    if len(services) > 0:
        return services[0]
    
    # Creating new service is needed
    g = urlparse(accessPoint)
    node = create_node_by_address(g.hostname)
    unis_id = "%s:port=%s:service=%s" % (node.unis_id, g.port, g.path)
    sresult = Service.objects.get_or_create(unis_id=unis_id)
    
    #service already exists but with different address
    if sresult[1] == False:
        return sresult[0]
    else:
        sresult[0].parent = node
        sresult[0].save()
        service = sresult[0]
        
    name = NetworkObjectNames.objects.create(name = Name.objects.create(value=accessPoint), networkobject=service)
    name.save()
    
    if serviceDescription is not None:
        desc = NetworkObjectDescriptions.objects.create(description = Description.objects.create(value=serviceDescription), networkobject=service)
        desc.save()
    
    
    # Creates a ps service properites bag for a service
    props = psServiceProperties()
    props.serviceName =  serviceName
    props.accessPoint =  accessPoint
    props.serviceType =  serviceType
    props.serviceDescription =  serviceDescription
    service.properties_bag.add(props)
    
    # Set the list of supported event types for a given psserviceproperties.
    for e in eventTypes:
        eresult = EventType.objects.get_or_create(value=e)
        if e[1] == True:
            eresult[0].save()
        eventprop = psServicePropertiesEventTypes.objects.create(psServiceProperties=props, eventtype=eresult[0])
        eventprop.save()
    
    logger.info("New service '%s' is created" % service)
    service.save()
    return service
Exemple #4
0
def create_psservice(serviceName, accessPoint, serviceType, serviceDescription,
                     eventTypes):
    """Create new service object in the topology model.
    If a service with the same accessPoint exists, this method will
    return a reference to the existing object.
    
    Arguments:
        serviceName: string name of the service
        accessPoint: string accessPoint of the service, must start with http: or https://
        serviceDescription:
        serviceType: e.g gLS, hLS, MA, MP
        eventTypes: dict or list of supported event types by the service
    """

    # Check if the service already exists
    services = Service.objects.filter(
        properties_bag__psserviceproperties__accessPoint=accessPoint)
    if len(services) > 0:
        return services[0]

    # Creating new service is needed
    g = urlparse(accessPoint)
    node = create_node_by_address(g.hostname)
    unis_id = "%s:port=%s:service=%s" % (node.unis_id, g.port, g.path)
    sresult = Service.objects.get_or_create(unis_id=unis_id)

    #service already exists but with different address
    if sresult[1] == False:
        return sresult[0]
    else:
        sresult[0].parent = node
        sresult[0].save()
        service = sresult[0]

    name = NetworkObjectNames.objects.create(
        name=Name.objects.create(value=accessPoint), networkobject=service)
    name.save()

    if serviceDescription is not None:
        desc = NetworkObjectDescriptions.objects.create(
            description=Description.objects.create(value=serviceDescription),
            networkobject=service)
        desc.save()

    # Creates a ps service properites bag for a service
    props = psServiceProperties()
    props.serviceName = serviceName
    props.accessPoint = accessPoint
    props.serviceType = serviceType
    props.serviceDescription = serviceDescription
    service.properties_bag.add(props)

    # Set the list of supported event types for a given psserviceproperties.
    for e in eventTypes:
        eresult = EventType.objects.get_or_create(value=e)
        if e[1] == True:
            eresult[0].save()
        eventprop = psServicePropertiesEventTypes.objects.create(
            psServiceProperties=props, eventtype=eresult[0])
        eventprop.save()

    logger.info("New service '%s' is created" % service)
    service.save()
    return service
Exemple #5
0
def create_psservice(service_name, access_point, service_type,
        service_description=None, event_types=[]):
    """
    Creates new UNIS Service object with
    L{periscope.topology.models.psServiceProperties} properties bag.
    If a service with the same I{access_point} exists, this method will
    return a reference to the existing object.
    
    @param service_name: the name of the service
    @type service_name: str
    @param access_point: full URL address.
    @type access_point: URL str
    @param service_description: optional description of the service
    @type service_description: str
    @param service_type: service type
    @type service_type: 'gLS', 'hLS', 'MA', 'MP'
    @param event_types: dict or list of supported event types by the service
    
    @returns: L{periscope.topology.models.Service}
    """
    
    # Check if the service already exists
    filter_q = Q(properties_bag__psserviceproperties__accessPoint=access_point)
    services = Service.objects.filter(filter_q)
    if len(services) > 0:
        return services[0]
    
    # Creating new service is needed
    parse = urlparse(access_point)
    node = find_node_by_address(parse.hostname)
    if not node:
        node = create_node_by_address(parse.hostname)
    unis_id = "%s:port=%s:service=%s" % (node.unis_id, parse.port, parse.path)
    service = Service.objects.create(unis_id=unis_id, parent=node)
    
    net_name = NetworkObjectNames.objects.create(networkobject=service,
            name=Name.objects.create(value=service_name))
    net_name.save()
    
    if service_description:
        serv_desc = NetworkObjectDescriptions.objects.create(
            networkobject=service,
            description=Description.objects.create(value=service_description))
    
    # Creates a ps service properites bag for a service
    props = psServiceProperties(serviceName=service_name,
                accessPoint=access_point,
                serviceType=service_type,
                serviceDescription=service_description)
    service.properties_bag.add(props)
    
    # Set the list of supported event types for a given psserviceproperties.
    for event_type in event_types:
        eresult = EventType.objects.get_or_create(value=event_type)
        if eresult[1] == True:
            eresult[0].save()
        
        event = eresult[0]
        psServicePropertiesEventTypes.objects.create(psServiceProperties=props,
            eventtype=event)
    
    logger.info("New service '%s' is created" % service)
    service.save()
    return service
Exemple #6
0
def create_psservice(service_name,
                     access_point,
                     service_type,
                     service_description=None,
                     event_types=[]):
    """
    Creates new UNIS Service object with
    L{periscope.topology.models.psServiceProperties} properties bag.
    If a service with the same I{access_point} exists, this method will
    return a reference to the existing object.
    
    @param service_name: the name of the service
    @type service_name: str
    @param access_point: full URL address.
    @type access_point: URL str
    @param service_description: optional description of the service
    @type service_description: str
    @param service_type: service type
    @type service_type: 'gLS', 'hLS', 'MA', 'MP'
    @param event_types: dict or list of supported event types by the service
    
    @returns: L{periscope.topology.models.Service}
    """

    # Check if the service already exists
    filter_q = Q(properties_bag__psserviceproperties__accessPoint=access_point)
    services = Service.objects.filter(filter_q)
    if len(services) > 0:
        return services[0]

    # Creating new service is needed
    parse = urlparse(access_point)
    node = find_node_by_address(parse.hostname)
    if not node:
        node = create_node_by_address(parse.hostname)
    unis_id = "%s:port=%s:service=%s" % (node.unis_id, parse.port, parse.path)
    service = Service.objects.create(unis_id=unis_id, parent=node)

    net_name = NetworkObjectNames.objects.create(
        networkobject=service, name=Name.objects.create(value=service_name))
    net_name.save()

    if service_description:
        serv_desc = NetworkObjectDescriptions.objects.create(
            networkobject=service,
            description=Description.objects.create(value=service_description))

    # Creates a ps service properites bag for a service
    props = psServiceProperties(serviceName=service_name,
                                accessPoint=access_point,
                                serviceType=service_type,
                                serviceDescription=service_description)
    service.properties_bag.add(props)

    # Set the list of supported event types for a given psserviceproperties.
    for event_type in event_types:
        eresult = EventType.objects.get_or_create(value=event_type)
        if eresult[1] == True:
            eresult[0].save()

        event = eresult[0]
        psServicePropertiesEventTypes.objects.create(psServiceProperties=props,
                                                     eventtype=event)

    logger.info("New service '%s' is created" % service)
    service.save()
    return service