from netaddr import IPNetwork, IPAddress, all_matching_cidrs
#import only if needed because not needed in test mode. To allow an easier installation import RADclass
from jsonschema import validate as js_v, exceptions as js_e
from netaddr import IPNetwork, IPAddress, all_matching_cidrs
#import only if needed because not needed in test mode. To allow an easier installation import RADclass
from jsonschema import validate as js_v, exceptions as js_e
http2db_image={'id':'uuid', 'created':'created_at', 'updated':'modified_at', 'public': 'public'}
http2db_server={'id':'uuid','hostId':'host_id','flavorRef':'flavor_id','imageRef':'image_id','created':'created_at'}
http2db_network={'id':'uuid','provider:vlan':'vlan', 'provider:physical': 'provider'}
http2db_ofc = {'id': 'uuid'}
http2db_port={'id':'uuid', 'network_id':'net_id', 'mac_address':'mac', 'device_owner':'type','device_id':'instance_id','binding:switch_port':'switch_port','binding:vlan':'vlan', 'bandwidth':'Mbps'}
http2db_image={'id':'uuid', 'created':'created_at', 'updated':'modified_at', 'public': 'public'}
http2db_server={'id':'uuid','hostId':'host_id','flavorRef':'flavor_id','imageRef':'image_id','created':'created_at'}
http2db_network={'id':'uuid','provider:vlan':'vlan', 'provider:physical': 'provider'}
http2db_ofc = {'id': 'uuid'}
http2db_port={'id':'uuid', 'network_id':'net_id', 'mac_address':'mac', 'device_owner':'type','device_id':'instance_id','binding:switch_port':'switch_port','binding:vlan':'vlan', 'bandwidth':'Mbps'}
deleted=[]
if type(data) is tuple or type(data) is list:
for d in data:
a= remove_extra_items(d, schema['items'])
if a is not None: deleted.append(a)
elif type(data) is dict:
deleted=[]
if type(data) is tuple or type(data) is list:
for d in data:
a= remove_extra_items(d, schema['items'])
if a is not None: deleted.append(a)
elif type(data) is dict:
- if 'properties' not in schema or k not in schema['properties'].keys():
+ if 'patternProperties' in schema and k not in schema['properties'].keys():
+ reg_ex_list = schema['patternProperties'].keys()
+ for reg_ex in reg_ex_list:
+ if not re.match(reg_ex, k):
+ del data[k]
+ deleted.append(k)
+ elif 'properties' not in schema or k not in schema['properties'].keys(): # or k not in schema['patternProperties'].keys():
for numa in host.get("numas", ()):
if "hugepages_consumed" in numa:
del numa["hugepages_consumed"]
for numa in host.get("numas", ()):
if "hugepages_consumed" in numa:
del numa["hugepages_consumed"]
+ for core in numa.get("cores", ()):
+ if "instance_id" in core:
+ del core["instance_id"]
+ if "v_thread_id" in core:
+ del core["v_thread_id"]
result, content = my.db.new_host(host)
if result >= 0:
if content['admin_state_up']:
result, content = my.db.new_host(host)
if result >= 0:
if content['admin_state_up']:
test=host_test_mode, image_path=config_dic['host_image_path'],
version=config_dic['version'], host_id=content['uuid'],
develop_mode=host_develop_mode, develop_bridge_iface=host_develop_bridge_iface)
test=host_test_mode, image_path=config_dic['host_image_path'],
version=config_dic['version'], host_id=content['uuid'],
develop_mode=host_develop_mode, develop_bridge_iface=host_develop_bridge_iface)
if config_dic['network_type'] == 'ovs':
# create bridge
create_dhcp_ovs_bridge()
config_dic['host_threads'][content['uuid']].insert_task("new-ovsbridge")
if config_dic['network_type'] == 'ovs':
# create bridge
create_dhcp_ovs_bridge()
config_dic['host_threads'][content['uuid']].insert_task("new-ovsbridge")
- # check if more host exist
- create_vxlan_mesh(content['uuid'])
+ # create vlxan bwt OVS controller and computes
+ create_vxlan_mesh(content['uuid'], my.logger)
change_keys_http2db(content, http2db_host, reverse=True)
if len(warning_text)>0:
content["warning"]= warning_text
change_keys_http2db(content, http2db_host, reverse=True)
if len(warning_text)>0:
content["warning"]= warning_text
http_controller = config_dic['http_threads'][threading.current_thread().name]
dhcp_controller = http_controller.ovim.get_dhcp_controller()
http_controller = config_dic['http_threads'][threading.current_thread().name]
dhcp_controller = http_controller.ovim.get_dhcp_controller()
http_controller = config_dic['http_threads'][threading.current_thread().name]
dhcp_controller = http_controller.ovim.get_dhcp_controller()
http_controller = config_dic['http_threads'][threading.current_thread().name]
dhcp_controller = http_controller.ovim.get_dhcp_controller()
- dhcp_controller.set_mac_dhcp_server(vm_ip, mac, vlan, dhcp_netmask, dhcp_path)
+ dhcp_controller.set_mac_dhcp_server(vm_ip, mac, vlan, dhcp_netmask, first_ip, dhcp_path)
dhcp_controller.delete_mac_dhcp_server(vm_ip, mac, vlan, dhcp_path)
dhcp_controller.delete_mac_dhcp_server(vm_ip, mac, vlan, dhcp_path)
+ try:
+ if compute['ip_name'] != 'localhost':
+ remote_ip = socket.gethostbyname(compute['ip_name'])
+ else:
+ remote_ip = 'localhost'
+ except socket.error as e:
+ if logger:
+ logger.error("Cannot get compute node remote ip from '{}'. Skipping: {}".format(
+ compute['ip_name'], e))
+ continue
+ # vxlan ovs_controller <=> compute node
vxlan_interface_name = get_vxlan_interface(compute['id'][:8])
config_dic['host_threads'][compute['id']].insert_task("new-vxlan", dhcp_compute_name, dhcp_controller.host)
vxlan_interface_name = get_vxlan_interface(compute['id'][:8])
config_dic['host_threads'][compute['id']].insert_task("new-vxlan", dhcp_compute_name, dhcp_controller.host)
- dhcp_controller.create_ovs_vxlan_tunnel(vxlan_interface_name, compute['ip_name'])
-
- # vlxan mesh creation between openvim computes
- for count, compute_owner in enumerate(computes_available):
- for compute in computes_available:
- if compute_owner['id'] == compute['id']:
- pass
- else:
- vxlan_interface_name = get_vxlan_interface(compute_owner['id'][:8])
- dhcp_controller.create_ovs_vxlan_tunnel(vxlan_interface_name, compute_owner['ip_name'])
- config_dic['host_threads'][compute['id']].insert_task("new-vxlan",
- vxlan_interface_name,
- compute_owner['ip_name'])
-
+ dhcp_controller.create_ovs_vxlan_tunnel(vxlan_interface_name, remote_ip)
+ # vxlan from others compute node to cthis ompute node
+ for compute_src in computes_available:
+ if compute_src['id'] == compute['id']:
+ continue
+ config_dic['host_threads'][compute_src['id']].insert_task("new-vxlan",
+ vxlan_interface_name,
+ remote_ip)
if config_dic['network_type'] == 'ovs':
# create mesh with new host data
config_dic['host_threads'][host_id].insert_task("new-ovsbridge")
if config_dic['network_type'] == 'ovs':
# create mesh with new host data
config_dic['host_threads'][host_id].insert_task("new-ovsbridge")
new_instance_result, new_instance = my.db.new_instance(content, nets, ports_to_free)
if new_instance_result < 0:
print "Error http_post_servers() :", new_instance_result, new_instance
new_instance_result, new_instance = my.db.new_instance(content, nets, ports_to_free)
if new_instance_result < 0:
print "Error http_post_servers() :", new_instance_result, new_instance
for port in ports_to_free:
r,c = config_dic['host_threads'][ server['host_id'] ].insert_task( 'restore-iface',*port )
if r < 0:
for port in ports_to_free:
r,c = config_dic['host_threads'][ server['host_id'] ].insert_task( 'restore-iface',*port )
if r < 0:
dhcp_enable = bool(server_net['network']['enable_dhcp'])
vm_dhcp_ip = c2[0]["ip_address"]
config_dic['host_threads'][server['host_id']].insert_task("create-ovs-bridge-port", vlan)
dhcp_enable = bool(server_net['network']['enable_dhcp'])
vm_dhcp_ip = c2[0]["ip_address"]
config_dic['host_threads'][server['host_id']].insert_task("create-ovs-bridge-port", vlan)
+ dns = server_net['network'].get("dns")
+ if dns:
+ dns = yaml.safe_load(server_net['network'].get("dns"))
+ routes = server_net['network'].get("routes")
+ if routes:
+ routes = yaml.safe_load(server_net['network'].get("routes"))
+ links = server_net['network'].get("links")
+ if links:
+ links = yaml.safe_load(server_net['network'].get("links"))
if dhcp_enable:
dhcp_firt_ip = str(server_net['network']['dhcp_first_ip'])
dhcp_last_ip = str(server_net['network']['dhcp_last_ip'])
dhcp_cidr = str(server_net['network']['cidr'])
gateway = str(server_net['network']['gateway_ip'])
if dhcp_enable:
dhcp_firt_ip = str(server_net['network']['dhcp_first_ip'])
dhcp_last_ip = str(server_net['network']['dhcp_last_ip'])
dhcp_cidr = str(server_net['network']['cidr'])
gateway = str(server_net['network']['gateway_ip'])
- http_controller.ovim.launch_dhcp_server(vlan, dhcp_firt_ip, dhcp_last_ip, dhcp_cidr, gateway)
+ http_controller.ovim.launch_dhcp_server(vlan, dhcp_firt_ip, dhcp_last_ip,
+ dhcp_cidr, gateway, dns, routes)
+ set_mac_dhcp(vm_dhcp_ip, vlan, dhcp_firt_ip, dhcp_last_ip, dhcp_cidr, c2[0]['mac'])
+
+ if links:
+ http_controller.ovim.launch_link_bridge_to_ovs(vlan, gateway, dhcp_cidr, links, routes)
+
def http_server_action(server_id, tenant_id, action):
'''Perform actions over a server as resume, reboot, terminate, ...'''
my = config_dic['http_threads'][ threading.current_thread().name ]
def http_server_action(server_id, tenant_id, action):
'''Perform actions over a server as resume, reboot, terminate, ...'''
my = config_dic['http_threads'][ threading.current_thread().name ]
#print "dhcp insert del task"
if r < 0:
print ':http_post_servers ERROR UPDATING dhcp_server !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + c
#print "dhcp insert del task"
if r < 0:
print ':http_post_servers ERROR UPDATING dhcp_server !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + c
- # delete ovs-port and linux bridge, contains a list of tuple (net_id,vlan)
+ # delete ovs-port and linux bridge, contains a list of tuple (net_id,vlan, vm_ip, mac)
+
delete_dhcp_ovs_bridge(vlan, net_id)
delete_mac_dhcp(vm_ip, vlan, mac)
delete_dhcp_ovs_bridge(vlan, net_id)
delete_mac_dhcp(vm_ip, vlan, mac)
+
+ net_data = my.ovim.show_network(net_id)
+ if net_data.get('links'):
+ links = yaml.load(net_data.get('links'))
+ my.ovim.delete_link_bridge_to_ovs(vlan, links)
+
config_dic['host_threads'][server['host_id']].insert_task('del-ovs-port', vlan, net_id)
if warn_text:
data["result"] += warn_text
config_dic['host_threads'][server['host_id']].insert_task('del-ovs-port', vlan, net_id)
if warn_text:
data["result"] += warn_text
r = remove_extra_items(http_content, network_new_schema)
if r is not None:
print "http_post_networks: Warning: remove extra items ", r
r = remove_extra_items(http_content, network_new_schema)
if r is not None:
print "http_post_networks: Warning: remove extra items ", r