예제 #1
0
def post_url(actionUrl, data={}, referer=base_url):
    if not os.path.exists(datapath): xbmcvfs.mkdir(datapath)
    net = Net(cookie_file=cookie_TviFile, proxy='', user_agent=user_agent, http_debug=True)
    try:
        ref_data = {'Referer': referer}
        html = net.http_POST(actionUrl, form_data=data, headers=ref_data).content.encode('latin-1', 'ignore')
        net.save_cookies(cookie_TviFile)
        return html
    except:
        xbmc.log("post_url fail =" + actionUrl)  # TODO: url?
        return ''
예제 #2
0
def free_cidr(cidr, uuid):
    """
    Frees a issued CIDR thus it can be reused.

    :param cidr: The currently used CIDR.
    :type cidr: ``str``
    :param uuid: The UUID of the Subnet, which uses this CIDR.
    :type uuid: ``str``
    :return: Returns False if the CIDR is None or the UUID did not correspond tho the used CIDR. Else it returns True.
    :rtype: ``bool``
    """
    if cidr is None:
        return False

    global __current_ip
    int_ip = Net.cidr_2_int(cidr)

    global lock
    lock.acquire()

    if int_ip in __issued_ips and __issued_ips[int_ip] == uuid:
        del __issued_ips[int_ip]
        if int_ip < __current_ip:
            __current_ip = int_ip
        lock.release()
        return True
    lock.release()
    return False
예제 #3
0
def post_url(actionUrl, data={}, referer=base_url):
    if not os.path.exists(datapath): xbmcvfs.mkdir(datapath)
    net = Net(cookie_file=cookie_TviFile,
              proxy='',
              user_agent=user_agent,
              http_debug=True)
    try:
        ref_data = {'Referer': referer}
        html = net.http_POST(actionUrl, form_data=data,
                             headers=ref_data).content.encode(
                                 'latin-1', 'ignore')
        net.save_cookies(cookie_TviFile)
        return html
    except:
        xbmc.log("post_url fail =" + actionUrl)  # TODO: url?
        return ''
예제 #4
0
파일: compute.py 프로젝트: stefannesic/sdci
    def create_network(self, name, stack_operation=False):
        """
        Creates a new network with the given name. Raises an exception when a network with the given name already
        exists!

        :param name: Name of the new network.
        :type name: ``str``
        :param stack_operation: Allows the heat parser to create modules without adapting the current emulation.
        :type stack_operation: ``bool``
        :return: :class:`heat.resources.net`
        """
        LOG.debug("Creating network with name %s" % name)
        if self.find_network_by_name_or_id(
                name) is not None and not stack_operation:
            LOG.warning(
                "Creating network with name %s failed, as it already exists" % name)
            raise Exception("Network with name %s already exists." % name)
        network = Net(name)
        network.id = str(uuid.uuid4())
        if not stack_operation:
            self.nets[network.id] = network
        return network
예제 #5
0
파일: compute.py 프로젝트: mpeuster/son-emu
    def create_network(self, name, stack_operation=False):
        """
        Creates a new network with the given name. Raises an exception when a network with the given name already
        exists!

        :param name: Name of the new network.
        :type name: ``str``
        :param stack_operation: Allows the heat parser to create modules without adapting the current emulation.
        :type stack_operation: ``bool``
        :return: :class:`heat.resources.net`
        """
        LOG.debug("Creating network with name %s" % name)
        if self.find_network_by_name_or_id(
                name) is not None and not stack_operation:
            LOG.warning(
                "Creating network with name %s failed, as it already exists" % name)
            raise Exception("Network with name %s already exists." % name)
        network = Net(name)
        network.id = str(uuid.uuid4())
        if not stack_operation:
            self.nets[network.id] = network
        return network
예제 #6
0
def is_cidr_issued(cidr):
    """
    Returns True if the CIDR is used.

    :param cidr: The requested CIDR.
    :type cidr: ``str``
    :return: Returns True if the CIDR is used, else False.
    :rtype: ``bool``
    """
    if cidr is None:
        return False

    int_ip = Net.cidr_2_int(cidr)

    if int_ip in __issued_ips:
        return True
    return False
