Пример #1
0
    def patch(self, configuration, view, absolute_name):
        """
        Update specified cname record belonging to default or provided Configuration and View plus Zone hierarchy.
        """
        data = cname_patch_parser.parse_args()
        configuration = g.user.get_api().get_configuration(configuration)
        view = configuration.get_view(view)

        absolute_name = data.get('absolute_name', absolute_name)
        cname_record = view.get_alias_record(absolute_name)
        if cname_record is None:
            return 'No matching CName Record(s) found', 404
        if data['properties'] is not None:
            properties = data.get('properties')
            cname_record._properties = util.properties_to_map(properties)
        if data['linked_record'] is not None:
            cname_record.set_property('linkedRecordName',
                                      data['linked_record'])
        if data['ttl'] is not None:
            cname_record.set_property('ttl', str(data.get('ttl')))
        if data['name'] is not None:
            cname_record.name = data['name']
        cname_record.update()
        result = cname_record.to_json()
        return result
Пример #2
0
    def patch(self, configuration, network):
        """
        Update IPv4 Network belonging to default or provided Configuration.
        Network can be of the format:

        1. 10.1.1.0
        2. 10.1.1.0/24
        """
        data = network_patch_parser.parse_args()
        configuration = g.user.get_api().get_configuration(configuration)
        network_ip = network.split('/')[0]
        network_range = configuration.get_ip_range_by_ip(
            configuration.IP4Network, network_ip)

        if network_range is None:
            return 'No matching IPv4 Network(s) found', 404
        if '/' in network and network_range.get_property('CIDR') != network:
            return 'No matching IPv4 Network(s) found', 404

        if data['properties'] is not None:
            properties = data.get('properties')
            network_range.set_properties(util.properties_to_map(properties))
        if data['name'] is not None:
            network_range.set_name(data['name'])
        network_range.update()
        result = network_range.to_json()
        return jsonify(result)
Пример #3
0
def get_gateway(obj):
    """get gateway of pool"""
    properties = properties_to_map(obj['properties'])
    if 'gateway' in properties.keys():
        return properties['gateway']
    else:
        return ''
Пример #4
0
def get_server_interface_id(config_id):
    """get server interface under configuration"""
    interfaces = []
    servers = g.user.get_api()._api_client.service.getEntities(
        config_id, Entity.Server, 0, MAX_COUNT)
    for server in servers:
        face = g.user.get_api()._api_client.service.getEntities(
            server['id'], Entity.NetworkServerInterface, 0, MAX_COUNT)
        interfaces += face
        face = g.user.get_api()._api_client.service.getEntities(
            server['id'], Entity.PublishedServerInterface, 0, MAX_COUNT)
        interfaces += face
    list_face = []
    for face in interfaces:
        type = face['type']
        id = face['id']
        properties = properties_to_map(face['properties'])
        ipaddress = ''
        if 'NetworkServerInterface' == type:
            ipaddress = properties['defaultInterfaceAddress']
        if 'PublishedServerInterface' == type:
            ipaddress = properties['publishedInterfaceAddress']

        list_face.append({'type': type, 'id': id, 'ipaddress': ipaddress})

    return list_face
Пример #5
0
def get_ip_cidr(obj):
    """get cidr of pool"""
    properties = properties_to_map(obj['properties'])
    type = obj['type']
    if 'IP4Block' == type or 'IP4Network' == type:
        return properties['CIDR']
    else:
        return properties['prefix']
Пример #6
0
def get_gateway_under_network(network_id):
    """get gateway ip under network"""
    ip_list = g.user.get_api()._api_client.service.getEntities(
        network_id, Entity.IP4Address, 0, 10)
    for ip in ip_list:
        properties = properties_to_map(ip['properties'])
        state = properties['state']
        if 'GATEWAY' == state:
            return ip['id']
    return None
Пример #7
0
def get_deploy_role_server(obj, type):
    """get deployment role server of pool by type (DHCP, DNS)"""
    list_server = []
    try:
        id = obj['id']
        servers = g.user.get_api()._api_client.service.getDeploymentRoles(id)
        for server in servers:
            if server['service'] == type:
                interface_id = server['serverInterfaceId']
                obj_interface = g.user.get_api(
                )._api_client.service.getEntityById(interface_id)
                properties = properties_to_map(obj_interface['properties'])
                if 'defaultInterfaceAddress' in properties.keys():
                    list_server.append(properties['defaultInterfaceAddress'])
    except:
        return []
    return list_server
