Пример #1
0
    template_file = open(filename)
    template_lines = template_file.readlines()
    template_file.close()

    txt = txtsubst(template_lines,
                   xvars,
                   Rcc["%s_file" % optname],
                   'utf8')

    system.file_writelines_flush_sync(Rcc["%s_file" % optname], txt)

    return backupfilename


HOSTS_SCHEMA = xys.load("""
hostname:   !~domain_label
domain:     !~search_domain
""")

def Hosts(args, options):    # pylint: disable-msg=W0613
    """
    POST /hosts

    >>> hosts({'hostname':  'xivo',
               'domain':    'localdomain'})
    """

    if not xys.validate(args, HOSTS_SCHEMA):
        raise HttpReqError(415, "invalid arguments for command")

    if not os.access(Rcc['hostname_path'], (os.X_OK | os.W_OK)):
        raise HttpReqError(415, "path not found or not writable or not executable: %r" % Rcc['hostname_path'])
Пример #2
0
                                                ''.join(xivo_config.generate_interfaces(old_lines, conf))},
                                           self.CONFIG['interfaces_file'],
                                           'utf8')

        if old_lines:
            old_lines.close()

        return (filecontent, backupfilepath)


    MODIFY_PHYSICAL_ETH_IPV4_SCHEMA = xys.load("""
    method:     !~~enum(static,dhcp)
    address?:   !~ipv4_address 192.168.0.1
    netmask?:   !~netmask 255.255.255.0
    broadcast?: !~ipv4_address 192.168.0.255
    gateway?:   !~ipv4_address 192.168.0.254
    mtu?:       !~~between(68,1500) 1500
    auto?:      !!bool True
    up?:        !!bool True
    options?:   !~~seqlen(0,64) [ !~~seqlen(2,2) ['dns-search', 'toto.tld tutu.tld'],
                                  !~~seqlen(2,2) ['dns-nameservers', '127.0.0.1 192.168.0.254'] ]
    """)

    def modify_physical_eth_ipv4(self, args, options):
        """
        POST /modify_physical_eth_ipv4

        >>> modify_physical_eth_ipv4({'method': 'dhcp',
                                      'auto':   True},
                                     {'ifname': 'eth0'})
        """
        self.args = args
Пример #3
0
    """
    GET /network_config
    
    Just returns the network configuration
    """
    if not NETLOCK.acquire_read(NET_LOCK_TIMEOUT):
        raise HttpReqError(503, "unable to take NETLOCK for reading after %s seconds" % NET_LOCK_TIMEOUT)
    try:
        netconf = xivo_config.load_current_configuration()
        return yaml_json.stringify_keys(netconf)
    finally:
        NETLOCK.release()


REN_ETH_SCHEMA = xys.load("""
old_name: !~~prefixedDec eth
new_name: !~~prefixedDec eth
""")

def rename_ethernet_interface(args):
    """
    POST /rename_ethernet_interface
    
    args ex:
    {'old_name': "eth42",
     'new_name': "eth1"}
    """
    if not xys.validate(args, REN_ETH_SCHEMA):
        raise HttpReqError(415, "invalid arguments for command")
    if not NETLOCK.acquire_write(NET_LOCK_TIMEOUT):
        raise HttpReqError(503, "unable to take NETLOCK for writing after %s seconds" % NET_LOCK_TIMEOUT)
    try: