diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..97626ba
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..7c4b884
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..9f615f2
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/openstack-scripts.iml b/.idea/openstack-scripts.iml
new file mode 100644
index 0000000..6711606
--- /dev/null
+++ b/.idea/openstack-scripts.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/NTT/ntt-29-3-16-test/.discover_deploy.py.swp b/NTT/ntt-29-3-16-test/.discover_deploy.py.swp
new file mode 100755
index 0000000..f7c19f0
Binary files /dev/null and b/NTT/ntt-29-3-16-test/.discover_deploy.py.swp differ
diff --git a/NTT/ntt-29-3-16-test/.discovery.py.swp b/NTT/ntt-29-3-16-test/.discovery.py.swp
new file mode 100755
index 0000000..41fba52
Binary files /dev/null and b/NTT/ntt-29-3-16-test/.discovery.py.swp differ
diff --git a/NTT/ntt-29-3-16-test/.idea/misc.xml b/NTT/ntt-29-3-16-test/.idea/misc.xml
new file mode 100755
index 0000000..7c4b884
--- /dev/null
+++ b/NTT/ntt-29-3-16-test/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/NTT/ntt-29-3-16-test/.idea/modules.xml b/NTT/ntt-29-3-16-test/.idea/modules.xml
new file mode 100755
index 0000000..64e6bd4
--- /dev/null
+++ b/NTT/ntt-29-3-16-test/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/NTT/ntt-29-3-16-test/.idea/ntt-29-2-16-test.iml b/NTT/ntt-29-3-16-test/.idea/ntt-29-2-16-test.iml
new file mode 100755
index 0000000..6f63a63
--- /dev/null
+++ b/NTT/ntt-29-3-16-test/.idea/ntt-29-2-16-test.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/NTT/ntt-29-3-16-test/.idea/workspace.xml b/NTT/ntt-29-3-16-test/.idea/workspace.xml
new file mode 100755
index 0000000..59b7f9e
--- /dev/null
+++ b/NTT/ntt-29-3-16-test/.idea/workspace.xml
@@ -0,0 +1,436 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1459230370172
+
+
+ 1459230370172
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/NTT/ntt-29-3-16-test/.networks.py.swp b/NTT/ntt-29-3-16-test/.networks.py.swp
new file mode 100755
index 0000000..a8931b6
Binary files /dev/null and b/NTT/ntt-29-3-16-test/.networks.py.swp differ
diff --git a/NTT/ntt-29-3-16-test/.t1.py.swp b/NTT/ntt-29-3-16-test/.t1.py.swp
new file mode 100755
index 0000000..2053542
Binary files /dev/null and b/NTT/ntt-29-3-16-test/.t1.py.swp differ
diff --git a/NTT/ntt-29-3-16-test/.vm_instances.py.swp b/NTT/ntt-29-3-16-test/.vm_instances.py.swp
new file mode 100755
index 0000000..c31dbb5
Binary files /dev/null and b/NTT/ntt-29-3-16-test/.vm_instances.py.swp differ
diff --git a/NTT/ntt-29-3-16-test/config.py b/NTT/ntt-29-3-16-test/config.py
new file mode 100755
index 0000000..59f058e
--- /dev/null
+++ b/NTT/ntt-29-3-16-test/config.py
@@ -0,0 +1,75 @@
+"""
+Description: Define the Scale Test Configuration with the below global \
+ parameters.
+Developer: gopal@onecloudinc.com
+"""
+
+# Tenant Settings
+
+OS_USERNAME = 'admin'
+OS_TENANT_NAME = 'admin'
+OS_PASSWORD = 'admin'
+OS_AUTH_URL = 'http://172.168.2.40:5000/v2.0/'
+
+# TENANT_CREATION = True
+
+TENANT_COUNT = 2
+TENANT_NAME_PREFIX = 'tenant-test'
+TENANT_BASE_INDEX = 101
+USER_COUNT = 1
+USER_PASSWORD = 'secret'
+NETWORK_COUNT = 2
+VM_COUNT = 1
+IMAGE_NAME = 'Cirros'
+FLAVOUR_NAME = 'm1.tiny'
+EXTERNAL_NETWORK = 'public'
+
+# Floating IP Settings
+
+FLOATING_IP_CREATION = True
+FLOATING_IP_POOL = 'public'
+
+TENANT_CREATION = False
+TENANT_NAME = ['tenant-test-101', 'tenant-test-102', 'tenant-test-103', 'tenant-test-104','tenant-test-105']
+
+
+# Cisco ASR Settings
+
+ENABLE_ASR_VERIFICATION = False
+DEPLOYMENT_ID = 'ans136'
+ASR_HOST = '10.10.10.10'
+ASR_USER = 'admin'
+ASR_PASSWORD = 'admin'
+
+
+"""
+Test Configuration Ends Here with the global parameters.
+"""
+
+
+def print_scale_test_config():
+ """
+ This method is used to print the current test configuration on scale test \
+ deployment initialization.
+ """
+ print '=' * 70
+ print " Configuration for this Scale Test"
+ print '=' * 70
+
+ print " Tenant will be created with prefix : " \
+ + TENANT_NAME_PREFIX
+ print " No of Tenants will be created : " \
+ + str(TENANT_COUNT)
+ print " Tenant base index range starts from : " \
+ + str(TENANT_BASE_INDEX)
+ print " No of Users per Tenant : " \
+ + str(USER_COUNT)
+ print " No of Networks : " \
+ + str(NETWORK_COUNT)
+ print " No of VMs per Network : " \
+ + str(VM_COUNT)
+ print " Name of the External Network with be connected with Router : " \
+ + EXTERNAL_NETWORK
+ print " Name of the Floating IP Pool will be used for Allocation : " \
+ + FLOATING_IP_POOL
+ print '=' * 70
diff --git a/NTT/ntt-29-3-16-test/config.pyc b/NTT/ntt-29-3-16-test/config.pyc
new file mode 100644
index 0000000..d2909c5
Binary files /dev/null and b/NTT/ntt-29-3-16-test/config.pyc differ
diff --git a/NTT/ntt-29-3-16-test/credentials.py b/NTT/ntt-29-3-16-test/credentials.py
new file mode 100755
index 0000000..a9b640c
--- /dev/null
+++ b/NTT/ntt-29-3-16-test/credentials.py
@@ -0,0 +1,46 @@
+"""
+Description: This script is to map the environment variables to credentials \
+ dict based on the client service API
+Developer: gopal@onecloudinc.com
+"""
+
+from config import OS_USERNAME, OS_TENANT_NAME, OS_PASSWORD, OS_AUTH_URL
+
+
+def get_credentials():
+ """
+ This method is used for authorization with keystone clients
+ """
+
+ data = {}
+ data['username'] = OS_USERNAME
+ data['password'] = OS_PASSWORD
+ data['auth_url'] = OS_AUTH_URL
+ data['tenant_name'] = OS_TENANT_NAME
+ return data
+
+
+def get_nova_credentials():
+ """
+ This method is used for authorization with nova clients
+ """
+
+ data = {}
+ data['username'] = OS_USERNAME
+ data['api_key'] = OS_PASSWORD
+ data['auth_url'] = OS_AUTH_URL
+ data['project_id'] = OS_TENANT_NAME
+ return data
+
+
+def get_tenant_nova_credentials(tenant_name):
+ """
+ This method is used for tenant authorization with nova clients
+ """
+
+ data = {}
+ data['username'] = OS_USERNAME
+ data['api_key'] = OS_PASSWORD
+ data['auth_url'] = OS_AUTH_URL
+ data['project_id'] = tenant_name
+ return data
diff --git a/NTT/ntt-29-3-16-test/credentials.pyc b/NTT/ntt-29-3-16-test/credentials.pyc
new file mode 100644
index 0000000..349cf3d
Binary files /dev/null and b/NTT/ntt-29-3-16-test/credentials.pyc differ
diff --git a/NTT/ntt-29-3-16-test/destroy_deploy.py b/NTT/ntt-29-3-16-test/destroy_deploy.py
new file mode 100755
index 0000000..3727a54
--- /dev/null
+++ b/NTT/ntt-29-3-16-test/destroy_deploy.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+
+"""
+Description: This script is to destory the L3/HA scale test deployment
+Developer: gopal@onecloudinc.com
+"""
+
+import os
+from neutronclient.v2_0 import client
+from keystoneclient.v2_0 import client as ksclient
+from credentials import get_credentials
+from config import TENANT_BASE_INDEX, TENANT_COUNT, TENANT_NAME_PREFIX, \
+ print_scale_test_config
+from networks import delete_network
+from tenants import delete_tenant
+from datetime import datetime, timedelta
+from pytz import timezone
+
+credentials = get_credentials()
+neutron = client.Client(**credentials)
+keystone = ksclient.Client(**credentials)
+fmt = "%Y-%m-%d %H:%M:%S %Z%z"
+
+
+def main():
+ """
+ This method will destory the scale test deployment based on the global \
+ config parameters mentioned on config.py file and creates the router with \
+ external gateway connectivity to public network.
+ """
+
+ print "\n"
+ print_scale_test_config()
+ print "\n"
+ print "Destroying Scale Test Deployment"
+ index = TENANT_BASE_INDEX
+ for i in range(1, TENANT_COUNT + 1):
+ tenant_name = TENANT_NAME_PREFIX + '-' + str(index)
+ index += 1
+ start_time = datetime.now(timezone('US/Pacific'))
+ try:
+ tenant = keystone.tenants.find(name=tenant_name)
+ delete_network(tenant_name)
+ delete_tenant(tenant_name)
+ except Exception:
+ print "\n"
+ print(" - Tenant Not Found: %s" % tenant_name)
+ pass
+ end_time = datetime.now(timezone('US/Pacific'))
+ print "\n"
+ print "-"*65
+ print (" Tenant & User Deletion Time Summary :")
+ print "-"*65
+ print "\n"
+ print(' - Test Started Time :\t %s' % (start_time.strftime(fmt)))
+ print(' - Test Ended Time :\t %s' % (end_time.strftime(fmt)))
+
+ print "=" * 50
+ print "\n"
+ print "Cleaned Scale Test Deployment"
+ print "\n"
+
+
+if __name__ == '__main__':
+ main_start_time = datetime.now(timezone('US/Pacific'))
+ main()
+ main_end_time = datetime.now(timezone('US/Pacific'))
+ total_time = (main_end_time - main_start_time)
+ print "-"*65
+ print (" Scale Test Deployment Consolidated Time Summary :")
+ print "-"*65
+ print "\n"
+ print(' - Test Started Time :\t %s' % (main_start_time.strftime(fmt)))
+ print(' - Test Ended Time :\t %s' % (main_end_time.strftime(fmt)))
+ print(' - Elapsed Time for Cleaned Scale Test Deployment: %d days, %d hours, %d minutes, %d seconds' % (total_time.days, (total_time.seconds/3600), (total_time.seconds % 3600 / 60), (total_time.seconds % 60)))
+ print "\n"
diff --git a/NTT/ntt-29-3-16-test/discover_deploy.py b/NTT/ntt-29-3-16-test/discover_deploy.py
new file mode 100755
index 0000000..e2dcaa0
--- /dev/null
+++ b/NTT/ntt-29-3-16-test/discover_deploy.py
@@ -0,0 +1,281 @@
+#!/usr/bin/env python
+
+"""
+Description: This script is to initialize the L3/HA scale test deployment
+Developer: gopal@onecloudinc.com
+"""
+import pdb
+import os
+from neutronclient.v2_0 import client
+from credentials import get_credentials
+from config import TENANT_BASE_INDEX, NETWORK_COUNT, \
+ EXTERNAL_NETWORK, print_scale_test_config, DEPLOYMENT_ID, \
+ ASR_HOST, ASR_USER, ASR_PASSWORD, ENABLE_ASR_VERIFICATION, TENANT_COUNT, \
+ TENANT_NAME_PREFIX, TENANT_NAME, TENANT_CREATION, VM_COUNT
+from tenants import create_tenant, discover_tenant
+from networks import create_network
+from vm_instances import discover_vm_on_network
+from prettytable import PrettyTable
+
+credentials = get_credentials()
+neutron = client.Client(**credentials)
+
+
+def print_tenant_info(tenant_data):
+
+ x = PrettyTable(['Tenant Name', 'Status'])
+ x.align["Tenant Name"] = "l" # Left align source tenant values
+ x.padding_width = 1
+ for entry in tenant_data:
+ x.add_row([entry['tenant_name'], entry['status']])
+ return x
+
+def print_discovered_tenant(tenant_data,router_data,test_data):
+ pdb.set_trace()
+ y=PrettyTable(['Tenant Name','Router Name','Network Name','Network CIDR'])
+ y.padding_width=1
+ for x in tenant_data:
+ for z in router_data:
+ for a in test_data:
+
+ y.add_row([x['tenant_name'],z['router_name'],a['network_data']['network_name'],a['network_data']['network_cidr']])
+ return y
+
+def print_consolidated_count(test_count):
+ pdb.set_trace()
+ y=PrettyTable(['Tenant Count','Router Count','Network Count','VM Count'])
+ y.padding_width=1
+ for i in test_count:
+ y.add_row([i['tenant_count'],i['router_count'],i['network_count']])
+ return y
+def print_router_info(router_data):
+ x = PrettyTable(['Tenant Name', 'Router Name', 'Status'])
+ x.align["Tenant Name"] = "l" # Left align source tenant values
+ x.padding_width = 1
+ for entry in router_data:
+ x.add_row([entry['tenant_name'], entry['router_name'],
+ entry['router_status']])
+ return x
+
+
+def print_network_info(test_data):
+ y = PrettyTable(['Tenant Name', 'Network Name', 'Network CIDR',
+ 'Vlan ID', 'Subnet Name', 'Status'])
+ y.align["Tenant_Name"] = "l" # Left align source tenant values
+ y.padding_width = 1
+ for entry in test_data:
+ y.add_row([entry['network_data']['tenant_name'],
+ entry['network_data']['network_name'],
+ entry['network_data']['network_cidr'],
+ entry['network_data']['network_vlan_id'],
+ entry['network_data']['subnet_name'],
+ entry['network_data']['status']])
+ return y
+
+
+def print_instance_info(test_data):
+
+ z = PrettyTable(['Tenant Name', 'Instance Name', 'Status'])
+ z.align["Tenant Name"] = "l" # Left align source tenant values
+ z.padding_width = 1
+ for data in test_data:
+ for ins in data['instance_data']:
+ z.add_row([data['network_data']['tenant_name'],
+ ins['instance_name'],
+ ins['status']])
+ return z
+
+
+
+
+
+
+def main():
+ """
+ This method will initialize the scale test deployment based on the global \
+ config parameters mentioned on config.py file and creates the router with \
+ external gateway connectivity to public network.
+ """
+
+ tenant_data = []
+ router_data = []
+ test_data = []
+ test_count={}
+ if TENANT_CREATION == True:
+ print "\n"
+ print_scale_test_config()
+ print "\n"
+ pdb.set_trace()
+ print "Starting Scale Test Deployment"
+ index = TENANT_BASE_INDEX
+ for i in range(1, TENANT_COUNT + 1):
+ tenant_name = TENANT_NAME_PREFIX + '-' + str(index)
+ index += 1
+ try:
+ tenant_data.append(create_tenant(tenant_name))
+ except Exception as exc:
+ print "Exception occured on Tenant Creation: %s" % (exc.message)
+ pass
+ test_count["tenant_count"]=len(tenant_data)
+ for tenant in tenant_data:
+
+ #test= {'count': {'tenant_count': len(tenant_data)}}
+ #test_count.append(test)
+ router_dict = {}
+ prefix = tenant['tenant_name']
+ router_name = prefix + '-router'
+ router_dict['tenant_name'] = tenant['tenant_name']
+ router_dict['router_name'] = router_name
+ router_dict['network_vlan'] = {}
+ router_dict['router_detail'] = {}
+ router_dict['ipnatpool_data'] = {}
+ router_dict['iproute_data'] = {}
+ router_dict['interface_data'] = []
+ router_dict['nat_data'] = []
+
+ router = neutron.list_routers(name=EXTERNAL_NETWORK)['routers']
+ if not router:
+ router_info = neutron.create_router({'router': {
+ 'name': router_name, 'tenant_id': tenant['tenant_id']}})
+ router = router_info['router']
+ status = True
+ elif router[0]['tenant_id'] == tenant['tenant_id']:
+ router = router[0]
+ status = True
+ else:
+ router = {}
+ status = False
+
+ router_dict['router_status'] = status
+ networks = neutron.list_networks(name=EXTERNAL_NETWORK)
+ network_id = networks['networks'][0]['id']
+ neutron.add_gateway_router(router['id'],
+ {'network_id': network_id,
+ 'tenant_id': tenant['tenant_id']})
+ router_id = router['id']
+ print(' - Created Router %s' % router['name'])
+
+ for i in range(1, NETWORK_COUNT + 1):
+ network_index = str(i)
+ network_cidr = str(i) + "." + str(i) + "." + str(i) + ".0/24"
+ test_data.append(create_network(tenant, router,
+ network_index, network_cidr))
+ network_vlan = {}
+ for entry in test_data:
+ network_vlan[str(entry['network_data']['network_vlan_id'])] = \
+ entry['network_data']['network_name']
+ router_dict['network_vlan'] = network_vlan
+
+ else:
+ print "\n"
+ print "=" * 50
+ print "Discovering Tenant Topology on Scale Test Deployment"
+ print "=" * 50
+ try:
+ pdb.set_trace()
+ for i in range(len(TENANT_NAME)):
+ tenant_name = TENANT_NAME[i]
+ tenant_data.append(discover_tenant(tenant_name))
+ #test= {'count': {'tenant_count': len(tenant_data)}}
+ #test_count.append(test)
+
+ for tenant in tenant_data:
+ router_dict = {}
+ prefix = tenant['tenant_name']
+ router_name = prefix + '-router'
+ router_dict['tenant_name'] = tenant['tenant_name']
+ router_dict['tenant_id'] = tenant['tenant_id']
+ router_dict['router_name'] = router_name
+ router_dict['network_vlan'] = {}
+ router_dict['router_detail'] = {}
+ router_dict['ipnatpool_data'] = {}
+ router_dict['iproute_data'] = {}
+ router_dict['interface_data'] = []
+ router_dict['nat_data'] = []
+ pdb.set_trace()
+ router = neutron.list_routers(name=router_name)['routers'][0]
+ if router['tenant_id'] == tenant['tenant_id']:
+ print(' - Router %s Discovered' % router_name)
+ status = True
+ else:
+ print(' - Router %s Not Found' % router_name)
+ status = False
+ router_id = router['id']
+ router_dict['router_status'] = status
+ router_data.append(router_dict)
+ #test1= {'count': {'router_count': len(router_data)}}
+ #test_count.append(test1)
+ test_count["router_count"]=len(router_data)
+ for i in range(1, NETWORK_COUNT + 1):
+ network_index = str(i)
+ network_cidr = str(i) + "." + str(i) + "." + str(i) + ".0/24"
+ network_name = prefix + '-net-' + network_index
+ subnet_name = prefix + "-subnet-" + network_index
+ ins_data = []
+ networks = neutron.list_networks(name=network_name)['networks']
+ for i in range(len(networks)):
+ if networks[i]['tenant_id'] == tenant['tenant_id']:
+ network_id = networks[i]['id']
+ network_vlan = networks[i]['provider:segmentation_id']
+ print(' - Network %s Discovered' % network_name)
+ print(' - Network ID %s Discovered' % network_id)
+ print(' - VLAN ID %s Discovered' % network_vlan)
+ status = True
+ for j in range(1, VM_COUNT + 1):
+ vm_name = network_name + '-vm-' + str(j)
+ ins_data.append(discover_vm_on_network(tenant['tenant_name'], vm_name, network_id))
+ else:
+ print(' - Network %s Not Found' % network_name)
+ status = False
+
+ result = {'network_data': {'tenant_name': tenant['tenant_name'],
+ 'network_name': network_name,
+ 'network_cidr': network_cidr,
+ 'subnet_name': subnet_name,
+ 'network_id': network_id,
+ 'network_vlan_id': network_vlan,
+ 'status':status},
+ 'instance_data': ins_data}
+ test_data.append(result)
+ test_count["network_count"]=test_data
+
+ except Exception:
+ print "\n"
+ print(' - Tenant %s Not Found' % tenant_name)
+
+
+ print "\n"
+ print "=" * 50
+ print "Scale Test Discovery Completed"
+ print "=" * 50
+
+ print "*" * 80
+ print "Scale Test Deployment OpenStack Report"
+ print "*" * 80
+
+ print "\n"
+ print " Tenant Discovery Results "
+ print print_tenant_info(tenant_data)
+ print "\n"
+ print " Router Discovery Results "
+ print print_router_info(router_data)
+ print "\n"
+ print " Network Discovery Results "
+ print print_network_info(test_data)
+ print "\n"
+
+ print " Instance Discovery Results "
+ print print_instance_info(test_data)
+ print "\n"
+
+ print " Tenant Name, Router Name, Network Name "
+ print print_discovered_tenant(tenant_data,router_data,test_data)
+ print "\n"
+
+ print" Overall Count of resources"
+ print print_consolidated_count(test_count)
+
+
+
+if __name__ == '__main__':
+ main()
diff --git a/NTT/ntt-29-3-16-test/discovery.py b/NTT/ntt-29-3-16-test/discovery.py
new file mode 100755
index 0000000..ec9934a
--- /dev/null
+++ b/NTT/ntt-29-3-16-test/discovery.py
@@ -0,0 +1,208 @@
+import pdb
+from neutronclient.v2_0 import client
+
+from credentials import get_credentials
+from config import TENANT_BASE_INDEX, NETWORK_COUNT, \
+ EXTERNAL_NETWORK, print_scale_test_config, DEPLOYMENT_ID, \
+ ASR_HOST, ASR_USER, ASR_PASSWORD, ENABLE_ASR_VERIFICATION, TENANT_COUNT, \
+ TENANT_NAME_PREFIX, TENANT_NAME, TENANT_CREATION, VM_COUNT
+from tenants import create_tenant, discover_tenant
+from vm_instances import discover_vm_on_network,launch_vm_on_network
+from networks import delete_networks,delete_vm
+credentials = get_credentials()
+neutron = client.Client(**credentials)
+tenant_data=[]
+router_data=[]
+network_dict={}
+
+def tenant_discovery():
+ pdb.set_trace()
+ #for i in range(len(TENANT_NAME)):
+ #tenant_name = TENANT_NAME[i]
+ #tenant_data.append(discover_tenant())
+ #discover_tenant()
+ tenant_data= [
+ {'id': u'2931fbe17e8445da875bb915a29d0bbf', 'name': u'admin'},
+ {'id': u'2e93f5f662974b1284e8be13dd472e48', 'name': u'demo'},
+ {'id': u'ae9e7941b6764accae72a99662c189a5', 'name': u'tenant-test-101'},
+ {'id': u'be0e4b8dc7754668b0e3d57e4f7f6f66', 'name': u'tenant-test-102'}]
+ #{'id': u'fbb4907f073d4b5881a85c1692ae027a', 'name': u'services'}]
+ #for i in range(len(tenant_data)):
+ #print tenant_data[i]
+
+# router_discovery(tenant_data)
+ network_data=network_discovery(tenant_data)
+
+ #discover_instance(tenant_data)
+ #launch_instance(tenant_data,network_data)
+ endpoint_discovery(tenant_data,network_data)
+# print tenant_data
+# print len(tenant_data)
+# destroy_all(tenant_data,network_data)
+
+def endpoint_discovery(tenant_data,network_data):
+ pdb.set_trace()
+ instance_list=[]
+ for tenant in tenant_data:
+ print("Get router information")
+ routers=get_router(tenant)
+ ports=get_ports(tenant)
+ instance_ports = get_instance_ports(ports)
+ print "tenant_name..%s"%(tenant['name'])
+ print "routers...%s"%(routers)
+ print "instance_ports....%s"%(instance_ports)
+ for ins in instance_ports:
+ instances={'instance_detail':{'fixed_ip':ins['fixed_ips']}} # list all instance fixed ips
+ instance_list.append(instances)
+ print instance_list
+
+
+def get_router(tenant):
+ routers=neutron.list_routers(tenant_id=tenant['id'])['routers']
+ return routers
+def get_ports(tenant):
+ ports=neutron.list_ports(tenant_id=tenant['id'])['ports']
+ return ports
+
+def get_instance_ports(ports):
+ pdb.set_trace()
+ instance_port_list = []
+ for port in ports:
+ if port['device_owner'] == 'compute:None':
+ instance_port_list.append(port)
+ return instance_port_list
+
+
+def destroy_all(tenant_data,network_data):
+ delete_vm(tenant_data,network_data)
+ delete_networks(tenant_data,network_data)
+
+def network_discovery(tenant_data):
+ pdb.set_trace()
+ network_detail=[]
+ subnet_detail=[]
+ net_sub={}
+ for tenant in tenant_data:
+
+ networks=neutron.list_networks(tenant_id=tenant['id'])['networks']
+ # list subnets under networks of all tenants
+ for net in networks:
+ nets={}
+ if net['tenant_id'] == tenant['id']:
+ nets={'network_list':{'tenant_name':tenant['name'],
+ 'network_name':net['name'],'network_id':net['id'],'shared':net['shared'],'subnets':net['subnets']}}
+ subnets=neutron.list_subnets(network_id=net['id'])['subnets']
+ for subnet in subnets:
+
+ #net_sub={'networks':{'tenant_name':tenant['name'],'network_name':net['name'],'network_id':net['id'],'shared':net['shared']},'subnets':{'subnet_name':subnet['name'],'cidr':subnet['cidr']}}
+ net_sub={'networks':{'tenant_name':tenant['name'],'network_name':net['name'],'network_id':net['id'],'shared':net['shared'],'subnet_name':subnet['name'],'cidr':subnet['cidr']}}
+
+ subnet_detail.append(net_sub)
+ print "\n"
+ print "List subnets along with network details"
+ print "tenant name %s"%(tenant['name'])
+ print "network_name %s"%(net['name'])
+ print "subnet_name %s"%(subnet['name'])
+ print "cidr\t %s"%(subnet['cidr'])
+
+
+
+
+ #subnets = net.get("subnets")
+ #subnet_list = neutron.list_subnets(id=subnets)
+ #print subnet_list.get("subnets", [])[0].get("cidr")
+ network_detail.append(nets)
+ #pdb.set_trace()
+ # subnets=neutron.list_subnets(tenant_id=tenant['id'])['subnets']
+ # for subnet in subnets:
+ #
+ # print "\n\n"
+ # print "tenant name %s"%(tenant['name'])
+ # print "network_id %s"%(subnet['network_id'])
+ #
+ # print "subnet_id %s"%(subnet['id'])
+ # print "cidr\t %s"%(subnet['cidr'])
+ #network_dict['network_list']=network_detail
+ return network_detail
+
+def launch_instance(tenant_data,network_data):
+ #pdb.set_trace()
+ inst_data=[]
+ count=1
+ for tenant in tenant_data:
+
+ for network in network_data:
+ pdb.set_trace()
+ vm_name=tenant['name'] + '-vm-' + str(count)
+ if ((network['network_list']['tenant_name'] == tenant['name']) and (network['network_list']['shared'] == False)):
+
+ inst_data.append(launch_vm_on_network(tenant['name'],vm_name,network['network_list']['network_id']))
+
+ count += 1
+
+def discover_instance(tenant_data):
+ instance_detail=[]
+ pdb.set_trace()
+ for tenant in tenant_data:
+
+ vm_dict={}
+ instance_detail.append(discover_vm_on_network(tenant['name']))
+ print instance_detail
+
+
+def router_discovery(tenant_data):
+ #pdb.set_trace()
+ for tenant in tenant_data:
+ #router_dict = {}
+ router=neutron.list_routers(tenant_id=tenant['id'])['routers']
+ for route in router:
+
+ router_dict={}
+ #for rout in router:
+
+ if route['tenant_id'] == tenant['id']:
+ print(' - Router %s Discovered' % route['name'])
+ status = True
+ router_id = route['id']
+ router_dict['tenant_name']=tenant["name"]
+ router_dict['router_status'] = status
+ router_dict['router_name']=route['name']
+ router_data.append(router_dict)
+
+ else:
+ print("Tenant %s not having any router"%(tenant['name']))
+ #if rout['tenant_id'] == tenant['id']:
+ #print(' - Router %s Discovered' % rout['name'])
+ #status = True
+ #router_id = rout['id']
+ #router_dict['tenant_name']=tenant["name"]
+ #router_dict['router_status'] = status
+ #router_dict['router_name']=rout['name']
+
+ else:
+ print(' - Router Not Found in %s tenant' % tenant['name'])
+ status = False
+ #router_id = rout['id']
+ #router_dict['router_status'] = status
+ #router_data.append(router_dict)
+
+
+ #router_id = router['id']
+ #router_dict['router_status'] = status
+ #router_data.append(router_dict)
+
+ return router_data
+
+def main():
+
+ tenant_discovery()
+
+
+
+
+
+
+
+if __name__ == '__main__':
+
+ main()
diff --git a/NTT/ntt-29-3-16-test/floating_ips.py b/NTT/ntt-29-3-16-test/floating_ips.py
new file mode 100755
index 0000000..e02a2d2
--- /dev/null
+++ b/NTT/ntt-29-3-16-test/floating_ips.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+"""
+Description: This script is to allocate & associate the floating IP.
+Developer: gopal@onecloudinc.com
+"""
+
+import os
+from neutronclient.v2_0 import client
+import novaclient.v1_1.client as nvclient
+from credentials import get_credentials, get_nova_credentials, \
+ get_tenant_nova_credentials
+from config import FLOATING_IP_POOL
+
+neutron_credentials = get_credentials()
+credentials = get_nova_credentials()
+neutron = client.Client(**neutron_credentials)
+nova = nvclient.Client(**credentials)
+if not nova.keypairs.findall(name="admin"):
+ with open(os.path.expanduser('~/.ssh/id_rsa.pub')) as fpubkey:
+ nova.keypairs.create(name="admin", public_key=fpubkey.read())
+
+
+def add_floating_ip_for_vm(tenant_name, instance):
+ """
+ This method is used to allocate & associate floating IP to the given VM\
+ based on the availability from the defined pool.
+ """
+ tenant_credentials = get_tenant_nova_credentials(tenant_name)
+ nova = nvclient.Client(**tenant_credentials)
+ floating_ip = nova.floating_ips.create(FLOATING_IP_POOL)
+ instance.add_floating_ip(floating_ip)
+ print " - Assigned Floating IP: " + str(floating_ip.ip)
+ return True
+
+
+def release_all_floating_ips():
+ """
+ This method is used to release all the disallocated floating IPs.
+ """
+ floating_ips = neutron.list_floatingips()['floatingips']
+ try:
+ for ip in floating_ips:
+ neutron.delete_floatingip(ip['id'])
+ except:
+ pass
+ return True
diff --git a/NTT/ntt-29-3-16-test/floating_ips.pyc b/NTT/ntt-29-3-16-test/floating_ips.pyc
new file mode 100644
index 0000000..e9a6886
Binary files /dev/null and b/NTT/ntt-29-3-16-test/floating_ips.pyc differ
diff --git a/NTT/ntt-29-3-16-test/networks.py b/NTT/ntt-29-3-16-test/networks.py
new file mode 100755
index 0000000..befd00e
--- /dev/null
+++ b/NTT/ntt-29-3-16-test/networks.py
@@ -0,0 +1,178 @@
+#!/usr/bin/env python
+"""
+Description: This script is to create network, subnets, router with \
+ external gateway mapping.
+Developer: gopal@onecloudinc.com
+"""
+import pdb
+import os
+from neutronclient.v2_0 import client
+from credentials import get_credentials
+from config import NETWORK_COUNT, VM_COUNT, FLOATING_IP_CREATION
+from vm_instances import launch_vm_on_network, terminate_vm_on_network
+from floating_ips import release_all_floating_ips
+from datetime import datetime, timedelta
+from pytz import timezone
+
+credentials = get_credentials()
+neutron = client.Client(**credentials)
+fmt = "%Y-%m-%d %H:%M:%S %Z%z"
+
+
+def create_network(tenant, router, network_index, network_cidr):
+ """
+ This method is used to create network, subnets, interfaces on router with \
+ external gateway mapping for the given network name and CIDR.
+ """
+
+ try:
+ prefix = tenant['tenant_name']
+ network_name = prefix + '-net-' + network_index
+ print "\n"
+ print "=" * 50
+ print " Initiated Network Creation for " + network_name
+ print "=" * 50
+ print "\n"
+
+ body_sample = {'network': {'name': network_name,
+ 'tenant_id': tenant['tenant_id']}}
+ start_time = datetime.now(timezone('US/Pacific'))
+ try:
+ net = neutron.create_network(body=body_sample)
+ net_dict = net['network']
+ network_id = net_dict['id']
+ network_vlan = net_dict['provider:segmentation_id']
+ print(' - Network %s created' % net_dict['name'])
+ net_status = True
+ except Exception:
+ net_dict = {}
+ net_status = False
+
+ subnet_name = prefix + "-subnet-" + network_index
+ try:
+ tenant_id = tenant['tenant_id']
+ body_create_subnet = {'subnets': [{'name': subnet_name,
+ 'cidr': network_cidr,
+ 'ip_version': 4,
+ 'network_id': network_id,
+ 'tenant_id': tenant_id}]}
+ subnet_detail = neutron.create_subnet(body=body_create_subnet)
+ subnet = subnet_detail['subnets'][0]
+ print(' - Created subnet %s' % subnet['name'])
+ net_status = True
+ except Exception:
+ subnet = {}
+ net_status = False
+
+ neutron.add_interface_router(router['id'], {'subnet_id': subnet['id'],
+ 'tenant_id': tenant['tenant_id']})
+ print (' - Created interface between %s' % subnet['name'])
+ finally:
+ print "\n"
+ msg = "<== Completed Network Creation with External Gateway "
+ msg += "Successfully ==>"
+ print msg
+ end_time = datetime.now(timezone('US/Pacific'))
+ print "\n"
+ print "-"*65
+ print (" Network %s Creation Time Summary :" % network_name)
+ print "-"*65
+ print "\n"
+ print(' - Test Started Time :\t %s' % (start_time.strftime(fmt)))
+ print(' - Test Ended Time :\t %s' % (end_time.strftime(fmt)))
+
+ print "\n"
+ print "=" * 50
+ print " Initiated VM Deployment " + network_name
+ print "=" * 50
+ print "\n"
+
+ ins_data = []
+ for i in range(1, VM_COUNT + 1):
+ vm_name = network_name + '-vm-' + str(i)
+ start_time = datetime.now(timezone('US/Pacific'))
+ ins_data.append(launch_vm_on_network(tenant['tenant_name'],
+ vm_name, network_id))
+ end_time = datetime.now(timezone('US/Pacific'))
+
+ print "\n"
+ msg = "<== Completed VM Launch on Network with Floating IP Allocation "
+ msg += "Successfully ==>"
+ print msg
+ print "\n"
+ print "-"*65
+ print (" Instance %s Creation Time Summary :" % vm_name)
+ print "-"*65
+ print "\n"
+ print(' - Test Started Time :\t %s' % (start_time.strftime(fmt)))
+ print(' - Test Ended Time :\t %s' % (end_time.strftime(fmt)))
+
+ result = {'network_data': {'tenant_name': tenant['tenant_name'],
+ 'network_name': network_name,
+ 'network_cidr': network_cidr,
+ 'subnet_name': subnet_name,
+ 'network_id': network_id,
+ 'network_vlan_id': network_vlan,
+ 'status': net_status},
+ 'instance_data': ins_data}
+ return result
+
+
+def delete_vm(tenant_data,network_data):
+ """
+ This method is used to delete vms, network, subnets, interfaces on router \
+ with external gateway mapping for the given network name and CIDR.
+ """
+ pdb.set_trace()
+ #prefix = tenant_name
+ network_list = []
+ router_list = []
+ count=1
+ #router_list.append(prefix + '-router')
+ #for i in range(1, NETWORK_COUNT + 1):
+ #network_list.append(prefix + '-net-' + str(i))
+ for tenant in tenant_data:
+ for network in network_data:
+ vm_name=tenant['name'] + '-vm-' + str(count)
+ if ((network['network_list']['tenant_name'] == tenant['name']) and (network['network_list']['shared'] == False)):
+
+
+ terminate_vm_on_network(tenant['name'], vm_name,network['network_list']['network_id'])
+ count += 1
+
+ release_all_floating_ips()
+def delete_networks(tenant_data,network_data):
+ pdb.set_trace()
+ networks=None
+ for tenant in tenant_data:
+ networks=neutron.list_networks(tenant_id=tenant['id'])['networks']
+ routers=neutron.list_routers(tenant_id=tenant['id'])['routers']
+ subnets=neutron.list_subnets(tenant_id=tenant['id'])['subnets']
+
+
+ for router in routers:
+ ports=neutron.list_ports(tenant_id=tenant['id'])['ports']
+ for port in ports:
+ #for subnet in subnets:
+ if (port['device_id'] == router['id'] and port['device_owner'] == 'network:router_interface'):
+ neutron.remove_interface_router(router['id'],{'subnet_id':port['fixed_ips'][0]['subnet_id']})
+ neutron.remove_gateway_router(router['id'])
+ neutron.delete_network(port['network_id'])
+ neutron.delete_router(router['id'])
+ #neutron.delete_network(network['id'])
+
+ #for network in networks:
+ #neutron.delete_network(network['id'])
+
+ #for subnet in subnets:
+ #for network in networks:
+
+
+
+
+
+ #if FLOATING_IP_CREATION:
+ #release_all_floating_ips()
+ #print "\n"
+ #print("<== Released all Floating IPs Successfully ==>")
+ #return True
diff --git a/NTT/ntt-29-3-16-test/networks.pyc b/NTT/ntt-29-3-16-test/networks.pyc
new file mode 100644
index 0000000..a483e90
Binary files /dev/null and b/NTT/ntt-29-3-16-test/networks.pyc differ
diff --git a/NTT/ntt-29-3-16-test/openstack_clean_script.py b/NTT/ntt-29-3-16-test/openstack_clean_script.py
new file mode 100755
index 0000000..bb04cd1
--- /dev/null
+++ b/NTT/ntt-29-3-16-test/openstack_clean_script.py
@@ -0,0 +1,158 @@
+import logging
+import pprint
+from novaclient import client as novclient
+from neutronclient.v2_0 import client as nclient
+import time
+import pdb
+import MySQLdb
+from keystoneclient.v2_0 import client as kclient
+def main():
+ net_list=['NET-A','NET-B','NET-C']
+ ext_net_list=['EXT-NET-A','EXT-NET-B']
+ ext_subnet_list=[]
+ flavor_list={}
+
+ router_list=['Router-A','Router-B']
+ subnet_list={'subnets':[{'name':'Subnet-A','network_id':'','ip_version':4,'cidr':'1.1.1.0/24'},{'name':'Subnet-B','network_id':'','ip_version':4,'cidr':'2.2.2.0/24'}]}
+ count = 0
+ instance_detail={}
+ networks={}
+ logging.basicConfig(level=logging.INFO)
+ logger=logging.getLogger(__name__)
+ logger.info("Keystone authentication started....")
+ time.sleep(5)
+ logger.info("Wait for 5 seconds...")
+ logger.info("done")
+ neutr=nclient.Client(username='admin',password='admin',tenant_name='admin',auth_url='http://192.168.1.12:5000/v2.0/')
+ novactr=novclient.Client('2',username='admin',api_key='admin',project_id='admin',auth_url='http://192.168.1.12:5000/v2.0/')
+ logger.info("Authentication success...")
+ #logger.info("getting input from user....")
+ #network_count=int(raw_input("Enter the no of network to created >>\t"))
+ #ext_network_count=int(raw_input("Enter the no of External network to be created >> \t"))
+ #instance_detail['name']=raw_input("Please provide name for instance")
+ #flavor_id=int(raw_input("Provide the flavor for the instance"))
+ #netw=neutr.list_networks()
+ #print netw
+ #ss=db_connection(flavor_list,novactr)
+ #us=ss.get(flavor_id)
+ #if us:
+ #logger.info("You choose %s flavor"%(us))
+ #else:
+ #logger.info("The flavor u choose is doesn't exists..")
+ #exit
+ #create_network(neutr,network_count,logger,net_list,count,subnet_list,novactr,flavor_id)
+ delete_network(neutr,novactr,logger,net_list,subnet_list)
+
+def create_network(neutr,network_count,logger,net_list,count,subnet_list,novactr,flavor_id):
+ pdb.set_trace()
+ logger.info("Start creating external network ")
+ ext_network=neutr.create_network({'network':{'name':'EXT-NET','admin_state_up':'True','router:external':'True'}})
+ ext_id=ext_network['network']['id']
+ vm_list=['vm-1','vm-2']
+ logger.info("Creating external network subnet...")
+ ext_subnet=neutr.create_subnet({'subnet':{'name':'EXT_subnet','network_id':ext_id,'ip_version':4,'cidr':'6.6.8.8/24'}})
+ time.sleep(2)
+ logger.info("creating router")
+ router1=neutr.create_router({'router':{'name':'Router-1','admin_state_up':'True'}})
+ router_id=router1['router']['id']
+ neutr.add_gateway_router(router_id,{'network_id':ext_id})
+
+ while count < network_count:
+
+ neut=neutr.create_network({'network':{'name':net_list[count],'admin_state_up':'True'}})
+ if neut:
+ net_id=neut['network']['id']
+ logger.info("Network %s sucessfully created.."%(net_list[count]))
+ time.sleep(4)
+ logger.info("Start creating subnets")
+ #nsub=neutr.create_subnet({'subnet':subnet_list['subnets'][count]})
+ nsub=neutr.create_subnet({'subnet':{'name':subnet_list['subnets'][count]['name'],'network_id':net_id,'ip_version':subnet_list['subnets'][count]['ip_version'],'cidr':subnet_list['subnets'][count]['cidr']}})
+ sub_id=nsub['subnet']['id']
+ if nsub:
+ logger.info("subnet is created for network %s"%(net_list[count]))
+ time.sleep(4)
+ logger.info("Adding interface to router")
+ neutr.add_interface_router(router_id,{'subnet_id':sub_id})
+ time.sleep(5)
+ logger.info("Ready to launch the instances")
+ pdb.set_trace()
+ image = novactr.images.find(name="cirros")
+ print net_id
+ instance = novactr.servers.create(name=vm_list[count], image=image, flavor=flavor_id, nics=[{'net-id':net_id}])
+ logger.info("Instance launched successfully on network %s"%(net_list[count]))
+ time.sleep(4)
+ count = count+1
+ else:
+ logger.info("Error in network creation")
+ time.sleep(3)
+ logger.info("setup is ready for testing..")
+
+def db_connection(flavor_list,novactr):
+ db=MySQLdb.connect(host="localhost",user="root",passwd="dafc1bce95654501",db="nova")
+ cur=db.cursor()
+ cur.execute("select id,name from instance_types")
+ ss=novactr.networks.list()
+ print ss
+ return dict(cur.fetchall())
+
+def delete_network(neutr,novactr,logger,net_list,subnet_list):
+ logger.info("Start cleaning the dashboard")
+ del_net={}
+ server_delete(novactr,logger)
+ delete_interface(neutr,logger)
+ count=0
+
+def server_delete(novactr,logger):
+ #pdb.set_trace()
+ logger.info("Fetching list of servers")
+ myserver=novactr.servers.list()
+ server_len=len(myserver)
+ for i in range(server_len):
+ ss=novactr.servers.delete(myserver[i])
+ if ss:
+ logger.info("Instances %s sucessfully deleted"%myserver[i])
+ time.sleep(1)
+def delete_interface(neutr,logger):
+
+ mynetwork=neutr.list_networks()
+ net_len=len(mynetwork['networks'])
+ myrouter=neutr.list_routers()
+ r_id=myrouter['routers'][0]['id']
+ port_delete(neutr,logger,r_id)
+ my_ports=neutr.list_ports()['ports']
+ port_gateway=[]
+ s=neutr.remove_gateway_router(r_id)
+ if s:
+ logger.info("gateway router is detached successful...")
+ myrouter=neutr.list_routers()['routers']
+ for r in range(len(myrouter)):
+
+ neutr.delete_router(myrouter[r]['id'])
+ logger.info("Deleting networks...")
+ time.sleep(2)
+ for j in range(net_len):
+ dd=neutr.delete_network(mynetwork['networks'][j]['id'])
+
+def port_delete(neutr,logger,r_id):
+ logger.info("listing port details..")
+ myports=neutr.list_ports()['ports']
+ port_list=[]
+ port_gateway=[]
+ for port in myports:
+
+ if (port['device_id'] == r_id and
+ port['device_owner'] == 'network:router_interface'):
+ port_list.append(port)
+ logger.info("Removing router interfaces..")
+
+ for i in range(len(port_list)):
+
+ del_inf=neutr.remove_interface_router(r_id,{'subnet_id':port_list[i]['fixed_ips'][0]['subnet_id']})
+
+#def get_id(novactr,logger):
+ #welcome=novactr.servers.list(413fb5d3-c1bc-4267-80ab-6a27d0cfd04b)
+ #print welcome
+
+
+if __name__ == '__main__':
+ main()
diff --git a/NTT/ntt-29-3-16-test/t1.py b/NTT/ntt-29-3-16-test/t1.py
new file mode 100755
index 0000000..a93a8ab
--- /dev/null
+++ b/NTT/ntt-29-3-16-test/t1.py
@@ -0,0 +1,17 @@
+from keystoneclient.v2_0 import client
+
+
+OS_USERNAME = 'admin'
+OS_TENANT_NAME = 'admin'
+OS_PASSWORD = 'admin'
+OS_AUTH_URL = 'http://172.168.2.40:5000/v2.0/'
+
+keystone = client.Client(username=OS_USERNAME, password=OS_PASSWORD, auth_url=OS_AUTH_URL)
+import pdb
+pdb.set_trace()
+
+tenants = keystone.tenants.list()
+for tenant in tenants:
+ print tenant.__dict__
+
+
diff --git a/NTT/ntt-29-3-16-test/t2.py b/NTT/ntt-29-3-16-test/t2.py
new file mode 100755
index 0000000..adb670c
--- /dev/null
+++ b/NTT/ntt-29-3-16-test/t2.py
@@ -0,0 +1,31 @@
+from neutronclient.v2_0 import client as neutron_client
+
+
+
+OS_USERNAME = 'admin'
+OS_TENANT_NAME = 'admin'
+OS_PASSWORD = 'admin'
+OS_AUTH_URL = 'http://172.168.2.40:5000/v2.0/'
+OS_TENANT_ID = '2931fbe17e8445da875bb915a29d0bbf'
+
+def get_credentials():
+ d = {}
+ d['username'] = OS_USERNAME
+ d['password'] = OS_PASSWORD
+ d['auth_url'] = OS_AUTH_URL
+ d['tenant_id'] = OS_TENANT_ID
+ return d
+
+tenants = [
+ {'id': u'2931fbe17e8445da875bb915a29d0bbf', 'name': u'admin'},
+ {'id': u'2e93f5f662974b1284e8be13dd472e48', 'name': u'demo'},
+ {'id': u'ae9e7941b6764accae72a99662c189a5', 'name': u'tenant-test-101'},
+ {'id': u'be0e4b8dc7754668b0e3d57e4f7f6f66', 'name': u'tenant-test-102'},
+ {'id': u'fbb4907f073d4b5881a85c1692ae027a', 'name': u'services'}
+]
+
+
+credentials = get_credentials()
+neutron = neutron_client.Client(**credentials)
+netw = neutron.list_networks()
+print netw
diff --git a/NTT/ntt-29-3-16-test/tenant.txt b/NTT/ntt-29-3-16-test/tenant.txt
new file mode 100755
index 0000000..2ecda20
--- /dev/null
+++ b/NTT/ntt-29-3-16-test/tenant.txt
@@ -0,0 +1,7 @@
+tenants = [
+ {'id': u'2931fbe17e8445da875bb915a29d0bbf', 'name': u'admin'},
+ {'id': u'2e93f5f662974b1284e8be13dd472e48', 'name': u'demo'},
+ {'id': u'ae9e7941b6764accae72a99662c189a5', 'name': u'tenant-test-101'},
+ {'id': u'be0e4b8dc7754668b0e3d57e4f7f6f66', 'name': u'tenant-test-102'},
+ {'id': u'fbb4907f073d4b5881a85c1692ae027a', 'name': u'services'}
+]
diff --git a/NTT/ntt-29-3-16-test/tenants.py b/NTT/ntt-29-3-16-test/tenants.py
new file mode 100755
index 0000000..ed40861
--- /dev/null
+++ b/NTT/ntt-29-3-16-test/tenants.py
@@ -0,0 +1,145 @@
+#!/usr/bin/env python
+"""
+Description: This script prepares new tenant with the following properties:
+1. Creates new tenant.
+2. Creates new user and this user is added _member_ to tenant. \
+Password is second argument of script
+3. Admin user will be added to tenant with role admin
+Developer: gopal@onecloudinc.com
+"""
+
+import os
+import pdb
+from keystoneclient.v2_0 import client as ksclient
+from credentials import get_credentials
+from config import USER_COUNT, USER_PASSWORD
+
+credentials = get_credentials()
+keystone = ksclient.Client(**credentials)
+assign_admin = True
+
+
+def create_tenant(tenant_name):
+ """
+ This method is used to create tenant and create number of users per tenant
+ """
+
+ print "\n"
+ print "=" * 50
+ print " Initiated Tenant Creation for " + tenant_name
+ print "=" * 50
+ print "\n"
+
+ try:
+ try:
+ new_tenant = keystone.tenants.create(tenant_name=tenant_name,
+ description="Scale tenant \
+ created",
+ enabled=True)
+ print(' - Tenant %s created' % tenant_name)
+ except Exception:
+ new_tenant = keystone.tenants.find(name=tenant_name)
+ tenant_id = new_tenant.id
+ tenant_status = True
+ user_data = []
+ for j in range(USER_COUNT):
+ j += 1
+ user_name = tenant_name + '-user-' + str(j)
+ user_data.append(create_user(user_name, tenant_id))
+ except Exception:
+ tenant_status = False
+
+ print "\n"
+ msg = ('<== Completed Tenant Creation and Users per Tenant '
+ 'with _member_ role ')
+ msg += 'Successfully ==>'
+ print msg
+ print "\n"
+
+ tenant_data = {'tenant_name': tenant_name,
+ 'tenant_id': tenant_id,
+ 'status': tenant_status}
+ return tenant_data
+
+
+def discover_tenant():
+ """
+ This method is used to discover tenant and discover number of users per tenant
+ """
+ global tenant_id,tenant_status
+ try:
+ pdb.set_trace()
+ new_tenant = keystone.tenants.list()
+ tenant_id = new_tenant.id
+ tenant_status = True
+ print "\n"
+ print(' - Tenant %s Discovered' % tenant_name)
+ print(' - Tenant_ID %s Discovered' % tenant_id)
+ except Exception:
+ pass
+
+ tenant_data = {'tenant_name': tenant_name,
+ 'tenant_id': tenant_id,
+ 'status': tenant_status}
+ return tenant_data
+
+
+def create_user(user_name, tenant_id):
+ """
+ This method is to create users per Tenant
+ """
+
+ try:
+ new_user = keystone.users.create(name=user_name,
+ password=USER_PASSWORD,
+ tenant_id=tenant_id)
+ print(' - Created User %s' % user_name)
+ except Exception:
+ new_user = keystone.users.find(name=user_name)
+ member_role = keystone.roles.find(name='_member_')
+ try:
+ keystone.roles.add_user_role(new_user, member_role, tenant_id)
+ except Exception:
+ pass
+ if assign_admin:
+ admin_user = keystone.users.find(name='admin')
+ admin_role = keystone.roles.find(name='admin')
+ try:
+ keystone.roles.add_user_role(admin_user, admin_role, tenant_id)
+ except Exception:
+ pass
+ user_data = {'name': new_user.name,
+ 'id': new_user.id}
+ return user_data
+
+
+def delete_tenant(tenant_name):
+ """
+ This method is used to delete tenant and users
+ """
+
+ try:
+ tenant = keystone.tenants.find(name=tenant_name)
+ for j in range(USER_COUNT):
+ j += 1
+ user_name = tenant_name + '-user-' + str(j)
+ delete_user(user_name, tenant.id)
+ tenant.delete()
+ print(' - Deleted Tenant %s ' % tenant_name)
+ except Exception:
+ pass
+ return True
+
+
+def delete_user(user_name, tenant_id):
+ """
+ This method is to delete users per Tenant
+ """
+ try:
+ user = keystone.users.find(name=user_name)
+ user.delete()
+ except Exception:
+ print(" - User Not Found: %s" % user_name)
+ pass
+ print(' - Deleted User %s' % user_name)
+ return True
diff --git a/NTT/ntt-29-3-16-test/tenants.pyc b/NTT/ntt-29-3-16-test/tenants.pyc
new file mode 100644
index 0000000..a20174b
Binary files /dev/null and b/NTT/ntt-29-3-16-test/tenants.pyc differ
diff --git a/NTT/ntt-29-3-16-test/user.txt b/NTT/ntt-29-3-16-test/user.txt
new file mode 100755
index 0000000..9e5d3d9
--- /dev/null
+++ b/NTT/ntt-29-3-16-test/user.txt
@@ -0,0 +1,7 @@
+#cloud-config
+chpasswd:
+ list: |
+ root:ubuntu
+ ubuntu:ubuntu
+ expire: False
+ssh_pwauth: True
diff --git a/NTT/ntt-29-3-16-test/vm_instances.py b/NTT/ntt-29-3-16-test/vm_instances.py
new file mode 100755
index 0000000..239e157
--- /dev/null
+++ b/NTT/ntt-29-3-16-test/vm_instances.py
@@ -0,0 +1,154 @@
+#!/usr/bin/env python
+"""
+Description: This script is to launching VMs on the network.
+Developer: gopal@onecloudinc.com
+"""
+
+import os
+import time
+import pdb
+import novaclient.v1_1.client as nvclient
+from novaclient.base import *
+from novaclient.exceptions import NotFound
+from config import FLOATING_IP_CREATION, IMAGE_NAME, FLAVOUR_NAME,OS_USERNAME, OS_TENANT_NAME, OS_PASSWORD, OS_AUTH_URL
+from credentials import get_nova_credentials, get_tenant_nova_credentials,get_credentials
+from floating_ips import add_floating_ip_for_vm
+import glanceclient.v2.client as glance_client
+import keystoneclient.v2_0.client as ksclient
+keystone = ksclient.Client(auth_url="http://172.168.2.40:35357/v2.0",
+ username="admin",
+ password="admin",
+ tenant_name="admin")
+token = keystone.auth_ref['token']['id']
+
+credentials = get_nova_credentials()
+nova = nvclient.Client(**credentials)
+#glance=glance_client.Client(username=OS_USERNAME,password=OS_PASSWORD,tenant_name=OS_TENANT_NAME,auth_url=OS_AUTH_URL)
+glance=glance_client.Client(endpoint="http://172.168.2.40:9292", token=token)
+
+
+if not nova.keypairs.findall(name="admin"):
+ with open(os.path.expanduser('~/.ssh/id_rsa.pub')) as fpubkey:
+ nova.keypairs.create(name="admin", public_key=fpubkey.read())
+
+def upload_image_glance():
+ #pdb.set_trace()
+ image_list=glance.images.list()
+ image_file="/home/onecloud/NTT/keerthi/ubuntu.img"
+ image=glance.images.create(disk_format="qcow2",container_format="bare",name="ubuntu")
+ print("image status %s"%(image.status))
+ ss=glance.images.upload(image.id,open('/home/onecloud/NTT/keerthi/ubuntu.img','rb'))
+ print("Current Image status <%s>"%(image.status))
+
+ #with open(image_file) as img:
+ #image=glance.images.create(name="ubuntu",disk_format="raw",container_format="bare",data=img)
+
+ #print("Current Image status %s"%(image.status))
+
+
+def launch_vm_on_network(tenant_name, vm_name, network_id):
+ """
+ This method is to launch VM on the given network & VM Name.
+ """
+ #pdb.set_trace()
+ instance=None
+ tenant_credentials = get_tenant_nova_credentials(tenant_name)
+
+ nova = nvclient.Client(**tenant_credentials)
+ nova.quotas.update(tenant_name, instances=-1, cores=-1, ram=-1, fixed_ips=-1, floating_ips=-1)
+ with open('user.txt') as userdata:
+ user_data = userdata.read()
+ try:
+ image_list=nova.images.find(name="ubuntu")
+ except NotFound:
+ upload_image_glance()
+
+ #for img in image:
+ #if img.name == 'ubuntu':
+ #print "image found"
+ try:
+
+ flavor = nova.flavors.find(name='traffic')
+ except:
+ flavor = nova.flavors.create(name="traffic",ram="2048",vcpus="1",disk="10")
+
+
+ try:
+
+ instance = nova.servers.create(name=vm_name, image=image_list,
+ flavor=flavor,
+ key_name="admin",
+ nics=[{'net-id': network_id}],userdata=user_data)
+ except Exception:
+ pass
+
+ # Poll at 15 second intervals, until the status is no longer 'BUILD'
+ print " * Instance <%s> created on network <%s>: "%(vm_name,str(network_id))
+ status = instance.status
+ while status == 'BUILD':
+ time.sleep(15)
+ # Retrieve the instance again so the status field updates
+ instance = nova.servers.get(instance.id)
+ status = instance.status
+
+ print " - Current status: %s" % status
+ if FLOATING_IP_CREATION:
+ add_floating_ip_for_vm(tenant_name, instance)
+
+ ins_data = {'instance_name': vm_name, 'status': status}
+ return ins_data
+
+#def endpoint_discovery(tenant_data,network_data):
+
+# tenant_credentials = get_tenant_nova_credentials(tenant_name)
+# nova = nvclient.Client(**tenant_credentials)
+# instance_list = nova.servers.list()
+
+
+def discover_vm_on_network(tenant_name):
+ """
+ This method is used to discover instances per tenant
+ """
+ name=None
+ status=None
+ try:
+ tenant_credentials = get_tenant_nova_credentials(tenant_name)
+ nova = nvclient.Client(**tenant_credentials)
+ instance_list=nova.servers.list()
+ #instance = nova.servers.find(name=vm_name)
+ if instance_list > 0:
+
+ for inst in instance_list:
+
+ instance_id = inst.id
+ name=inst.name
+ inst_find=nova.servers.find(id=instance_id)
+ print(' - Instance %s Discovered' % inst.name)
+ print(' - Instance ID %s Discovered' % instance_id)
+ print(' - Instance %s Status' % inst.status)
+ status=inst.status
+ except Exception:
+ print(' - Instance Not Found')
+ status = False
+
+ ins_data = {'instance_name': name,
+ 'status': status }
+ return ins_data
+
+
+def terminate_vm_on_network(tenant_name, vm_name, network_id):
+ """
+ This method is to terminate VM on the given network & VM Name.
+ """
+ pdb.set_trace()
+ tenant_credentials = get_tenant_nova_credentials(tenant_name)
+ nova = nvclient.Client(**tenant_credentials)
+ nova.quotas.delete(tenant_name)
+ try:
+ instance = nova.servers.find(name=vm_name)
+ nova.servers.delete(instance.id)
+ print " * Instance terminated on network: " + str(network_id)
+ except Exception:
+ print " * Instance Not Found on network: " + str(network_id)
+ pass
+ return True
diff --git a/NTT/ntt-29-3-16-test/vm_instances.pyc b/NTT/ntt-29-3-16-test/vm_instances.pyc
new file mode 100644
index 0000000..147b8d3
Binary files /dev/null and b/NTT/ntt-29-3-16-test/vm_instances.pyc differ
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/.discover_deploy.py.swp b/NTT/ntt-30-3-16/ntt-30-3-16/.discover_deploy.py.swp
new file mode 100755
index 0000000..f7c19f0
Binary files /dev/null and b/NTT/ntt-30-3-16/ntt-30-3-16/.discover_deploy.py.swp differ
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/.discovery.py.swo b/NTT/ntt-30-3-16/ntt-30-3-16/.discovery.py.swo
new file mode 100644
index 0000000..16b9ced
Binary files /dev/null and b/NTT/ntt-30-3-16/ntt-30-3-16/.discovery.py.swo differ
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/.discovery.py.swp b/NTT/ntt-30-3-16/ntt-30-3-16/.discovery.py.swp
new file mode 100755
index 0000000..41fba52
Binary files /dev/null and b/NTT/ntt-30-3-16/ntt-30-3-16/.discovery.py.swp differ
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/.idea/misc.xml b/NTT/ntt-30-3-16/ntt-30-3-16/.idea/misc.xml
new file mode 100644
index 0000000..7c4b884
--- /dev/null
+++ b/NTT/ntt-30-3-16/ntt-30-3-16/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/.idea/modules.xml b/NTT/ntt-30-3-16/ntt-30-3-16/.idea/modules.xml
new file mode 100644
index 0000000..64e6bd4
--- /dev/null
+++ b/NTT/ntt-30-3-16/ntt-30-3-16/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/.idea/ntt-29-2-16-test.iml b/NTT/ntt-30-3-16/ntt-30-3-16/.idea/ntt-29-2-16-test.iml
new file mode 100644
index 0000000..6f63a63
--- /dev/null
+++ b/NTT/ntt-30-3-16/ntt-30-3-16/.idea/ntt-29-2-16-test.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/.idea/workspace.xml b/NTT/ntt-30-3-16/ntt-30-3-16/.idea/workspace.xml
new file mode 100644
index 0000000..5570e2d
--- /dev/null
+++ b/NTT/ntt-30-3-16/ntt-30-3-16/.idea/workspace.xml
@@ -0,0 +1,426 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1459230370172
+
+
+ 1459230370172
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/.networks.py.swp b/NTT/ntt-30-3-16/ntt-30-3-16/.networks.py.swp
new file mode 100755
index 0000000..a8931b6
Binary files /dev/null and b/NTT/ntt-30-3-16/ntt-30-3-16/.networks.py.swp differ
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/.t1.py.swp b/NTT/ntt-30-3-16/ntt-30-3-16/.t1.py.swp
new file mode 100755
index 0000000..2053542
Binary files /dev/null and b/NTT/ntt-30-3-16/ntt-30-3-16/.t1.py.swp differ
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/.vm_instances.py.swo b/NTT/ntt-30-3-16/ntt-30-3-16/.vm_instances.py.swo
new file mode 100644
index 0000000..3d84a7a
Binary files /dev/null and b/NTT/ntt-30-3-16/ntt-30-3-16/.vm_instances.py.swo differ
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/.vm_instances.py.swp b/NTT/ntt-30-3-16/ntt-30-3-16/.vm_instances.py.swp
new file mode 100755
index 0000000..c31dbb5
Binary files /dev/null and b/NTT/ntt-30-3-16/ntt-30-3-16/.vm_instances.py.swp differ
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/config.py b/NTT/ntt-30-3-16/ntt-30-3-16/config.py
new file mode 100755
index 0000000..59f058e
--- /dev/null
+++ b/NTT/ntt-30-3-16/ntt-30-3-16/config.py
@@ -0,0 +1,75 @@
+"""
+Description: Define the Scale Test Configuration with the below global \
+ parameters.
+Developer: gopal@onecloudinc.com
+"""
+
+# Tenant Settings
+
+OS_USERNAME = 'admin'
+OS_TENANT_NAME = 'admin'
+OS_PASSWORD = 'admin'
+OS_AUTH_URL = 'http://172.168.2.40:5000/v2.0/'
+
+# TENANT_CREATION = True
+
+TENANT_COUNT = 2
+TENANT_NAME_PREFIX = 'tenant-test'
+TENANT_BASE_INDEX = 101
+USER_COUNT = 1
+USER_PASSWORD = 'secret'
+NETWORK_COUNT = 2
+VM_COUNT = 1
+IMAGE_NAME = 'Cirros'
+FLAVOUR_NAME = 'm1.tiny'
+EXTERNAL_NETWORK = 'public'
+
+# Floating IP Settings
+
+FLOATING_IP_CREATION = True
+FLOATING_IP_POOL = 'public'
+
+TENANT_CREATION = False
+TENANT_NAME = ['tenant-test-101', 'tenant-test-102', 'tenant-test-103', 'tenant-test-104','tenant-test-105']
+
+
+# Cisco ASR Settings
+
+ENABLE_ASR_VERIFICATION = False
+DEPLOYMENT_ID = 'ans136'
+ASR_HOST = '10.10.10.10'
+ASR_USER = 'admin'
+ASR_PASSWORD = 'admin'
+
+
+"""
+Test Configuration Ends Here with the global parameters.
+"""
+
+
+def print_scale_test_config():
+ """
+ This method is used to print the current test configuration on scale test \
+ deployment initialization.
+ """
+ print '=' * 70
+ print " Configuration for this Scale Test"
+ print '=' * 70
+
+ print " Tenant will be created with prefix : " \
+ + TENANT_NAME_PREFIX
+ print " No of Tenants will be created : " \
+ + str(TENANT_COUNT)
+ print " Tenant base index range starts from : " \
+ + str(TENANT_BASE_INDEX)
+ print " No of Users per Tenant : " \
+ + str(USER_COUNT)
+ print " No of Networks : " \
+ + str(NETWORK_COUNT)
+ print " No of VMs per Network : " \
+ + str(VM_COUNT)
+ print " Name of the External Network with be connected with Router : " \
+ + EXTERNAL_NETWORK
+ print " Name of the Floating IP Pool will be used for Allocation : " \
+ + FLOATING_IP_POOL
+ print '=' * 70
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/config.pyc b/NTT/ntt-30-3-16/ntt-30-3-16/config.pyc
new file mode 100755
index 0000000..d30452b
Binary files /dev/null and b/NTT/ntt-30-3-16/ntt-30-3-16/config.pyc differ
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/credentials.py b/NTT/ntt-30-3-16/ntt-30-3-16/credentials.py
new file mode 100755
index 0000000..a9b640c
--- /dev/null
+++ b/NTT/ntt-30-3-16/ntt-30-3-16/credentials.py
@@ -0,0 +1,46 @@
+"""
+Description: This script is to map the environment variables to credentials \
+ dict based on the client service API
+Developer: gopal@onecloudinc.com
+"""
+
+from config import OS_USERNAME, OS_TENANT_NAME, OS_PASSWORD, OS_AUTH_URL
+
+
+def get_credentials():
+ """
+ This method is used for authorization with keystone clients
+ """
+
+ data = {}
+ data['username'] = OS_USERNAME
+ data['password'] = OS_PASSWORD
+ data['auth_url'] = OS_AUTH_URL
+ data['tenant_name'] = OS_TENANT_NAME
+ return data
+
+
+def get_nova_credentials():
+ """
+ This method is used for authorization with nova clients
+ """
+
+ data = {}
+ data['username'] = OS_USERNAME
+ data['api_key'] = OS_PASSWORD
+ data['auth_url'] = OS_AUTH_URL
+ data['project_id'] = OS_TENANT_NAME
+ return data
+
+
+def get_tenant_nova_credentials(tenant_name):
+ """
+ This method is used for tenant authorization with nova clients
+ """
+
+ data = {}
+ data['username'] = OS_USERNAME
+ data['api_key'] = OS_PASSWORD
+ data['auth_url'] = OS_AUTH_URL
+ data['project_id'] = tenant_name
+ return data
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/credentials.pyc b/NTT/ntt-30-3-16/ntt-30-3-16/credentials.pyc
new file mode 100755
index 0000000..9658494
Binary files /dev/null and b/NTT/ntt-30-3-16/ntt-30-3-16/credentials.pyc differ
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/destroy_deploy.py b/NTT/ntt-30-3-16/ntt-30-3-16/destroy_deploy.py
new file mode 100755
index 0000000..3727a54
--- /dev/null
+++ b/NTT/ntt-30-3-16/ntt-30-3-16/destroy_deploy.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+
+"""
+Description: This script is to destory the L3/HA scale test deployment
+Developer: gopal@onecloudinc.com
+"""
+
+import os
+from neutronclient.v2_0 import client
+from keystoneclient.v2_0 import client as ksclient
+from credentials import get_credentials
+from config import TENANT_BASE_INDEX, TENANT_COUNT, TENANT_NAME_PREFIX, \
+ print_scale_test_config
+from networks import delete_network
+from tenants import delete_tenant
+from datetime import datetime, timedelta
+from pytz import timezone
+
+credentials = get_credentials()
+neutron = client.Client(**credentials)
+keystone = ksclient.Client(**credentials)
+fmt = "%Y-%m-%d %H:%M:%S %Z%z"
+
+
+def main():
+ """
+ This method will destory the scale test deployment based on the global \
+ config parameters mentioned on config.py file and creates the router with \
+ external gateway connectivity to public network.
+ """
+
+ print "\n"
+ print_scale_test_config()
+ print "\n"
+ print "Destroying Scale Test Deployment"
+ index = TENANT_BASE_INDEX
+ for i in range(1, TENANT_COUNT + 1):
+ tenant_name = TENANT_NAME_PREFIX + '-' + str(index)
+ index += 1
+ start_time = datetime.now(timezone('US/Pacific'))
+ try:
+ tenant = keystone.tenants.find(name=tenant_name)
+ delete_network(tenant_name)
+ delete_tenant(tenant_name)
+ except Exception:
+ print "\n"
+ print(" - Tenant Not Found: %s" % tenant_name)
+ pass
+ end_time = datetime.now(timezone('US/Pacific'))
+ print "\n"
+ print "-"*65
+ print (" Tenant & User Deletion Time Summary :")
+ print "-"*65
+ print "\n"
+ print(' - Test Started Time :\t %s' % (start_time.strftime(fmt)))
+ print(' - Test Ended Time :\t %s' % (end_time.strftime(fmt)))
+
+ print "=" * 50
+ print "\n"
+ print "Cleaned Scale Test Deployment"
+ print "\n"
+
+
+if __name__ == '__main__':
+ main_start_time = datetime.now(timezone('US/Pacific'))
+ main()
+ main_end_time = datetime.now(timezone('US/Pacific'))
+ total_time = (main_end_time - main_start_time)
+ print "-"*65
+ print (" Scale Test Deployment Consolidated Time Summary :")
+ print "-"*65
+ print "\n"
+ print(' - Test Started Time :\t %s' % (main_start_time.strftime(fmt)))
+ print(' - Test Ended Time :\t %s' % (main_end_time.strftime(fmt)))
+ print(' - Elapsed Time for Cleaned Scale Test Deployment: %d days, %d hours, %d minutes, %d seconds' % (total_time.days, (total_time.seconds/3600), (total_time.seconds % 3600 / 60), (total_time.seconds % 60)))
+ print "\n"
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/discover_deploy.py b/NTT/ntt-30-3-16/ntt-30-3-16/discover_deploy.py
new file mode 100755
index 0000000..e2dcaa0
--- /dev/null
+++ b/NTT/ntt-30-3-16/ntt-30-3-16/discover_deploy.py
@@ -0,0 +1,281 @@
+#!/usr/bin/env python
+
+"""
+Description: This script is to initialize the L3/HA scale test deployment
+Developer: gopal@onecloudinc.com
+"""
+import pdb
+import os
+from neutronclient.v2_0 import client
+from credentials import get_credentials
+from config import TENANT_BASE_INDEX, NETWORK_COUNT, \
+ EXTERNAL_NETWORK, print_scale_test_config, DEPLOYMENT_ID, \
+ ASR_HOST, ASR_USER, ASR_PASSWORD, ENABLE_ASR_VERIFICATION, TENANT_COUNT, \
+ TENANT_NAME_PREFIX, TENANT_NAME, TENANT_CREATION, VM_COUNT
+from tenants import create_tenant, discover_tenant
+from networks import create_network
+from vm_instances import discover_vm_on_network
+from prettytable import PrettyTable
+
+credentials = get_credentials()
+neutron = client.Client(**credentials)
+
+
+def print_tenant_info(tenant_data):
+
+ x = PrettyTable(['Tenant Name', 'Status'])
+ x.align["Tenant Name"] = "l" # Left align source tenant values
+ x.padding_width = 1
+ for entry in tenant_data:
+ x.add_row([entry['tenant_name'], entry['status']])
+ return x
+
+def print_discovered_tenant(tenant_data,router_data,test_data):
+ pdb.set_trace()
+ y=PrettyTable(['Tenant Name','Router Name','Network Name','Network CIDR'])
+ y.padding_width=1
+ for x in tenant_data:
+ for z in router_data:
+ for a in test_data:
+
+ y.add_row([x['tenant_name'],z['router_name'],a['network_data']['network_name'],a['network_data']['network_cidr']])
+ return y
+
+def print_consolidated_count(test_count):
+ pdb.set_trace()
+ y=PrettyTable(['Tenant Count','Router Count','Network Count','VM Count'])
+ y.padding_width=1
+ for i in test_count:
+ y.add_row([i['tenant_count'],i['router_count'],i['network_count']])
+ return y
+def print_router_info(router_data):
+ x = PrettyTable(['Tenant Name', 'Router Name', 'Status'])
+ x.align["Tenant Name"] = "l" # Left align source tenant values
+ x.padding_width = 1
+ for entry in router_data:
+ x.add_row([entry['tenant_name'], entry['router_name'],
+ entry['router_status']])
+ return x
+
+
+def print_network_info(test_data):
+ y = PrettyTable(['Tenant Name', 'Network Name', 'Network CIDR',
+ 'Vlan ID', 'Subnet Name', 'Status'])
+ y.align["Tenant_Name"] = "l" # Left align source tenant values
+ y.padding_width = 1
+ for entry in test_data:
+ y.add_row([entry['network_data']['tenant_name'],
+ entry['network_data']['network_name'],
+ entry['network_data']['network_cidr'],
+ entry['network_data']['network_vlan_id'],
+ entry['network_data']['subnet_name'],
+ entry['network_data']['status']])
+ return y
+
+
+def print_instance_info(test_data):
+
+ z = PrettyTable(['Tenant Name', 'Instance Name', 'Status'])
+ z.align["Tenant Name"] = "l" # Left align source tenant values
+ z.padding_width = 1
+ for data in test_data:
+ for ins in data['instance_data']:
+ z.add_row([data['network_data']['tenant_name'],
+ ins['instance_name'],
+ ins['status']])
+ return z
+
+
+
+
+
+
+def main():
+ """
+ This method will initialize the scale test deployment based on the global \
+ config parameters mentioned on config.py file and creates the router with \
+ external gateway connectivity to public network.
+ """
+
+ tenant_data = []
+ router_data = []
+ test_data = []
+ test_count={}
+ if TENANT_CREATION == True:
+ print "\n"
+ print_scale_test_config()
+ print "\n"
+ pdb.set_trace()
+ print "Starting Scale Test Deployment"
+ index = TENANT_BASE_INDEX
+ for i in range(1, TENANT_COUNT + 1):
+ tenant_name = TENANT_NAME_PREFIX + '-' + str(index)
+ index += 1
+ try:
+ tenant_data.append(create_tenant(tenant_name))
+ except Exception as exc:
+ print "Exception occured on Tenant Creation: %s" % (exc.message)
+ pass
+ test_count["tenant_count"]=len(tenant_data)
+ for tenant in tenant_data:
+
+ #test= {'count': {'tenant_count': len(tenant_data)}}
+ #test_count.append(test)
+ router_dict = {}
+ prefix = tenant['tenant_name']
+ router_name = prefix + '-router'
+ router_dict['tenant_name'] = tenant['tenant_name']
+ router_dict['router_name'] = router_name
+ router_dict['network_vlan'] = {}
+ router_dict['router_detail'] = {}
+ router_dict['ipnatpool_data'] = {}
+ router_dict['iproute_data'] = {}
+ router_dict['interface_data'] = []
+ router_dict['nat_data'] = []
+
+ router = neutron.list_routers(name=EXTERNAL_NETWORK)['routers']
+ if not router:
+ router_info = neutron.create_router({'router': {
+ 'name': router_name, 'tenant_id': tenant['tenant_id']}})
+ router = router_info['router']
+ status = True
+ elif router[0]['tenant_id'] == tenant['tenant_id']:
+ router = router[0]
+ status = True
+ else:
+ router = {}
+ status = False
+
+ router_dict['router_status'] = status
+ networks = neutron.list_networks(name=EXTERNAL_NETWORK)
+ network_id = networks['networks'][0]['id']
+ neutron.add_gateway_router(router['id'],
+ {'network_id': network_id,
+ 'tenant_id': tenant['tenant_id']})
+ router_id = router['id']
+ print(' - Created Router %s' % router['name'])
+
+ for i in range(1, NETWORK_COUNT + 1):
+ network_index = str(i)
+ network_cidr = str(i) + "." + str(i) + "." + str(i) + ".0/24"
+ test_data.append(create_network(tenant, router,
+ network_index, network_cidr))
+ network_vlan = {}
+ for entry in test_data:
+ network_vlan[str(entry['network_data']['network_vlan_id'])] = \
+ entry['network_data']['network_name']
+ router_dict['network_vlan'] = network_vlan
+
+ else:
+ print "\n"
+ print "=" * 50
+ print "Discovering Tenant Topology on Scale Test Deployment"
+ print "=" * 50
+ try:
+ pdb.set_trace()
+ for i in range(len(TENANT_NAME)):
+ tenant_name = TENANT_NAME[i]
+ tenant_data.append(discover_tenant(tenant_name))
+ #test= {'count': {'tenant_count': len(tenant_data)}}
+ #test_count.append(test)
+
+ for tenant in tenant_data:
+ router_dict = {}
+ prefix = tenant['tenant_name']
+ router_name = prefix + '-router'
+ router_dict['tenant_name'] = tenant['tenant_name']
+ router_dict['tenant_id'] = tenant['tenant_id']
+ router_dict['router_name'] = router_name
+ router_dict['network_vlan'] = {}
+ router_dict['router_detail'] = {}
+ router_dict['ipnatpool_data'] = {}
+ router_dict['iproute_data'] = {}
+ router_dict['interface_data'] = []
+ router_dict['nat_data'] = []
+ pdb.set_trace()
+ router = neutron.list_routers(name=router_name)['routers'][0]
+ if router['tenant_id'] == tenant['tenant_id']:
+ print(' - Router %s Discovered' % router_name)
+ status = True
+ else:
+ print(' - Router %s Not Found' % router_name)
+ status = False
+ router_id = router['id']
+ router_dict['router_status'] = status
+ router_data.append(router_dict)
+ #test1= {'count': {'router_count': len(router_data)}}
+ #test_count.append(test1)
+ test_count["router_count"]=len(router_data)
+ for i in range(1, NETWORK_COUNT + 1):
+ network_index = str(i)
+ network_cidr = str(i) + "." + str(i) + "." + str(i) + ".0/24"
+ network_name = prefix + '-net-' + network_index
+ subnet_name = prefix + "-subnet-" + network_index
+ ins_data = []
+ networks = neutron.list_networks(name=network_name)['networks']
+ for i in range(len(networks)):
+ if networks[i]['tenant_id'] == tenant['tenant_id']:
+ network_id = networks[i]['id']
+ network_vlan = networks[i]['provider:segmentation_id']
+ print(' - Network %s Discovered' % network_name)
+ print(' - Network ID %s Discovered' % network_id)
+ print(' - VLAN ID %s Discovered' % network_vlan)
+ status = True
+ for j in range(1, VM_COUNT + 1):
+ vm_name = network_name + '-vm-' + str(j)
+ ins_data.append(discover_vm_on_network(tenant['tenant_name'], vm_name, network_id))
+ else:
+ print(' - Network %s Not Found' % network_name)
+ status = False
+
+ result = {'network_data': {'tenant_name': tenant['tenant_name'],
+ 'network_name': network_name,
+ 'network_cidr': network_cidr,
+ 'subnet_name': subnet_name,
+ 'network_id': network_id,
+ 'network_vlan_id': network_vlan,
+ 'status':status},
+ 'instance_data': ins_data}
+ test_data.append(result)
+ test_count["network_count"]=test_data
+
+ except Exception:
+ print "\n"
+ print(' - Tenant %s Not Found' % tenant_name)
+
+
+ print "\n"
+ print "=" * 50
+ print "Scale Test Discovery Completed"
+ print "=" * 50
+
+ print "*" * 80
+ print "Scale Test Deployment OpenStack Report"
+ print "*" * 80
+
+ print "\n"
+ print " Tenant Discovery Results "
+ print print_tenant_info(tenant_data)
+ print "\n"
+ print " Router Discovery Results "
+ print print_router_info(router_data)
+ print "\n"
+ print " Network Discovery Results "
+ print print_network_info(test_data)
+ print "\n"
+
+ print " Instance Discovery Results "
+ print print_instance_info(test_data)
+ print "\n"
+
+ print " Tenant Name, Router Name, Network Name "
+ print print_discovered_tenant(tenant_data,router_data,test_data)
+ print "\n"
+
+ print" Overall Count of resources"
+ print print_consolidated_count(test_count)
+
+
+
+if __name__ == '__main__':
+ main()
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/discovery.py b/NTT/ntt-30-3-16/ntt-30-3-16/discovery.py
new file mode 100755
index 0000000..bbe1d80
--- /dev/null
+++ b/NTT/ntt-30-3-16/ntt-30-3-16/discovery.py
@@ -0,0 +1,296 @@
+import pdb
+from neutronclient.v2_0 import client
+import novaclient.v1_1.client as nvclient
+
+from credentials import get_credentials,get_tenant_nova_credentials
+from config import TENANT_BASE_INDEX, NETWORK_COUNT, \
+ EXTERNAL_NETWORK, print_scale_test_config, DEPLOYMENT_ID, \
+ ASR_HOST, ASR_USER, ASR_PASSWORD, ENABLE_ASR_VERIFICATION, TENANT_COUNT, \
+ TENANT_NAME_PREFIX, TENANT_NAME, TENANT_CREATION, VM_COUNT
+from tenants import create_tenant, discover_tenant
+from vm_instances import discover_vm_on_network,launch_vm_on_network,vm_endpoint_discovery
+from networks import delete_networks,delete_vm
+credentials = get_credentials()
+neutron = client.Client(**credentials)
+tenant_data=[]
+router_data=[]
+network_dict={}
+
+def tenant_discovery():
+ pdb.set_trace()
+ #for i in range(len(TENANT_NAME)):
+ #tenant_name = TENANT_NAME[i]
+ #tenant_data.append(discover_tenant())
+ #discover_tenant()
+ tenant_data= [
+ {'id': u'2931fbe17e8445da875bb915a29d0bbf', 'name': u'admin'},
+ {'id': u'2e93f5f662974b1284e8be13dd472e48', 'name': u'demo'},
+ {'id': u'ae9e7941b6764accae72a99662c189a5', 'name': u'tenant-test-101'},
+ {'id': u'be0e4b8dc7754668b0e3d57e4f7f6f66', 'name': u'tenant-test-102'}]
+ #{'id': u'fbb4907f073d4b5881a85c1692ae027a', 'name': u'services'}]
+ #for i in range(len(tenant_data)):
+ #print tenant_data[i]
+
+# router_discovery(tenant_data)
+ network_data=network_discovery(tenant_data) #List all subnets under each network from each tenant
+
+ #discover_instance(tenant_data)
+ #launch_instance(tenant_data,network_data)
+ endpoints=endpoint_discovery(tenant_data,network_data)
+ print endpoints
+# print tenant_data
+# print len(tenant_data)
+# destroy_all(tenant_data,network_data)
+
+
+def endpoint_discovery(tenant_data,network_data):
+ pdb.set_trace()
+ instance_list=[]
+ endpoint_list=[]
+ final_data=[]
+ for tenant in tenant_data:
+ print("Get router information")
+ routers=get_router(tenant)
+ ports=get_ports(tenant)
+ instance_ports = get_instance_ports(ports)
+ for router in routers:
+ router_detail = {}
+ router_detail['id'] = router['id']
+ router_detail['ports'] = get_router_ports(router, ports)
+ subnets = []
+ instance_list = []
+ for port in router_detail['ports']:
+
+ subnets.append(get_port_subnets(tenant, port))
+ router_detail['subnets'] = subnets
+ for subnet in router_detail['subnets']:
+ if subnet['id'] != '':
+ endpoint_detail = get_subnet_endpoints(tenant, instance_ports, subnet)
+ ip_list = []
+ subnet['instances'] = endpoint_detail
+ for entry in endpoint_detail:
+ server = get_instance_detail(tenant['name'],entry['device_id'])
+ if entry['device_id'] not in instance_list and \
+ server.status == 'ACTIVE':
+ instance_list.append(entry['device_id'])
+ ip_list.append(entry['ip_address'])
+ endpoint_list.append({'endpoints': ip_list,'tenant_name':tenant['name'],'subnet':subnet})
+
+
+
+
+
+ #print "tenant_name..%s"%(tenant['name'])
+ #print "routers...%s"%(routers)
+ #print "instance_ports....%s"%(instance_ports)
+ #for ins in instance_ports:
+ #pdb.set_trace()
+ #instances={'instance_detail':{'fixed_ip':ins['fixed_ips']}} # list all instance fixed ips
+ #instance_list.append(instances)
+ #return instance_list
+ return endpoint_list
+
+def get_instance_detail(tenant,instance):
+
+ tenant_credentials = get_tenant_nova_credentials(tenant)
+ nova = nvclient.Client(**tenant_credentials)
+ return nova.servers.get(instance)
+
+def get_router_ports(router,ports):
+
+ router_port_list = []
+ for port in ports:
+ if (port['device_id'] == router['id'] and
+ port['device_owner'] == 'network:router_interface'):
+ router_port_list.append(port)
+ return router_port_list
+
+def get_port_subnets(tenant,port):
+
+ subnet = get_subnet_detail(tenant, port['fixed_ips'][0]['subnet_id'])['subnet']
+ return {'id': port['fixed_ips'][0]['subnet_id'], 'name': subnet['name'],
+ 'ip_address': port['fixed_ips'][0]['ip_address'],'allocation_pool':subnet['allocation_pools']}
+
+def get_subnet_detail(tenant, subnet):
+
+ return neutron.show_subnet(subnet)
+
+def get_subnet_endpoints(tenant,ports,subnet):
+
+ endpoints = []
+ for port in ports:
+ endpoint_detail = {}
+ if port['fixed_ips'][0]['subnet_id'] == subnet['id']:
+ device_id = port['device_id'].encode('unicode_escape')
+ ip = port['fixed_ips'][0]['ip_address'].encode('unicode_escape')
+ endpoint_detail['device_id'] = device_id
+ endpoint_detail['ip_address'] = ip
+ endpoints.append(endpoint_detail)
+ return endpoints
+
+
+def get_router(tenant):
+ routers=neutron.list_routers(tenant_id=tenant['id'])['routers']
+ return routers
+def get_ports(tenant):
+ ports=neutron.list_ports(tenant_id=tenant['id'])['ports']
+ return ports
+
+def get_instance_ports(ports):
+ pdb.set_trace()
+ instance_port_list = []
+ for port in ports:
+ if port['device_owner'] == 'compute:compute':
+ instance_port_list.append(port)
+ return instance_port_list
+
+def destroy_all(tenant_data,network_data):
+
+ delete_vm(tenant_data,network_data)
+ delete_networks(tenant_data,network_data)
+
+def network_discovery(tenant_data):
+ pdb.set_trace()
+ network_detail=[]
+ subnet_detail=[]
+ instance_list=[]
+ net_sub={}
+ for tenant in tenant_data:
+
+ networks=neutron.list_networks(tenant_id=tenant['id'])['networks']
+
+
+# List all subnets under each network and the tenants
+ for net in networks:
+ nets={}
+ if net['tenant_id'] == tenant['id']:
+ nets={'network_list':{'tenant_name':tenant['name'],
+ 'network_name':net['name'],'network_id':net['id'],'shared':net['shared'],'subnets':net['subnets']}}
+ subnets=neutron.list_subnets(network_id=net['id'])['subnets']
+ for subnet in subnets:
+ #net_sub={'networks':{'tenant_name':tenant['name'],'network_name':net['name'],'network_id':net['id'],'shared':net['shared']},'subnets':{'subnet_name':subnet['name'],'cidr':subnet['cidr']}}
+ net_sub={'networks':{'tenant_name':tenant['name'],'network_name':net['name'],'network_id':net['id'],'shared':net['shared'],'subnet_name':subnet['name'],'cidr':subnet['cidr']}}
+
+ subnet_detail.append(net_sub)
+ print "\n"
+ print "List subnets along with network details"
+ print "tenant name %s"%(tenant['name'])
+ print "network_name %s"%(net['name'])
+ print "subnet_name %s"%(subnet['name'])
+ print "cidr\t %s"%(subnet['cidr'])
+ print "allocation pools...%s"%(subnet['allocation_pools'])
+ print "\n"
+
+ #routers=get_router(tenant)
+ #ports=get_ports(tenant)
+ #instance_ports = get_instance_ports(ports)
+ #for ins in instance_ports:
+ #pdb.set_trace()
+ #instances={'instance_detail':{'fixed_ip':ins['fixed_ips']}}
+ #instance_list.append(instances)
+
+ #vm_endpoint_discovery(tenant['name'])
+
+
+
+
+ #subnets = net.get("subnets")
+ #subnet_list = neutron.list_subnets(id=subnets)
+ #print subnet_list.get("subnets", [])[0].get("cidr")
+ network_detail.append(nets)
+
+ #pdb.set_trace()
+ # subnets=neutron.list_subnets(tenant_id=tenant['id'])['subnets']
+ # for subnet in subnets:
+ #
+ # print "\n\n"
+ # print "tenant name %s"%(tenant['name'])
+ # print "network_id %s"%(subnet['network_id'])
+ #
+ # print "subnet_id %s"%(subnet['id'])
+ # print "cidr\t %s"%(subnet['cidr'])
+ #network_dict['network_list']=network_detail
+
+ return network_detail
+
+def launch_instance(tenant_data,network_data):
+ #pdb.set_trace()
+ inst_data=[]
+ count=1
+ for tenant in tenant_data:
+
+ for network in network_data:
+ pdb.set_trace()
+ vm_name=tenant['name'] + '-vm-' + str(count)
+ if ((network['network_list']['tenant_name'] == tenant['name']) and (network['network_list']['shared'] == False)):
+
+ inst_data.append(launch_vm_on_network(tenant['name'],vm_name,network['network_list']['network_id']))
+
+ count += 1
+
+def discover_instance(tenant_data):
+ instance_detail=[]
+ pdb.set_trace()
+ for tenant in tenant_data:
+
+ vm_dict={}
+ instance_detail.append(discover_vm_on_network(tenant['name']))
+ print instance_detail
+
+
+def router_discovery(tenant_data):
+ #pdb.set_trace()
+ for tenant in tenant_data:
+ #router_dict = {}
+ router=neutron.list_routers(tenant_id=tenant['id'])['routers']
+ for route in router:
+
+ router_dict={}
+ #for rout in router:
+
+ if route['tenant_id'] == tenant['id']:
+ print(' - Router %s Discovered' % route['name'])
+ status = True
+ router_id = route['id']
+ router_dict['tenant_name']=tenant["name"]
+ router_dict['router_status'] = status
+ router_dict['router_name']=route['name']
+ router_data.append(router_dict)
+
+ else:
+ print("Tenant %s not having any router"%(tenant['name']))
+ #if rout['tenant_id'] == tenant['id']:
+ #print(' - Router %s Discovered' % rout['name'])
+ #status = True
+ #router_id = rout['id']
+ #router_dict['tenant_name']=tenant["name"]
+ #router_dict['router_status'] = status
+ #router_dict['router_name']=rout['name']
+
+ else:
+ print(' - Router Not Found in %s tenant' % tenant['name'])
+ status = False
+ #router_id = rout['id']
+ #router_dict['router_status'] = status
+ #router_data.append(router_dict)
+
+
+ #router_id = router['id']
+ #router_dict['router_status'] = status
+ #router_data.append(router_dict)
+
+ print router_data
+
+def main():
+
+ tenant_discovery()
+
+
+
+
+
+
+
+if __name__ == '__main__':
+
+ main()
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/floating_ips.py b/NTT/ntt-30-3-16/ntt-30-3-16/floating_ips.py
new file mode 100755
index 0000000..e02a2d2
--- /dev/null
+++ b/NTT/ntt-30-3-16/ntt-30-3-16/floating_ips.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+"""
+Description: This script is to allocate & associate the floating IP.
+Developer: gopal@onecloudinc.com
+"""
+
+import os
+from neutronclient.v2_0 import client
+import novaclient.v1_1.client as nvclient
+from credentials import get_credentials, get_nova_credentials, \
+ get_tenant_nova_credentials
+from config import FLOATING_IP_POOL
+
+neutron_credentials = get_credentials()
+credentials = get_nova_credentials()
+neutron = client.Client(**neutron_credentials)
+nova = nvclient.Client(**credentials)
+if not nova.keypairs.findall(name="admin"):
+ with open(os.path.expanduser('~/.ssh/id_rsa.pub')) as fpubkey:
+ nova.keypairs.create(name="admin", public_key=fpubkey.read())
+
+
+def add_floating_ip_for_vm(tenant_name, instance):
+ """
+ This method is used to allocate & associate floating IP to the given VM\
+ based on the availability from the defined pool.
+ """
+ tenant_credentials = get_tenant_nova_credentials(tenant_name)
+ nova = nvclient.Client(**tenant_credentials)
+ floating_ip = nova.floating_ips.create(FLOATING_IP_POOL)
+ instance.add_floating_ip(floating_ip)
+ print " - Assigned Floating IP: " + str(floating_ip.ip)
+ return True
+
+
+def release_all_floating_ips():
+ """
+ This method is used to release all the disallocated floating IPs.
+ """
+ floating_ips = neutron.list_floatingips()['floatingips']
+ try:
+ for ip in floating_ips:
+ neutron.delete_floatingip(ip['id'])
+ except:
+ pass
+ return True
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/floating_ips.pyc b/NTT/ntt-30-3-16/ntt-30-3-16/floating_ips.pyc
new file mode 100755
index 0000000..9309696
Binary files /dev/null and b/NTT/ntt-30-3-16/ntt-30-3-16/floating_ips.pyc differ
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/networks.py b/NTT/ntt-30-3-16/ntt-30-3-16/networks.py
new file mode 100755
index 0000000..befd00e
--- /dev/null
+++ b/NTT/ntt-30-3-16/ntt-30-3-16/networks.py
@@ -0,0 +1,178 @@
+#!/usr/bin/env python
+"""
+Description: This script is to create network, subnets, router with \
+ external gateway mapping.
+Developer: gopal@onecloudinc.com
+"""
+import pdb
+import os
+from neutronclient.v2_0 import client
+from credentials import get_credentials
+from config import NETWORK_COUNT, VM_COUNT, FLOATING_IP_CREATION
+from vm_instances import launch_vm_on_network, terminate_vm_on_network
+from floating_ips import release_all_floating_ips
+from datetime import datetime, timedelta
+from pytz import timezone
+
+credentials = get_credentials()
+neutron = client.Client(**credentials)
+fmt = "%Y-%m-%d %H:%M:%S %Z%z"
+
+
+def create_network(tenant, router, network_index, network_cidr):
+ """
+ This method is used to create network, subnets, interfaces on router with \
+ external gateway mapping for the given network name and CIDR.
+ """
+
+ try:
+ prefix = tenant['tenant_name']
+ network_name = prefix + '-net-' + network_index
+ print "\n"
+ print "=" * 50
+ print " Initiated Network Creation for " + network_name
+ print "=" * 50
+ print "\n"
+
+ body_sample = {'network': {'name': network_name,
+ 'tenant_id': tenant['tenant_id']}}
+ start_time = datetime.now(timezone('US/Pacific'))
+ try:
+ net = neutron.create_network(body=body_sample)
+ net_dict = net['network']
+ network_id = net_dict['id']
+ network_vlan = net_dict['provider:segmentation_id']
+ print(' - Network %s created' % net_dict['name'])
+ net_status = True
+ except Exception:
+ net_dict = {}
+ net_status = False
+
+ subnet_name = prefix + "-subnet-" + network_index
+ try:
+ tenant_id = tenant['tenant_id']
+ body_create_subnet = {'subnets': [{'name': subnet_name,
+ 'cidr': network_cidr,
+ 'ip_version': 4,
+ 'network_id': network_id,
+ 'tenant_id': tenant_id}]}
+ subnet_detail = neutron.create_subnet(body=body_create_subnet)
+ subnet = subnet_detail['subnets'][0]
+ print(' - Created subnet %s' % subnet['name'])
+ net_status = True
+ except Exception:
+ subnet = {}
+ net_status = False
+
+ neutron.add_interface_router(router['id'], {'subnet_id': subnet['id'],
+ 'tenant_id': tenant['tenant_id']})
+ print (' - Created interface between %s' % subnet['name'])
+ finally:
+ print "\n"
+ msg = "<== Completed Network Creation with External Gateway "
+ msg += "Successfully ==>"
+ print msg
+ end_time = datetime.now(timezone('US/Pacific'))
+ print "\n"
+ print "-"*65
+ print (" Network %s Creation Time Summary :" % network_name)
+ print "-"*65
+ print "\n"
+ print(' - Test Started Time :\t %s' % (start_time.strftime(fmt)))
+ print(' - Test Ended Time :\t %s' % (end_time.strftime(fmt)))
+
+ print "\n"
+ print "=" * 50
+ print " Initiated VM Deployment " + network_name
+ print "=" * 50
+ print "\n"
+
+ ins_data = []
+ for i in range(1, VM_COUNT + 1):
+ vm_name = network_name + '-vm-' + str(i)
+ start_time = datetime.now(timezone('US/Pacific'))
+ ins_data.append(launch_vm_on_network(tenant['tenant_name'],
+ vm_name, network_id))
+ end_time = datetime.now(timezone('US/Pacific'))
+
+ print "\n"
+ msg = "<== Completed VM Launch on Network with Floating IP Allocation "
+ msg += "Successfully ==>"
+ print msg
+ print "\n"
+ print "-"*65
+ print (" Instance %s Creation Time Summary :" % vm_name)
+ print "-"*65
+ print "\n"
+ print(' - Test Started Time :\t %s' % (start_time.strftime(fmt)))
+ print(' - Test Ended Time :\t %s' % (end_time.strftime(fmt)))
+
+ result = {'network_data': {'tenant_name': tenant['tenant_name'],
+ 'network_name': network_name,
+ 'network_cidr': network_cidr,
+ 'subnet_name': subnet_name,
+ 'network_id': network_id,
+ 'network_vlan_id': network_vlan,
+ 'status': net_status},
+ 'instance_data': ins_data}
+ return result
+
+
+def delete_vm(tenant_data,network_data):
+ """
+ This method is used to delete vms, network, subnets, interfaces on router \
+ with external gateway mapping for the given network name and CIDR.
+ """
+ pdb.set_trace()
+ #prefix = tenant_name
+ network_list = []
+ router_list = []
+ count=1
+ #router_list.append(prefix + '-router')
+ #for i in range(1, NETWORK_COUNT + 1):
+ #network_list.append(prefix + '-net-' + str(i))
+ for tenant in tenant_data:
+ for network in network_data:
+ vm_name=tenant['name'] + '-vm-' + str(count)
+ if ((network['network_list']['tenant_name'] == tenant['name']) and (network['network_list']['shared'] == False)):
+
+
+ terminate_vm_on_network(tenant['name'], vm_name,network['network_list']['network_id'])
+ count += 1
+
+ release_all_floating_ips()
+def delete_networks(tenant_data,network_data):
+ pdb.set_trace()
+ networks=None
+ for tenant in tenant_data:
+ networks=neutron.list_networks(tenant_id=tenant['id'])['networks']
+ routers=neutron.list_routers(tenant_id=tenant['id'])['routers']
+ subnets=neutron.list_subnets(tenant_id=tenant['id'])['subnets']
+
+
+ for router in routers:
+ ports=neutron.list_ports(tenant_id=tenant['id'])['ports']
+ for port in ports:
+ #for subnet in subnets:
+ if (port['device_id'] == router['id'] and port['device_owner'] == 'network:router_interface'):
+ neutron.remove_interface_router(router['id'],{'subnet_id':port['fixed_ips'][0]['subnet_id']})
+ neutron.remove_gateway_router(router['id'])
+ neutron.delete_network(port['network_id'])
+ neutron.delete_router(router['id'])
+ #neutron.delete_network(network['id'])
+
+ #for network in networks:
+ #neutron.delete_network(network['id'])
+
+ #for subnet in subnets:
+ #for network in networks:
+
+
+
+
+
+ #if FLOATING_IP_CREATION:
+ #release_all_floating_ips()
+ #print "\n"
+ #print("<== Released all Floating IPs Successfully ==>")
+ #return True
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/networks.pyc b/NTT/ntt-30-3-16/ntt-30-3-16/networks.pyc
new file mode 100755
index 0000000..12bd62b
Binary files /dev/null and b/NTT/ntt-30-3-16/ntt-30-3-16/networks.pyc differ
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/openstack_clean_script.py b/NTT/ntt-30-3-16/ntt-30-3-16/openstack_clean_script.py
new file mode 100755
index 0000000..bb04cd1
--- /dev/null
+++ b/NTT/ntt-30-3-16/ntt-30-3-16/openstack_clean_script.py
@@ -0,0 +1,158 @@
+import logging
+import pprint
+from novaclient import client as novclient
+from neutronclient.v2_0 import client as nclient
+import time
+import pdb
+import MySQLdb
+from keystoneclient.v2_0 import client as kclient
+def main():
+ net_list=['NET-A','NET-B','NET-C']
+ ext_net_list=['EXT-NET-A','EXT-NET-B']
+ ext_subnet_list=[]
+ flavor_list={}
+
+ router_list=['Router-A','Router-B']
+ subnet_list={'subnets':[{'name':'Subnet-A','network_id':'','ip_version':4,'cidr':'1.1.1.0/24'},{'name':'Subnet-B','network_id':'','ip_version':4,'cidr':'2.2.2.0/24'}]}
+ count = 0
+ instance_detail={}
+ networks={}
+ logging.basicConfig(level=logging.INFO)
+ logger=logging.getLogger(__name__)
+ logger.info("Keystone authentication started....")
+ time.sleep(5)
+ logger.info("Wait for 5 seconds...")
+ logger.info("done")
+ neutr=nclient.Client(username='admin',password='admin',tenant_name='admin',auth_url='http://192.168.1.12:5000/v2.0/')
+ novactr=novclient.Client('2',username='admin',api_key='admin',project_id='admin',auth_url='http://192.168.1.12:5000/v2.0/')
+ logger.info("Authentication success...")
+ #logger.info("getting input from user....")
+ #network_count=int(raw_input("Enter the no of network to created >>\t"))
+ #ext_network_count=int(raw_input("Enter the no of External network to be created >> \t"))
+ #instance_detail['name']=raw_input("Please provide name for instance")
+ #flavor_id=int(raw_input("Provide the flavor for the instance"))
+ #netw=neutr.list_networks()
+ #print netw
+ #ss=db_connection(flavor_list,novactr)
+ #us=ss.get(flavor_id)
+ #if us:
+ #logger.info("You choose %s flavor"%(us))
+ #else:
+ #logger.info("The flavor u choose is doesn't exists..")
+ #exit
+ #create_network(neutr,network_count,logger,net_list,count,subnet_list,novactr,flavor_id)
+ delete_network(neutr,novactr,logger,net_list,subnet_list)
+
+def create_network(neutr,network_count,logger,net_list,count,subnet_list,novactr,flavor_id):
+ pdb.set_trace()
+ logger.info("Start creating external network ")
+ ext_network=neutr.create_network({'network':{'name':'EXT-NET','admin_state_up':'True','router:external':'True'}})
+ ext_id=ext_network['network']['id']
+ vm_list=['vm-1','vm-2']
+ logger.info("Creating external network subnet...")
+ ext_subnet=neutr.create_subnet({'subnet':{'name':'EXT_subnet','network_id':ext_id,'ip_version':4,'cidr':'6.6.8.8/24'}})
+ time.sleep(2)
+ logger.info("creating router")
+ router1=neutr.create_router({'router':{'name':'Router-1','admin_state_up':'True'}})
+ router_id=router1['router']['id']
+ neutr.add_gateway_router(router_id,{'network_id':ext_id})
+
+ while count < network_count:
+
+ neut=neutr.create_network({'network':{'name':net_list[count],'admin_state_up':'True'}})
+ if neut:
+ net_id=neut['network']['id']
+ logger.info("Network %s sucessfully created.."%(net_list[count]))
+ time.sleep(4)
+ logger.info("Start creating subnets")
+ #nsub=neutr.create_subnet({'subnet':subnet_list['subnets'][count]})
+ nsub=neutr.create_subnet({'subnet':{'name':subnet_list['subnets'][count]['name'],'network_id':net_id,'ip_version':subnet_list['subnets'][count]['ip_version'],'cidr':subnet_list['subnets'][count]['cidr']}})
+ sub_id=nsub['subnet']['id']
+ if nsub:
+ logger.info("subnet is created for network %s"%(net_list[count]))
+ time.sleep(4)
+ logger.info("Adding interface to router")
+ neutr.add_interface_router(router_id,{'subnet_id':sub_id})
+ time.sleep(5)
+ logger.info("Ready to launch the instances")
+ pdb.set_trace()
+ image = novactr.images.find(name="cirros")
+ print net_id
+ instance = novactr.servers.create(name=vm_list[count], image=image, flavor=flavor_id, nics=[{'net-id':net_id}])
+ logger.info("Instance launched successfully on network %s"%(net_list[count]))
+ time.sleep(4)
+ count = count+1
+ else:
+ logger.info("Error in network creation")
+ time.sleep(3)
+ logger.info("setup is ready for testing..")
+
+def db_connection(flavor_list,novactr):
+ db=MySQLdb.connect(host="localhost",user="root",passwd="dafc1bce95654501",db="nova")
+ cur=db.cursor()
+ cur.execute("select id,name from instance_types")
+ ss=novactr.networks.list()
+ print ss
+ return dict(cur.fetchall())
+
+def delete_network(neutr,novactr,logger,net_list,subnet_list):
+ logger.info("Start cleaning the dashboard")
+ del_net={}
+ server_delete(novactr,logger)
+ delete_interface(neutr,logger)
+ count=0
+
+def server_delete(novactr,logger):
+ #pdb.set_trace()
+ logger.info("Fetching list of servers")
+ myserver=novactr.servers.list()
+ server_len=len(myserver)
+ for i in range(server_len):
+ ss=novactr.servers.delete(myserver[i])
+ if ss:
+ logger.info("Instances %s sucessfully deleted"%myserver[i])
+ time.sleep(1)
+def delete_interface(neutr,logger):
+
+ mynetwork=neutr.list_networks()
+ net_len=len(mynetwork['networks'])
+ myrouter=neutr.list_routers()
+ r_id=myrouter['routers'][0]['id']
+ port_delete(neutr,logger,r_id)
+ my_ports=neutr.list_ports()['ports']
+ port_gateway=[]
+ s=neutr.remove_gateway_router(r_id)
+ if s:
+ logger.info("gateway router is detached successful...")
+ myrouter=neutr.list_routers()['routers']
+ for r in range(len(myrouter)):
+
+ neutr.delete_router(myrouter[r]['id'])
+ logger.info("Deleting networks...")
+ time.sleep(2)
+ for j in range(net_len):
+ dd=neutr.delete_network(mynetwork['networks'][j]['id'])
+
+def port_delete(neutr,logger,r_id):
+ logger.info("listing port details..")
+ myports=neutr.list_ports()['ports']
+ port_list=[]
+ port_gateway=[]
+ for port in myports:
+
+ if (port['device_id'] == r_id and
+ port['device_owner'] == 'network:router_interface'):
+ port_list.append(port)
+ logger.info("Removing router interfaces..")
+
+ for i in range(len(port_list)):
+
+ del_inf=neutr.remove_interface_router(r_id,{'subnet_id':port_list[i]['fixed_ips'][0]['subnet_id']})
+
+#def get_id(novactr,logger):
+ #welcome=novactr.servers.list(413fb5d3-c1bc-4267-80ab-6a27d0cfd04b)
+ #print welcome
+
+
+if __name__ == '__main__':
+ main()
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/t1.py b/NTT/ntt-30-3-16/ntt-30-3-16/t1.py
new file mode 100755
index 0000000..a93a8ab
--- /dev/null
+++ b/NTT/ntt-30-3-16/ntt-30-3-16/t1.py
@@ -0,0 +1,17 @@
+from keystoneclient.v2_0 import client
+
+
+OS_USERNAME = 'admin'
+OS_TENANT_NAME = 'admin'
+OS_PASSWORD = 'admin'
+OS_AUTH_URL = 'http://172.168.2.40:5000/v2.0/'
+
+keystone = client.Client(username=OS_USERNAME, password=OS_PASSWORD, auth_url=OS_AUTH_URL)
+import pdb
+pdb.set_trace()
+
+tenants = keystone.tenants.list()
+for tenant in tenants:
+ print tenant.__dict__
+
+
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/t2.py b/NTT/ntt-30-3-16/ntt-30-3-16/t2.py
new file mode 100755
index 0000000..adb670c
--- /dev/null
+++ b/NTT/ntt-30-3-16/ntt-30-3-16/t2.py
@@ -0,0 +1,31 @@
+from neutronclient.v2_0 import client as neutron_client
+
+
+
+OS_USERNAME = 'admin'
+OS_TENANT_NAME = 'admin'
+OS_PASSWORD = 'admin'
+OS_AUTH_URL = 'http://172.168.2.40:5000/v2.0/'
+OS_TENANT_ID = '2931fbe17e8445da875bb915a29d0bbf'
+
+def get_credentials():
+ d = {}
+ d['username'] = OS_USERNAME
+ d['password'] = OS_PASSWORD
+ d['auth_url'] = OS_AUTH_URL
+ d['tenant_id'] = OS_TENANT_ID
+ return d
+
+tenants = [
+ {'id': u'2931fbe17e8445da875bb915a29d0bbf', 'name': u'admin'},
+ {'id': u'2e93f5f662974b1284e8be13dd472e48', 'name': u'demo'},
+ {'id': u'ae9e7941b6764accae72a99662c189a5', 'name': u'tenant-test-101'},
+ {'id': u'be0e4b8dc7754668b0e3d57e4f7f6f66', 'name': u'tenant-test-102'},
+ {'id': u'fbb4907f073d4b5881a85c1692ae027a', 'name': u'services'}
+]
+
+
+credentials = get_credentials()
+neutron = neutron_client.Client(**credentials)
+netw = neutron.list_networks()
+print netw
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/tenant.txt b/NTT/ntt-30-3-16/ntt-30-3-16/tenant.txt
new file mode 100755
index 0000000..2ecda20
--- /dev/null
+++ b/NTT/ntt-30-3-16/ntt-30-3-16/tenant.txt
@@ -0,0 +1,7 @@
+tenants = [
+ {'id': u'2931fbe17e8445da875bb915a29d0bbf', 'name': u'admin'},
+ {'id': u'2e93f5f662974b1284e8be13dd472e48', 'name': u'demo'},
+ {'id': u'ae9e7941b6764accae72a99662c189a5', 'name': u'tenant-test-101'},
+ {'id': u'be0e4b8dc7754668b0e3d57e4f7f6f66', 'name': u'tenant-test-102'},
+ {'id': u'fbb4907f073d4b5881a85c1692ae027a', 'name': u'services'}
+]
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/tenants.py b/NTT/ntt-30-3-16/ntt-30-3-16/tenants.py
new file mode 100755
index 0000000..ed40861
--- /dev/null
+++ b/NTT/ntt-30-3-16/ntt-30-3-16/tenants.py
@@ -0,0 +1,145 @@
+#!/usr/bin/env python
+"""
+Description: This script prepares new tenant with the following properties:
+1. Creates new tenant.
+2. Creates new user and this user is added _member_ to tenant. \
+Password is second argument of script
+3. Admin user will be added to tenant with role admin
+Developer: gopal@onecloudinc.com
+"""
+
+import os
+import pdb
+from keystoneclient.v2_0 import client as ksclient
+from credentials import get_credentials
+from config import USER_COUNT, USER_PASSWORD
+
+credentials = get_credentials()
+keystone = ksclient.Client(**credentials)
+assign_admin = True
+
+
+def create_tenant(tenant_name):
+ """
+ This method is used to create tenant and create number of users per tenant
+ """
+
+ print "\n"
+ print "=" * 50
+ print " Initiated Tenant Creation for " + tenant_name
+ print "=" * 50
+ print "\n"
+
+ try:
+ try:
+ new_tenant = keystone.tenants.create(tenant_name=tenant_name,
+ description="Scale tenant \
+ created",
+ enabled=True)
+ print(' - Tenant %s created' % tenant_name)
+ except Exception:
+ new_tenant = keystone.tenants.find(name=tenant_name)
+ tenant_id = new_tenant.id
+ tenant_status = True
+ user_data = []
+ for j in range(USER_COUNT):
+ j += 1
+ user_name = tenant_name + '-user-' + str(j)
+ user_data.append(create_user(user_name, tenant_id))
+ except Exception:
+ tenant_status = False
+
+ print "\n"
+ msg = ('<== Completed Tenant Creation and Users per Tenant '
+ 'with _member_ role ')
+ msg += 'Successfully ==>'
+ print msg
+ print "\n"
+
+ tenant_data = {'tenant_name': tenant_name,
+ 'tenant_id': tenant_id,
+ 'status': tenant_status}
+ return tenant_data
+
+
+def discover_tenant():
+ """
+ This method is used to discover tenant and discover number of users per tenant
+ """
+ global tenant_id,tenant_status
+ try:
+ pdb.set_trace()
+ new_tenant = keystone.tenants.list()
+ tenant_id = new_tenant.id
+ tenant_status = True
+ print "\n"
+ print(' - Tenant %s Discovered' % tenant_name)
+ print(' - Tenant_ID %s Discovered' % tenant_id)
+ except Exception:
+ pass
+
+ tenant_data = {'tenant_name': tenant_name,
+ 'tenant_id': tenant_id,
+ 'status': tenant_status}
+ return tenant_data
+
+
+def create_user(user_name, tenant_id):
+ """
+ This method is to create users per Tenant
+ """
+
+ try:
+ new_user = keystone.users.create(name=user_name,
+ password=USER_PASSWORD,
+ tenant_id=tenant_id)
+ print(' - Created User %s' % user_name)
+ except Exception:
+ new_user = keystone.users.find(name=user_name)
+ member_role = keystone.roles.find(name='_member_')
+ try:
+ keystone.roles.add_user_role(new_user, member_role, tenant_id)
+ except Exception:
+ pass
+ if assign_admin:
+ admin_user = keystone.users.find(name='admin')
+ admin_role = keystone.roles.find(name='admin')
+ try:
+ keystone.roles.add_user_role(admin_user, admin_role, tenant_id)
+ except Exception:
+ pass
+ user_data = {'name': new_user.name,
+ 'id': new_user.id}
+ return user_data
+
+
+def delete_tenant(tenant_name):
+ """
+ This method is used to delete tenant and users
+ """
+
+ try:
+ tenant = keystone.tenants.find(name=tenant_name)
+ for j in range(USER_COUNT):
+ j += 1
+ user_name = tenant_name + '-user-' + str(j)
+ delete_user(user_name, tenant.id)
+ tenant.delete()
+ print(' - Deleted Tenant %s ' % tenant_name)
+ except Exception:
+ pass
+ return True
+
+
+def delete_user(user_name, tenant_id):
+ """
+ This method is to delete users per Tenant
+ """
+ try:
+ user = keystone.users.find(name=user_name)
+ user.delete()
+ except Exception:
+ print(" - User Not Found: %s" % user_name)
+ pass
+ print(' - Deleted User %s' % user_name)
+ return True
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/tenants.pyc b/NTT/ntt-30-3-16/ntt-30-3-16/tenants.pyc
new file mode 100755
index 0000000..a84e29f
Binary files /dev/null and b/NTT/ntt-30-3-16/ntt-30-3-16/tenants.pyc differ
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/user.txt b/NTT/ntt-30-3-16/ntt-30-3-16/user.txt
new file mode 100755
index 0000000..9e5d3d9
--- /dev/null
+++ b/NTT/ntt-30-3-16/ntt-30-3-16/user.txt
@@ -0,0 +1,7 @@
+#cloud-config
+chpasswd:
+ list: |
+ root:ubuntu
+ ubuntu:ubuntu
+ expire: False
+ssh_pwauth: True
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/vm_instances.py b/NTT/ntt-30-3-16/ntt-30-3-16/vm_instances.py
new file mode 100755
index 0000000..792d9ca
--- /dev/null
+++ b/NTT/ntt-30-3-16/ntt-30-3-16/vm_instances.py
@@ -0,0 +1,179 @@
+#!/usr/bin/env python
+"""
+Description: This script is to launching VMs on the network.
+Developer: gopal@onecloudinc.com
+"""
+
+import os
+import time
+import pdb
+import novaclient.v1_1.client as nvclient
+from novaclient.base import *
+from novaclient.exceptions import NotFound
+from config import FLOATING_IP_CREATION, IMAGE_NAME, FLAVOUR_NAME,OS_USERNAME, OS_TENANT_NAME, OS_PASSWORD, OS_AUTH_URL
+from credentials import get_nova_credentials, get_tenant_nova_credentials,get_credentials
+from floating_ips import add_floating_ip_for_vm
+import glanceclient.v2.client as glance_client
+import keystoneclient.v2_0.client as ksclient
+keystone = ksclient.Client(auth_url="http://172.168.2.40:35357/v2.0",
+ username="admin",
+ password="admin",
+ tenant_name="admin")
+token = keystone.auth_ref['token']['id']
+
+credentials = get_nova_credentials()
+nova = nvclient.Client(**credentials)
+#glance=glance_client.Client(username=OS_USERNAME,password=OS_PASSWORD,tenant_name=OS_TENANT_NAME,auth_url=OS_AUTH_URL)
+glance=glance_client.Client(endpoint="http://172.168.2.40:9292", token=token)
+
+
+if not nova.keypairs.findall(name="admin"):
+ with open(os.path.expanduser('~/.ssh/id_rsa.pub')) as fpubkey:
+ nova.keypairs.create(name="admin", public_key=fpubkey.read())
+
+def upload_image_glance():
+ #pdb.set_trace()
+ image_list=glance.images.list()
+ image_file="/home/onecloud/NTT/keerthi/ubuntu.img"
+ image=glance.images.create(disk_format="qcow2",container_format="bare",name="ubuntu")
+ print("image status %s"%(image.status))
+ ss=glance.images.upload(image.id,open('/home/onecloud/NTT/keerthi/ubuntu.img','rb'))
+ print("Current Image status <%s>"%(image.status))
+
+ #with open(image_file) as img:
+ #image=glance.images.create(name="ubuntu",disk_format="raw",container_format="bare",data=img)
+
+ #print("Current Image status %s"%(image.status))
+
+
+def launch_vm_on_network(tenant_name, vm_name, network_id):
+ """
+ This method is to launch VM on the given network & VM Name.
+ """
+ #pdb.set_trace()
+ instance=None
+ tenant_credentials = get_tenant_nova_credentials(tenant_name)
+
+ nova = nvclient.Client(**tenant_credentials)
+ nova.quotas.update(tenant_name, instances=-1, cores=-1, ram=-1, fixed_ips=-1, floating_ips=-1)
+ with open('user.txt') as userdata:
+ user_data = userdata.read()
+ try:
+ image_list=nova.images.find(name="ubuntu")
+ except NotFound:
+ upload_image_glance()
+
+ #for img in image:
+ #if img.name == 'ubuntu':
+ #print "image found"
+ try:
+
+ flavor = nova.flavors.find(name='traffic')
+ except:
+ flavor = nova.flavors.create(name="traffic",ram="2048",vcpus="1",disk="10")
+
+
+ try:
+
+ instance = nova.servers.create(name=vm_name, image=image_list,
+ flavor=flavor,
+ key_name="admin",
+ availability_zone="compute:openstack-aio",
+ nics=[{'net-id': network_id}],userdata=user_data)
+ except Exception:
+ pass
+
+ # Poll at 15 second intervals, until the status is no longer 'BUILD'
+ print " * Instance <%s> created on network <%s>: "%(vm_name,str(network_id))
+ status = instance.status
+ while status == 'BUILD':
+ time.sleep(15)
+ # Retrieve the instance again so the status field updates
+ instance = nova.servers.get(instance.id)
+ status = instance.status
+
+ print " - Current status: %s" % status
+ if FLOATING_IP_CREATION:
+ add_floating_ip_for_vm(tenant_name, instance)
+
+ ins_data = {'instance_name': vm_name, 'status': status}
+ return ins_data
+
+#def endpoint_discovery(tenant_data,network_data):
+
+# tenant_credentials = get_tenant_nova_credentials(tenant_name)
+# nova = nvclient.Client(**tenant_credentials)
+# instance_list = nova.servers.list()
+
+
+def vm_endpoint_discovery(tenant_name):
+ pdb.set_trace()
+
+ name=None
+ status=None
+ try:
+ tenant_credentials = get_tenant_nova_credentials(tenant_name)
+ nova = nvclient.Client(**tenant_credentials)
+ instance_list=nova.servers.list()
+ #instance = nova.servers.find(name=vm_name)
+ if instance_list > 0:
+
+ for inst in instance_list:
+
+ instance_id = inst.id
+ name=inst.name
+ networks=inst.networks
+
+
+
+ except Exception:
+ print(' - Instance Not Found')
+
+
+def discover_vm_on_network(tenant_name):
+ """
+ This method is used to discover instances per tenant
+ """
+ name=None
+ status=None
+ try:
+ tenant_credentials = get_tenant_nova_credentials(tenant_name)
+ nova = nvclient.Client(**tenant_credentials)
+ instance_list=nova.servers.list()
+ #instance = nova.servers.find(name=vm_name)
+ if instance_list > 0:
+
+ for inst in instance_list:
+
+ instance_id = inst.id
+ name=inst.name
+ inst_find=nova.servers.find(id=instance_id)
+ print(' - Instance %s Discovered' % inst.name)
+ print(' - Instance ID %s Discovered' % instance_id)
+ print(' - Instance %s Status' % inst.status)
+ status=inst.status
+ except Exception:
+ print(' - Instance Not Found')
+ status = False
+
+ ins_data = {'instance_name': name,
+ 'status': status }
+ return ins_data
+
+
+def terminate_vm_on_network(tenant_name, vm_name, network_id):
+ """
+ This method is to terminate VM on the given network & VM Name.
+ """
+ pdb.set_trace()
+ tenant_credentials = get_tenant_nova_credentials(tenant_name)
+ nova = nvclient.Client(**tenant_credentials)
+ nova.quotas.delete(tenant_name)
+ try:
+ instance = nova.servers.find(name=vm_name)
+ nova.servers.delete(instance.id)
+ print " * Instance terminated on network: " + str(network_id)
+ except Exception:
+ print " * Instance Not Found on network: " + str(network_id)
+ pass
+ return True
diff --git a/NTT/ntt-30-3-16/ntt-30-3-16/vm_instances.pyc b/NTT/ntt-30-3-16/ntt-30-3-16/vm_instances.pyc
new file mode 100644
index 0000000..6d6b422
Binary files /dev/null and b/NTT/ntt-30-3-16/ntt-30-3-16/vm_instances.pyc differ
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/.idea/misc.xml b/NTT/ntt-31-3-16/ntt-31-3-16/.idea/misc.xml
new file mode 100644
index 0000000..7c4b884
--- /dev/null
+++ b/NTT/ntt-31-3-16/ntt-31-3-16/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/.idea/modules.xml b/NTT/ntt-31-3-16/ntt-31-3-16/.idea/modules.xml
new file mode 100644
index 0000000..64e6bd4
--- /dev/null
+++ b/NTT/ntt-31-3-16/ntt-31-3-16/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/.idea/ntt-29-2-16-test.iml b/NTT/ntt-31-3-16/ntt-31-3-16/.idea/ntt-29-2-16-test.iml
new file mode 100644
index 0000000..6f63a63
--- /dev/null
+++ b/NTT/ntt-31-3-16/ntt-31-3-16/.idea/ntt-29-2-16-test.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/.idea/workspace.xml b/NTT/ntt-31-3-16/ntt-31-3-16/.idea/workspace.xml
new file mode 100644
index 0000000..5570e2d
--- /dev/null
+++ b/NTT/ntt-31-3-16/ntt-31-3-16/.idea/workspace.xml
@@ -0,0 +1,426 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1459230370172
+
+
+ 1459230370172
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/config.py b/NTT/ntt-31-3-16/ntt-31-3-16/config.py
new file mode 100755
index 0000000..59f058e
--- /dev/null
+++ b/NTT/ntt-31-3-16/ntt-31-3-16/config.py
@@ -0,0 +1,75 @@
+"""
+Description: Define the Scale Test Configuration with the below global \
+ parameters.
+Developer: gopal@onecloudinc.com
+"""
+
+# Tenant Settings
+
+OS_USERNAME = 'admin'
+OS_TENANT_NAME = 'admin'
+OS_PASSWORD = 'admin'
+OS_AUTH_URL = 'http://172.168.2.40:5000/v2.0/'
+
+# TENANT_CREATION = True
+
+TENANT_COUNT = 2
+TENANT_NAME_PREFIX = 'tenant-test'
+TENANT_BASE_INDEX = 101
+USER_COUNT = 1
+USER_PASSWORD = 'secret'
+NETWORK_COUNT = 2
+VM_COUNT = 1
+IMAGE_NAME = 'Cirros'
+FLAVOUR_NAME = 'm1.tiny'
+EXTERNAL_NETWORK = 'public'
+
+# Floating IP Settings
+
+FLOATING_IP_CREATION = True
+FLOATING_IP_POOL = 'public'
+
+TENANT_CREATION = False
+TENANT_NAME = ['tenant-test-101', 'tenant-test-102', 'tenant-test-103', 'tenant-test-104','tenant-test-105']
+
+
+# Cisco ASR Settings
+
+ENABLE_ASR_VERIFICATION = False
+DEPLOYMENT_ID = 'ans136'
+ASR_HOST = '10.10.10.10'
+ASR_USER = 'admin'
+ASR_PASSWORD = 'admin'
+
+
+"""
+Test Configuration Ends Here with the global parameters.
+"""
+
+
+def print_scale_test_config():
+ """
+ This method is used to print the current test configuration on scale test \
+ deployment initialization.
+ """
+ print '=' * 70
+ print " Configuration for this Scale Test"
+ print '=' * 70
+
+ print " Tenant will be created with prefix : " \
+ + TENANT_NAME_PREFIX
+ print " No of Tenants will be created : " \
+ + str(TENANT_COUNT)
+ print " Tenant base index range starts from : " \
+ + str(TENANT_BASE_INDEX)
+ print " No of Users per Tenant : " \
+ + str(USER_COUNT)
+ print " No of Networks : " \
+ + str(NETWORK_COUNT)
+ print " No of VMs per Network : " \
+ + str(VM_COUNT)
+ print " Name of the External Network with be connected with Router : " \
+ + EXTERNAL_NETWORK
+ print " Name of the Floating IP Pool will be used for Allocation : " \
+ + FLOATING_IP_POOL
+ print '=' * 70
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/config.pyc b/NTT/ntt-31-3-16/ntt-31-3-16/config.pyc
new file mode 100755
index 0000000..d30452b
Binary files /dev/null and b/NTT/ntt-31-3-16/ntt-31-3-16/config.pyc differ
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/credentials.py b/NTT/ntt-31-3-16/ntt-31-3-16/credentials.py
new file mode 100755
index 0000000..a9b640c
--- /dev/null
+++ b/NTT/ntt-31-3-16/ntt-31-3-16/credentials.py
@@ -0,0 +1,46 @@
+"""
+Description: This script is to map the environment variables to credentials \
+ dict based on the client service API
+Developer: gopal@onecloudinc.com
+"""
+
+from config import OS_USERNAME, OS_TENANT_NAME, OS_PASSWORD, OS_AUTH_URL
+
+
+def get_credentials():
+ """
+ This method is used for authorization with keystone clients
+ """
+
+ data = {}
+ data['username'] = OS_USERNAME
+ data['password'] = OS_PASSWORD
+ data['auth_url'] = OS_AUTH_URL
+ data['tenant_name'] = OS_TENANT_NAME
+ return data
+
+
+def get_nova_credentials():
+ """
+ This method is used for authorization with nova clients
+ """
+
+ data = {}
+ data['username'] = OS_USERNAME
+ data['api_key'] = OS_PASSWORD
+ data['auth_url'] = OS_AUTH_URL
+ data['project_id'] = OS_TENANT_NAME
+ return data
+
+
+def get_tenant_nova_credentials(tenant_name):
+ """
+ This method is used for tenant authorization with nova clients
+ """
+
+ data = {}
+ data['username'] = OS_USERNAME
+ data['api_key'] = OS_PASSWORD
+ data['auth_url'] = OS_AUTH_URL
+ data['project_id'] = tenant_name
+ return data
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/credentials.pyc b/NTT/ntt-31-3-16/ntt-31-3-16/credentials.pyc
new file mode 100755
index 0000000..9658494
Binary files /dev/null and b/NTT/ntt-31-3-16/ntt-31-3-16/credentials.pyc differ
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/destroy_deploy.py b/NTT/ntt-31-3-16/ntt-31-3-16/destroy_deploy.py
new file mode 100755
index 0000000..3727a54
--- /dev/null
+++ b/NTT/ntt-31-3-16/ntt-31-3-16/destroy_deploy.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+
+"""
+Description: This script is to destory the L3/HA scale test deployment
+Developer: gopal@onecloudinc.com
+"""
+
+import os
+from neutronclient.v2_0 import client
+from keystoneclient.v2_0 import client as ksclient
+from credentials import get_credentials
+from config import TENANT_BASE_INDEX, TENANT_COUNT, TENANT_NAME_PREFIX, \
+ print_scale_test_config
+from networks import delete_network
+from tenants import delete_tenant
+from datetime import datetime, timedelta
+from pytz import timezone
+
+credentials = get_credentials()
+neutron = client.Client(**credentials)
+keystone = ksclient.Client(**credentials)
+fmt = "%Y-%m-%d %H:%M:%S %Z%z"
+
+
+def main():
+ """
+ This method will destory the scale test deployment based on the global \
+ config parameters mentioned on config.py file and creates the router with \
+ external gateway connectivity to public network.
+ """
+
+ print "\n"
+ print_scale_test_config()
+ print "\n"
+ print "Destroying Scale Test Deployment"
+ index = TENANT_BASE_INDEX
+ for i in range(1, TENANT_COUNT + 1):
+ tenant_name = TENANT_NAME_PREFIX + '-' + str(index)
+ index += 1
+ start_time = datetime.now(timezone('US/Pacific'))
+ try:
+ tenant = keystone.tenants.find(name=tenant_name)
+ delete_network(tenant_name)
+ delete_tenant(tenant_name)
+ except Exception:
+ print "\n"
+ print(" - Tenant Not Found: %s" % tenant_name)
+ pass
+ end_time = datetime.now(timezone('US/Pacific'))
+ print "\n"
+ print "-"*65
+ print (" Tenant & User Deletion Time Summary :")
+ print "-"*65
+ print "\n"
+ print(' - Test Started Time :\t %s' % (start_time.strftime(fmt)))
+ print(' - Test Ended Time :\t %s' % (end_time.strftime(fmt)))
+
+ print "=" * 50
+ print "\n"
+ print "Cleaned Scale Test Deployment"
+ print "\n"
+
+
+if __name__ == '__main__':
+ main_start_time = datetime.now(timezone('US/Pacific'))
+ main()
+ main_end_time = datetime.now(timezone('US/Pacific'))
+ total_time = (main_end_time - main_start_time)
+ print "-"*65
+ print (" Scale Test Deployment Consolidated Time Summary :")
+ print "-"*65
+ print "\n"
+ print(' - Test Started Time :\t %s' % (main_start_time.strftime(fmt)))
+ print(' - Test Ended Time :\t %s' % (main_end_time.strftime(fmt)))
+ print(' - Elapsed Time for Cleaned Scale Test Deployment: %d days, %d hours, %d minutes, %d seconds' % (total_time.days, (total_time.seconds/3600), (total_time.seconds % 3600 / 60), (total_time.seconds % 60)))
+ print "\n"
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/discover_deploy.py b/NTT/ntt-31-3-16/ntt-31-3-16/discover_deploy.py
new file mode 100755
index 0000000..e2dcaa0
--- /dev/null
+++ b/NTT/ntt-31-3-16/ntt-31-3-16/discover_deploy.py
@@ -0,0 +1,281 @@
+#!/usr/bin/env python
+
+"""
+Description: This script is to initialize the L3/HA scale test deployment
+Developer: gopal@onecloudinc.com
+"""
+import pdb
+import os
+from neutronclient.v2_0 import client
+from credentials import get_credentials
+from config import TENANT_BASE_INDEX, NETWORK_COUNT, \
+ EXTERNAL_NETWORK, print_scale_test_config, DEPLOYMENT_ID, \
+ ASR_HOST, ASR_USER, ASR_PASSWORD, ENABLE_ASR_VERIFICATION, TENANT_COUNT, \
+ TENANT_NAME_PREFIX, TENANT_NAME, TENANT_CREATION, VM_COUNT
+from tenants import create_tenant, discover_tenant
+from networks import create_network
+from vm_instances import discover_vm_on_network
+from prettytable import PrettyTable
+
+credentials = get_credentials()
+neutron = client.Client(**credentials)
+
+
+def print_tenant_info(tenant_data):
+
+ x = PrettyTable(['Tenant Name', 'Status'])
+ x.align["Tenant Name"] = "l" # Left align source tenant values
+ x.padding_width = 1
+ for entry in tenant_data:
+ x.add_row([entry['tenant_name'], entry['status']])
+ return x
+
+def print_discovered_tenant(tenant_data,router_data,test_data):
+ pdb.set_trace()
+ y=PrettyTable(['Tenant Name','Router Name','Network Name','Network CIDR'])
+ y.padding_width=1
+ for x in tenant_data:
+ for z in router_data:
+ for a in test_data:
+
+ y.add_row([x['tenant_name'],z['router_name'],a['network_data']['network_name'],a['network_data']['network_cidr']])
+ return y
+
+def print_consolidated_count(test_count):
+ pdb.set_trace()
+ y=PrettyTable(['Tenant Count','Router Count','Network Count','VM Count'])
+ y.padding_width=1
+ for i in test_count:
+ y.add_row([i['tenant_count'],i['router_count'],i['network_count']])
+ return y
+def print_router_info(router_data):
+ x = PrettyTable(['Tenant Name', 'Router Name', 'Status'])
+ x.align["Tenant Name"] = "l" # Left align source tenant values
+ x.padding_width = 1
+ for entry in router_data:
+ x.add_row([entry['tenant_name'], entry['router_name'],
+ entry['router_status']])
+ return x
+
+
+def print_network_info(test_data):
+ y = PrettyTable(['Tenant Name', 'Network Name', 'Network CIDR',
+ 'Vlan ID', 'Subnet Name', 'Status'])
+ y.align["Tenant_Name"] = "l" # Left align source tenant values
+ y.padding_width = 1
+ for entry in test_data:
+ y.add_row([entry['network_data']['tenant_name'],
+ entry['network_data']['network_name'],
+ entry['network_data']['network_cidr'],
+ entry['network_data']['network_vlan_id'],
+ entry['network_data']['subnet_name'],
+ entry['network_data']['status']])
+ return y
+
+
+def print_instance_info(test_data):
+
+ z = PrettyTable(['Tenant Name', 'Instance Name', 'Status'])
+ z.align["Tenant Name"] = "l" # Left align source tenant values
+ z.padding_width = 1
+ for data in test_data:
+ for ins in data['instance_data']:
+ z.add_row([data['network_data']['tenant_name'],
+ ins['instance_name'],
+ ins['status']])
+ return z
+
+
+
+
+
+
+def main():
+ """
+ This method will initialize the scale test deployment based on the global \
+ config parameters mentioned on config.py file and creates the router with \
+ external gateway connectivity to public network.
+ """
+
+ tenant_data = []
+ router_data = []
+ test_data = []
+ test_count={}
+ if TENANT_CREATION == True:
+ print "\n"
+ print_scale_test_config()
+ print "\n"
+ pdb.set_trace()
+ print "Starting Scale Test Deployment"
+ index = TENANT_BASE_INDEX
+ for i in range(1, TENANT_COUNT + 1):
+ tenant_name = TENANT_NAME_PREFIX + '-' + str(index)
+ index += 1
+ try:
+ tenant_data.append(create_tenant(tenant_name))
+ except Exception as exc:
+ print "Exception occured on Tenant Creation: %s" % (exc.message)
+ pass
+ test_count["tenant_count"]=len(tenant_data)
+ for tenant in tenant_data:
+
+ #test= {'count': {'tenant_count': len(tenant_data)}}
+ #test_count.append(test)
+ router_dict = {}
+ prefix = tenant['tenant_name']
+ router_name = prefix + '-router'
+ router_dict['tenant_name'] = tenant['tenant_name']
+ router_dict['router_name'] = router_name
+ router_dict['network_vlan'] = {}
+ router_dict['router_detail'] = {}
+ router_dict['ipnatpool_data'] = {}
+ router_dict['iproute_data'] = {}
+ router_dict['interface_data'] = []
+ router_dict['nat_data'] = []
+
+ router = neutron.list_routers(name=EXTERNAL_NETWORK)['routers']
+ if not router:
+ router_info = neutron.create_router({'router': {
+ 'name': router_name, 'tenant_id': tenant['tenant_id']}})
+ router = router_info['router']
+ status = True
+ elif router[0]['tenant_id'] == tenant['tenant_id']:
+ router = router[0]
+ status = True
+ else:
+ router = {}
+ status = False
+
+ router_dict['router_status'] = status
+ networks = neutron.list_networks(name=EXTERNAL_NETWORK)
+ network_id = networks['networks'][0]['id']
+ neutron.add_gateway_router(router['id'],
+ {'network_id': network_id,
+ 'tenant_id': tenant['tenant_id']})
+ router_id = router['id']
+ print(' - Created Router %s' % router['name'])
+
+ for i in range(1, NETWORK_COUNT + 1):
+ network_index = str(i)
+ network_cidr = str(i) + "." + str(i) + "." + str(i) + ".0/24"
+ test_data.append(create_network(tenant, router,
+ network_index, network_cidr))
+ network_vlan = {}
+ for entry in test_data:
+ network_vlan[str(entry['network_data']['network_vlan_id'])] = \
+ entry['network_data']['network_name']
+ router_dict['network_vlan'] = network_vlan
+
+ else:
+ print "\n"
+ print "=" * 50
+ print "Discovering Tenant Topology on Scale Test Deployment"
+ print "=" * 50
+ try:
+ pdb.set_trace()
+ for i in range(len(TENANT_NAME)):
+ tenant_name = TENANT_NAME[i]
+ tenant_data.append(discover_tenant(tenant_name))
+ #test= {'count': {'tenant_count': len(tenant_data)}}
+ #test_count.append(test)
+
+ for tenant in tenant_data:
+ router_dict = {}
+ prefix = tenant['tenant_name']
+ router_name = prefix + '-router'
+ router_dict['tenant_name'] = tenant['tenant_name']
+ router_dict['tenant_id'] = tenant['tenant_id']
+ router_dict['router_name'] = router_name
+ router_dict['network_vlan'] = {}
+ router_dict['router_detail'] = {}
+ router_dict['ipnatpool_data'] = {}
+ router_dict['iproute_data'] = {}
+ router_dict['interface_data'] = []
+ router_dict['nat_data'] = []
+ pdb.set_trace()
+ router = neutron.list_routers(name=router_name)['routers'][0]
+ if router['tenant_id'] == tenant['tenant_id']:
+ print(' - Router %s Discovered' % router_name)
+ status = True
+ else:
+ print(' - Router %s Not Found' % router_name)
+ status = False
+ router_id = router['id']
+ router_dict['router_status'] = status
+ router_data.append(router_dict)
+ #test1= {'count': {'router_count': len(router_data)}}
+ #test_count.append(test1)
+ test_count["router_count"]=len(router_data)
+ for i in range(1, NETWORK_COUNT + 1):
+ network_index = str(i)
+ network_cidr = str(i) + "." + str(i) + "." + str(i) + ".0/24"
+ network_name = prefix + '-net-' + network_index
+ subnet_name = prefix + "-subnet-" + network_index
+ ins_data = []
+ networks = neutron.list_networks(name=network_name)['networks']
+ for i in range(len(networks)):
+ if networks[i]['tenant_id'] == tenant['tenant_id']:
+ network_id = networks[i]['id']
+ network_vlan = networks[i]['provider:segmentation_id']
+ print(' - Network %s Discovered' % network_name)
+ print(' - Network ID %s Discovered' % network_id)
+ print(' - VLAN ID %s Discovered' % network_vlan)
+ status = True
+ for j in range(1, VM_COUNT + 1):
+ vm_name = network_name + '-vm-' + str(j)
+ ins_data.append(discover_vm_on_network(tenant['tenant_name'], vm_name, network_id))
+ else:
+ print(' - Network %s Not Found' % network_name)
+ status = False
+
+ result = {'network_data': {'tenant_name': tenant['tenant_name'],
+ 'network_name': network_name,
+ 'network_cidr': network_cidr,
+ 'subnet_name': subnet_name,
+ 'network_id': network_id,
+ 'network_vlan_id': network_vlan,
+ 'status':status},
+ 'instance_data': ins_data}
+ test_data.append(result)
+ test_count["network_count"]=test_data
+
+ except Exception:
+ print "\n"
+ print(' - Tenant %s Not Found' % tenant_name)
+
+
+ print "\n"
+ print "=" * 50
+ print "Scale Test Discovery Completed"
+ print "=" * 50
+
+ print "*" * 80
+ print "Scale Test Deployment OpenStack Report"
+ print "*" * 80
+
+ print "\n"
+ print " Tenant Discovery Results "
+ print print_tenant_info(tenant_data)
+ print "\n"
+ print " Router Discovery Results "
+ print print_router_info(router_data)
+ print "\n"
+ print " Network Discovery Results "
+ print print_network_info(test_data)
+ print "\n"
+
+ print " Instance Discovery Results "
+ print print_instance_info(test_data)
+ print "\n"
+
+ print " Tenant Name, Router Name, Network Name "
+ print print_discovered_tenant(tenant_data,router_data,test_data)
+ print "\n"
+
+ print" Overall Count of resources"
+ print print_consolidated_count(test_count)
+
+
+
+if __name__ == '__main__':
+ main()
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/discovery.py b/NTT/ntt-31-3-16/ntt-31-3-16/discovery.py
new file mode 100755
index 0000000..2d8ee79
--- /dev/null
+++ b/NTT/ntt-31-3-16/ntt-31-3-16/discovery.py
@@ -0,0 +1,318 @@
+import pdb
+import subprocess
+import ipaddress
+from netaddr import *
+from neutronclient.v2_0 import client
+import novaclient.v1_1.client as nvclient
+
+from credentials import get_credentials,get_tenant_nova_credentials
+from config import TENANT_BASE_INDEX, NETWORK_COUNT, \
+ EXTERNAL_NETWORK, print_scale_test_config, DEPLOYMENT_ID, \
+ ASR_HOST, ASR_USER, ASR_PASSWORD, ENABLE_ASR_VERIFICATION, TENANT_COUNT, \
+ TENANT_NAME_PREFIX, TENANT_NAME, TENANT_CREATION, VM_COUNT
+from tenants import create_tenant, discover_tenant
+from vm_instances import discover_vm_on_network,launch_vm_on_network,vm_endpoint_discovery
+from networks import delete_networks,delete_vm
+credentials = get_credentials()
+neutron = client.Client(**credentials)
+tenant_data=[]
+router_data=[]
+network_dict={}
+
+def tenant_discovery():
+ pdb.set_trace()
+ #for i in range(len(TENANT_NAME)):
+ #tenant_name = TENANT_NAME[i]
+ #tenant_data.append(discover_tenant())
+ #discover_tenant()
+ tenant_data= [
+ {'id': u'2931fbe17e8445da875bb915a29d0bbf', 'name': u'admin'},
+ {'id': u'2e93f5f662974b1284e8be13dd472e48', 'name': u'demo'},
+ {'id': u'ae9e7941b6764accae72a99662c189a5', 'name': u'tenant-test-101'},
+ {'id': u'be0e4b8dc7754668b0e3d57e4f7f6f66', 'name': u'tenant-test-102'}]
+ #{'id': u'fbb4907f073d4b5881a85c1692ae027a', 'name': u'services'}]
+ #for i in range(len(tenant_data)):
+ #print tenant_data[i]
+
+# router_discovery(tenant_data)
+ network_data=network_discovery(tenant_data) #List all subnets under each network from each tenant
+
+ #discover_instance(tenant_data)
+ #launch_instance(tenant_data,network_data)
+ endpoints=endpoint_discovery(tenant_data,network_data)
+ print endpoints
+# print tenant_data
+# print len(tenant_data)
+# destroy_all(tenant_data,network_data)
+
+def get_ip_range():
+
+ ips=IPRange("9.9.9.0","9.9.9.10")
+ return ips
+
+def endpoint_discovery(tenant_data,network_data):
+ pdb.set_trace()
+ instance_list=[]
+ endpoint_list=[]
+ final_data=[]
+
+ for tenant in tenant_data:
+ print("Get router information")
+ routers=get_router(tenant)
+ ports=get_ports(tenant)
+ instance_ports = get_instance_ports(ports)
+ for router in routers:
+ router_detail = {}
+ router_detail['id'] = router['id']
+ router_detail['ports'] = get_router_ports(router, ports)
+ subnets = []
+ instance_list = []
+ for port in router_detail['ports']:
+
+ subnets.append(get_port_subnets(tenant, port))
+ router_detail['subnets'] = subnets
+ for subnet in router_detail['subnets']:
+ if subnet['id'] != '':
+ endpoint_detail = get_subnet_endpoints(tenant, instance_ports, subnet)
+ ip_list = []
+ subnet['instances'] = endpoint_detail
+ for entry in endpoint_detail:
+ server = get_instance_detail(tenant['name'],entry['device_id'])
+ if entry['device_id'] not in instance_list and \
+ server.status == 'ACTIVE':
+ ips=get_ip_range()
+ ip_list.append(entry['ip_address'])
+
+ ipset=IPSet(ip_list)
+ for ip in ips:
+ if ip in ipset:
+ print("instance %s found"%(entry['ip_address']))
+ instance_list.append(entry['device_id'])
+ endpoint_list.append({'endpoints': ip_list,'tenant_name':tenant['name'],'subnet':subnet})
+
+ # check for vms in range and issue ping signal
+ #for ip in ips:
+ #if ip in ipset:
+ #print("instance %s found"%(entry['ip_address']))
+ #ip_net=ipaddress.ip_address(uentry['ip_address'])
+ #output = subprocess.Popen(['ping', '-c','2',entry['ip_address']],stdout=subprocess.PIPE)
+ #myout=output.communicate()[0]
+ #print myout
+
+
+
+
+ #print "tenant_name..%s"%(tenant['name'])
+ #print "routers...%s"%(routers)
+ #print "instance_ports....%s"%(instance_ports)
+ #for ins in instance_ports:
+ #pdb.set_trace()
+ #instances={'instance_detail':{'fixed_ip':ins['fixed_ips']}} # list all instance fixed ips
+ #instance_list.append(instances)
+ #return instance_list
+ return endpoint_list
+
+def get_instance_detail(tenant,instance):
+
+ tenant_credentials = get_tenant_nova_credentials(tenant)
+ nova = nvclient.Client(**tenant_credentials)
+ return nova.servers.get(instance)
+
+def get_router_ports(router,ports):
+
+ router_port_list = []
+ for port in ports:
+ if (port['device_id'] == router['id'] and
+ port['device_owner'] == 'network:router_interface'):
+ router_port_list.append(port)
+ return router_port_list
+
+def get_port_subnets(tenant,port):
+
+ subnet = get_subnet_detail(tenant, port['fixed_ips'][0]['subnet_id'])['subnet']
+ return {'id': port['fixed_ips'][0]['subnet_id'], 'name': subnet['name'],
+ 'ip_address': port['fixed_ips'][0]['ip_address'],'allocation_pool':subnet['allocation_pools']}
+
+def get_subnet_detail(tenant, subnet):
+
+ return neutron.show_subnet(subnet)
+
+def get_subnet_endpoints(tenant,ports,subnet):
+
+ endpoints = []
+ for port in ports:
+ endpoint_detail = {}
+ if port['fixed_ips'][0]['subnet_id'] == subnet['id']:
+ device_id = port['device_id'].encode('unicode_escape')
+ ip = port['fixed_ips'][0]['ip_address'].encode('unicode_escape')
+ endpoint_detail['device_id'] = device_id
+ endpoint_detail['ip_address'] = ip
+ endpoints.append(endpoint_detail)
+ return endpoints
+
+
+def get_router(tenant):
+ routers=neutron.list_routers(tenant_id=tenant['id'])['routers']
+ return routers
+def get_ports(tenant):
+ ports=neutron.list_ports(tenant_id=tenant['id'])['ports']
+ return ports
+
+def get_instance_ports(ports):
+ pdb.set_trace()
+ instance_port_list = []
+ for port in ports:
+ if port['device_owner'] == 'compute:compute':
+ instance_port_list.append(port)
+ return instance_port_list
+
+def destroy_all(tenant_data,network_data):
+
+ delete_vm(tenant_data,network_data)
+ delete_networks(tenant_data,network_data)
+
+def network_discovery(tenant_data):
+ pdb.set_trace()
+ network_detail=[]
+ subnet_detail=[]
+ instance_list=[]
+ net_sub={}
+ for tenant in tenant_data:
+
+ networks=neutron.list_networks(tenant_id=tenant['id'])['networks']
+
+
+# List all subnets under each network and the tenants
+ for net in networks:
+ nets={}
+ if net['tenant_id'] == tenant['id']:
+ nets={'network_list':{'tenant_name':tenant['name'],
+ 'network_name':net['name'],'network_id':net['id'],'shared':net['shared'],'subnets':net['subnets']}}
+ subnets=neutron.list_subnets(network_id=net['id'])['subnets']
+ for subnet in subnets:
+ #net_sub={'networks':{'tenant_name':tenant['name'],'network_name':net['name'],'network_id':net['id'],'shared':net['shared']},'subnets':{'subnet_name':subnet['name'],'cidr':subnet['cidr']}}
+ net_sub={'networks':{'tenant_name':tenant['name'],'network_name':net['name'],'network_id':net['id'],'shared':net['shared'],'subnet_name':subnet['name'],'cidr':subnet['cidr']}}
+
+ subnet_detail.append(net_sub)
+ print "\n"
+ print "List subnets along with network details"
+ print "tenant name %s"%(tenant['name'])
+ print "network_name %s"%(net['name'])
+ print "subnet_name %s"%(subnet['name'])
+ print "cidr\t %s"%(subnet['cidr'])
+ print "allocation pools...%s"%(subnet['allocation_pools'])
+ print "\n"
+
+ #routers=get_router(tenant)
+ #ports=get_ports(tenant)
+ #instance_ports = get_instance_ports(ports)
+ #for ins in instance_ports:
+ #pdb.set_trace()
+ #instances={'instance_detail':{'fixed_ip':ins['fixed_ips']}}
+ #instance_list.append(instances)
+
+ #vm_endpoint_discovery(tenant['name'])
+
+
+
+
+ #subnets = net.get("subnets")
+ #subnet_list = neutron.list_subnets(id=subnets)
+ #print subnet_list.get("subnets", [])[0].get("cidr")
+ network_detail.append(nets)
+
+ #pdb.set_trace()
+ # subnets=neutron.list_subnets(tenant_id=tenant['id'])['subnets']
+ # for subnet in subnets:
+ #
+ # print "\n\n"
+ # print "tenant name %s"%(tenant['name'])
+ # print "network_id %s"%(subnet['network_id'])
+ #
+ # print "subnet_id %s"%(subnet['id'])
+ # print "cidr\t %s"%(subnet['cidr'])
+ #network_dict['network_list']=network_detail
+
+ return network_detail
+
+def launch_instance(tenant_data,network_data):
+ #pdb.set_trace()
+ inst_data=[]
+ count=1
+ for tenant in tenant_data:
+
+ for network in network_data:
+ pdb.set_trace()
+ vm_name=tenant['name'] + '-vm-' + str(count)
+ if ((network['network_list']['tenant_name'] == tenant['name']) and (network['network_list']['shared'] == False)):
+
+ inst_data.append(launch_vm_on_network(tenant['name'],vm_name,network['network_list']['network_id']))
+
+ count += 1
+
+def discover_instance(tenant_data):
+ instance_detail=[]
+ pdb.set_trace()
+ for tenant in tenant_data:
+
+ vm_dict={}
+ instance_detail.append(discover_vm_on_network(tenant['name']))
+ print instance_detail
+
+
+def router_discovery(tenant_data):
+ #pdb.set_trace()
+ for tenant in tenant_data:
+ #router_dict = {}
+ router=neutron.list_routers(tenant_id=tenant['id'])['routers']
+ for route in router:
+
+ router_dict={}
+ #for rout in router:
+
+ if route['tenant_id'] == tenant['id']:
+ print(' - Router %s Discovered' % route['name'])
+ status = True
+ router_id = route['id']
+ router_dict['tenant_name']=tenant["name"]
+ router_dict['router_status'] = status
+ router_dict['router_name']=route['name']
+ router_data.append(router_dict)
+
+ else:
+ print("Tenant %s not having any router"%(tenant['name']))
+ #if rout['tenant_id'] == tenant['id']:
+ #print(' - Router %s Discovered' % rout['name'])
+ #status = True
+ #router_id = rout['id']
+ #router_dict['tenant_name']=tenant["name"]
+ #router_dict['router_status'] = status
+ #router_dict['router_name']=rout['name']
+
+ else:
+ print(' - Router Not Found in %s tenant' % tenant['name'])
+ status = False
+ #router_id = rout['id']
+ #router_dict['router_status'] = status
+ #router_data.append(router_dict)
+
+
+ #router_id = router['id']
+ #router_dict['router_status'] = status
+ #router_data.append(router_dict)
+
+ print router_data
+
+def main():
+
+ tenant_discovery()
+
+
+
+
+
+
+
+if __name__ == '__main__':
+
+ main()
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/floating_ips.py b/NTT/ntt-31-3-16/ntt-31-3-16/floating_ips.py
new file mode 100755
index 0000000..e02a2d2
--- /dev/null
+++ b/NTT/ntt-31-3-16/ntt-31-3-16/floating_ips.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+"""
+Description: This script is to allocate & associate the floating IP.
+Developer: gopal@onecloudinc.com
+"""
+
+import os
+from neutronclient.v2_0 import client
+import novaclient.v1_1.client as nvclient
+from credentials import get_credentials, get_nova_credentials, \
+ get_tenant_nova_credentials
+from config import FLOATING_IP_POOL
+
+neutron_credentials = get_credentials()
+credentials = get_nova_credentials()
+neutron = client.Client(**neutron_credentials)
+nova = nvclient.Client(**credentials)
+if not nova.keypairs.findall(name="admin"):
+ with open(os.path.expanduser('~/.ssh/id_rsa.pub')) as fpubkey:
+ nova.keypairs.create(name="admin", public_key=fpubkey.read())
+
+
+def add_floating_ip_for_vm(tenant_name, instance):
+ """
+ This method is used to allocate & associate floating IP to the given VM\
+ based on the availability from the defined pool.
+ """
+ tenant_credentials = get_tenant_nova_credentials(tenant_name)
+ nova = nvclient.Client(**tenant_credentials)
+ floating_ip = nova.floating_ips.create(FLOATING_IP_POOL)
+ instance.add_floating_ip(floating_ip)
+ print " - Assigned Floating IP: " + str(floating_ip.ip)
+ return True
+
+
+def release_all_floating_ips():
+ """
+ This method is used to release all the disallocated floating IPs.
+ """
+ floating_ips = neutron.list_floatingips()['floatingips']
+ try:
+ for ip in floating_ips:
+ neutron.delete_floatingip(ip['id'])
+ except:
+ pass
+ return True
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/floating_ips.pyc b/NTT/ntt-31-3-16/ntt-31-3-16/floating_ips.pyc
new file mode 100755
index 0000000..9309696
Binary files /dev/null and b/NTT/ntt-31-3-16/ntt-31-3-16/floating_ips.pyc differ
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/networks.py b/NTT/ntt-31-3-16/ntt-31-3-16/networks.py
new file mode 100755
index 0000000..befd00e
--- /dev/null
+++ b/NTT/ntt-31-3-16/ntt-31-3-16/networks.py
@@ -0,0 +1,178 @@
+#!/usr/bin/env python
+"""
+Description: This script is to create network, subnets, router with \
+ external gateway mapping.
+Developer: gopal@onecloudinc.com
+"""
+import pdb
+import os
+from neutronclient.v2_0 import client
+from credentials import get_credentials
+from config import NETWORK_COUNT, VM_COUNT, FLOATING_IP_CREATION
+from vm_instances import launch_vm_on_network, terminate_vm_on_network
+from floating_ips import release_all_floating_ips
+from datetime import datetime, timedelta
+from pytz import timezone
+
+credentials = get_credentials()
+neutron = client.Client(**credentials)
+fmt = "%Y-%m-%d %H:%M:%S %Z%z"
+
+
+def create_network(tenant, router, network_index, network_cidr):
+ """
+ This method is used to create network, subnets, interfaces on router with \
+ external gateway mapping for the given network name and CIDR.
+ """
+
+ try:
+ prefix = tenant['tenant_name']
+ network_name = prefix + '-net-' + network_index
+ print "\n"
+ print "=" * 50
+ print " Initiated Network Creation for " + network_name
+ print "=" * 50
+ print "\n"
+
+ body_sample = {'network': {'name': network_name,
+ 'tenant_id': tenant['tenant_id']}}
+ start_time = datetime.now(timezone('US/Pacific'))
+ try:
+ net = neutron.create_network(body=body_sample)
+ net_dict = net['network']
+ network_id = net_dict['id']
+ network_vlan = net_dict['provider:segmentation_id']
+ print(' - Network %s created' % net_dict['name'])
+ net_status = True
+ except Exception:
+ net_dict = {}
+ net_status = False
+
+ subnet_name = prefix + "-subnet-" + network_index
+ try:
+ tenant_id = tenant['tenant_id']
+ body_create_subnet = {'subnets': [{'name': subnet_name,
+ 'cidr': network_cidr,
+ 'ip_version': 4,
+ 'network_id': network_id,
+ 'tenant_id': tenant_id}]}
+ subnet_detail = neutron.create_subnet(body=body_create_subnet)
+ subnet = subnet_detail['subnets'][0]
+ print(' - Created subnet %s' % subnet['name'])
+ net_status = True
+ except Exception:
+ subnet = {}
+ net_status = False
+
+ neutron.add_interface_router(router['id'], {'subnet_id': subnet['id'],
+ 'tenant_id': tenant['tenant_id']})
+ print (' - Created interface between %s' % subnet['name'])
+ finally:
+ print "\n"
+ msg = "<== Completed Network Creation with External Gateway "
+ msg += "Successfully ==>"
+ print msg
+ end_time = datetime.now(timezone('US/Pacific'))
+ print "\n"
+ print "-"*65
+ print (" Network %s Creation Time Summary :" % network_name)
+ print "-"*65
+ print "\n"
+ print(' - Test Started Time :\t %s' % (start_time.strftime(fmt)))
+ print(' - Test Ended Time :\t %s' % (end_time.strftime(fmt)))
+
+ print "\n"
+ print "=" * 50
+ print " Initiated VM Deployment " + network_name
+ print "=" * 50
+ print "\n"
+
+ ins_data = []
+ for i in range(1, VM_COUNT + 1):
+ vm_name = network_name + '-vm-' + str(i)
+ start_time = datetime.now(timezone('US/Pacific'))
+ ins_data.append(launch_vm_on_network(tenant['tenant_name'],
+ vm_name, network_id))
+ end_time = datetime.now(timezone('US/Pacific'))
+
+ print "\n"
+ msg = "<== Completed VM Launch on Network with Floating IP Allocation "
+ msg += "Successfully ==>"
+ print msg
+ print "\n"
+ print "-"*65
+ print (" Instance %s Creation Time Summary :" % vm_name)
+ print "-"*65
+ print "\n"
+ print(' - Test Started Time :\t %s' % (start_time.strftime(fmt)))
+ print(' - Test Ended Time :\t %s' % (end_time.strftime(fmt)))
+
+ result = {'network_data': {'tenant_name': tenant['tenant_name'],
+ 'network_name': network_name,
+ 'network_cidr': network_cidr,
+ 'subnet_name': subnet_name,
+ 'network_id': network_id,
+ 'network_vlan_id': network_vlan,
+ 'status': net_status},
+ 'instance_data': ins_data}
+ return result
+
+
+def delete_vm(tenant_data,network_data):
+ """
+ This method is used to delete vms, network, subnets, interfaces on router \
+ with external gateway mapping for the given network name and CIDR.
+ """
+ pdb.set_trace()
+ #prefix = tenant_name
+ network_list = []
+ router_list = []
+ count=1
+ #router_list.append(prefix + '-router')
+ #for i in range(1, NETWORK_COUNT + 1):
+ #network_list.append(prefix + '-net-' + str(i))
+ for tenant in tenant_data:
+ for network in network_data:
+ vm_name=tenant['name'] + '-vm-' + str(count)
+ if ((network['network_list']['tenant_name'] == tenant['name']) and (network['network_list']['shared'] == False)):
+
+
+ terminate_vm_on_network(tenant['name'], vm_name,network['network_list']['network_id'])
+ count += 1
+
+ release_all_floating_ips()
+def delete_networks(tenant_data,network_data):
+ pdb.set_trace()
+ networks=None
+ for tenant in tenant_data:
+ networks=neutron.list_networks(tenant_id=tenant['id'])['networks']
+ routers=neutron.list_routers(tenant_id=tenant['id'])['routers']
+ subnets=neutron.list_subnets(tenant_id=tenant['id'])['subnets']
+
+
+ for router in routers:
+ ports=neutron.list_ports(tenant_id=tenant['id'])['ports']
+ for port in ports:
+ #for subnet in subnets:
+ if (port['device_id'] == router['id'] and port['device_owner'] == 'network:router_interface'):
+ neutron.remove_interface_router(router['id'],{'subnet_id':port['fixed_ips'][0]['subnet_id']})
+ neutron.remove_gateway_router(router['id'])
+ neutron.delete_network(port['network_id'])
+ neutron.delete_router(router['id'])
+ #neutron.delete_network(network['id'])
+
+ #for network in networks:
+ #neutron.delete_network(network['id'])
+
+ #for subnet in subnets:
+ #for network in networks:
+
+
+
+
+
+ #if FLOATING_IP_CREATION:
+ #release_all_floating_ips()
+ #print "\n"
+ #print("<== Released all Floating IPs Successfully ==>")
+ #return True
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/networks.pyc b/NTT/ntt-31-3-16/ntt-31-3-16/networks.pyc
new file mode 100755
index 0000000..12bd62b
Binary files /dev/null and b/NTT/ntt-31-3-16/ntt-31-3-16/networks.pyc differ
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/openstack_clean_script.py b/NTT/ntt-31-3-16/ntt-31-3-16/openstack_clean_script.py
new file mode 100755
index 0000000..bb04cd1
--- /dev/null
+++ b/NTT/ntt-31-3-16/ntt-31-3-16/openstack_clean_script.py
@@ -0,0 +1,158 @@
+import logging
+import pprint
+from novaclient import client as novclient
+from neutronclient.v2_0 import client as nclient
+import time
+import pdb
+import MySQLdb
+from keystoneclient.v2_0 import client as kclient
+def main():
+ net_list=['NET-A','NET-B','NET-C']
+ ext_net_list=['EXT-NET-A','EXT-NET-B']
+ ext_subnet_list=[]
+ flavor_list={}
+
+ router_list=['Router-A','Router-B']
+ subnet_list={'subnets':[{'name':'Subnet-A','network_id':'','ip_version':4,'cidr':'1.1.1.0/24'},{'name':'Subnet-B','network_id':'','ip_version':4,'cidr':'2.2.2.0/24'}]}
+ count = 0
+ instance_detail={}
+ networks={}
+ logging.basicConfig(level=logging.INFO)
+ logger=logging.getLogger(__name__)
+ logger.info("Keystone authentication started....")
+ time.sleep(5)
+ logger.info("Wait for 5 seconds...")
+ logger.info("done")
+ neutr=nclient.Client(username='admin',password='admin',tenant_name='admin',auth_url='http://192.168.1.12:5000/v2.0/')
+ novactr=novclient.Client('2',username='admin',api_key='admin',project_id='admin',auth_url='http://192.168.1.12:5000/v2.0/')
+ logger.info("Authentication success...")
+ #logger.info("getting input from user....")
+ #network_count=int(raw_input("Enter the no of network to created >>\t"))
+ #ext_network_count=int(raw_input("Enter the no of External network to be created >> \t"))
+ #instance_detail['name']=raw_input("Please provide name for instance")
+ #flavor_id=int(raw_input("Provide the flavor for the instance"))
+ #netw=neutr.list_networks()
+ #print netw
+ #ss=db_connection(flavor_list,novactr)
+ #us=ss.get(flavor_id)
+ #if us:
+ #logger.info("You choose %s flavor"%(us))
+ #else:
+ #logger.info("The flavor u choose is doesn't exists..")
+ #exit
+ #create_network(neutr,network_count,logger,net_list,count,subnet_list,novactr,flavor_id)
+ delete_network(neutr,novactr,logger,net_list,subnet_list)
+
+def create_network(neutr,network_count,logger,net_list,count,subnet_list,novactr,flavor_id):
+ pdb.set_trace()
+ logger.info("Start creating external network ")
+ ext_network=neutr.create_network({'network':{'name':'EXT-NET','admin_state_up':'True','router:external':'True'}})
+ ext_id=ext_network['network']['id']
+ vm_list=['vm-1','vm-2']
+ logger.info("Creating external network subnet...")
+ ext_subnet=neutr.create_subnet({'subnet':{'name':'EXT_subnet','network_id':ext_id,'ip_version':4,'cidr':'6.6.8.8/24'}})
+ time.sleep(2)
+ logger.info("creating router")
+ router1=neutr.create_router({'router':{'name':'Router-1','admin_state_up':'True'}})
+ router_id=router1['router']['id']
+ neutr.add_gateway_router(router_id,{'network_id':ext_id})
+
+ while count < network_count:
+
+ neut=neutr.create_network({'network':{'name':net_list[count],'admin_state_up':'True'}})
+ if neut:
+ net_id=neut['network']['id']
+ logger.info("Network %s sucessfully created.."%(net_list[count]))
+ time.sleep(4)
+ logger.info("Start creating subnets")
+ #nsub=neutr.create_subnet({'subnet':subnet_list['subnets'][count]})
+ nsub=neutr.create_subnet({'subnet':{'name':subnet_list['subnets'][count]['name'],'network_id':net_id,'ip_version':subnet_list['subnets'][count]['ip_version'],'cidr':subnet_list['subnets'][count]['cidr']}})
+ sub_id=nsub['subnet']['id']
+ if nsub:
+ logger.info("subnet is created for network %s"%(net_list[count]))
+ time.sleep(4)
+ logger.info("Adding interface to router")
+ neutr.add_interface_router(router_id,{'subnet_id':sub_id})
+ time.sleep(5)
+ logger.info("Ready to launch the instances")
+ pdb.set_trace()
+ image = novactr.images.find(name="cirros")
+ print net_id
+ instance = novactr.servers.create(name=vm_list[count], image=image, flavor=flavor_id, nics=[{'net-id':net_id}])
+ logger.info("Instance launched successfully on network %s"%(net_list[count]))
+ time.sleep(4)
+ count = count+1
+ else:
+ logger.info("Error in network creation")
+ time.sleep(3)
+ logger.info("setup is ready for testing..")
+
+def db_connection(flavor_list,novactr):
+ db=MySQLdb.connect(host="localhost",user="root",passwd="dafc1bce95654501",db="nova")
+ cur=db.cursor()
+ cur.execute("select id,name from instance_types")
+ ss=novactr.networks.list()
+ print ss
+ return dict(cur.fetchall())
+
+def delete_network(neutr,novactr,logger,net_list,subnet_list):
+ logger.info("Start cleaning the dashboard")
+ del_net={}
+ server_delete(novactr,logger)
+ delete_interface(neutr,logger)
+ count=0
+
+def server_delete(novactr,logger):
+ #pdb.set_trace()
+ logger.info("Fetching list of servers")
+ myserver=novactr.servers.list()
+ server_len=len(myserver)
+ for i in range(server_len):
+ ss=novactr.servers.delete(myserver[i])
+ if ss:
+ logger.info("Instances %s sucessfully deleted"%myserver[i])
+ time.sleep(1)
+def delete_interface(neutr,logger):
+
+ mynetwork=neutr.list_networks()
+ net_len=len(mynetwork['networks'])
+ myrouter=neutr.list_routers()
+ r_id=myrouter['routers'][0]['id']
+ port_delete(neutr,logger,r_id)
+ my_ports=neutr.list_ports()['ports']
+ port_gateway=[]
+ s=neutr.remove_gateway_router(r_id)
+ if s:
+ logger.info("gateway router is detached successful...")
+ myrouter=neutr.list_routers()['routers']
+ for r in range(len(myrouter)):
+
+ neutr.delete_router(myrouter[r]['id'])
+ logger.info("Deleting networks...")
+ time.sleep(2)
+ for j in range(net_len):
+ dd=neutr.delete_network(mynetwork['networks'][j]['id'])
+
+def port_delete(neutr,logger,r_id):
+ logger.info("listing port details..")
+ myports=neutr.list_ports()['ports']
+ port_list=[]
+ port_gateway=[]
+ for port in myports:
+
+ if (port['device_id'] == r_id and
+ port['device_owner'] == 'network:router_interface'):
+ port_list.append(port)
+ logger.info("Removing router interfaces..")
+
+ for i in range(len(port_list)):
+
+ del_inf=neutr.remove_interface_router(r_id,{'subnet_id':port_list[i]['fixed_ips'][0]['subnet_id']})
+
+#def get_id(novactr,logger):
+ #welcome=novactr.servers.list(413fb5d3-c1bc-4267-80ab-6a27d0cfd04b)
+ #print welcome
+
+
+if __name__ == '__main__':
+ main()
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/t1.py b/NTT/ntt-31-3-16/ntt-31-3-16/t1.py
new file mode 100755
index 0000000..a93a8ab
--- /dev/null
+++ b/NTT/ntt-31-3-16/ntt-31-3-16/t1.py
@@ -0,0 +1,17 @@
+from keystoneclient.v2_0 import client
+
+
+OS_USERNAME = 'admin'
+OS_TENANT_NAME = 'admin'
+OS_PASSWORD = 'admin'
+OS_AUTH_URL = 'http://172.168.2.40:5000/v2.0/'
+
+keystone = client.Client(username=OS_USERNAME, password=OS_PASSWORD, auth_url=OS_AUTH_URL)
+import pdb
+pdb.set_trace()
+
+tenants = keystone.tenants.list()
+for tenant in tenants:
+ print tenant.__dict__
+
+
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/t2.py b/NTT/ntt-31-3-16/ntt-31-3-16/t2.py
new file mode 100755
index 0000000..adb670c
--- /dev/null
+++ b/NTT/ntt-31-3-16/ntt-31-3-16/t2.py
@@ -0,0 +1,31 @@
+from neutronclient.v2_0 import client as neutron_client
+
+
+
+OS_USERNAME = 'admin'
+OS_TENANT_NAME = 'admin'
+OS_PASSWORD = 'admin'
+OS_AUTH_URL = 'http://172.168.2.40:5000/v2.0/'
+OS_TENANT_ID = '2931fbe17e8445da875bb915a29d0bbf'
+
+def get_credentials():
+ d = {}
+ d['username'] = OS_USERNAME
+ d['password'] = OS_PASSWORD
+ d['auth_url'] = OS_AUTH_URL
+ d['tenant_id'] = OS_TENANT_ID
+ return d
+
+tenants = [
+ {'id': u'2931fbe17e8445da875bb915a29d0bbf', 'name': u'admin'},
+ {'id': u'2e93f5f662974b1284e8be13dd472e48', 'name': u'demo'},
+ {'id': u'ae9e7941b6764accae72a99662c189a5', 'name': u'tenant-test-101'},
+ {'id': u'be0e4b8dc7754668b0e3d57e4f7f6f66', 'name': u'tenant-test-102'},
+ {'id': u'fbb4907f073d4b5881a85c1692ae027a', 'name': u'services'}
+]
+
+
+credentials = get_credentials()
+neutron = neutron_client.Client(**credentials)
+netw = neutron.list_networks()
+print netw
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/tenant.txt b/NTT/ntt-31-3-16/ntt-31-3-16/tenant.txt
new file mode 100755
index 0000000..2ecda20
--- /dev/null
+++ b/NTT/ntt-31-3-16/ntt-31-3-16/tenant.txt
@@ -0,0 +1,7 @@
+tenants = [
+ {'id': u'2931fbe17e8445da875bb915a29d0bbf', 'name': u'admin'},
+ {'id': u'2e93f5f662974b1284e8be13dd472e48', 'name': u'demo'},
+ {'id': u'ae9e7941b6764accae72a99662c189a5', 'name': u'tenant-test-101'},
+ {'id': u'be0e4b8dc7754668b0e3d57e4f7f6f66', 'name': u'tenant-test-102'},
+ {'id': u'fbb4907f073d4b5881a85c1692ae027a', 'name': u'services'}
+]
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/tenants.py b/NTT/ntt-31-3-16/ntt-31-3-16/tenants.py
new file mode 100755
index 0000000..ed40861
--- /dev/null
+++ b/NTT/ntt-31-3-16/ntt-31-3-16/tenants.py
@@ -0,0 +1,145 @@
+#!/usr/bin/env python
+"""
+Description: This script prepares new tenant with the following properties:
+1. Creates new tenant.
+2. Creates new user and this user is added _member_ to tenant. \
+Password is second argument of script
+3. Admin user will be added to tenant with role admin
+Developer: gopal@onecloudinc.com
+"""
+
+import os
+import pdb
+from keystoneclient.v2_0 import client as ksclient
+from credentials import get_credentials
+from config import USER_COUNT, USER_PASSWORD
+
+credentials = get_credentials()
+keystone = ksclient.Client(**credentials)
+assign_admin = True
+
+
+def create_tenant(tenant_name):
+ """
+ This method is used to create tenant and create number of users per tenant
+ """
+
+ print "\n"
+ print "=" * 50
+ print " Initiated Tenant Creation for " + tenant_name
+ print "=" * 50
+ print "\n"
+
+ try:
+ try:
+ new_tenant = keystone.tenants.create(tenant_name=tenant_name,
+ description="Scale tenant \
+ created",
+ enabled=True)
+ print(' - Tenant %s created' % tenant_name)
+ except Exception:
+ new_tenant = keystone.tenants.find(name=tenant_name)
+ tenant_id = new_tenant.id
+ tenant_status = True
+ user_data = []
+ for j in range(USER_COUNT):
+ j += 1
+ user_name = tenant_name + '-user-' + str(j)
+ user_data.append(create_user(user_name, tenant_id))
+ except Exception:
+ tenant_status = False
+
+ print "\n"
+ msg = ('<== Completed Tenant Creation and Users per Tenant '
+ 'with _member_ role ')
+ msg += 'Successfully ==>'
+ print msg
+ print "\n"
+
+ tenant_data = {'tenant_name': tenant_name,
+ 'tenant_id': tenant_id,
+ 'status': tenant_status}
+ return tenant_data
+
+
+def discover_tenant():
+ """
+ This method is used to discover tenant and discover number of users per tenant
+ """
+ global tenant_id,tenant_status
+ try:
+ pdb.set_trace()
+ new_tenant = keystone.tenants.list()
+ tenant_id = new_tenant.id
+ tenant_status = True
+ print "\n"
+ print(' - Tenant %s Discovered' % tenant_name)
+ print(' - Tenant_ID %s Discovered' % tenant_id)
+ except Exception:
+ pass
+
+ tenant_data = {'tenant_name': tenant_name,
+ 'tenant_id': tenant_id,
+ 'status': tenant_status}
+ return tenant_data
+
+
+def create_user(user_name, tenant_id):
+ """
+ This method is to create users per Tenant
+ """
+
+ try:
+ new_user = keystone.users.create(name=user_name,
+ password=USER_PASSWORD,
+ tenant_id=tenant_id)
+ print(' - Created User %s' % user_name)
+ except Exception:
+ new_user = keystone.users.find(name=user_name)
+ member_role = keystone.roles.find(name='_member_')
+ try:
+ keystone.roles.add_user_role(new_user, member_role, tenant_id)
+ except Exception:
+ pass
+ if assign_admin:
+ admin_user = keystone.users.find(name='admin')
+ admin_role = keystone.roles.find(name='admin')
+ try:
+ keystone.roles.add_user_role(admin_user, admin_role, tenant_id)
+ except Exception:
+ pass
+ user_data = {'name': new_user.name,
+ 'id': new_user.id}
+ return user_data
+
+
+def delete_tenant(tenant_name):
+ """
+ This method is used to delete tenant and users
+ """
+
+ try:
+ tenant = keystone.tenants.find(name=tenant_name)
+ for j in range(USER_COUNT):
+ j += 1
+ user_name = tenant_name + '-user-' + str(j)
+ delete_user(user_name, tenant.id)
+ tenant.delete()
+ print(' - Deleted Tenant %s ' % tenant_name)
+ except Exception:
+ pass
+ return True
+
+
+def delete_user(user_name, tenant_id):
+ """
+ This method is to delete users per Tenant
+ """
+ try:
+ user = keystone.users.find(name=user_name)
+ user.delete()
+ except Exception:
+ print(" - User Not Found: %s" % user_name)
+ pass
+ print(' - Deleted User %s' % user_name)
+ return True
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/tenants.pyc b/NTT/ntt-31-3-16/ntt-31-3-16/tenants.pyc
new file mode 100755
index 0000000..a84e29f
Binary files /dev/null and b/NTT/ntt-31-3-16/ntt-31-3-16/tenants.pyc differ
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/user.txt b/NTT/ntt-31-3-16/ntt-31-3-16/user.txt
new file mode 100755
index 0000000..9e5d3d9
--- /dev/null
+++ b/NTT/ntt-31-3-16/ntt-31-3-16/user.txt
@@ -0,0 +1,7 @@
+#cloud-config
+chpasswd:
+ list: |
+ root:ubuntu
+ ubuntu:ubuntu
+ expire: False
+ssh_pwauth: True
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/vm_instances.py b/NTT/ntt-31-3-16/ntt-31-3-16/vm_instances.py
new file mode 100755
index 0000000..792d9ca
--- /dev/null
+++ b/NTT/ntt-31-3-16/ntt-31-3-16/vm_instances.py
@@ -0,0 +1,179 @@
+#!/usr/bin/env python
+"""
+Description: This script is to launching VMs on the network.
+Developer: gopal@onecloudinc.com
+"""
+
+import os
+import time
+import pdb
+import novaclient.v1_1.client as nvclient
+from novaclient.base import *
+from novaclient.exceptions import NotFound
+from config import FLOATING_IP_CREATION, IMAGE_NAME, FLAVOUR_NAME,OS_USERNAME, OS_TENANT_NAME, OS_PASSWORD, OS_AUTH_URL
+from credentials import get_nova_credentials, get_tenant_nova_credentials,get_credentials
+from floating_ips import add_floating_ip_for_vm
+import glanceclient.v2.client as glance_client
+import keystoneclient.v2_0.client as ksclient
+keystone = ksclient.Client(auth_url="http://172.168.2.40:35357/v2.0",
+ username="admin",
+ password="admin",
+ tenant_name="admin")
+token = keystone.auth_ref['token']['id']
+
+credentials = get_nova_credentials()
+nova = nvclient.Client(**credentials)
+#glance=glance_client.Client(username=OS_USERNAME,password=OS_PASSWORD,tenant_name=OS_TENANT_NAME,auth_url=OS_AUTH_URL)
+glance=glance_client.Client(endpoint="http://172.168.2.40:9292", token=token)
+
+
+if not nova.keypairs.findall(name="admin"):
+ with open(os.path.expanduser('~/.ssh/id_rsa.pub')) as fpubkey:
+ nova.keypairs.create(name="admin", public_key=fpubkey.read())
+
+def upload_image_glance():
+ #pdb.set_trace()
+ image_list=glance.images.list()
+ image_file="/home/onecloud/NTT/keerthi/ubuntu.img"
+ image=glance.images.create(disk_format="qcow2",container_format="bare",name="ubuntu")
+ print("image status %s"%(image.status))
+ ss=glance.images.upload(image.id,open('/home/onecloud/NTT/keerthi/ubuntu.img','rb'))
+ print("Current Image status <%s>"%(image.status))
+
+ #with open(image_file) as img:
+ #image=glance.images.create(name="ubuntu",disk_format="raw",container_format="bare",data=img)
+
+ #print("Current Image status %s"%(image.status))
+
+
+def launch_vm_on_network(tenant_name, vm_name, network_id):
+ """
+ This method is to launch VM on the given network & VM Name.
+ """
+ #pdb.set_trace()
+ instance=None
+ tenant_credentials = get_tenant_nova_credentials(tenant_name)
+
+ nova = nvclient.Client(**tenant_credentials)
+ nova.quotas.update(tenant_name, instances=-1, cores=-1, ram=-1, fixed_ips=-1, floating_ips=-1)
+ with open('user.txt') as userdata:
+ user_data = userdata.read()
+ try:
+ image_list=nova.images.find(name="ubuntu")
+ except NotFound:
+ upload_image_glance()
+
+ #for img in image:
+ #if img.name == 'ubuntu':
+ #print "image found"
+ try:
+
+ flavor = nova.flavors.find(name='traffic')
+ except:
+ flavor = nova.flavors.create(name="traffic",ram="2048",vcpus="1",disk="10")
+
+
+ try:
+
+ instance = nova.servers.create(name=vm_name, image=image_list,
+ flavor=flavor,
+ key_name="admin",
+ availability_zone="compute:openstack-aio",
+ nics=[{'net-id': network_id}],userdata=user_data)
+ except Exception:
+ pass
+
+ # Poll at 15 second intervals, until the status is no longer 'BUILD'
+ print " * Instance <%s> created on network <%s>: "%(vm_name,str(network_id))
+ status = instance.status
+ while status == 'BUILD':
+ time.sleep(15)
+ # Retrieve the instance again so the status field updates
+ instance = nova.servers.get(instance.id)
+ status = instance.status
+
+ print " - Current status: %s" % status
+ if FLOATING_IP_CREATION:
+ add_floating_ip_for_vm(tenant_name, instance)
+
+ ins_data = {'instance_name': vm_name, 'status': status}
+ return ins_data
+
+#def endpoint_discovery(tenant_data,network_data):
+
+# tenant_credentials = get_tenant_nova_credentials(tenant_name)
+# nova = nvclient.Client(**tenant_credentials)
+# instance_list = nova.servers.list()
+
+
+def vm_endpoint_discovery(tenant_name):
+ pdb.set_trace()
+
+ name=None
+ status=None
+ try:
+ tenant_credentials = get_tenant_nova_credentials(tenant_name)
+ nova = nvclient.Client(**tenant_credentials)
+ instance_list=nova.servers.list()
+ #instance = nova.servers.find(name=vm_name)
+ if instance_list > 0:
+
+ for inst in instance_list:
+
+ instance_id = inst.id
+ name=inst.name
+ networks=inst.networks
+
+
+
+ except Exception:
+ print(' - Instance Not Found')
+
+
+def discover_vm_on_network(tenant_name):
+ """
+ This method is used to discover instances per tenant
+ """
+ name=None
+ status=None
+ try:
+ tenant_credentials = get_tenant_nova_credentials(tenant_name)
+ nova = nvclient.Client(**tenant_credentials)
+ instance_list=nova.servers.list()
+ #instance = nova.servers.find(name=vm_name)
+ if instance_list > 0:
+
+ for inst in instance_list:
+
+ instance_id = inst.id
+ name=inst.name
+ inst_find=nova.servers.find(id=instance_id)
+ print(' - Instance %s Discovered' % inst.name)
+ print(' - Instance ID %s Discovered' % instance_id)
+ print(' - Instance %s Status' % inst.status)
+ status=inst.status
+ except Exception:
+ print(' - Instance Not Found')
+ status = False
+
+ ins_data = {'instance_name': name,
+ 'status': status }
+ return ins_data
+
+
+def terminate_vm_on_network(tenant_name, vm_name, network_id):
+ """
+ This method is to terminate VM on the given network & VM Name.
+ """
+ pdb.set_trace()
+ tenant_credentials = get_tenant_nova_credentials(tenant_name)
+ nova = nvclient.Client(**tenant_credentials)
+ nova.quotas.delete(tenant_name)
+ try:
+ instance = nova.servers.find(name=vm_name)
+ nova.servers.delete(instance.id)
+ print " * Instance terminated on network: " + str(network_id)
+ except Exception:
+ print " * Instance Not Found on network: " + str(network_id)
+ pass
+ return True
diff --git a/NTT/ntt-31-3-16/ntt-31-3-16/vm_instances.pyc b/NTT/ntt-31-3-16/ntt-31-3-16/vm_instances.pyc
new file mode 100644
index 0000000..6d6b422
Binary files /dev/null and b/NTT/ntt-31-3-16/ntt-31-3-16/vm_instances.pyc differ
diff --git a/openstack-scripts/.idea/encodings.xml b/openstack-scripts/.idea/encodings.xml
new file mode 100644
index 0000000..97626ba
--- /dev/null
+++ b/openstack-scripts/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/openstack-scripts/.idea/misc.xml b/openstack-scripts/.idea/misc.xml
new file mode 100644
index 0000000..e18a1c7
--- /dev/null
+++ b/openstack-scripts/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/openstack-scripts/.idea/modules.xml b/openstack-scripts/.idea/modules.xml
new file mode 100644
index 0000000..9f615f2
--- /dev/null
+++ b/openstack-scripts/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/openstack-scripts/.idea/openstack-scripts.iml b/openstack-scripts/.idea/openstack-scripts.iml
new file mode 100644
index 0000000..d0876a7
--- /dev/null
+++ b/openstack-scripts/.idea/openstack-scripts.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/openstack-scripts/.idea/workspace.xml b/openstack-scripts/.idea/workspace.xml
new file mode 100644
index 0000000..077d757
--- /dev/null
+++ b/openstack-scripts/.idea/workspace.xml
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1461766552056
+
+
+ 1461766552056
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/openstack-scripts/__init__.py b/openstack-scripts/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/openstack-scripts/config.py b/openstack-scripts/config.py
new file mode 100644
index 0000000..8284fcb
--- /dev/null
+++ b/openstack-scripts/config.py
@@ -0,0 +1,75 @@
+"""
+Description: Define the Scale Test Configuration with the below global \
+ parameters.
+Developer: gopal@onecloudinc.com
+"""
+
+# Tenant Settings
+
+OS_USERNAME = 'admin'
+OS_TENANT_NAME = 'admin'
+OS_PASSWORD = 'admin'
+OS_AUTH_URL = 'http://172.168.2.62:5000/v2.0/'
+
+# TENANT_CREATION = True
+
+TENANT_COUNT = 2
+TENANT_NAME_PREFIX = 'tenant-test'
+TENANT_BASE_INDEX = 101
+USER_COUNT = 1
+USER_PASSWORD = 'secret'
+NETWORK_COUNT = 2
+VM_COUNT = 1
+IMAGE_NAME = 'Cirros'
+FLAVOUR_NAME = 'm1.tiny'
+EXTERNAL_NETWORK = 'public'
+
+# Floating IP Settings
+
+FLOATING_IP_CREATION = True
+FLOATING_IP_POOL = 'public'
+
+TENANT_CREATION = False
+TENANT_NAME = ['tenant-test-101', 'tenant-test-102', 'tenant-test-103', 'tenant-test-104','tenant-test-105']
+
+
+# Cisco ASR Settings
+
+ENABLE_ASR_VERIFICATION = False
+DEPLOYMENT_ID = 'ans136'
+ASR_HOST = '10.10.10.10'
+ASR_USER = 'admin'
+ASR_PASSWORD = 'admin'
+
+
+"""
+Test Configuration Ends Here with the global parameters.
+"""
+
+
+def print_scale_test_config():
+ """
+ This method is used to print the current test configuration on scale test \
+ deployment initialization.
+ """
+ print '=' * 70
+ print " Configuration for this Scale Test"
+ print '=' * 70
+
+ print " Tenant will be created with prefix : " \
+ + TENANT_NAME_PREFIX
+ print " No of Tenants will be created : " \
+ + str(TENANT_COUNT)
+ print " Tenant base index range starts from : " \
+ + str(TENANT_BASE_INDEX)
+ print " No of Users per Tenant : " \
+ + str(USER_COUNT)
+ print " No of Networks : " \
+ + str(NETWORK_COUNT)
+ print " No of VMs per Network : " \
+ + str(VM_COUNT)
+ print " Name of the External Network with be connected with Router : " \
+ + EXTERNAL_NETWORK
+ print " Name of the Floating IP Pool will be used for Allocation : " \
+ + FLOATING_IP_POOL
+ print '=' * 70
diff --git a/openstack-scripts/config.pyc b/openstack-scripts/config.pyc
new file mode 100644
index 0000000..c3f9f09
Binary files /dev/null and b/openstack-scripts/config.pyc differ
diff --git a/openstack-scripts/credentials.py b/openstack-scripts/credentials.py
new file mode 100644
index 0000000..a9b640c
--- /dev/null
+++ b/openstack-scripts/credentials.py
@@ -0,0 +1,46 @@
+"""
+Description: This script is to map the environment variables to credentials \
+ dict based on the client service API
+Developer: gopal@onecloudinc.com
+"""
+
+from config import OS_USERNAME, OS_TENANT_NAME, OS_PASSWORD, OS_AUTH_URL
+
+
+def get_credentials():
+ """
+ This method is used for authorization with keystone clients
+ """
+
+ data = {}
+ data['username'] = OS_USERNAME
+ data['password'] = OS_PASSWORD
+ data['auth_url'] = OS_AUTH_URL
+ data['tenant_name'] = OS_TENANT_NAME
+ return data
+
+
+def get_nova_credentials():
+ """
+ This method is used for authorization with nova clients
+ """
+
+ data = {}
+ data['username'] = OS_USERNAME
+ data['api_key'] = OS_PASSWORD
+ data['auth_url'] = OS_AUTH_URL
+ data['project_id'] = OS_TENANT_NAME
+ return data
+
+
+def get_tenant_nova_credentials(tenant_name):
+ """
+ This method is used for tenant authorization with nova clients
+ """
+
+ data = {}
+ data['username'] = OS_USERNAME
+ data['api_key'] = OS_PASSWORD
+ data['auth_url'] = OS_AUTH_URL
+ data['project_id'] = tenant_name
+ return data
diff --git a/openstack-scripts/credentials.pyc b/openstack-scripts/credentials.pyc
new file mode 100644
index 0000000..35cab1a
Binary files /dev/null and b/openstack-scripts/credentials.pyc differ
diff --git a/openstack-scripts/destroy_deploy.py b/openstack-scripts/destroy_deploy.py
new file mode 100644
index 0000000..3727a54
--- /dev/null
+++ b/openstack-scripts/destroy_deploy.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+
+"""
+Description: This script is to destory the L3/HA scale test deployment
+Developer: gopal@onecloudinc.com
+"""
+
+import os
+from neutronclient.v2_0 import client
+from keystoneclient.v2_0 import client as ksclient
+from credentials import get_credentials
+from config import TENANT_BASE_INDEX, TENANT_COUNT, TENANT_NAME_PREFIX, \
+ print_scale_test_config
+from networks import delete_network
+from tenants import delete_tenant
+from datetime import datetime, timedelta
+from pytz import timezone
+
+credentials = get_credentials()
+neutron = client.Client(**credentials)
+keystone = ksclient.Client(**credentials)
+fmt = "%Y-%m-%d %H:%M:%S %Z%z"
+
+
+def main():
+ """
+ This method will destory the scale test deployment based on the global \
+ config parameters mentioned on config.py file and creates the router with \
+ external gateway connectivity to public network.
+ """
+
+ print "\n"
+ print_scale_test_config()
+ print "\n"
+ print "Destroying Scale Test Deployment"
+ index = TENANT_BASE_INDEX
+ for i in range(1, TENANT_COUNT + 1):
+ tenant_name = TENANT_NAME_PREFIX + '-' + str(index)
+ index += 1
+ start_time = datetime.now(timezone('US/Pacific'))
+ try:
+ tenant = keystone.tenants.find(name=tenant_name)
+ delete_network(tenant_name)
+ delete_tenant(tenant_name)
+ except Exception:
+ print "\n"
+ print(" - Tenant Not Found: %s" % tenant_name)
+ pass
+ end_time = datetime.now(timezone('US/Pacific'))
+ print "\n"
+ print "-"*65
+ print (" Tenant & User Deletion Time Summary :")
+ print "-"*65
+ print "\n"
+ print(' - Test Started Time :\t %s' % (start_time.strftime(fmt)))
+ print(' - Test Ended Time :\t %s' % (end_time.strftime(fmt)))
+
+ print "=" * 50
+ print "\n"
+ print "Cleaned Scale Test Deployment"
+ print "\n"
+
+
+if __name__ == '__main__':
+ main_start_time = datetime.now(timezone('US/Pacific'))
+ main()
+ main_end_time = datetime.now(timezone('US/Pacific'))
+ total_time = (main_end_time - main_start_time)
+ print "-"*65
+ print (" Scale Test Deployment Consolidated Time Summary :")
+ print "-"*65
+ print "\n"
+ print(' - Test Started Time :\t %s' % (main_start_time.strftime(fmt)))
+ print(' - Test Ended Time :\t %s' % (main_end_time.strftime(fmt)))
+ print(' - Elapsed Time for Cleaned Scale Test Deployment: %d days, %d hours, %d minutes, %d seconds' % (total_time.days, (total_time.seconds/3600), (total_time.seconds % 3600 / 60), (total_time.seconds % 60)))
+ print "\n"
diff --git a/openstack-scripts/discover_deploy.py b/openstack-scripts/discover_deploy.py
new file mode 100644
index 0000000..e2dcaa0
--- /dev/null
+++ b/openstack-scripts/discover_deploy.py
@@ -0,0 +1,281 @@
+#!/usr/bin/env python
+
+"""
+Description: This script is to initialize the L3/HA scale test deployment
+Developer: gopal@onecloudinc.com
+"""
+import pdb
+import os
+from neutronclient.v2_0 import client
+from credentials import get_credentials
+from config import TENANT_BASE_INDEX, NETWORK_COUNT, \
+ EXTERNAL_NETWORK, print_scale_test_config, DEPLOYMENT_ID, \
+ ASR_HOST, ASR_USER, ASR_PASSWORD, ENABLE_ASR_VERIFICATION, TENANT_COUNT, \
+ TENANT_NAME_PREFIX, TENANT_NAME, TENANT_CREATION, VM_COUNT
+from tenants import create_tenant, discover_tenant
+from networks import create_network
+from vm_instances import discover_vm_on_network
+from prettytable import PrettyTable
+
+credentials = get_credentials()
+neutron = client.Client(**credentials)
+
+
+def print_tenant_info(tenant_data):
+
+ x = PrettyTable(['Tenant Name', 'Status'])
+ x.align["Tenant Name"] = "l" # Left align source tenant values
+ x.padding_width = 1
+ for entry in tenant_data:
+ x.add_row([entry['tenant_name'], entry['status']])
+ return x
+
+def print_discovered_tenant(tenant_data,router_data,test_data):
+ pdb.set_trace()
+ y=PrettyTable(['Tenant Name','Router Name','Network Name','Network CIDR'])
+ y.padding_width=1
+ for x in tenant_data:
+ for z in router_data:
+ for a in test_data:
+
+ y.add_row([x['tenant_name'],z['router_name'],a['network_data']['network_name'],a['network_data']['network_cidr']])
+ return y
+
+def print_consolidated_count(test_count):
+ pdb.set_trace()
+ y=PrettyTable(['Tenant Count','Router Count','Network Count','VM Count'])
+ y.padding_width=1
+ for i in test_count:
+ y.add_row([i['tenant_count'],i['router_count'],i['network_count']])
+ return y
+def print_router_info(router_data):
+ x = PrettyTable(['Tenant Name', 'Router Name', 'Status'])
+ x.align["Tenant Name"] = "l" # Left align source tenant values
+ x.padding_width = 1
+ for entry in router_data:
+ x.add_row([entry['tenant_name'], entry['router_name'],
+ entry['router_status']])
+ return x
+
+
+def print_network_info(test_data):
+ y = PrettyTable(['Tenant Name', 'Network Name', 'Network CIDR',
+ 'Vlan ID', 'Subnet Name', 'Status'])
+ y.align["Tenant_Name"] = "l" # Left align source tenant values
+ y.padding_width = 1
+ for entry in test_data:
+ y.add_row([entry['network_data']['tenant_name'],
+ entry['network_data']['network_name'],
+ entry['network_data']['network_cidr'],
+ entry['network_data']['network_vlan_id'],
+ entry['network_data']['subnet_name'],
+ entry['network_data']['status']])
+ return y
+
+
+def print_instance_info(test_data):
+
+ z = PrettyTable(['Tenant Name', 'Instance Name', 'Status'])
+ z.align["Tenant Name"] = "l" # Left align source tenant values
+ z.padding_width = 1
+ for data in test_data:
+ for ins in data['instance_data']:
+ z.add_row([data['network_data']['tenant_name'],
+ ins['instance_name'],
+ ins['status']])
+ return z
+
+
+
+
+
+
+def main():
+ """
+ This method will initialize the scale test deployment based on the global \
+ config parameters mentioned on config.py file and creates the router with \
+ external gateway connectivity to public network.
+ """
+
+ tenant_data = []
+ router_data = []
+ test_data = []
+ test_count={}
+ if TENANT_CREATION == True:
+ print "\n"
+ print_scale_test_config()
+ print "\n"
+ pdb.set_trace()
+ print "Starting Scale Test Deployment"
+ index = TENANT_BASE_INDEX
+ for i in range(1, TENANT_COUNT + 1):
+ tenant_name = TENANT_NAME_PREFIX + '-' + str(index)
+ index += 1
+ try:
+ tenant_data.append(create_tenant(tenant_name))
+ except Exception as exc:
+ print "Exception occured on Tenant Creation: %s" % (exc.message)
+ pass
+ test_count["tenant_count"]=len(tenant_data)
+ for tenant in tenant_data:
+
+ #test= {'count': {'tenant_count': len(tenant_data)}}
+ #test_count.append(test)
+ router_dict = {}
+ prefix = tenant['tenant_name']
+ router_name = prefix + '-router'
+ router_dict['tenant_name'] = tenant['tenant_name']
+ router_dict['router_name'] = router_name
+ router_dict['network_vlan'] = {}
+ router_dict['router_detail'] = {}
+ router_dict['ipnatpool_data'] = {}
+ router_dict['iproute_data'] = {}
+ router_dict['interface_data'] = []
+ router_dict['nat_data'] = []
+
+ router = neutron.list_routers(name=EXTERNAL_NETWORK)['routers']
+ if not router:
+ router_info = neutron.create_router({'router': {
+ 'name': router_name, 'tenant_id': tenant['tenant_id']}})
+ router = router_info['router']
+ status = True
+ elif router[0]['tenant_id'] == tenant['tenant_id']:
+ router = router[0]
+ status = True
+ else:
+ router = {}
+ status = False
+
+ router_dict['router_status'] = status
+ networks = neutron.list_networks(name=EXTERNAL_NETWORK)
+ network_id = networks['networks'][0]['id']
+ neutron.add_gateway_router(router['id'],
+ {'network_id': network_id,
+ 'tenant_id': tenant['tenant_id']})
+ router_id = router['id']
+ print(' - Created Router %s' % router['name'])
+
+ for i in range(1, NETWORK_COUNT + 1):
+ network_index = str(i)
+ network_cidr = str(i) + "." + str(i) + "." + str(i) + ".0/24"
+ test_data.append(create_network(tenant, router,
+ network_index, network_cidr))
+ network_vlan = {}
+ for entry in test_data:
+ network_vlan[str(entry['network_data']['network_vlan_id'])] = \
+ entry['network_data']['network_name']
+ router_dict['network_vlan'] = network_vlan
+
+ else:
+ print "\n"
+ print "=" * 50
+ print "Discovering Tenant Topology on Scale Test Deployment"
+ print "=" * 50
+ try:
+ pdb.set_trace()
+ for i in range(len(TENANT_NAME)):
+ tenant_name = TENANT_NAME[i]
+ tenant_data.append(discover_tenant(tenant_name))
+ #test= {'count': {'tenant_count': len(tenant_data)}}
+ #test_count.append(test)
+
+ for tenant in tenant_data:
+ router_dict = {}
+ prefix = tenant['tenant_name']
+ router_name = prefix + '-router'
+ router_dict['tenant_name'] = tenant['tenant_name']
+ router_dict['tenant_id'] = tenant['tenant_id']
+ router_dict['router_name'] = router_name
+ router_dict['network_vlan'] = {}
+ router_dict['router_detail'] = {}
+ router_dict['ipnatpool_data'] = {}
+ router_dict['iproute_data'] = {}
+ router_dict['interface_data'] = []
+ router_dict['nat_data'] = []
+ pdb.set_trace()
+ router = neutron.list_routers(name=router_name)['routers'][0]
+ if router['tenant_id'] == tenant['tenant_id']:
+ print(' - Router %s Discovered' % router_name)
+ status = True
+ else:
+ print(' - Router %s Not Found' % router_name)
+ status = False
+ router_id = router['id']
+ router_dict['router_status'] = status
+ router_data.append(router_dict)
+ #test1= {'count': {'router_count': len(router_data)}}
+ #test_count.append(test1)
+ test_count["router_count"]=len(router_data)
+ for i in range(1, NETWORK_COUNT + 1):
+ network_index = str(i)
+ network_cidr = str(i) + "." + str(i) + "." + str(i) + ".0/24"
+ network_name = prefix + '-net-' + network_index
+ subnet_name = prefix + "-subnet-" + network_index
+ ins_data = []
+ networks = neutron.list_networks(name=network_name)['networks']
+ for i in range(len(networks)):
+ if networks[i]['tenant_id'] == tenant['tenant_id']:
+ network_id = networks[i]['id']
+ network_vlan = networks[i]['provider:segmentation_id']
+ print(' - Network %s Discovered' % network_name)
+ print(' - Network ID %s Discovered' % network_id)
+ print(' - VLAN ID %s Discovered' % network_vlan)
+ status = True
+ for j in range(1, VM_COUNT + 1):
+ vm_name = network_name + '-vm-' + str(j)
+ ins_data.append(discover_vm_on_network(tenant['tenant_name'], vm_name, network_id))
+ else:
+ print(' - Network %s Not Found' % network_name)
+ status = False
+
+ result = {'network_data': {'tenant_name': tenant['tenant_name'],
+ 'network_name': network_name,
+ 'network_cidr': network_cidr,
+ 'subnet_name': subnet_name,
+ 'network_id': network_id,
+ 'network_vlan_id': network_vlan,
+ 'status':status},
+ 'instance_data': ins_data}
+ test_data.append(result)
+ test_count["network_count"]=test_data
+
+ except Exception:
+ print "\n"
+ print(' - Tenant %s Not Found' % tenant_name)
+
+
+ print "\n"
+ print "=" * 50
+ print "Scale Test Discovery Completed"
+ print "=" * 50
+
+ print "*" * 80
+ print "Scale Test Deployment OpenStack Report"
+ print "*" * 80
+
+ print "\n"
+ print " Tenant Discovery Results "
+ print print_tenant_info(tenant_data)
+ print "\n"
+ print " Router Discovery Results "
+ print print_router_info(router_data)
+ print "\n"
+ print " Network Discovery Results "
+ print print_network_info(test_data)
+ print "\n"
+
+ print " Instance Discovery Results "
+ print print_instance_info(test_data)
+ print "\n"
+
+ print " Tenant Name, Router Name, Network Name "
+ print print_discovered_tenant(tenant_data,router_data,test_data)
+ print "\n"
+
+ print" Overall Count of resources"
+ print print_consolidated_count(test_count)
+
+
+
+if __name__ == '__main__':
+ main()
diff --git a/openstack-scripts/discovery.py b/openstack-scripts/discovery.py
new file mode 100644
index 0000000..6806b50
--- /dev/null
+++ b/openstack-scripts/discovery.py
@@ -0,0 +1,252 @@
+import pdb
+import subprocess
+
+from netaddr import *
+from neutronclient.v2_0 import client
+import novaclient.v1_1.client as nvclient
+
+from credentials import get_credentials,get_tenant_nova_credentials
+
+from vm_instances import discover_vm_on_network,launch_vm_on_network,vm_endpoint_discovery
+from networks import delete_networks,delete_vm
+credentials = get_credentials()
+neutron = client.Client(**credentials)
+tenant_data=[]
+router_data=[]
+network_dict={}
+network_data=[]
+
+def tenant_discovery():
+ pdb.set_trace()
+ tenant_data = [{'id': u'79bb772c47c24744853824305c796ea7','name': u'admin'}]
+ network_data=network_discovery(tenant_data)
+
+# discover_instance(tenant_data)
+ #launch_instance(tenant_data,network_data)
+ endpoints=endpoint_discovery(tenant_data,network_data)
+ print endpoints
+# destroy_all(tenant_data,network_data)
+
+def get_ip_range():
+
+ ips=IPRange("1.1.1.0","1.1.1.254")
+ return ips
+
+def endpoint_discovery(tenant_data,network_data):
+ pdb.set_trace()
+ instance_list=[]
+ endpoint_list=[]
+ final_data=[]
+
+ for tenant in tenant_data:
+ print("Get router information")
+ routers=get_router(tenant)
+ ports=get_ports(tenant)
+ instance_ports = get_instance_ports(ports)
+ for router in routers:
+ router_detail = {}
+ router_detail['id'] = router['id']
+ router_detail['ports'] = get_router_ports(router, ports)
+ subnets = []
+ instance_list = []
+ for port in router_detail['ports']:
+
+ subnets.append(get_port_subnets(tenant, port))
+ router_detail['subnets'] = subnets
+ for subnet in router_detail['subnets']:
+ if subnet['id'] != '':
+ endpoint_detail = get_subnet_endpoints(tenant, instance_ports, subnet)
+ ip_list = []
+ subnet['instances'] = endpoint_detail
+ for entry in endpoint_detail:
+ server = get_instance_detail(tenant['name'],entry['device_id'])
+ if entry['device_id'] not in instance_list and \
+ server.status == 'ACTIVE':
+ ips=get_ip_range()
+ ip_list.append(entry['ip_address'])
+
+ ipset=IPSet(ip_list)
+ for ip in ips:
+ if ip in ipset:
+ print("instance %s found"%(entry['ip_address']))
+ instance_list.append(entry['device_id'])
+ endpoint_list.append({'endpoints': ip_list,'tenant_name':tenant['name'],'subnet':subnet})
+
+ return endpoint_list
+
+def get_instance_detail(tenant,instance):
+
+ tenant_credentials = get_tenant_nova_credentials(tenant)
+ nova = nvclient.Client(**tenant_credentials)
+ return nova.servers.get(instance)
+
+def get_router_ports(router,ports):
+
+ router_port_list = []
+ for port in ports:
+ if (port['device_id'] == router['id'] and
+ port['device_owner'] == 'network:router_interface'):
+ router_port_list.append(port)
+ return router_port_list
+
+def get_port_subnets(tenant,port):
+
+ subnet = get_subnet_detail(tenant, port['fixed_ips'][0]['subnet_id'])['subnet']
+ return {'id': port['fixed_ips'][0]['subnet_id'], 'name': subnet['name'],
+ 'ip_address': port['fixed_ips'][0]['ip_address'],'allocation_pool':subnet['allocation_pools']}
+
+def get_subnet_detail(tenant, subnet):
+
+ return neutron.show_subnet(subnet)
+
+def get_subnet_endpoints(tenant,ports,subnet):
+
+ endpoints = []
+ for port in ports:
+ endpoint_detail = {}
+ if port['fixed_ips'][0]['subnet_id'] == subnet['id']:
+ device_id = port['device_id'].encode('unicode_escape')
+ ip = port['fixed_ips'][0]['ip_address'].encode('unicode_escape')
+ endpoint_detail['device_id'] = device_id
+ endpoint_detail['ip_address'] = ip
+ endpoints.append(endpoint_detail)
+ return endpoints
+
+
+def get_router(tenant):
+ routers=neutron.list_routers(tenant_id=tenant['id'])['routers']
+ return routers
+def get_ports(tenant):
+ ports=neutron.list_ports(tenant_id=tenant['id'])['ports']
+ return ports
+
+def get_instance_ports(ports):
+ pdb.set_trace()
+ instance_port_list = []
+ for port in ports:
+ if port['device_owner'] == 'compute:nova' or port['device_owner'] == 'compute:compute' :
+ instance_port_list.append(port)
+ return instance_port_list
+
+def destroy_all(tenant_data,network_data):
+
+ delete_vm(tenant_data,network_data)
+ delete_networks(tenant_data,network_data)
+
+def network_discovery(tenant_data):
+ pdb.set_trace()
+ network_detail=[]
+ subnet_detail=[]
+ instance_list=[]
+ net_sub={}
+ for tenant in tenant_data:
+
+ networks=neutron.list_networks(tenant_id=tenant['id'])['networks']
+
+
+# List all subnets under each network and the tenants
+ for net in networks:
+ nets={}
+ if net['tenant_id'] == tenant['id']:
+ nets={'network_list':{'tenant_name':tenant['name'],
+ 'network_name':net['name'],'network_id':net['id'],'shared':net['shared'],'subnets':net['subnets']}}
+ subnets=neutron.list_subnets(network_id=net['id'])['subnets']
+ for subnet in subnets:
+ #net_sub={'networks':{'tenant_name':tenant['name'],'network_name':net['name'],'network_id':net['id'],'shared':net['shared']},'subnets':{'subnet_name':subnet['name'],'cidr':subnet['cidr']}}
+ net_sub={'networks':{'tenant_name':tenant['name'],'network_name':net['name'],'network_id':net['id'],'shared':net['shared'],'subnet_name':subnet['name'],'cidr':subnet['cidr']}}
+
+ subnet_detail.append(net_sub)
+ print "\n"
+ print "List subnets along with network details"
+ print "tenant name %s"%(tenant['name'])
+ print "network_name %s"%(net['name'])
+ print "subnet_name %s"%(subnet['name'])
+ print "cidr\t %s"%(subnet['cidr'])
+ print "allocation pools...%s"%(subnet['allocation_pools'])
+ print "\n"
+
+ network_detail.append(nets)
+
+ return network_detail
+
+def launch_instance(tenant_data,network_data):
+ #pdb.set_trace()
+ inst_data=[]
+ count=1
+ for tenant in tenant_data:
+
+ for network in network_data:
+ pdb.set_trace()
+ vm_name=tenant['name'] + '-vm-' + str(count)
+ if ((network['network_list']['tenant_name'] == tenant['name']) and (network['network_list']['shared'] == True)):
+
+ inst_data.append(launch_vm_on_network(tenant['name'],vm_name,network['network_list']['network_id']))
+
+ count += 1
+
+def discover_instance(tenant_data):
+ instance_detail=[]
+ pdb.set_trace()
+ for tenant in tenant_data:
+
+ vm_dict={}
+ instance_detail.append(discover_vm_on_network(tenant['name']))
+ print instance_detail
+
+
+def router_discovery(tenant_data):
+ #pdb.set_trace()
+ for tenant in tenant_data:
+ #router_dict = {}
+ router=neutron.list_routers(tenant_id=tenant['id'])['routers']
+ for route in router:
+
+ router_dict={}
+ #for rout in router:
+
+ if route['tenant_id'] == tenant['id']:
+ print(' - Router %s Discovered' % route['name'])
+ status = True
+ router_id = route['id']
+ router_dict['tenant_name']=tenant["name"]
+ router_dict['router_status'] = status
+ router_dict['router_name']=route['name']
+ router_data.append(router_dict)
+
+ else:
+ print("Tenant %s not having any router"%(tenant['name']))
+ #if rout['tenant_id'] == tenant['id']:
+ #print(' - Router %s Discovered' % rout['name'])
+ #status = True
+ #router_id = rout['id']
+ #router_dict['tenant_name']=tenant["name"]
+ #router_dict['router_status'] = status
+ #router_dict['router_name']=rout['name']
+
+ else:
+ print(' - Router Not Found in %s tenant' % tenant['name'])
+ status = False
+ #router_id = rout['id']
+ #router_dict['router_status'] = status
+ #router_data.append(router_dict)
+
+
+ #router_id = router['id']
+ #router_dict['router_status'] = status
+ #router_data.append(router_dict)
+
+ print router_data
+
+def main():
+
+ tenant_discovery()
+
+
+
+
+
+
+
+if __name__ == '__main__':
+
+ main()
diff --git a/openstack-scripts/discovery.pyc b/openstack-scripts/discovery.pyc
new file mode 100644
index 0000000..4191812
Binary files /dev/null and b/openstack-scripts/discovery.pyc differ
diff --git a/openstack-scripts/floating_ips.py b/openstack-scripts/floating_ips.py
new file mode 100644
index 0000000..2ff4ded
--- /dev/null
+++ b/openstack-scripts/floating_ips.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+"""
+Description: This script is to allocate & associate the floating IP.
+Developer: gopal@onecloudinc.com
+"""
+
+import pdb
+from neutronclient.v2_0 import client
+import novaclient.v1_1.client as nvclient
+from credentials import get_credentials, get_nova_credentials, \
+ get_tenant_nova_credentials
+from config import FLOATING_IP_POOL
+
+neutron_credentials = get_credentials()
+credentials = get_nova_credentials()
+neutron = client.Client(**neutron_credentials)
+nova = nvclient.Client(**credentials)
+
+#if not nova.keypairs.findall(name="admin"):
+ #with open(os.path.expanduser('~/.ssh/id_rsa.pub')) as fpubkey:
+ #nova.keypairs.create(name="admin", public_key=fpubkey.read())
+
+
+def add_floating_ip_for_vm(tenant_name, instance):
+ """
+ This method is used to allocate & associate floating IP to the given VM\
+ based on the availability from the defined pool.
+ """
+ tenant_credentials = get_tenant_nova_credentials(tenant_name)
+ pdb.set_trace()
+ nova = nvclient.Client(**tenant_credentials)
+ floating_ip = nova.floating_ips.create(FLOATING_IP_POOL)
+ instance.add_floating_ip(floating_ip)
+ print " - Assigned Floating IP: " + str(floating_ip.ip)
+ return True
+
+
+def release_all_floating_ips():
+ """
+ This method is used to release all the disallocated floating IPs.
+ """
+ floating_ips = neutron.list_floatingips()['floatingips']
+ try:
+ for ip in floating_ips:
+ neutron.delete_floatingip(ip['id'])
+ except:
+ pass
+ return True
diff --git a/openstack-scripts/floating_ips.pyc b/openstack-scripts/floating_ips.pyc
new file mode 100644
index 0000000..e20bcd4
Binary files /dev/null and b/openstack-scripts/floating_ips.pyc differ
diff --git a/openstack-scripts/main.py b/openstack-scripts/main.py
new file mode 100644
index 0000000..e5acd04
--- /dev/null
+++ b/openstack-scripts/main.py
@@ -0,0 +1,7 @@
+import pdb
+from discovery import *
+def main():
+ tenant_discovery()
+
+if __name__ == '__main__':
+ main()
diff --git a/openstack-scripts/networks.py b/openstack-scripts/networks.py
new file mode 100644
index 0000000..befd00e
--- /dev/null
+++ b/openstack-scripts/networks.py
@@ -0,0 +1,178 @@
+#!/usr/bin/env python
+"""
+Description: This script is to create network, subnets, router with \
+ external gateway mapping.
+Developer: gopal@onecloudinc.com
+"""
+import pdb
+import os
+from neutronclient.v2_0 import client
+from credentials import get_credentials
+from config import NETWORK_COUNT, VM_COUNT, FLOATING_IP_CREATION
+from vm_instances import launch_vm_on_network, terminate_vm_on_network
+from floating_ips import release_all_floating_ips
+from datetime import datetime, timedelta
+from pytz import timezone
+
+credentials = get_credentials()
+neutron = client.Client(**credentials)
+fmt = "%Y-%m-%d %H:%M:%S %Z%z"
+
+
+def create_network(tenant, router, network_index, network_cidr):
+ """
+ This method is used to create network, subnets, interfaces on router with \
+ external gateway mapping for the given network name and CIDR.
+ """
+
+ try:
+ prefix = tenant['tenant_name']
+ network_name = prefix + '-net-' + network_index
+ print "\n"
+ print "=" * 50
+ print " Initiated Network Creation for " + network_name
+ print "=" * 50
+ print "\n"
+
+ body_sample = {'network': {'name': network_name,
+ 'tenant_id': tenant['tenant_id']}}
+ start_time = datetime.now(timezone('US/Pacific'))
+ try:
+ net = neutron.create_network(body=body_sample)
+ net_dict = net['network']
+ network_id = net_dict['id']
+ network_vlan = net_dict['provider:segmentation_id']
+ print(' - Network %s created' % net_dict['name'])
+ net_status = True
+ except Exception:
+ net_dict = {}
+ net_status = False
+
+ subnet_name = prefix + "-subnet-" + network_index
+ try:
+ tenant_id = tenant['tenant_id']
+ body_create_subnet = {'subnets': [{'name': subnet_name,
+ 'cidr': network_cidr,
+ 'ip_version': 4,
+ 'network_id': network_id,
+ 'tenant_id': tenant_id}]}
+ subnet_detail = neutron.create_subnet(body=body_create_subnet)
+ subnet = subnet_detail['subnets'][0]
+ print(' - Created subnet %s' % subnet['name'])
+ net_status = True
+ except Exception:
+ subnet = {}
+ net_status = False
+
+ neutron.add_interface_router(router['id'], {'subnet_id': subnet['id'],
+ 'tenant_id': tenant['tenant_id']})
+ print (' - Created interface between %s' % subnet['name'])
+ finally:
+ print "\n"
+ msg = "<== Completed Network Creation with External Gateway "
+ msg += "Successfully ==>"
+ print msg
+ end_time = datetime.now(timezone('US/Pacific'))
+ print "\n"
+ print "-"*65
+ print (" Network %s Creation Time Summary :" % network_name)
+ print "-"*65
+ print "\n"
+ print(' - Test Started Time :\t %s' % (start_time.strftime(fmt)))
+ print(' - Test Ended Time :\t %s' % (end_time.strftime(fmt)))
+
+ print "\n"
+ print "=" * 50
+ print " Initiated VM Deployment " + network_name
+ print "=" * 50
+ print "\n"
+
+ ins_data = []
+ for i in range(1, VM_COUNT + 1):
+ vm_name = network_name + '-vm-' + str(i)
+ start_time = datetime.now(timezone('US/Pacific'))
+ ins_data.append(launch_vm_on_network(tenant['tenant_name'],
+ vm_name, network_id))
+ end_time = datetime.now(timezone('US/Pacific'))
+
+ print "\n"
+ msg = "<== Completed VM Launch on Network with Floating IP Allocation "
+ msg += "Successfully ==>"
+ print msg
+ print "\n"
+ print "-"*65
+ print (" Instance %s Creation Time Summary :" % vm_name)
+ print "-"*65
+ print "\n"
+ print(' - Test Started Time :\t %s' % (start_time.strftime(fmt)))
+ print(' - Test Ended Time :\t %s' % (end_time.strftime(fmt)))
+
+ result = {'network_data': {'tenant_name': tenant['tenant_name'],
+ 'network_name': network_name,
+ 'network_cidr': network_cidr,
+ 'subnet_name': subnet_name,
+ 'network_id': network_id,
+ 'network_vlan_id': network_vlan,
+ 'status': net_status},
+ 'instance_data': ins_data}
+ return result
+
+
+def delete_vm(tenant_data,network_data):
+ """
+ This method is used to delete vms, network, subnets, interfaces on router \
+ with external gateway mapping for the given network name and CIDR.
+ """
+ pdb.set_trace()
+ #prefix = tenant_name
+ network_list = []
+ router_list = []
+ count=1
+ #router_list.append(prefix + '-router')
+ #for i in range(1, NETWORK_COUNT + 1):
+ #network_list.append(prefix + '-net-' + str(i))
+ for tenant in tenant_data:
+ for network in network_data:
+ vm_name=tenant['name'] + '-vm-' + str(count)
+ if ((network['network_list']['tenant_name'] == tenant['name']) and (network['network_list']['shared'] == False)):
+
+
+ terminate_vm_on_network(tenant['name'], vm_name,network['network_list']['network_id'])
+ count += 1
+
+ release_all_floating_ips()
+def delete_networks(tenant_data,network_data):
+ pdb.set_trace()
+ networks=None
+ for tenant in tenant_data:
+ networks=neutron.list_networks(tenant_id=tenant['id'])['networks']
+ routers=neutron.list_routers(tenant_id=tenant['id'])['routers']
+ subnets=neutron.list_subnets(tenant_id=tenant['id'])['subnets']
+
+
+ for router in routers:
+ ports=neutron.list_ports(tenant_id=tenant['id'])['ports']
+ for port in ports:
+ #for subnet in subnets:
+ if (port['device_id'] == router['id'] and port['device_owner'] == 'network:router_interface'):
+ neutron.remove_interface_router(router['id'],{'subnet_id':port['fixed_ips'][0]['subnet_id']})
+ neutron.remove_gateway_router(router['id'])
+ neutron.delete_network(port['network_id'])
+ neutron.delete_router(router['id'])
+ #neutron.delete_network(network['id'])
+
+ #for network in networks:
+ #neutron.delete_network(network['id'])
+
+ #for subnet in subnets:
+ #for network in networks:
+
+
+
+
+
+ #if FLOATING_IP_CREATION:
+ #release_all_floating_ips()
+ #print "\n"
+ #print("<== Released all Floating IPs Successfully ==>")
+ #return True
diff --git a/openstack-scripts/networks.pyc b/openstack-scripts/networks.pyc
new file mode 100644
index 0000000..1b064ab
Binary files /dev/null and b/openstack-scripts/networks.pyc differ
diff --git a/openstack-scripts/openstack_clean_script.py b/openstack-scripts/openstack_clean_script.py
new file mode 100644
index 0000000..bb04cd1
--- /dev/null
+++ b/openstack-scripts/openstack_clean_script.py
@@ -0,0 +1,158 @@
+import logging
+import pprint
+from novaclient import client as novclient
+from neutronclient.v2_0 import client as nclient
+import time
+import pdb
+import MySQLdb
+from keystoneclient.v2_0 import client as kclient
+def main():
+ net_list=['NET-A','NET-B','NET-C']
+ ext_net_list=['EXT-NET-A','EXT-NET-B']
+ ext_subnet_list=[]
+ flavor_list={}
+
+ router_list=['Router-A','Router-B']
+ subnet_list={'subnets':[{'name':'Subnet-A','network_id':'','ip_version':4,'cidr':'1.1.1.0/24'},{'name':'Subnet-B','network_id':'','ip_version':4,'cidr':'2.2.2.0/24'}]}
+ count = 0
+ instance_detail={}
+ networks={}
+ logging.basicConfig(level=logging.INFO)
+ logger=logging.getLogger(__name__)
+ logger.info("Keystone authentication started....")
+ time.sleep(5)
+ logger.info("Wait for 5 seconds...")
+ logger.info("done")
+ neutr=nclient.Client(username='admin',password='admin',tenant_name='admin',auth_url='http://192.168.1.12:5000/v2.0/')
+ novactr=novclient.Client('2',username='admin',api_key='admin',project_id='admin',auth_url='http://192.168.1.12:5000/v2.0/')
+ logger.info("Authentication success...")
+ #logger.info("getting input from user....")
+ #network_count=int(raw_input("Enter the no of network to created >>\t"))
+ #ext_network_count=int(raw_input("Enter the no of External network to be created >> \t"))
+ #instance_detail['name']=raw_input("Please provide name for instance")
+ #flavor_id=int(raw_input("Provide the flavor for the instance"))
+ #netw=neutr.list_networks()
+ #print netw
+ #ss=db_connection(flavor_list,novactr)
+ #us=ss.get(flavor_id)
+ #if us:
+ #logger.info("You choose %s flavor"%(us))
+ #else:
+ #logger.info("The flavor u choose is doesn't exists..")
+ #exit
+ #create_network(neutr,network_count,logger,net_list,count,subnet_list,novactr,flavor_id)
+ delete_network(neutr,novactr,logger,net_list,subnet_list)
+
+def create_network(neutr,network_count,logger,net_list,count,subnet_list,novactr,flavor_id):
+ pdb.set_trace()
+ logger.info("Start creating external network ")
+ ext_network=neutr.create_network({'network':{'name':'EXT-NET','admin_state_up':'True','router:external':'True'}})
+ ext_id=ext_network['network']['id']
+ vm_list=['vm-1','vm-2']
+ logger.info("Creating external network subnet...")
+ ext_subnet=neutr.create_subnet({'subnet':{'name':'EXT_subnet','network_id':ext_id,'ip_version':4,'cidr':'6.6.8.8/24'}})
+ time.sleep(2)
+ logger.info("creating router")
+ router1=neutr.create_router({'router':{'name':'Router-1','admin_state_up':'True'}})
+ router_id=router1['router']['id']
+ neutr.add_gateway_router(router_id,{'network_id':ext_id})
+
+ while count < network_count:
+
+ neut=neutr.create_network({'network':{'name':net_list[count],'admin_state_up':'True'}})
+ if neut:
+ net_id=neut['network']['id']
+ logger.info("Network %s sucessfully created.."%(net_list[count]))
+ time.sleep(4)
+ logger.info("Start creating subnets")
+ #nsub=neutr.create_subnet({'subnet':subnet_list['subnets'][count]})
+ nsub=neutr.create_subnet({'subnet':{'name':subnet_list['subnets'][count]['name'],'network_id':net_id,'ip_version':subnet_list['subnets'][count]['ip_version'],'cidr':subnet_list['subnets'][count]['cidr']}})
+ sub_id=nsub['subnet']['id']
+ if nsub:
+ logger.info("subnet is created for network %s"%(net_list[count]))
+ time.sleep(4)
+ logger.info("Adding interface to router")
+ neutr.add_interface_router(router_id,{'subnet_id':sub_id})
+ time.sleep(5)
+ logger.info("Ready to launch the instances")
+ pdb.set_trace()
+ image = novactr.images.find(name="cirros")
+ print net_id
+ instance = novactr.servers.create(name=vm_list[count], image=image, flavor=flavor_id, nics=[{'net-id':net_id}])
+ logger.info("Instance launched successfully on network %s"%(net_list[count]))
+ time.sleep(4)
+ count = count+1
+ else:
+ logger.info("Error in network creation")
+ time.sleep(3)
+ logger.info("setup is ready for testing..")
+
+def db_connection(flavor_list,novactr):
+ db=MySQLdb.connect(host="localhost",user="root",passwd="dafc1bce95654501",db="nova")
+ cur=db.cursor()
+ cur.execute("select id,name from instance_types")
+ ss=novactr.networks.list()
+ print ss
+ return dict(cur.fetchall())
+
+def delete_network(neutr,novactr,logger,net_list,subnet_list):
+ logger.info("Start cleaning the dashboard")
+ del_net={}
+ server_delete(novactr,logger)
+ delete_interface(neutr,logger)
+ count=0
+
+def server_delete(novactr,logger):
+ #pdb.set_trace()
+ logger.info("Fetching list of servers")
+ myserver=novactr.servers.list()
+ server_len=len(myserver)
+ for i in range(server_len):
+ ss=novactr.servers.delete(myserver[i])
+ if ss:
+ logger.info("Instances %s sucessfully deleted"%myserver[i])
+ time.sleep(1)
+def delete_interface(neutr,logger):
+
+ mynetwork=neutr.list_networks()
+ net_len=len(mynetwork['networks'])
+ myrouter=neutr.list_routers()
+ r_id=myrouter['routers'][0]['id']
+ port_delete(neutr,logger,r_id)
+ my_ports=neutr.list_ports()['ports']
+ port_gateway=[]
+ s=neutr.remove_gateway_router(r_id)
+ if s:
+ logger.info("gateway router is detached successful...")
+ myrouter=neutr.list_routers()['routers']
+ for r in range(len(myrouter)):
+
+ neutr.delete_router(myrouter[r]['id'])
+ logger.info("Deleting networks...")
+ time.sleep(2)
+ for j in range(net_len):
+ dd=neutr.delete_network(mynetwork['networks'][j]['id'])
+
+def port_delete(neutr,logger,r_id):
+ logger.info("listing port details..")
+ myports=neutr.list_ports()['ports']
+ port_list=[]
+ port_gateway=[]
+ for port in myports:
+
+ if (port['device_id'] == r_id and
+ port['device_owner'] == 'network:router_interface'):
+ port_list.append(port)
+ logger.info("Removing router interfaces..")
+
+ for i in range(len(port_list)):
+
+ del_inf=neutr.remove_interface_router(r_id,{'subnet_id':port_list[i]['fixed_ips'][0]['subnet_id']})
+
+#def get_id(novactr,logger):
+ #welcome=novactr.servers.list(413fb5d3-c1bc-4267-80ab-6a27d0cfd04b)
+ #print welcome
+
+
+if __name__ == '__main__':
+ main()
diff --git a/openstack-scripts/requirement.txt b/openstack-scripts/requirement.txt
new file mode 100644
index 0000000..f628b4f
--- /dev/null
+++ b/openstack-scripts/requirement.txt
@@ -0,0 +1,62 @@
+Babel==2.3.3
+cliff==2.0.0
+cmd2==0.6.8
+configobj==5.0.6
+debtcollector==1.3.0
+Django==1.9.2
+django-filters==0.2.1
+django-rest-auth==0.6.0
+djangorestframework==3.3.2
+djangorestframework-jwt==1.7.2
+ecdsa==0.13
+Fabric==1.10.2
+fabtools==0.19.0
+funcsigs==1.0.0
+functools32==3.2.3.post2
+futures==3.0.5
+iso8601==0.1.11
+jsonpatch==1.13
+jsonpointer==1.10
+jsonschema==2.5.1
+keystoneauth1==2.6.0
+logging==0.4.9.6
+Markdown==2.6.5
+monotonic==1.0
+msgpack-python==0.4.7
+multiprocessing==2.6.2.1
+MySQL-python==1.2.5
+netaddr==0.7.18
+netifaces==0.10.4
+ordereddict==1.1
+oslo.config==3.9.0
+oslo.i18n==3.5.0
+oslo.serialization==2.4.0
+oslo.utils==3.8.0
+paramiko==1.15.2
+pbr==1.9.1
+pexpect==4.0.1
+positional==1.0.1
+prettytable==0.7.2
+ptyprocess==0.5.1
+pudb==2015.3
+pycrypto==2.6.1
+Pygments==2.0.2
+PyJWT==1.4.0
+pyparsing==2.1.1
+python-glanceclient==2.0.0
+python-group-based-policy-client==0.9.2
+python-heatclient==0.6.0
+python-keystoneclient==1.6.0
+python-neutronclient==2.6.0
+python-novaclient==2.17.0
+python-swiftclient==2.4.0
+pytz==2016.3
+PyYAML==3.11
+requests==2.9.1
+simplejson==3.8.2
+six==1.10.0
+stevedore==1.12.0
+unicodecsv==0.14.1
+urwid==1.3.0
+warlock==1.2.0
+wrapt==1.10.8
diff --git a/openstack-scripts/samples_test/__init__.py b/openstack-scripts/samples_test/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/openstack-scripts/samples_test/main.py b/openstack-scripts/samples_test/main.py
new file mode 100644
index 0000000..04289ef
--- /dev/null
+++ b/openstack-scripts/samples_test/main.py
@@ -0,0 +1,20 @@
+from multiprocessing import *
+import multiprocessing
+
+def myfunction(a,b,q):
+
+ c = a * b
+ q.put(c)
+
+def main():
+ jobs=[]
+ q = Queue()
+ for i in range(2):
+ p = Process(target=myfunction,args = (2,3,q))
+ jobs.append(p)
+ p.start()
+ print q.get()
+
+
+if __name__ == '__main__':
+ main()
\ No newline at end of file
diff --git a/openstack-scripts/samples_test/main.pyc b/openstack-scripts/samples_test/main.pyc
new file mode 100644
index 0000000..8b0696d
Binary files /dev/null and b/openstack-scripts/samples_test/main.pyc differ
diff --git a/openstack-scripts/t1.py b/openstack-scripts/t1.py
new file mode 100644
index 0000000..a93a8ab
--- /dev/null
+++ b/openstack-scripts/t1.py
@@ -0,0 +1,17 @@
+from keystoneclient.v2_0 import client
+
+
+OS_USERNAME = 'admin'
+OS_TENANT_NAME = 'admin'
+OS_PASSWORD = 'admin'
+OS_AUTH_URL = 'http://172.168.2.40:5000/v2.0/'
+
+keystone = client.Client(username=OS_USERNAME, password=OS_PASSWORD, auth_url=OS_AUTH_URL)
+import pdb
+pdb.set_trace()
+
+tenants = keystone.tenants.list()
+for tenant in tenants:
+ print tenant.__dict__
+
+
diff --git a/openstack-scripts/t2.py b/openstack-scripts/t2.py
new file mode 100644
index 0000000..adb670c
--- /dev/null
+++ b/openstack-scripts/t2.py
@@ -0,0 +1,31 @@
+from neutronclient.v2_0 import client as neutron_client
+
+
+
+OS_USERNAME = 'admin'
+OS_TENANT_NAME = 'admin'
+OS_PASSWORD = 'admin'
+OS_AUTH_URL = 'http://172.168.2.40:5000/v2.0/'
+OS_TENANT_ID = '2931fbe17e8445da875bb915a29d0bbf'
+
+def get_credentials():
+ d = {}
+ d['username'] = OS_USERNAME
+ d['password'] = OS_PASSWORD
+ d['auth_url'] = OS_AUTH_URL
+ d['tenant_id'] = OS_TENANT_ID
+ return d
+
+tenants = [
+ {'id': u'2931fbe17e8445da875bb915a29d0bbf', 'name': u'admin'},
+ {'id': u'2e93f5f662974b1284e8be13dd472e48', 'name': u'demo'},
+ {'id': u'ae9e7941b6764accae72a99662c189a5', 'name': u'tenant-test-101'},
+ {'id': u'be0e4b8dc7754668b0e3d57e4f7f6f66', 'name': u'tenant-test-102'},
+ {'id': u'fbb4907f073d4b5881a85c1692ae027a', 'name': u'services'}
+]
+
+
+credentials = get_credentials()
+neutron = neutron_client.Client(**credentials)
+netw = neutron.list_networks()
+print netw
diff --git a/openstack-scripts/tenant.txt b/openstack-scripts/tenant.txt
new file mode 100644
index 0000000..2ecda20
--- /dev/null
+++ b/openstack-scripts/tenant.txt
@@ -0,0 +1,7 @@
+tenants = [
+ {'id': u'2931fbe17e8445da875bb915a29d0bbf', 'name': u'admin'},
+ {'id': u'2e93f5f662974b1284e8be13dd472e48', 'name': u'demo'},
+ {'id': u'ae9e7941b6764accae72a99662c189a5', 'name': u'tenant-test-101'},
+ {'id': u'be0e4b8dc7754668b0e3d57e4f7f6f66', 'name': u'tenant-test-102'},
+ {'id': u'fbb4907f073d4b5881a85c1692ae027a', 'name': u'services'}
+]
diff --git a/openstack-scripts/tenants.py b/openstack-scripts/tenants.py
new file mode 100644
index 0000000..ed40861
--- /dev/null
+++ b/openstack-scripts/tenants.py
@@ -0,0 +1,145 @@
+#!/usr/bin/env python
+"""
+Description: This script prepares new tenant with the following properties:
+1. Creates new tenant.
+2. Creates new user and this user is added _member_ to tenant. \
+Password is second argument of script
+3. Admin user will be added to tenant with role admin
+Developer: gopal@onecloudinc.com
+"""
+
+import os
+import pdb
+from keystoneclient.v2_0 import client as ksclient
+from credentials import get_credentials
+from config import USER_COUNT, USER_PASSWORD
+
+credentials = get_credentials()
+keystone = ksclient.Client(**credentials)
+assign_admin = True
+
+
+def create_tenant(tenant_name):
+ """
+ This method is used to create tenant and create number of users per tenant
+ """
+
+ print "\n"
+ print "=" * 50
+ print " Initiated Tenant Creation for " + tenant_name
+ print "=" * 50
+ print "\n"
+
+ try:
+ try:
+ new_tenant = keystone.tenants.create(tenant_name=tenant_name,
+ description="Scale tenant \
+ created",
+ enabled=True)
+ print(' - Tenant %s created' % tenant_name)
+ except Exception:
+ new_tenant = keystone.tenants.find(name=tenant_name)
+ tenant_id = new_tenant.id
+ tenant_status = True
+ user_data = []
+ for j in range(USER_COUNT):
+ j += 1
+ user_name = tenant_name + '-user-' + str(j)
+ user_data.append(create_user(user_name, tenant_id))
+ except Exception:
+ tenant_status = False
+
+ print "\n"
+ msg = ('<== Completed Tenant Creation and Users per Tenant '
+ 'with _member_ role ')
+ msg += 'Successfully ==>'
+ print msg
+ print "\n"
+
+ tenant_data = {'tenant_name': tenant_name,
+ 'tenant_id': tenant_id,
+ 'status': tenant_status}
+ return tenant_data
+
+
+def discover_tenant():
+ """
+ This method is used to discover tenant and discover number of users per tenant
+ """
+ global tenant_id,tenant_status
+ try:
+ pdb.set_trace()
+ new_tenant = keystone.tenants.list()
+ tenant_id = new_tenant.id
+ tenant_status = True
+ print "\n"
+ print(' - Tenant %s Discovered' % tenant_name)
+ print(' - Tenant_ID %s Discovered' % tenant_id)
+ except Exception:
+ pass
+
+ tenant_data = {'tenant_name': tenant_name,
+ 'tenant_id': tenant_id,
+ 'status': tenant_status}
+ return tenant_data
+
+
+def create_user(user_name, tenant_id):
+ """
+ This method is to create users per Tenant
+ """
+
+ try:
+ new_user = keystone.users.create(name=user_name,
+ password=USER_PASSWORD,
+ tenant_id=tenant_id)
+ print(' - Created User %s' % user_name)
+ except Exception:
+ new_user = keystone.users.find(name=user_name)
+ member_role = keystone.roles.find(name='_member_')
+ try:
+ keystone.roles.add_user_role(new_user, member_role, tenant_id)
+ except Exception:
+ pass
+ if assign_admin:
+ admin_user = keystone.users.find(name='admin')
+ admin_role = keystone.roles.find(name='admin')
+ try:
+ keystone.roles.add_user_role(admin_user, admin_role, tenant_id)
+ except Exception:
+ pass
+ user_data = {'name': new_user.name,
+ 'id': new_user.id}
+ return user_data
+
+
+def delete_tenant(tenant_name):
+ """
+ This method is used to delete tenant and users
+ """
+
+ try:
+ tenant = keystone.tenants.find(name=tenant_name)
+ for j in range(USER_COUNT):
+ j += 1
+ user_name = tenant_name + '-user-' + str(j)
+ delete_user(user_name, tenant.id)
+ tenant.delete()
+ print(' - Deleted Tenant %s ' % tenant_name)
+ except Exception:
+ pass
+ return True
+
+
+def delete_user(user_name, tenant_id):
+ """
+ This method is to delete users per Tenant
+ """
+ try:
+ user = keystone.users.find(name=user_name)
+ user.delete()
+ except Exception:
+ print(" - User Not Found: %s" % user_name)
+ pass
+ print(' - Deleted User %s' % user_name)
+ return True
diff --git a/openstack-scripts/tenants.pyc b/openstack-scripts/tenants.pyc
new file mode 100644
index 0000000..da06d96
Binary files /dev/null and b/openstack-scripts/tenants.pyc differ
diff --git a/openstack-scripts/user.txt b/openstack-scripts/user.txt
new file mode 100644
index 0000000..9e5d3d9
--- /dev/null
+++ b/openstack-scripts/user.txt
@@ -0,0 +1,7 @@
+#cloud-config
+chpasswd:
+ list: |
+ root:ubuntu
+ ubuntu:ubuntu
+ expire: False
+ssh_pwauth: True
diff --git a/openstack-scripts/vm_instances.py b/openstack-scripts/vm_instances.py
new file mode 100644
index 0000000..5f31854
--- /dev/null
+++ b/openstack-scripts/vm_instances.py
@@ -0,0 +1,178 @@
+#!/usr/bin/env python
+"""
+Description: This script is to launching VMs on the network.
+Developer: gopal@onecloudinc.com
+"""
+
+import os
+import time
+import pdb
+import novaclient.v1_1.client as nvclient
+from novaclient.base import *
+from novaclient.exceptions import NotFound
+from config import FLOATING_IP_CREATION, IMAGE_NAME, FLAVOUR_NAME,OS_USERNAME, OS_TENANT_NAME, OS_PASSWORD, OS_AUTH_URL
+from credentials import get_nova_credentials, get_tenant_nova_credentials,get_credentials
+from floating_ips import add_floating_ip_for_vm
+import glanceclient.v2.client as glance_client
+import keystoneclient.v2_0.client as ksclient
+keystone = ksclient.Client(auth_url="http://172.168.2.62:35357/v2.0",
+ username="admin",
+ password="admin",
+ tenant_name="admin")
+token = keystone.auth_ref['token']['id']
+
+credentials = get_nova_credentials()
+nova = nvclient.Client(**credentials)
+#glance=glance_client.Client(username=OS_USERNAME,password=OS_PASSWORD,tenant_name=OS_TENANT_NAME,auth_url=OS_AUTH_URL)
+glance=glance_client.Client(endpoint="http://172.168.2.62:9292", token=token)
+
+
+#if not nova.keypairs.findall(name="admin"):
+ #ith open(os.path.expanduser('~/.ssh/id_rsa.pub')) as fpubkey:
+ #nova.keypairs.create(name="admin", public_key=fpubkey.read())
+
+def upload_image_glance():
+ #pdb.set_trace()
+ image_list=glance.images.list()
+ image_file="/home/onecloud/NTT/keerthi/ubuntu.img"
+ image=glance.images.create(disk_format="qcow2",container_format="bare",name="ubuntu")
+ print("image status %s"%(image.status))
+ ss=glance.images.upload(image.id,open('/home/onecloud/NTT/keerthi/ubuntu.img','rb'))
+ print("Current Image status <%s>"%(image.status))
+
+ #with open(image_file) as img:
+ #image=glance.images.create(name="ubuntu",disk_format="raw",container_format="bare",data=img)
+
+ #print("Current Image status %s"%(image.status))
+
+
+def launch_vm_on_network(tenant_name, vm_name, network_id):
+ """
+ This method is to launch VM on the given network & VM Name.
+ """
+ pdb.set_trace()
+
+ tenant_credentials = get_tenant_nova_credentials(tenant_name)
+
+ nova = nvclient.Client(**tenant_credentials)
+ nova.quotas.update(tenant_name, instances=-1, cores=-1, ram=-1, fixed_ips=-1, floating_ips=-1)
+ with open('user.txt') as userdata:
+ user_data = userdata.read()
+ try:
+ image_list=nova.images.find(name="cirros-0.3.4-x86_64-uec")
+ except NotFound:
+ upload_image_glance()
+
+ #for img in image:
+ #if img.name == 'ubuntu':
+ #print "image found"
+ try:
+
+ flavor = nova.flavors.find(name='traffic')
+ except:
+ flavor = nova.flavors.create(name="traffic",ram="512",vcpus="1",disk="1")
+ instance=None
+
+ try:
+ pdb.set_trace()
+ instance = nova.servers.create(name=vm_name, image=image_list,
+ flavor=flavor,
+ availability_zone="compute:compute",
+ nics=[{'net-id': network_id}],userdata=user_data)
+ except Exception:
+ pass
+
+ # Poll at 15 second intervals, until the status is no longer 'BUILD'
+ print " * Instance <%s> created on network <%s>: "%(vm_name,str(network_id))
+ status = instance.status
+ while status == 'BUILD':
+ time.sleep(15)
+ # Retrieve the instance again so the status field updates
+ instance = nova.servers.get(instance.id)
+ status = instance.status
+
+ print " - Current status: %s" % status
+ if FLOATING_IP_CREATION:
+ add_floating_ip_for_vm(tenant_name, instance)
+
+ ins_data = {'instance_name': vm_name, 'status': status}
+ return ins_data
+
+#def endpoint_discovery(tenant_data,network_data):
+
+# tenant_credentials = get_tenant_nova_credentials(tenant_name)
+# nova = nvclient.Client(**tenant_credentials)
+# instance_list = nova.servers.list()
+
+
+def vm_endpoint_discovery(tenant_name):
+ pdb.set_trace()
+
+ name=None
+ status=None
+ try:
+ tenant_credentials = get_tenant_nova_credentials(tenant_name)
+ nova = nvclient.Client(**tenant_credentials)
+ instance_list=nova.servers.list()
+ #instance = nova.servers.find(name=vm_name)
+ if instance_list > 0:
+
+ for inst in instance_list:
+
+ instance_id = inst.id
+ name=inst.name
+ networks=inst.networks
+
+
+
+ except Exception:
+ print(' - Instance Not Found')
+
+
+def discover_vm_on_network(tenant_name):
+ """
+ This method is used to discover instances per tenant
+ """
+ name=None
+ status=None
+ try:
+ tenant_credentials = get_tenant_nova_credentials(tenant_name)
+ nova = nvclient.Client(**tenant_credentials)
+ instance_list=nova.servers.list()
+ #instance = nova.servers.find(name=vm_name)
+ if instance_list > 0:
+
+ for inst in instance_list:
+
+ instance_id = inst.id
+ name=inst.name
+ inst_find=nova.servers.find(id=instance_id)
+ print(' - Instance %s Discovered' % inst.name)
+ print(' - Instance ID %s Discovered' % instance_id)
+ print(' - Instance %s Status' % inst.status)
+ status=inst.status
+ except Exception:
+ print(' - Instance Not Found')
+ status = False
+
+ ins_data = {'instance_name': name,
+ 'status': status }
+ return ins_data
+
+
+def terminate_vm_on_network(tenant_name, vm_name, network_id):
+ """
+ This method is to terminate VM on the given network & VM Name.
+ """
+ pdb.set_trace()
+ tenant_credentials = get_tenant_nova_credentials(tenant_name)
+ nova = nvclient.Client(**tenant_credentials)
+ nova.quotas.delete(tenant_name)
+ try:
+ instance = nova.servers.find(name=vm_name)
+ nova.servers.delete(instance.id)
+ print " * Instance terminated on network: " + str(network_id)
+ except Exception:
+ print " * Instance Not Found on network: " + str(network_id)
+ pass
+ return True
diff --git a/openstack-scripts/vm_instances.pyc b/openstack-scripts/vm_instances.pyc
new file mode 100644
index 0000000..2bd0e1d
Binary files /dev/null and b/openstack-scripts/vm_instances.pyc differ