def all_bonding(vmid):
	vm = get_vm(vmid)
	addr = vm['mgraddr']
	
	result = []
	bond_dic = {}
	
	nics = FabricUtilNFV.getInterfaces(addr, vm['sshid'], vm['sshpw'], None)
	
	logger.debug(json.dumps(nics, indent=4))
	
	nicinfo = FabricUtilNFV.getIfConfig(addr, vm['sshid'], vm['sshpw'], "")
	
	#bonging 정보만 추출.
	for nic in nics:
		if "address" in nic and nic["address"] == 'dhcp':
			nic["ipaddr"] = nicinfo[nic["ethName"]]
				
		
		if nic["ethName"].startswith("bond"):
			nic['ethernets'] = []
			nic['config'] = FabricUtilNFV.get_vyatta_conf(vmid, "$SHOW interfaces")
			bond_dic[nic["ethName"]] = nic
		elif nic.has_key('bond-group'):
			bond_dic[nic["bond-group"]]['ethernets'].append(nic["ethName"])
			
	
	for bond_id in bond_dic:
		result.append(bond_dic[bond_id])
	
	
	return result
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)
示例#3
0
def get_nat(vmid, rulenum, ruletype):
    logger.debug("get_nat call!!")

    vm = get_vm(vmid)

    results = []
    nats = FabricUtilNFV.getNATs(vm["mgraddr"], vm["sshid"], vm["sshpw"])
    for nat in nats:
        if ruletype:
            if ruletype == "source" and nat["isSource"] == True:
                if rulenum:
                    if rulenum == nat["rule"]:
                        results.append(nat)
                else:
                    results.append(nat)
            elif ruletype == "destination" and nat["isSource"] == False:
                if rulenum:
                    if rulenum == nat["rule"]:
                        results.append(nat)
                else:
                    results.append(nat)
        else:
            if rulenum:
                if rulenum == nat["rule"]:
                    results.append(nat)
            else:
                results.append(nat)

    return results
示例#4
0
def get_nat(vmid, rulenum, ruletype):
    logger.debug("get_nat call!!")

    vm = get_vm(vmid)

    results = []
    nats = FabricUtilNFV.getNATs(vm['mgraddr'], vm['sshid'], vm['sshpw'])
    for nat in nats:
        if ruletype:
            if ruletype == "source" and nat['isSource'] == True:
                if rulenum:
                    if rulenum == nat['rule']:
                        results.append(nat)
                else:
                    results.append(nat)
            elif ruletype == "destination" and nat['isSource'] == False:
                if rulenum:
                    if rulenum == nat['rule']:
                        results.append(nat)
                else:
                    results.append(nat)
        else:
            if rulenum:
                if rulenum == nat['rule']:
                    results.append(nat)
            else:
                results.append(nat)

    return results
示例#5
0
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)
示例#6
0
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)
示例#8
0
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 get_dhcp(vmid): 
    logger.debug("get_dhcp call!!")
    
    vm = get_vm(vmid)
    
    result = {}
    services = FabricUtilNFV.getServices(vm['mgraddr'], vm['sshid'], vm['sshpw'])
    for service in services:
        if 'service' in service and service['service'] == 'dhcp-server':
            result = service

    return result
def get_static_routing(vmid): 
    logger.debug("get_static_routing call!!")
    
    vm = get_vm(vmid)
    
    result = {}
    protocols = FabricUtilNFV.getProtocols(vm['mgraddr'], vm['sshid'], vm['sshpw'])
    for protocol in protocols:
        if 'protocol' in protocol and protocol['protocol'] == 'static':
            result = protocol

    return result
示例#11
0
def get_remote_service(vmid):
    logger.debug("get_remote_service call!!")
    
    vm = get_vm(vmid)
    
    results = []
    services = FabricUtilNFV.getServices(vm['mgraddr'], vm['sshid'], vm['sshpw'])
    for service in services:
        if service['service'] == 'ssh' or service['service'] == 'https':
            results.append(service)

    return results
def get_system(vmid):
    logger.debug("get_system call!!")
    
    vm = get_vm(vmid)
    
    results = []
    system = FabricUtilNFV.getSystem(vm['mgraddr'], vm['sshid'], vm['sshpw'])
    for prop in system:
        if prop['category'] == 'host-name' or prop['category'] == 'time-zone' or prop['category'] == 'login':
            results.append(prop)

    return results