Пример #8
0
    def post(self, configuration, view, zone):
        """
        Create a zone or subzone belonging to default or provided Configuration and View plus Zone hierarchy.
        Subzones can be recursively retrieved by specifying extra "zones" parameters.
        Zones should be of the format:

        1. zone_name
        2. zone_name1/zones/zone_name2
        """
        data = entity_parser.parse_args()
        configuration = g.user.get_api().get_configuration(configuration)
        view = configuration.get_view(view)
        zone = generate_zone_fqdn(zone, view)
        if zone is None:
            return 'No matching Zone(s) found', 404
        zone_name = data['name']
        kwargs = util.properties_to_map(data['properties'])
        zone = view.add_zone('%s' % zone_name, **kwargs)
        return zone.to_json(), 201
Пример #9
0
    def patch(self, configuration, view, absolute_name):
        """
        Update specified host record belonging to default or provided Configuration and View plus Zone hierarchy.
        """
        data = host_patch_parser.parse_args()
        configuration = g.user.get_api().get_configuration(configuration)
        view = configuration.get_view(view)

        absolute_name = data.get('absolute_name', absolute_name)
        host_record = view.get_host_record(absolute_name)
        if host_record is None:
            return 'No matching Host Record(s) found', 404
        if data['properties'] is not None:
            properties = data.get('properties')
            host_record.properties = util.properties_to_map(properties)
        if data['ip4_address'] is not None:
            host_record.set_property('addresses', data['ip4_address'])
        if data['ttl'] is not None:
            host_record.set_property('ttl', str(data.get('ttl')))
        host_record.update()
        result = host_record.to_json()
        return result
Пример #10
0
def get_zones_data(hint):
    """
    Get a list of zone FQDNs that corresponds to the given hint.

    :return: FQDN of any zones that match the given hint as data in JSON, using result template format.
    """
    # Declare variables
    result = get_result_template()
    result['data']['autocomplete_field'] = []

    # Retrieve the configuration and view object
    try:
        configuration = g.user.get_api().get_configuration(
            config.default_configuration)
        view = configuration.get_view(config.default_view)
    except PortalException as e:
        result['status'] = FAIL
        g.user.logger.warning('%s' % e, msg_type=g.user.logger.EXCEPTION)
        return result

    # If null user input then set hint to empty to pre-populate the dropdown, otherwise search with user input
    if safe_str(hint) == 'null':
        properties = 'hint=|'
    else:
        properties = 'hint=' + hint

    # Retrieve zones
    zones = g.user.get_api()._api_client.service.getZonesByHint(
        view.get_id(), 0, 5, properties)

    # If valid zones are retrieved then extract the absolute name and append to result
    if has_response(zones):
        for zone in zones.item:
            result['data']['autocomplete_field'].append(
                properties_to_map(zone['properties'])['absoluteName'])

    result['status'] = SUCCESS
    return result
Пример #11
0
def assign_gateway(parent_id, gateway_ip):
    """assign gateway for entity"""
    options_message = []
    try:
        ip = gateway_ip.split('/')[0]
        if util.is_valid_ipv4_address(ip):
            entity = g.user.get_api()._api_client.service.getEntityById(
                parent_id)
            properties = properties_to_map(entity['properties'])
            properties['gateway'] = gateway_ip
            entity['properties'] = map_to_properties(properties)
            g.user.get_api()._api_client.service.update(entity)
        elif util.is_valid_ipv6_address(ip):
            addip6_gateway(parent_id, gateway_ip)
        else:
            options_message.append(
                'Gateway Ip \'{0}\' is invalid'.format(gateway_ip))
            return options_message
    except Exception as ex:
        options_message.append(
            'Assign gateway \'{0}\' is failed, exception: {1}'.format(
                gateway_ip, ex.message))
    return options_message
Пример #12
0
 def patch(self, configuration, ipv4_address):
     """
     Update IPv4 Address.
     """
     data = ip4_address_patch_parser.parse_args()
     try:
         configuration = g.user.get_api().get_configuration(configuration)
         address = configuration.get_ip4_address(ipv4_address)
     except Exception as e:
         return util.safe_str(e), 404
     try:
         if data['mac_address'] is not None:
             address.set_property('macAddress', data['mac_address'])
         if data['action'] is not None:
             address.change_state_ip4_address(data['action'],
                                              data['mac_address'])
         if data['properties'] is not None:
             properties = data.get('properties')
             address.set_properties(util.properties_to_map(properties))
         address.update()
         result = address.to_json()
         return jsonify(result)
     except Exception as e:
         return util.safe_str(e), 409