From d06b586f54ee5be7d688093e4017520f1b398c94 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Thu, 22 Dec 2016 11:39:52 +0100 Subject: [PATCH] Modify network table to ease OS integration --- models/fednet_pool.rb | 15 +++++++++++++-- models/site_pool.rb | 8 ++++---- models/tenant_pool.rb | 6 +++++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/models/fednet_pool.rb b/models/fednet_pool.rb index 7c709d7..ffd3e33 100644 --- a/models/fednet_pool.rb +++ b/models/fednet_pool.rb @@ -120,10 +120,21 @@ def update(id, username, is_admin, new_fednet) # Build the network table net_array = Array.new fednet_hash[:netsegments].each{|ns| - net_array << ns[:cmp_blob] + net_array_element = Hash.new + net_array_element[:name] = ns[:name] + net_array_element[:vnid] = ns[:cmp_net_id] + net_array_element[:site] = FederatedSDN::SitePool.new().get(ns[:site_id]).name + net_array_element[:tenant_id] = FederatedSDN::TenantPool.new().get_tenant_id_in_site(owner, net_array_element[:site]) + net_array_element[:cmp_blob] = ns[:cmp_blob] + + net_array << net_array_element } - result = link("opennebula", fednet_hash[:linktype], token, fa_array, net_array) + result = link("opennebula", + fednet_hash[:linktype], + token, + fa_array, + net_array) if result.code == 0 new_resource["status"] = "linked" diff --git a/models/site_pool.rb b/models/site_pool.rb index f7d0839..343ea86 100644 --- a/models/site_pool.rb +++ b/models/site_pool.rb @@ -25,11 +25,11 @@ def initialize() end def bootstrap - DB.run "CREATE TABLE #{TABLE_NAME} "\ - "(id integer primary key autoincrement,"\ - " name varchar(255) UNIQUE,"\ + DB.run "CREATE TABLE #{TABLE_NAME} "\ + "(id integer primary key autoincrement,"\ + " name varchar(255) UNIQUE,"\ " type varchar(255),"\ - " cmp_endpoint varchar(255))" + " cmp_endpoint varchar(255))" end # Needs at least name and cmp_endpoint diff --git a/models/tenant_pool.rb b/models/tenant_pool.rb index 458133c..b4e21af 100644 --- a/models/tenant_pool.rb +++ b/models/tenant_pool.rb @@ -42,7 +42,7 @@ def bootstrap # Add root admin user username = FederatedSDN::CONF[:root_username] - password = FederatedSDN::CONF[:root_password] + password = FederatedSDN::CONF[:root_password] id = 1 tenant_hash = { @@ -274,6 +274,10 @@ def is_admin(username) @table.filter(:name => username).first[:type] == "admin" end + def get_tenant_id_in_site(username, site) + tenant_id = @table.filter(:name => username).first[:id] + @table_to_site.filter(:tenant_id => tenant_id).filter(:site_id => site_id).first[:user_id_in_site] + end def validate_user(site_type, cmp_endpoint, username, password) cmd = ADAPTERS_LOCATION + "/" + site_type.downcase + "/"