def get_static_routing(vmid):
    logger.debug("get_static_routing call!!")

    vm = get_vm(vmid)

    result = {}
    protocols = FabricUtilNFV.getProtocols(vm['mgraddr'], vm['sshid'],
                                           vm['sshpw'])
    for protocol in protocols:
        if 'protocol' in protocol and protocol['protocol'] == 'static':
            result = protocol

    return result
示例#14
0
def get_system(vmid):
    logger.debug("get_system call!!")

    vm = get_vm(vmid)

    results = []
    system = FabricUtilNFV.getSystem(vm['mgraddr'], vm['sshid'], vm['sshpw'])
    for prop in system:
        if prop['category'] == 'host-name' or prop[
                'category'] == 'time-zone' or prop['category'] == 'login':
            results.append(prop)

    return results
示例#15
0
def get_dhcp(vmid):
    logger.debug("get_dhcp call!!")

    vm = get_vm(vmid)

    result = {}
    services = FabricUtilNFV.getServices(vm['mgraddr'], vm['sshid'],
                                         vm['sshpw'])
    for service in services:
        if 'service' in service and service['service'] == 'dhcp-server':
            result = service

    return result
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 get_bonding(vmid, bondid):
	vm = get_vm(vmid)
	
	addr = vm['mgraddr']

	results = {}
	nics = FabricUtilNFV.getInterfaces(addr, vm['sshid'], vm['sshpw'], None)
	bonding = {}
	nicinfo = FabricUtilNFV.getIfConfig(addr, vm['sshid'], vm['sshpw'], "")
	
	for nic in nics:
		logger.debug(bondid + ": " + nic['ethName'])
		if bondid == nic['ethName']:
			nic['config'] = FabricUtilNFV.get_vyatta_conf(vmid, "$SHOW interfaces")
			
			if "address" in nic and nic["address"] == 'dhcp':
				nic["ipaddr"] = nicinfo[nic['ethName']]
					
			
			bonding[bondid] = nic
			bonding['ethernets'] = []
			bonding['disables'] = []
			results['success'] = 'success'
			
		elif nic.has_key('bond-group') and bondid == nic['bond-group']:
			bonding['ethernets'].append(nic['ethName'])
		elif nic.has_key('bond-group'):
			bonding['disables'].append(nic['ethName'])
		
	if results.has_key('success'):
		results['msg'] = json.dumps(bonding)
	else:
		results['success'] = 'fail'
		results['errmsg'] = 'bonding not found.'

	return results
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)
示例#19
0
def update_nic(vmid, params):
	
	pdiff = PyUtils.diff_vyatta_conf(params['before'], params['after'])
	
	if len(pdiff) == 0:
		logger.debug("NIC 수정사항이 없습니다.")
		return {"success": "success", "msg": "수정 사항이 없습니다."}
	
	vms = read_repository("vms")
	
	for vm in vms:
		print vm['_id'] + " : " + vmid
		if '_id' in vm and vmid == vm['_id']:
			break
	if vm == None:
		raise ValueError("get_vm not found: " + vmid)

	pEthName = params['after']['ethName']
	addr = vm['mgraddr']
	
	env.hosts = [ addr ]
	env.user = vm['sshid']
	env.password = vm['sshpw']
	env.shell = '/bin/vbash -ic'
	results = execute(update_nic_task, hosts=[addr], ethName = pEthName, diff=pdiff)
	
	
	# vms.json 파일도 변경해주기.
	modified = False
	for key in pdiff:
		if "disable" == key:
			vm["interfaces"][pEthName]["disable"] = pdiff[key]
			modified = True
		if "hw-id" == key:
			vm["interfaces"][pEthName]["macaddr"] = pdiff[key]
			modified = True
		if "address" == key:
			modified = True
			if pdiff[key] == "dhcp":
				nicinfo = FabricUtilNFV.getIfConfig(addr, vm['sshid'], vm['sshpw'], pEthName)
				vm["interfaces"][pEthName]["ipaddr"] = nicinfo[pEthName]
			else:
				vm["interfaces"][pEthName]["ipaddr"] = pdiff[key]
	
	if modified:
		write_repository('vms', vms)
	
	return results[addr]
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)
示例#21
0
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_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)
示例#24
0
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)
示例#25
0
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)
示例#28
0
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)
示例#30
0
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 flush_static_routing_task():
    commands = []
    commands.append("$RESET ip route cache")
            
    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)
示例#33
0
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)
示例#34
0
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)
示例#35
0
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)