예제 #7
0
def abrir_url(url, referer=base_url):  # TODO: main url processor?
    if not os.path.exists(datapath): xbmcvfs.mkdir(datapath)

    net = Net(cookie_file=cookie_TviFile, proxy='', user_agent=user_agent, http_debug=True)
    if os.path.exists(cookie_TviFile): net.set_cookies(cookie_TviFile)
    try:
        ref_data = {'Referer': referer}
        html = net.http_GET(url, headers=ref_data).content.encode('latin-1', 'ignore')
        net.save_cookies(cookie_TviFile)
        return html
    except:
        xbmc.log("abrir_url fail =" + url)
        return ''
예제 #8
0
def abrir_url(url, referer=base_url):  # TODO: main url processor?
    if not os.path.exists(datapath): xbmcvfs.mkdir(datapath)

    net = Net(cookie_file=cookie_TviFile,
              proxy='',
              user_agent=user_agent,
              http_debug=True)
    if os.path.exists(cookie_TviFile): net.set_cookies(cookie_TviFile)
    try:
        ref_data = {'Referer': referer}
        html = net.http_GET(url, headers=ref_data).content.encode(
            'latin-1', 'ignore')
        net.save_cookies(cookie_TviFile)
        return html
    except:
        xbmc.log("abrir_url fail =" + url)
        return ''
예제 #9
0
def is_my_cidr(cidr, uuid):
    """
    Checks if the UUID and the used CIDR are related.

    :param cidr: The issued CIDR.
    :type cidr: ``str``
    :param uuid: The Subnet UUID.
    :type uuid: ``str``
    :return: Returns False if the CIDR is None or if the CIDR is not issued. Else returns True.
    :rtype: ``bool``
    """
    if cidr is None:
        return False

    int_ip = Net.cidr_2_int(cidr)

    if not int_ip in __issued_ips:
        return False

    if __issued_ips[int_ip] == uuid:
        return True
    return False
예제 #10
0
def get_new_cidr(uuid):
    """
    Calculates a unused cidr for a subnet.

    :param uuid: The UUID of the subnet - Thus it can store which subnet gets which CIDR
    :type uuid: ``str``
    :return: Returns None if all available CIDR are used. Otherwise returns a valid CIDR.
    :rtype: ``str``
    """
    global lock
    lock.acquire()

    global __current_ip
    while __first_ip <= __current_ip < __last_ip and __current_ip in __issued_ips:
        __current_ip += __default_subnet_size

    if __current_ip >= __last_ip or __current_ip < __first_ip or __current_ip in __issued_ips:
        return None

    __issued_ips[__current_ip] = uuid
    lock.release()

    return Net.int_2_ip(__current_ip) + '/' + str(__default_subnet_bitmask)
예제 #11
0
def assign_cidr(cidr, uuid):
    """
    Allows a subnet to request a specific CIDR.

    :param cidr: The requested CIDR.
    :type cidr: ``str``
    :param uuid: The Subnet UUID.
    :type uuid: ``str``
    :return: Returns False if the CIDR is None or if the CIDR is already issued. Returns True if the CIDR could be
     assigned to the UUID.
    """
    if cidr is None:
        return False

    int_ip = Net.cidr_2_int(cidr)

    if int_ip in __issued_ips:
        return False

    global lock
    lock.acquire()
    __issued_ips[int_ip] = uuid
    lock.release()
    return True
예제 #12
0
from resources.net import Net
import threading

lock = threading.Lock()

__issued_ips = dict()
__default_subnet_size = 256
__default_subnet_bitmask = 24
__first_ip = Net.ip_2_int('10.0.0.0')
__last_ip = Net.ip_2_int('10.255.255.255')
__current_ip = __first_ip


def get_new_cidr(uuid):
    """
    Calculates a unused cidr for a subnet.

    :param uuid: The UUID of the subnet - Thus it can store which subnet gets which CIDR
    :type uuid: ``str``
    :return: Returns None if all available CIDR are used. Otherwise returns a valid CIDR.
    :rtype: ``str``
    """
    global lock
    lock.acquire()

    global __current_ip
    while __first_ip <= __current_ip < __last_ip and __current_ip in __issued_ips:
        __current_ip += __default_subnet_size

    if __current_ip >= __last_ip or __current_ip < __first_ip or __current_ip in __issued_ips:
        return None