def update_bonding_task(bondid, bondinfo): commands = [] # 이전 ethernets 삭제 if 'ethernets' in bondinfo and len(bondinfo['ethernets']) > 0: for eth in bondinfo['before_eths']: commands.append("$DELETE interfaces ethernet %s bond-group" % eth) for key in bondinfo: if '_' in key: _key = key.replace('_',' ') else: _key = key if key in ['before_eths','ipaddr']: continue elif key == "disable" and bondinfo[key] == False: bondinfo[key] = '' # delete 만 하기 위해. if key == 'ethernets': for eth in bondinfo[key]: commands.append("$SET interfaces ethernet %s bond-group %s" % (eth, bondid)) else: commands.append("$DELETE interfaces bonding %s %s" % (bondid, _key)) if key == "disable" and bondinfo[key] == True: commands.append("$SET interfaces bonding %s %s" % (bondid, key)) elif len(bondinfo[key]) > 0: #값이 있을때만 set commands.append("$SET interfaces bonding %s %s %s" % (bondid, _key, bondinfo[key])) return FabricUtilNFV.send_vyatta_command(commands)
def delete_nat_task(natinfo): rulenum = natinfo['rulenum'] ruletype = natinfo['ruletype'] commands = [] commands.append("$DELETE nat " + ruletype + " rule " + rulenum) return FabricUtilNFV.send_vyatta_command(commands)
def delete_nat_task(natinfo): rulenum = natinfo["rulenum"] ruletype = natinfo["ruletype"] commands = [] commands.append("$DELETE nat " + ruletype + " rule " + rulenum) return FabricUtilNFV.send_vyatta_command(commands)
def delete_bonding_task(bondinfo): bondid = bondinfo['bondid'] commands = [] for eth in bondinfo["ethernets"]: commands.append("$DELETE interfaces ethernet %s bond-group" % eth) commands.append("$DELETE interfaces bonding " + bondid) return FabricUtilNFV.send_vyatta_command(commands)
def set_login_user_task(userinfo): if 'username' in userinfo: username = userinfo['username'] else: username = None if 'level' in userinfo: level = userinfo['level'] else: level = None if 'password' in userinfo: password = userinfo['password'] else: password = None if 'key_id' in userinfo: key_id = userinfo['key_id'] else: key_id = None if 'key_type' in userinfo: key_type = userinfo['key_type'] else: key_type = None if 'key_value' in userinfo: key_value = userinfo['key_value'] else: key_value = None commands = [] if username: commands.append("$DELETE system login user " + username) if level: commands.append("$SET system login user " + username + " level " + level) else: commands.append("$SET system login user " + username) if password: commands.append("$SET system login user " + username + " authentication plaintext-password " + password) if key_id and key_type and key_value: commands.append("$SET system login user " + username + " authentication public-keys " + key_id + " type " + key_type) commands.append("$SET system login user " + username + " authentication public-keys " + key_id + " key " + key_value) return FabricUtilNFV.send_vyatta_command(commands)
def set_login_user_task(userinfo): if 'username' in userinfo: username = userinfo['username'] else: username = None if 'level' in userinfo: level = userinfo['level'] else: level = None if 'password' in userinfo: password = userinfo['password'] else: password = None if 'key_id' in userinfo: key_id = userinfo['key_id'] else: key_id = None if 'key_type' in userinfo: key_type = userinfo['key_type'] else: key_type = None if 'key_value' in userinfo: key_value = userinfo['key_value'] else: key_value = None commands = [] if username: commands.append("$DELETE system login user " + username) if level: commands.append("$SET system login user " + username + " level " + level) else: commands.append("$SET system login user " + username) if password: commands.append("$SET system login user " + username + " authentication plaintext-password " + password) if key_id and key_type and key_value: commands.append("$SET system login user " + username + " authentication public-keys " + key_id + " type " + key_type) commands.append("$SET system login user " + username + " authentication public-keys " + key_id + " key " + key_value) return FabricUtilNFV.send_vyatta_command(commands)
def create_bonding_task(bondinfo): bondid = bondinfo['bondid'] commands = [] commands.append("$DELETE interfaces bonding " + bondid) commands.append("$SET interfaces bonding " + bondid) commands.append("$SET interfaces bonding %s address %s" % (bondid, bondinfo['address'])) commands.append("$SET interfaces bonding %s mode %s" % (bondid, bondinfo['mode'])) for ethernet in bondinfo['ethernets']: commands.append("$DELETE interfaces ethernet %s bond-group" % ethernet) commands.append("$DELETE interfaces ethernet %s address" % ethernet) commands.append("$SET interfaces ethernet %s bond-group %s " % (ethernet, bondid)) return FabricUtilNFV.send_vyatta_command(commands)
def delete_static_routing_task(routinginfo): if 'routing_subnet' in routinginfo: routing_subnet = routinginfo['routing_subnet'] else: routing_subnet = None if 'routing_type' in routinginfo: routing_type = routinginfo['routing_type'] else: routing_type = None if 'routing_table' in routinginfo: routing_table = routinginfo['routing_table'] else: routing_table = None if 'is_last_in_table' in routinginfo: is_last_in_table = routinginfo['is_last_in_table'] else: is_last_in_table = None commands = [] if routing_table and routing_table != "": if is_last_in_table and (is_last_in_table == True or is_last_in_table == "true"): commands.append("$DELETE protocols static table " + routing_table) else: if routing_type == "route": commands.append("$DELETE protocols static table " + routing_table + " route " + routing_subnet) else: commands.append("$DELETE protocols static table " + routing_table + " interface-route " + routing_subnet) else: if routing_type == "route": commands.append("$DELETE protocols static route " + routing_subnet) else: commands.append("$DELETE protocols static interface-route " + routing_subnet) return FabricUtilNFV.send_vyatta_command(commands)
def set_global_system_task(systeminfo): if 'hostname' in systeminfo: hostname = systeminfo['hostname'] else: hostname = None if 'timezone' in systeminfo: timezone = systeminfo['timezone'] else: timezone = None commands = [] if hostname: commands.append("$SET system host-name " + hostname) if timezone: commands.append("$SET system time-zone " + timezone) return FabricUtilNFV.send_vyatta_command(commands)
def delete_dhcp_task(dhcpinfo): if 'shared_network_name' in dhcpinfo: shared_network_name = dhcpinfo['shared_network_name'] else: shared_network_name = None if 'is_last' in dhcpinfo: is_last = dhcpinfo['is_last'] else: is_last = None commands = [] if is_last and (is_last == True or is_last == 'true'): commands.append("$DELETE service dhcp-server") else: if shared_network_name: commands.append("$DELETE service dhcp-server shared-network-name " + shared_network_name) return FabricUtilNFV.send_vyatta_command(commands)
def set_global_system_task(systeminfo): if 'hostname' in systeminfo: hostname = systeminfo['hostname'] else: hostname = None if 'timezone' in systeminfo: timezone = systeminfo['timezone'] else: timezone = None commands = [] if hostname: commands.append("$SET system host-name " + hostname) if timezone: commands.append("$SET system time-zone " + timezone) return FabricUtilNFV.send_vyatta_command(commands)
def set_dhcp_global_task(dhcpinfo): if 'disabled' in dhcpinfo: disabled = dhcpinfo['disabled'] else: disabled = None if 'dynamic_dns_update' in dhcpinfo: dynamic_dns_update = dhcpinfo['dynamic_dns_update'] else: dynamic_dns_update = None if 'parameters' in dhcpinfo: parameters = dhcpinfo['parameters'] else: parameters = None commands = [] if disabled and (disabled == True or disabled == 'true'): commands.append("$SET service dhcp-server disabled true") else: commands.append("$SET service dhcp-server disabled false") if dynamic_dns_update and (dynamic_dns_update == True or dynamic_dns_update == 'true'): commands.append( "$SET service dhcp-server dynamic-dns-update enable true") else: commands.append( "$SET service dhcp-server dynamic-dns-update enable false") commands.append("$DELETE service dhcp-server global-parameters") if parameters: params = parameters.split(',') for param in params: commands.append("$SET service dhcp-server global-parameters '" + param + "'") return FabricUtilNFV.send_vyatta_command(commands)
def delete_dhcp_task(dhcpinfo): if 'shared_network_name' in dhcpinfo: shared_network_name = dhcpinfo['shared_network_name'] else: shared_network_name = None if 'is_last' in dhcpinfo: is_last = dhcpinfo['is_last'] else: is_last = None commands = [] if is_last and (is_last == True or is_last == 'true'): commands.append("$DELETE service dhcp-server") else: if shared_network_name: commands.append( "$DELETE service dhcp-server shared-network-name " + shared_network_name) return FabricUtilNFV.send_vyatta_command(commands)
def delete_static_routing_task(routinginfo): if 'routing_subnet' in routinginfo: routing_subnet = routinginfo['routing_subnet'] else: routing_subnet = None if 'routing_type' in routinginfo: routing_type = routinginfo['routing_type'] else: routing_type = None if 'routing_table' in routinginfo: routing_table = routinginfo['routing_table'] else: routing_table = None if 'is_last_in_table' in routinginfo: is_last_in_table = routinginfo['is_last_in_table'] else: is_last_in_table = None commands = [] if routing_table and routing_table != "": if is_last_in_table and (is_last_in_table == True or is_last_in_table == "true"): commands.append("$DELETE protocols static table " + routing_table) else: if routing_type == "route": commands.append("$DELETE protocols static table " + routing_table + " route " + routing_subnet) else: commands.append("$DELETE protocols static table " + routing_table + " interface-route " + routing_subnet) else: if routing_type == "route": commands.append("$DELETE protocols static route " + routing_subnet) else: commands.append("$DELETE protocols static interface-route " + routing_subnet) return FabricUtilNFV.send_vyatta_command(commands)
def set_dhcp_global_task(dhcpinfo): if 'disabled' in dhcpinfo: disabled = dhcpinfo['disabled'] else: disabled = None if 'dynamic_dns_update' in dhcpinfo: dynamic_dns_update = dhcpinfo['dynamic_dns_update'] else: dynamic_dns_update = None if 'parameters' in dhcpinfo: parameters = dhcpinfo['parameters'] else: parameters = None commands = [] if disabled and (disabled == True or disabled == 'true'): commands.append("$SET service dhcp-server disabled true") else: commands.append("$SET service dhcp-server disabled false") if dynamic_dns_update and (dynamic_dns_update == True or dynamic_dns_update == 'true'): commands.append("$SET service dhcp-server dynamic-dns-update enable true") else: commands.append("$SET service dhcp-server dynamic-dns-update enable false") commands.append("$DELETE service dhcp-server global-parameters") if parameters: params = parameters.split(',') for param in params: commands.append("$SET service dhcp-server global-parameters '" + param + "'") return FabricUtilNFV.send_vyatta_command(commands)
def update_nic_task(ethName, diff): ''' options = { "duplex": "duplex", "smp_affinity": "smp_affinity", "hw-id": "hw_id", "speed": "speed", "address": "address" } ''' commands = [] for key in diff: if key == "disable" and diff[key] == False: diff[key] = '' # delete 만 하기 위해. if '_' in key: _key = key.replace('_',' ') elif 'ipaddr' == key: continue else: _key = key # 무조건 삭제후 commands.append("$DELETE interfaces ethernet %s %s" % (ethName, key)) if key == "disable" and diff[key] == True: commands.append("$SET interfaces ethernet %s %s" % (ethName, key)) elif len(diff[key]) > 0: #값이 있을때만 set commands.append("$SET interfaces ethernet %s %s %s" % (ethName, key, diff[key])) return FabricUtilNFV.send_vyatta_command(commands)
def set_static_routing_task(routinginfo): if 'routing_subnet' in routinginfo: routing_subnet = routinginfo['routing_subnet'] else: routing_subnet = None if 'routing_type' in routinginfo: routing_type = routinginfo['routing_type'] else: routing_type = None if 'routing_table' in routinginfo: routing_table = routinginfo['routing_table'] else: routing_table = None if 'routing_next_hop_before' in routinginfo: routing_next_hop_before = routinginfo['routing_next_hop_before'] else: routing_next_hop_before = None if 'routing_next_hop' in routinginfo: routing_next_hop = routinginfo['routing_next_hop'] else: routing_next_hop = None if 'routing_distance' in routinginfo: routing_distance = routinginfo['routing_distance'] else: routing_distance = 1 if 'routing_blackhole' in routinginfo: routing_blackhole = routinginfo['routing_blackhole'] else: routing_blackhole = None if 'routing_disable' in routinginfo: routing_disable = routinginfo['routing_disable'] else: routing_disable = None if routing_distance == None or routing_distance == "" or int(routing_distance) <= 0 or int(routing_distance) > 255: routing_distance = 1 commands = [] if routing_table and routing_table != "" and int(routing_table) > 0 and int(routing_table) < 256: if routing_type == "route": if routing_next_hop_before: commands.append("$DELETE protocols static table " + str(routing_table) + " route " + routing_subnet + " next-hop " + routing_next_hop_before) if routing_blackhole and (routing_blackhole == True or routing_blackhole == "true"): commands.append("$SET protocols static table " + str(routing_table) + " route " + routing_subnet + " blackhole distance " + str(routing_distance)) else: commands.append("$SET protocols static table " + str(routing_table) + " route " + routing_subnet + " next-hop " + routing_next_hop + " distance " + str(routing_distance)) if routing_disable and (routing_disable == True or routing_disable == "true"): commands.append("$SET protocols static table " + str(routing_table) + " route " + routing_subnet + " next-hop " + routing_next_hop + " disable") else: if routing_next_hop_before: commands.append("$DELETE protocols static table " + str(routing_table) + " interface-route " + routing_subnet + " next-hop-interface " + routing_next_hop_before) commands.append("$SET protocols static table " + str(routing_table) + " interface-route " + routing_subnet + " next-hop-interface " + routing_next_hop + " distance " + str(routing_distance)) if routing_disable and (routing_disable == True or routing_disable == "true"): commands.append("$SET protocols static table " + str(routing_table) + " interface-route " + routing_subnet + " next-hop-interface " + routing_next_hop + " disable") else: if routing_type == "route": if routing_next_hop_before: commands.append("$DELETE protocols static route " + routing_subnet + " next-hop " + routing_next_hop_before) if routing_blackhole and (routing_blackhole == True or routing_blackhole == "true"): commands.append("$SET protocols static route " + routing_subnet + " blackhole distance " + str(routing_distance)) else: commands.append("$SET protocols static route " + routing_subnet + " next-hop " + routing_next_hop + " distance " + str(routing_distance)) if routing_disable and (routing_disable == True or routing_disable == "true"): commands.append("$SET protocols static route " + routing_subnet + " next-hop " + routing_next_hop + " disable") else: if routing_next_hop_before: commands.append("$DELETE protocols static interface-route " + routing_subnet + " next-hop-interface " + routing_next_hop_before) commands.append("$SET protocols static interface-route " + routing_subnet + " next-hop-interface " + routing_next_hop + " distance " + str(routing_distance)) if routing_disable and (routing_disable == True or routing_disable == "true"): commands.append("$SET protocols static interface-route " + routing_subnet + " next-hop-interface " + routing_next_hop + " disable") return FabricUtilNFV.send_vyatta_command(commands)
def set_dhcp_task(dhcpinfo): if 'disable' in dhcpinfo: disable = dhcpinfo['disable'] else: disable = None if 'authoritative' in dhcpinfo: authoritative = dhcpinfo['authoritative'] else: authoritative = None if 'shared_network_name' in dhcpinfo: shared_network_name = dhcpinfo['shared_network_name'] else: shared_network_name = None if 'subnet_ipv4net' in dhcpinfo: subnet_ipv4net = dhcpinfo['subnet_ipv4net'] else: subnet_ipv4net = None if 'start_ip' in dhcpinfo: start_ip = dhcpinfo['start_ip'] else: start_ip = None if 'stop_ip' in dhcpinfo: stop_ip = dhcpinfo['stop_ip'] else: stop_ip = None if 'default_router' in dhcpinfo: default_router = dhcpinfo['default_router'] else: default_router = None if 'dns_server' in dhcpinfo: dns_server = dhcpinfo['dns_server'] else: dns_server = None if 'domain_name' in dhcpinfo: domain_name = dhcpinfo['domain_name'] else: domain_name = None if 'static_mapping' in dhcpinfo: static_mapping = dhcpinfo['static_mapping'] else: static_mapping = None commands = [] if shared_network_name: if subnet_ipv4net and start_ip and stop_ip: # 1. Set shared-network-name (require : name, ipv4net, start, stop) commands.append("$SET service dhcp-server shared-network-name " + shared_network_name + " subnet " + subnet_ipv4net + " start " + start_ip + " stop " + stop_ip) # 2. Set or Delete default-router if default_router: commands.append( "$SET service dhcp-server shared-network-name " + shared_network_name + " subnet " + subnet_ipv4net + " default-router " + default_router) else: commands.append( "$DELETE service dhcp-server shared-network-name " + shared_network_name + " subnet " + subnet_ipv4net + " default-router") # 3. Delete and Set dns-server commands.append( "$DELETE service dhcp-server shared-network-name " + shared_network_name + " subnet " + subnet_ipv4net + " dns-server") if dns_server: dnsservers = dns_server.split(',') for dnsserver in dnsservers: commands.append( "$SET service dhcp-server shared-network-name " + shared_network_name + " subnet " + subnet_ipv4net + " dns-server " + dnsserver) # 4. Set of Delete domain-name if domain_name: commands.append( "$SET service dhcp-server shared-network-name " + shared_network_name + " subnet " + subnet_ipv4net + " domain-name " + domain_name) else: commands.append( "$DELETE service dhcp-server shared-network-name " + shared_network_name + " subnet " + subnet_ipv4net + " domain-name") # 5. Delete and Set static-mapping commands.append( "$DELETE service dhcp-server shared-network-name " + shared_network_name + " subnet " + subnet_ipv4net + " static-mapping") if static_mapping: for mapping in static_mapping: commands.append( "$SET service dhcp-server shared-network-name " + shared_network_name + " subnet " + subnet_ipv4net + " static-mapping " + mapping['map_name'] + " ip-address " + mapping['map_ip']) commands.append( "$SET service dhcp-server shared-network-name " + shared_network_name + " subnet " + subnet_ipv4net + " static-mapping " + mapping['map_name'] + " mac-address " + mapping['map_mac']) # 6. Set or Delete authoritative if authoritative and (authoritative == True or authoritative == 'true'): commands.append("$SET service dhcp-server shared-network-name " + shared_network_name + " authoritative enable") else: commands.append("$SET service dhcp-server shared-network-name " + shared_network_name + " authoritative disable") # 7. Set of Delete disable if disable and (disable == True or disable == 'true'): commands.append("$SET service dhcp-server shared-network-name " + shared_network_name + " disable") else: commands.append( "$DELETE service dhcp-server shared-network-name " + shared_network_name + " disable") return FabricUtilNFV.send_vyatta_command(commands)
def set_dhcp_task(dhcpinfo): if 'disable' in dhcpinfo: disable = dhcpinfo['disable'] else: disable = None if 'authoritative' in dhcpinfo: authoritative = dhcpinfo['authoritative'] else: authoritative = None if 'shared_network_name' in dhcpinfo: shared_network_name = dhcpinfo['shared_network_name'] else: shared_network_name = None if 'subnet_ipv4net' in dhcpinfo: subnet_ipv4net = dhcpinfo['subnet_ipv4net'] else: subnet_ipv4net = None if 'start_ip' in dhcpinfo: start_ip = dhcpinfo['start_ip'] else: start_ip = None if 'stop_ip' in dhcpinfo: stop_ip = dhcpinfo['stop_ip'] else: stop_ip = None if 'default_router' in dhcpinfo: default_router = dhcpinfo['default_router'] else: default_router = None if 'dns_server' in dhcpinfo: dns_server = dhcpinfo['dns_server'] else: dns_server = None if 'domain_name' in dhcpinfo: domain_name = dhcpinfo['domain_name'] else: domain_name = None if 'static_mapping' in dhcpinfo: static_mapping = dhcpinfo['static_mapping'] else: static_mapping = None commands = [] if shared_network_name: if subnet_ipv4net and start_ip and stop_ip: # 1. Set shared-network-name (require : name, ipv4net, start, stop) commands.append("$SET service dhcp-server shared-network-name " + shared_network_name + " subnet " + subnet_ipv4net + " start " + start_ip + " stop " + stop_ip) # 2. Set or Delete default-router if default_router: commands.append("$SET service dhcp-server shared-network-name " + shared_network_name + " subnet " + subnet_ipv4net + " default-router " + default_router) else: commands.append("$DELETE service dhcp-server shared-network-name " + shared_network_name + " subnet " + subnet_ipv4net + " default-router") # 3. Delete and Set dns-server commands.append("$DELETE service dhcp-server shared-network-name " + shared_network_name + " subnet " + subnet_ipv4net + " dns-server") if dns_server: dnsservers = dns_server.split(',') for dnsserver in dnsservers: commands.append("$SET service dhcp-server shared-network-name " + shared_network_name + " subnet " + subnet_ipv4net + " dns-server " + dnsserver) # 4. Set of Delete domain-name if domain_name: commands.append("$SET service dhcp-server shared-network-name " + shared_network_name + " subnet " + subnet_ipv4net + " domain-name " + domain_name) else: commands.append("$DELETE service dhcp-server shared-network-name " + shared_network_name + " subnet " + subnet_ipv4net + " domain-name") # 5. Delete and Set static-mapping commands.append("$DELETE service dhcp-server shared-network-name " + shared_network_name + " subnet " + subnet_ipv4net + " static-mapping") if static_mapping: for mapping in static_mapping: commands.append("$SET service dhcp-server shared-network-name " + shared_network_name + " subnet " + subnet_ipv4net + " static-mapping " + mapping['map_name'] + " ip-address " + mapping['map_ip']) commands.append("$SET service dhcp-server shared-network-name " + shared_network_name + " subnet " + subnet_ipv4net + " static-mapping " + mapping['map_name'] + " mac-address " + mapping['map_mac']) # 6. Set or Delete authoritative if authoritative and (authoritative == True or authoritative == 'true'): commands.append("$SET service dhcp-server shared-network-name " + shared_network_name + " authoritative enable") else: commands.append("$SET service dhcp-server shared-network-name " + shared_network_name + " authoritative disable") # 7. Set of Delete disable if disable and (disable == True or disable == 'true'): commands.append("$SET service dhcp-server shared-network-name " + shared_network_name + " disable") else: commands.append("$DELETE service dhcp-server shared-network-name " + shared_network_name + " disable") return FabricUtilNFV.send_vyatta_command(commands)
def create_nat_task(natinfo): rulenum = natinfo['rulenum'] ruletype = natinfo['ruletype'] if 'ibnic' in natinfo: ibnic = natinfo['ibnic'] else: ibnic = None if 'obnic' in natinfo: obnic = natinfo['obnic'] else: obnic = None if 'srcaddr' in natinfo: srcaddr = natinfo['srcaddr'] else: srcaddr = None if 'destaddr' in natinfo: destaddr = natinfo['destaddr'] else: destaddr = None if 'srcport' in natinfo: srcport = natinfo['srcport'] else: srcport = None if 'destport' in natinfo: destport = natinfo['destport'] else: destport = None if 'protocol' in natinfo: protocol = natinfo['protocol'] else: protocol = None if 'transaddr' in natinfo: transaddr = natinfo['transaddr'] else: transaddr = None if 'transport' in natinfo: transport = natinfo['transport'] else: transport = None if 'masquerade' in natinfo: masquerade = natinfo['masquerade'] else: masquerade = None if 'disable' in natinfo: disable = natinfo['disable'] else: disable = None if 'exclude' in natinfo: exclude = natinfo['exclude'] else: exclude = None commands = [] if ruletype == "destination" and ibnic: commands.append("$SET nat " + ruletype + " rule " + rulenum + " inbound-interface " + ibnic) if ruletype == "source" and obnic: commands.append("$SET nat " + ruletype + " rule " + rulenum + " outbound-interface " + obnic) if srcaddr: commands.append("$SET nat " + ruletype + " rule " + rulenum + " source address " + srcaddr) if srcport: commands.append("$SET nat " + ruletype + " rule " + rulenum + " source port " + srcport) if destaddr: commands.append("$SET nat " + ruletype + " rule " + rulenum + " destination address " + destaddr) if destport: commands.append("$SET nat " + ruletype + " rule " + rulenum + " destination port " + destport) if protocol: commands.append("$SET nat " + ruletype + " rule " + rulenum + " protocol " + str(protocol).lower()) if transaddr: commands.append("$SET nat " + ruletype + " rule " + rulenum + " translation address " + transaddr) else: if masquerade: commands.append("$SET nat " + ruletype + " rule " + rulenum + " translation address masquerade") if transport: commands.append("$SET nat " + ruletype + " rule " + rulenum + " translation port " + transport) if disable: commands.append("$SET nat " + ruletype + " rule " + rulenum + " disable") if exclude: commands.append("$SET nat " + ruletype + " rule " + rulenum + " exclude") return FabricUtilNFV.send_vyatta_command(commands)
def flush_static_routing_task(): commands = [] commands.append("$RESET ip route cache") return FabricUtilNFV.send_vyatta_command(commands)
def set_static_routing_task(routinginfo): if 'routing_subnet' in routinginfo: routing_subnet = routinginfo['routing_subnet'] else: routing_subnet = None if 'routing_type' in routinginfo: routing_type = routinginfo['routing_type'] else: routing_type = None if 'routing_table' in routinginfo: routing_table = routinginfo['routing_table'] else: routing_table = None if 'routing_next_hop_before' in routinginfo: routing_next_hop_before = routinginfo['routing_next_hop_before'] else: routing_next_hop_before = None if 'routing_next_hop' in routinginfo: routing_next_hop = routinginfo['routing_next_hop'] else: routing_next_hop = None if 'routing_distance' in routinginfo: routing_distance = routinginfo['routing_distance'] else: routing_distance = 1 if 'routing_blackhole' in routinginfo: routing_blackhole = routinginfo['routing_blackhole'] else: routing_blackhole = None if 'routing_disable' in routinginfo: routing_disable = routinginfo['routing_disable'] else: routing_disable = None if routing_distance == None or routing_distance == "" or int( routing_distance) <= 0 or int(routing_distance) > 255: routing_distance = 1 commands = [] if routing_table and routing_table != "" and int( routing_table) > 0 and int(routing_table) < 256: if routing_type == "route": if routing_next_hop_before: commands.append("$DELETE protocols static table " + str(routing_table) + " route " + routing_subnet + " next-hop " + routing_next_hop_before) if routing_blackhole and (routing_blackhole == True or routing_blackhole == "true"): commands.append("$SET protocols static table " + str(routing_table) + " route " + routing_subnet + " blackhole distance " + str(routing_distance)) else: commands.append("$SET protocols static table " + str(routing_table) + " route " + routing_subnet + " next-hop " + routing_next_hop + " distance " + str(routing_distance)) if routing_disable and (routing_disable == True or routing_disable == "true"): commands.append("$SET protocols static table " + str(routing_table) + " route " + routing_subnet + " next-hop " + routing_next_hop + " disable") else: if routing_next_hop_before: commands.append("$DELETE protocols static table " + str(routing_table) + " interface-route " + routing_subnet + " next-hop-interface " + routing_next_hop_before) commands.append("$SET protocols static table " + str(routing_table) + " interface-route " + routing_subnet + " next-hop-interface " + routing_next_hop + " distance " + str(routing_distance)) if routing_disable and (routing_disable == True or routing_disable == "true"): commands.append("$SET protocols static table " + str(routing_table) + " interface-route " + routing_subnet + " next-hop-interface " + routing_next_hop + " disable") else: if routing_type == "route": if routing_next_hop_before: commands.append("$DELETE protocols static route " + routing_subnet + " next-hop " + routing_next_hop_before) if routing_blackhole and (routing_blackhole == True or routing_blackhole == "true"): commands.append("$SET protocols static route " + routing_subnet + " blackhole distance " + str(routing_distance)) else: commands.append("$SET protocols static route " + routing_subnet + " next-hop " + routing_next_hop + " distance " + str(routing_distance)) if routing_disable and (routing_disable == True or routing_disable == "true"): commands.append("$SET protocols static route " + routing_subnet + " next-hop " + routing_next_hop + " disable") else: if routing_next_hop_before: commands.append("$DELETE protocols static interface-route " + routing_subnet + " next-hop-interface " + routing_next_hop_before) commands.append("$SET protocols static interface-route " + routing_subnet + " next-hop-interface " + routing_next_hop + " distance " + str(routing_distance)) if routing_disable and (routing_disable == True or routing_disable == "true"): commands.append("$SET protocols static interface-route " + routing_subnet + " next-hop-interface " + routing_next_hop + " disable") return FabricUtilNFV.send_vyatta_command(commands)
def flush_static_routing_task(): commands = [] commands.append("$RESET ip route cache") return FabricUtilNFV.send_vyatta_command(commands)
def update_remote_service_task(serviceinfo): if 'httpsenable' in serviceinfo: httpsenable = serviceinfo['httpsenable'] else: httpsenable = None if 'httpsaddr' in serviceinfo: httpsaddr = serviceinfo['httpsaddr'] else: httpsaddr = None if 'sshenable' in serviceinfo: sshenable = serviceinfo['sshenable'] else: sshenable = None if 'allowroot' in serviceinfo: allowroot = serviceinfo['allowroot'] else: allowroot = None if 'sshaddr' in serviceinfo: sshaddr = serviceinfo['sshaddr'] else: sshaddr = None if 'sshport' in serviceinfo: sshport = serviceinfo['sshport'] else: sshport = None commands = [] if httpsenable and (httpsenable == True or httpsenable == 'true'): commands.append("$SET service https") commands.append("$DELETE service https listen-address") if httpsaddr and httpsaddr != "": addrs = httpsaddr.split(',') for addr in addrs: commands.append("$SET service https listen-address " + addr) else: commands.append("$DELETE service https") ''' # SSH 관련 기능은 관리상의 이슈로 현재는 읽기 전용으로만 제공 if sshenable and sshenable == 'true': commands.append("$DELETE service ssh listen-address") if allowroot and allowroot == 'true': commands.append("$SET service ssh allow-root") else: commands.append("$DELETE service ssh allow-root") if sshport: commands.append("$SET service ssh port " + sshport) if sshaddr and sshaddr != "": addrs = sshaddr.split(',') for addr in addrs: commands.append("$SET service ssh listen-address " + addr) ''' return FabricUtilNFV.send_vyatta_command(commands)
def create_nat_task(natinfo): rulenum = natinfo["rulenum"] ruletype = natinfo["ruletype"] if "ibnic" in natinfo: ibnic = natinfo["ibnic"] else: ibnic = None if "obnic" in natinfo: obnic = natinfo["obnic"] else: obnic = None if "srcaddr" in natinfo: srcaddr = natinfo["srcaddr"] else: srcaddr = None if "destaddr" in natinfo: destaddr = natinfo["destaddr"] else: destaddr = None if "srcport" in natinfo: srcport = natinfo["srcport"] else: srcport = None if "destport" in natinfo: destport = natinfo["destport"] else: destport = None if "protocol" in natinfo: protocol = natinfo["protocol"] else: protocol = None if "transaddr" in natinfo: transaddr = natinfo["transaddr"] else: transaddr = None if "transport" in natinfo: transport = natinfo["transport"] else: transport = None if "masquerade" in natinfo: masquerade = natinfo["masquerade"] else: masquerade = None if "disable" in natinfo: disable = natinfo["disable"] else: disable = None if "exclude" in natinfo: exclude = natinfo["exclude"] else: exclude = None commands = [] if ruletype == "destination" and ibnic: commands.append("$SET nat " + ruletype + " rule " + rulenum + " inbound-interface " + ibnic) if ruletype == "source" and obnic: commands.append("$SET nat " + ruletype + " rule " + rulenum + " outbound-interface " + obnic) if srcaddr: commands.append("$SET nat " + ruletype + " rule " + rulenum + " source address " + srcaddr) if srcport: commands.append("$SET nat " + ruletype + " rule " + rulenum + " source port " + srcport) if destaddr: commands.append("$SET nat " + ruletype + " rule " + rulenum + " destination address " + destaddr) if destport: commands.append("$SET nat " + ruletype + " rule " + rulenum + " destination port " + destport) if protocol: commands.append("$SET nat " + ruletype + " rule " + rulenum + " protocol " + str(protocol).lower()) if transaddr: commands.append("$SET nat " + ruletype + " rule " + rulenum + " translation address " + transaddr) else: if masquerade: commands.append("$SET nat " + ruletype + " rule " + rulenum + " translation address masquerade") if transport: commands.append("$SET nat " + ruletype + " rule " + rulenum + " translation port " + transport) if disable: commands.append("$SET nat " + ruletype + " rule " + rulenum + " disable") if exclude: commands.append("$SET nat " + ruletype + " rule " + rulenum + " exclude") return FabricUtilNFV.send_vyatta_command(commands)