def _addNewProxy(addr,port=None) : """ Access the GRAM SSH proxy daemon and create a new proxy with the given address """ #pdb.set_trace(); portNumber = SSHProxyTable._add(addr, port) if portNumber == 0 : return 0 #network functionality on a separate node now cmd_string = '' if config.openstack_type == 'juno': cmd_string = 'ssh -t %s sudo ' % config.network_host_addr cmd_string = cmd_string + '%s ' % config.ssh_proxy_exe cmd_string = cmd_string + '-m C -a %s ' % addr cmd_string = cmd_string + ' -p %d ' % portNumber cmd_string = cmd_string + ' -n %s ' % open_stack_interface._getConfigParam('/etc/gram/config.json','mgmt_ns') config.logger.info("Setting up ssh proxy: " + cmd_string) try : open_stack_interface._execCommand(cmd_string) except : config.logger.error("Unable to create SSH proxy for address %s" % addr) return 0 return portNumber
def _addNewProxy(addr, port=None): """ Access the GRAM SSH proxy daemon and create a new proxy with the given address """ #pdb.set_trace(); portNumber = SSHProxyTable._add(addr, port) if portNumber == 0: return 0 #network functionality on a separate node now cmd_string = '' if config.openstack_type == 'juno': cmd_string = 'ssh -t %s sudo ' % config.network_host_addr cmd_string = cmd_string + '%s ' % config.ssh_proxy_exe cmd_string = cmd_string + '-m C -a %s ' % addr cmd_string = cmd_string + ' -p %d ' % portNumber cmd_string = cmd_string + ' -n %s ' % open_stack_interface._getConfigParam( '/etc/gram/config.json', 'mgmt_ns') config.logger.info("Setting up ssh proxy: " + cmd_string) try: open_stack_interface._execCommand(cmd_string) except: config.logger.error("Unable to create SSH proxy for address %s" % addr) return 0 return portNumber
def configMetadataSvcs(slice_object, users, install_list, execute_list, num_nics, control_nic_prefix, scriptFilename = 'userdata.txt') : """ Generate a script file to be used within the user_data option of a nova boot call Parameters- users: dictionary of json specs describing new accounts to create at boot install_list: list of _InstallItem class objects to incorporate into the script execute_list: list of _ExecuteItem class objects to incorporate into the script num_nics: total number of NICs defined for the overall slice control_nic_prefix: the first three octets of the control NIC IP address scriptFilename: the pathname for the combined generated script """ # Generate script files for network configuration support, file installs, boot executable # invocations, and user accounts. # When all files are generated, then combine them into a single gzipped mime file #pdb.set_trace() cmd_count = 0 cmd = 'write-mime-multipart --output=%s ' % scriptFilename rmcmd = [] # Generate boothook script to reset network interfaces and default gateway scriptName = _generateNicInterfaceScript(slice_object, num_nics, control_nic_prefix) if scriptName != "" : cmd += scriptName + ':text/cloud-boothook ' rmcmd.append(scriptName) cmd_count = cmd_count + 1 # Generate support for file installs and executes if len(install_list) > 0 or len(execute_list) > 0 : scriptName = _generateScriptExeAndInstalls(install_list, execute_list) if scriptName != "" : cmd += scriptName + ':text/cloud-config ' rmcmd.append(scriptName) cmd_count = cmd_count + 1 # Generate support for creating new user accounts # Iterate through the list of users and create a separate script text file for each for user in users : scriptName = _generateAccount(user) if scriptName != "" : cmd += scriptName + ':text/x-shellscript ' rmcmd.append(scriptName) cmd_count = cmd_count + 1 # Combine all scripts into a single mime'd and gzip'ed file, if necessary if cmd_count > 0 : open_stack_interface._execCommand(cmd) #SD cmd = 'gzip -f %s ' % scriptFilename #SD open_stack_interface._execCommand(cmd) # Delete the temporary files for item in rmcmd : os.unlink(item) return cmd_count
def check_gram_services(): print 'Checking GRAM services...' services = ['gram-am', 'gram-ctrl', 'gram-vmoc', 'gram-ch'] for service in services: cmd = 'service ' + service + ' status' result = osi._execCommand(cmd) if not result.find('stop') < 0: print 'Warning: the following service is not running, will attempt to restart it - ' + service cmd = 'service ' + service + ' restart' osi._execCommand(cmd) cmd = 'service ' + service + ' status' result = osi._execCommand(cmd) if result.find('stop'): print 'Error: the following service is still not running - ' + service + '\nCheck logs in /var/logs/upstart/' else: print service + ' - running'
def check_gram_services(): print 'Checking GRAM services...' services = ['gram-am','gram-ctrl','gram-vmoc','gram-ch'] for service in services: cmd = 'service ' + service + ' status' result = osi._execCommand(cmd) if not result.find('stop') < 0: print 'Warning: the following service is not running, will attempt to restart it - ' + service cmd = 'service ' + service + ' restart' osi._execCommand(cmd) cmd = 'service ' + service + ' status' result = osi._execCommand(cmd) if result.find('stop'): print 'Error: the following service is still not running - ' + service + '\nCheck logs in /var/logs/upstart/' else: print service + ' - running'
def _getMgmtNamespace(): """ Looks at the namespaces on the machine and finds one that has the management network and the external network: """ mgmt_addr = (netaddr.IPNetwork(config.management_network_cidr)).broadcast public_addr = config.public_subnet_start_ip net_node_addr = config.network_host_addr ssh_prefix = 'ssh gram@' + net_node_addr + ' sudo ' # get a list of the namespaces if config.openstack_type == 'grizzly': command = 'ip netns list' else: command = ssh_prefix + 'ip netns list' print "Checking for management namespace.\n" output = osi._execCommand(command) output_lines = output.split('\n') # check for both public and mgmt address in each namespace has_mgmt = 0 has_public = 0 for line in output_lines: if not line: return None try: if config.openstack_type == 'grizzly': command = 'ip netns exec ' + line + ' ifconfig' else: command = ssh_prefix + 'ip netns exec ' + line + ' ifconfig' print "Checking through ifconfig return.\n" ifconfig = osi._execCommand(command) except subprocess.CalledProcessError as e: continue ifconfig_lines = ifconfig.split('\n') for ifconfig_line in ifconfig_lines: if str(mgmt_addr) in ifconfig_line: has_mgmt = 1 if public_addr in ifconfig_line: has_public = 1 if has_mgmt and has_public: return line else: has_mgmt = 0 has_public = 0 return None
def _getMgmtNamespace() : """ Looks at the namespaces on the machine and finds one that has the management network and the external network: """ mgmt_addr = (netaddr.IPNetwork(config.management_network_cidr)).broadcast public_addr = config.public_subnet_start_ip net_node_addr = config.network_host_addr ssh_prefix = 'ssh gram@' + net_node_addr + ' sudo ' # get a list of the namespaces if config.openstack_type == 'grizzly': command = 'ip netns list' else: command = ssh_prefix + 'ip netns list' print "Checking for management namespace.\n" output = osi._execCommand(command) output_lines = output.split('\n') # check for both public and mgmt address in each namespace has_mgmt = 0 has_public = 0 for line in output_lines: if not line: return None try: if config.openstack_type == 'grizzly': command = 'ip netns exec ' + line + ' ifconfig' else: command = ssh_prefix + 'ip netns exec ' + line + ' ifconfig' print "Checking through ifconfig return.\n" ifconfig = osi._execCommand(command) except subprocess.CalledProcessError as e: continue ifconfig_lines = ifconfig.split('\n') for ifconfig_line in ifconfig_lines: if str(mgmt_addr) in ifconfig_line: has_mgmt = 1 if public_addr in ifconfig_line: has_public = 1 if has_mgmt and has_public: return line else: has_mgmt = 0 has_public = 0 return None
def get_keystone_status(): success = False try: command = "keystone tenant-list" tenants = osi._execCommand(command) success = True except: pass return success
def check_openstack_services(): print 'checking OpenStack services...' if config.openstack_type == "juno": services = [ 'nova-api', 'nova-cert', 'nova-conductor', 'nova-consoleauth ', 'nova-novncproxy', 'nova-scheduler', 'neutron-server', 'glance-registry', 'glance-api', 'keystone' ] remote_services = [ 'neutron-dhcp-agent', 'neutron-metadata-agent', 'neutron-l3-agent', 'neutron-plugin-openvswitch-agent' ] else: services = [ 'nova-api', 'nova-cert', 'nova-conductor', 'nova-consoleauth ', 'nova-novncproxy', 'nova-scheduler', 'glance-registry', 'glance-api', 'keystone', 'quantum-dhcp-agent', 'quantum-metadata-agent', 'quantum-server', 'quantum-l3-agent', 'quantum-plugin-openvswitch-agent' ] remote_services = [] for service in services: cmd = 'service ' + service + ' status' result = osi._execCommand(cmd) if not result.find('stop') < 0: print 'Warning: the following service is not running, will attempt to restart it - ' + service cmd = 'service ' + service + ' restart' osi._execCommand(cmd) cmd = 'service ' + service + ' status' result = osi._execCommand(cmd) if result.find('stop'): print 'Error: the following service is still not running, check logs in /var/logs' else: print service + ' - running' net_node_addr = osi._getConfigParam('/etc/gram/config.json', 'network_host_addr') for service in remote_services: print 'Network node status for ' + service + '\n' cmd = 'ssh gram@' + net_node_addr + ' service ' + service + ' status' result = osi._execCommand(cmd) if not result.find('stop') < 0: print 'Warning: the following service is not running, will attempt to restart it - ' + service cmd = 'ssh gram@' + net_node_addr + ' service ' + service + ' restart' cmd = 'service ' + service + ' restart' osi._execCommand(cmd) print 'Checking status\n' cmd = 'ssh gram@' + net_node_addr + ' service ' + service + ' status' result = osi._execCommand(cmd) if result.find('stop'): print 'Error: the following service is still not running, check logs in /var/logs' else: print service + ' - running'
def get_network_status(): success = False net_node_addr = config.network_host_addr try: command = '%s net-list' % config.network_type output = osi._execCommand(command) success = True except: pass return success
def _removeProxy(addr) : """ Access the GRAM SSH proxy daemon and delete the with the given address """ #pdb.set_trace(); portNumber = SSHProxyTable._remove(addr) if portNumber > 0 : cmd_string = '' if config.openstack_type == 'juno': cmd_string = 'ssh -t %s sudo ' % config.network_host_addr cmd_string = cmd_string + '%s ' % config.ssh_proxy_exe cmd_string = cmd_string + '-m D -a %s ' % addr cmd_string = cmd_string + ' -p %d ' % portNumber cmd_string = cmd_string + ' -n %s ' % open_stack_interface._getConfigParam('/etc/gram/config.json','mgmt_ns') try: open_stack_interface._execCommand(cmd_string) except : config.logger.error("Address %s not present in SSH proxy" % addr)
def _removeProxy(addr): """ Access the GRAM SSH proxy daemon and delete the with the given address """ #pdb.set_trace(); portNumber = SSHProxyTable._remove(addr) if portNumber > 0: cmd_string = '' if config.openstack_type == 'juno': cmd_string = 'ssh -t %s sudo ' % config.network_host_addr cmd_string = cmd_string + '%s ' % config.ssh_proxy_exe cmd_string = cmd_string + '-m D -a %s ' % addr cmd_string = cmd_string + ' -p %d ' % portNumber cmd_string = cmd_string + ' -n %s ' % open_stack_interface._getConfigParam( '/etc/gram/config.json', 'mgmt_ns') try: open_stack_interface._execCommand(cmd_string) except: config.logger.error("Address %s not present in SSH proxy" % addr)
def _getIpTable(): """ Print out the IP tables """ #pdb.set_trace(); cmd_string = "" if config.openstack_type == 'juno': cmd_string = 'ssh -t %s sudo ' % config.network_host_addr cmd_string = cmd_string + '%s ' % config.ssh_proxy_exe cmd_string = cmd_string + ' -m L -n %s' % open_stack_interface._getConfigParam('/etc/gram/config.json','mgmt_ns') output = "" try: output = open_stack_interface._execCommand(cmd_string) except : config.logger.error("Address %s not present in SSH proxy" % addr) return output
def check_openstack_services(): print 'checking OpenStack services...' if config.openstack_type == "juno": services = ['nova-api','nova-cert','nova-conductor','nova-consoleauth ','nova-novncproxy','nova-scheduler', 'neutron-server', 'glance-registry','glance-api','keystone'] remote_services = ['neutron-dhcp-agent','neutron-metadata-agent', 'neutron-l3-agent','neutron-plugin-openvswitch-agent'] else: services = ['nova-api','nova-cert','nova-conductor','nova-consoleauth ','nova-novncproxy','nova-scheduler', 'glance-registry','glance-api','keystone', 'quantum-dhcp-agent','quantum-metadata-agent','quantum-server','quantum-l3-agent','quantum-plugin-openvswitch-agent'] remote_services = [] for service in services: cmd = 'service ' + service + ' status' result = osi._execCommand(cmd) if not result.find('stop') < 0: print 'Warning: the following service is not running, will attempt to restart it - ' + service cmd = 'service ' + service + ' restart' osi._execCommand(cmd) cmd = 'service ' + service + ' status' result = osi._execCommand(cmd) if result.find('stop'): print 'Error: the following service is still not running, check logs in /var/logs' else: print service + ' - running' net_node_addr = osi._getConfigParam('/etc/gram/config.json','network_host_addr') for service in remote_services: print 'Network node status for ' + service + '\n' cmd = 'ssh gram@' + net_node_addr + ' service ' + service + ' status' result = osi._execCommand(cmd) if not result.find('stop') < 0: print 'Warning: the following service is not running, will attempt to restart it - ' + service cmd = 'ssh gram@' + net_node_addr + ' service ' + service + ' restart' cmd = 'service ' + service + ' restart' osi._execCommand(cmd) print 'Checking status\n' cmd = 'ssh gram@' + net_node_addr + ' service ' + service + ' status' result = osi._execCommand(cmd) if result.find('stop'): print 'Error: the following service is still not running, check logs in /var/logs' else: print service + ' - running'
def _getIpTable(): """ Print out the IP tables """ #pdb.set_trace(); cmd_string = "" if config.openstack_type == 'juno': cmd_string = 'ssh -t %s sudo ' % config.network_host_addr cmd_string = cmd_string + '%s ' % config.ssh_proxy_exe cmd_string = cmd_string + ' -m L -n %s' % open_stack_interface._getConfigParam( '/etc/gram/config.json', 'mgmt_ns') output = "" try: output = open_stack_interface._execCommand(cmd_string) except: config.logger.error("Address %s not present in SSH proxy" % addr) return output
def periodic_cleanup(self): token_table_user = '******' token_table_database = 'keystone' token_retention_window_days = 1 while True: cmd = None try: config.logger.info("Cleaning up expired slivers") cmd = "mysql -u%s -p%s -h%s %s -e 'DELETE FROM token WHERE NOT DATE_SUB(CURDATE(),INTERVAL %d DAY) <= expires'" % \ (token_table_user, config.mysql_password, config.control_host_addr, token_table_database, token_retention_window_days) except Exception, e: print e # print cmd os.system(cmd) cmd = "openstack project list" output = open_stack_interface._execCommand(cmd) output_fields = open_stack_interface._parseTableOutput(output) tenant_uuids = output_fields['ID'] print "TENANT_UUIDS = %s" % tenant_uuids try: config.logger.info("Cleaning up dangling secgrps") uuids_expr = ",".join("'" + tenant_uuid + "'" \ for tenant_uuid in tenant_uuids) for table_name in ['securitygrouprules', 'securitygroups']: cmd = "mysql -u%s -p%s -h%s %s -e %sDELETE from %s where tenant_id not in (%s)%s" % \ (config.network_user, config.mysql_password, config.control_host_addr, config.network_database, '"', table_name, uuids_expr, '"') print cmd #RRH - have to figure out why tables don't exist in the neutron database - os.system(cmd) except Exception, e: print e
def periodic_cleanup(self): token_table_user = '******' token_table_database = 'keystone' token_retention_window_days = 1 while True: cmd = None try: config.logger.info("Cleaning up expired slivers") cmd = "mysql -u%s -p%s -h%s %s -e 'DELETE FROM token WHERE NOT DATE_SUB(CURDATE(),INTERVAL %d DAY) <= expires'" % \ (token_table_user, config.mysql_password, config.control_host_addr, token_table_database, token_retention_window_days) except Exception, e: print e # print cmd os.system(cmd) cmd = "keystone tenant-list" output = open_stack_interface._execCommand(cmd) output_fields = open_stack_interface._parseTableOutput(output) tenant_uuids = output_fields['id'] # print "TENANT_UUIDS = %s" % tenant_uuids try: config.logger.info("Cleaning up danglihg secgrps") uuids_expr = ",".join("'" + tenant_uuid + "'" \ for tenant_uuid in tenant_uuids) for table_name in ['securitygrouprules', 'securitygroups']: cmd = "mysql -u%s -p%s -h%s %s -e %sDELETE from %s where tenant_id not in (%s)%s" % \ (config.network_user, config.mysql_password, config.control_host_addr, config.network_database, '"', table_name, uuids_expr, '"') # print cmd os.system(cmd) except Exception, e: print e
for slice in slices: print 'Cleaning up slice %s' % slice if ':' in slice: tenant_name = slice # Assume it is a URN else: tenant_name = 'geni:gpo:gcf+slice+' + slice tenant_admin = 'admin-' + tenant_name # Figure out the uuid of this tenant cmd_string = 'keystone tenant-list' print cmd_string output = open_stack_interface._execCommand(cmd_string) tenant_uuid = open_stack_interface._getUUIDByName(output, tenant_name) if tenant_uuid == None : # Tenant does not exist. Exit! print 'Cannot find tenant %s\n' % tenant_name sys.exit(1) # Figure out the uuid of the tenant admin cmd_string = 'keystone user-list' print cmd_string output = open_stack_interface._execCommand(cmd_string) tenant_admin_uuid = open_stack_interface._getUUIDByName(output, tenant_admin) if tenant_admin_uuid == None : # Tenant admin does not exist but tenant does. Delete the tenant # and then exit.
def check_mgmt_ns(recreate=False): mgmt_ns = _getMgmtNamespace() conf_mgmt_ns = config.mgmt_ns mgmt_net_name = config.management_network_name mgmt_net_cidr = config.management_network_cidr mgmt_net_vlan = config.management_network_vlan public_subnet_start_ip = config.public_subnet_start_ip public_subnet_end_ip = config.public_subnet_end_ip public_gateway_ip = config.public_gateway_ip public_subnet_cidr = config.public_subnet_cidr net_node_addr = config.network_host_addr network_conf = "/etc/%s/l3_agent.ini" % config.network_type if not mgmt_ns or recreate: print "WARNING: Management namespace NOT found" if config.network_type == 'quantum': nscmd = 'sudo quantum-l3-agent restart' else: nscmd = 'ssh gram@' + net_node_addr + \ ' sudo service neutron-l3-agent restart' for x in range(0, 10): print "Restarting L3 service to attempt to recover the namespace - attempt " + str( x) osi._execCommand(nscmd) time.sleep(20) mgmt_ns = _getMgmtNamespace() if mgmt_ns: break if not mgmt_ns: print "WARNING: Unable to recover management namespace" input_var = raw_input( "Do you wish to recreate the management network? [y/N]: ") if input_var == 'y': input_var = raw_input( "You must delete 'externalRouter' (router),'public' (network) and " + mgmt_net_name + " (network). Using the Horizon interface is recommended. Have you done this and are ready to proceed? [y/N] " ) if input_var == 'y': cmd = ( "%s net-create " + mgmt_net_name + " --provider:network_type vlan --provider:physical_network physnet2 --provider:segmentation_id " + mgmt_net_vlan + " --shared") % config.network_type osi._execCommand(cmd) cmd = ("%s subnet-create " + mgmt_net_name + " " + mgmt_net_cidr) % config.network_type output = osi._execCommand(cmd) MGMT_SUBNET_ID = osi._getValueByPropertyName(output, 'id') cmd = ("%s net-create public --router:external=True" ) % config.network_type output = osi._execCommand(cmd) PUBLIC_NET_ID = osi._getValueByPropertyName(output, 'id') cmd = ("%s subnet-create --allocation_pool" + \ " start=" + public_subnet_start_ip + \ ",end=" + public_subnet_end_ip + \ " --gateway=" + public_gateway_ip + \ " " + str(PUBLIC_NET_ID) + " " + public_subnet_cidr + \ " -- --enable_dhcp=False") % config.network_type output = osi._execCommand(cmd) cmd = ("%s router-create externalRouter" ) % config.network_type output = osi._execCommand(cmd) EXTERNAL_ROUTER_ID = osi._getValueByPropertyName( output, 'id') cmd = ("%s router-gateway-set externalRouter " + PUBLIC_NET_ID) % config.network_type output = osi._execCommand(cmd) cmd = ("%s router-interface-add externalRouter " + MGMT_SUBNET_ID) % config.network_type output = osi._execCommand(cmd) if config.openstack_type == "juno": print "Sending public net id to the network node.\n" cmd = "ssh gram@" + net_node_addr + " echo " + PUBLIC_NET_ID + " > /home/gram/neutron_public_net" output = osi._execCommand(cmd) print "Sending external router id to the network node.\n" cmd = "ssh gram@" + net_node_addr + " echo " + EXTERNAL_ROUTER_ID + " > /home/gram/neutron_ext_router" output = osi._execCommand(cmd) print "Rewriting network node neutron l3 agent config files.\n" cmd = "ssh gram@" + net_node_addr + " sudo /home/gram/gram/juno/install/network_files/synch_control_network.sh" osi._execCommand(cmd) else: osi._execCommand("service neutron-l3-agent restart") mgmt_ns = _getMgmtNamespace() if mgmt_ns: if conf_mgmt_ns and conf_mgmt_ns == mgmt_ns: print "Found management namespace and it matches config" elif conf_mgmt_ns: print "WARNING: Found management namespace but it does not match config" print "Rewriting config value" _setField('mgmt_ns', mgmt_ns) osi._execCommand("service gram-am restart")
def check_openstack_consistency(): # Get all the tenants tenants = {} command_string = "keystone tenant-list" output = osi._execCommand(command_string) output_lines = output.split('\n') for i in range(3, len(output_lines)-2): line = output_lines[i] parts = line.split('|') tenant_id = parts[1].strip() name = parts[2].strip() tenants[tenant_id] = name # Get all VM's vms = [] command_string = 'nova list --all-tenants' output = osi._execCommand(command_string) output_lines = output.split('\n') for i in range(3, len(output_lines)-2): line = output_lines[i] parts = line.split('|') vms.append(parts[1].strip()) # Get all ports ports = [] command_string = '%s port-list' % config.network_type output = osi._execCommand(command_string) output_lines = output.split('\n') for i in range(3, len(output_lines)-2): line = output_lines[i] parts = line.split('|') ports.append(parts[1].strip()) # Get all nets nets = [] command_string = 'net-list' % config.network_type output = osi._execCommand(command_string) output_lines = output.split('\n') for i in range(3, len(output_lines)-2): line = output_lines[i] parts = line.split('|') nets.append(parts[1].strip()) print "Checking that all NOVA VM's have a valid tenant ID" # Check that all VM's belong to a tenant for vm in vms: command_string = 'nova show %s' % vm output = osi._execCommand(command_string) output_lines = output.split('\n') tenant_name = '***' matching_tenant_id = None for i in range(3, len(output_lines)-2): line = output_lines[i] parts = line.split('|') if parts[1].strip() == 'tenant_id': tenant_id = parts[2].strip() if tenants.has_key(tenant_id): tenant_name = tenants[tenant_id] break print "VM " + vm + " " + str(tenant_id) + " " + str(tenant_name) print print "Checking that all network ports have a valid tenant ID" for port in ports: command_string = '%s port-show %s' % (config.network_type, port) output = osi._execCommand(command_string) output_lines = output.split('\n') tenant_id = '' for i in range(3, len(output_lines)-2): line = output_lines[i] parts = line.split('|') if parts[1].strip() == 'tenant_id': tenant_id = parts[2].strip() tenant_name = '***' if tenants.has_key(tenant_id): tenant_name = tenants[tenant_id] break print "PORT " + port + " " + tenant_id + " " + str(tenant_name) print print "Checking that all network nets have a valid tenant ID" for net in nets: command_string = '%s net-show %s' % (config.network_type, net) output = osi._execCommand(command_string) output_lines = output.split('\n') tenant_id = '' for i in range(3, len(output_lines)-2): line = output_lines[i] parts = line.split('|') if parts[1].strip() == 'tenant_id': tenant_id = parts[2].strip() tenant_name = '***' if tenants.has_key(tenant_id): tenant_name = tenants[tenant_id] break print "NET " + port + " " + tenant_id + " " + str(tenant_name)
def configMetadataSvcs(slice_object, users, install_list, execute_list, num_nics, control_nic_prefix, scriptFilename='userdata.txt'): """ Generate a script file to be used within the user_data option of a nova boot call Parameters- users: dictionary of json specs describing new accounts to create at boot install_list: list of _InstallItem class objects to incorporate into the script execute_list: list of _ExecuteItem class objects to incorporate into the script num_nics: total number of NICs defined for the overall slice control_nic_prefix: the first three octets of the control NIC IP address scriptFilename: the pathname for the combined generated script """ # Generate script files for network configuration support, file installs, boot executable # invocations, and user accounts. # When all files are generated, then combine them into a single gzipped mime file #pdb.set_trace() cmd_count = 0 cmd = 'write-mime-multipart --output=%s ' % scriptFilename rmcmd = [] # Generate boothook script to reset network interfaces and default gateway scriptName = _generateNicInterfaceScript(slice_object, num_nics, control_nic_prefix) if scriptName != "": cmd += scriptName + ':text/cloud-boothook ' rmcmd.append(scriptName) cmd_count = cmd_count + 1 # Generate support for file installs and executes if len(install_list) > 0 or len(execute_list) > 0: scriptName = _generateScriptExeAndInstalls(install_list, execute_list) if scriptName != "": cmd += scriptName + ':text/cloud-config ' rmcmd.append(scriptName) cmd_count = cmd_count + 1 # Generate support for creating new user accounts # Iterate through the list of users and create a separate script text file for each for user in users: scriptName = _generateAccount(user) if scriptName != "": cmd += scriptName + ':text/x-shellscript ' rmcmd.append(scriptName) cmd_count = cmd_count + 1 # Combine all scripts into a single mime'd and gzip'ed file, if necessary if cmd_count > 0: open_stack_interface._execCommand(cmd) #SD cmd = 'gzip -f %s ' % scriptFilename #SD open_stack_interface._execCommand(cmd) # Delete the temporary files for item in rmcmd: os.unlink(item) return cmd_count
for slice in slices: print 'Cleaning up slice %s' % slice if ':' in slice: tenant_name = slice # Assume it is a URN else: tenant_name = 'geni:gpo:gcf+slice+' + slice tenant_admin = 'admin-' + tenant_name # Figure out the uuid of this tenant cmd_string = 'keystone tenant-list' print cmd_string output = open_stack_interface._execCommand(cmd_string) tenant_uuid = open_stack_interface._getUUIDByName(output, tenant_name) if tenant_uuid == None: # Tenant does not exist. Exit! print 'Cannot find tenant %s\n' % tenant_name sys.exit(1) # Figure out the uuid of the tenant admin cmd_string = 'keystone user-list' print cmd_string output = open_stack_interface._execCommand(cmd_string) tenant_admin_uuid = open_stack_interface._getUUIDByName( output, tenant_admin) if tenant_admin_uuid == None: # Tenant admin does not exist but tenant does. Delete the tenant # and then exit.
def check_mgmt_ns(recreate=False): mgmt_ns = _getMgmtNamespace() conf_mgmt_ns = config.mgmt_ns mgmt_net_name = config.management_network_name mgmt_net_cidr = config.management_network_cidr mgmt_net_vlan = config.management_network_vlan public_subnet_start_ip = config.public_subnet_start_ip public_subnet_end_ip = config.public_subnet_end_ip public_gateway_ip = config.public_gateway_ip public_subnet_cidr = config.public_subnet_cidr net_node_addr = config.network_host_addr network_conf = "/etc/%s/l3_agent.ini" % config.network_type if not mgmt_ns or recreate: print "WARNING: Management namespace NOT found" if config.network_type == 'quantum': nscmd = 'sudo quantum-l3-agent restart' else: nscmd = 'ssh gram@' + net_node_addr + \ ' sudo service neutron-l3-agent restart' for x in range(0,10): print "Restarting L3 service to attempt to recover the namespace - attempt " + str(x) osi._execCommand(nscmd) time.sleep(20) mgmt_ns = _getMgmtNamespace() if mgmt_ns: break if not mgmt_ns: print "WARNING: Unable to recover management namespace" input_var = raw_input("Do you wish to recreate the management network? [y/N]: ") if input_var == 'y': input_var = raw_input("You must delete 'externalRouter' (router),'public' (network) and " + mgmt_net_name + " (network). Using the Horizon interface is recommended. Have you done this and are ready to proceed? [y/N] ") if input_var == 'y': cmd = ("%s net-create " + mgmt_net_name + " --provider:network_type vlan --provider:physical_network physnet2 --provider:segmentation_id " + mgmt_net_vlan + " --shared") % config.network_type osi._execCommand(cmd) cmd = ("%s subnet-create " + mgmt_net_name + " " + mgmt_net_cidr) % config.network_type output = osi._execCommand(cmd) MGMT_SUBNET_ID = osi._getValueByPropertyName(output, 'id') cmd = ("%s net-create public --router:external=True") % config.network_type output = osi._execCommand(cmd) PUBLIC_NET_ID = osi._getValueByPropertyName(output, 'id') cmd = ("%s subnet-create --allocation_pool" + \ " start=" + public_subnet_start_ip + \ ",end=" + public_subnet_end_ip + \ " --gateway=" + public_gateway_ip + \ " " + str(PUBLIC_NET_ID) + " " + public_subnet_cidr + \ " -- --enable_dhcp=False") % config.network_type output = osi._execCommand(cmd) cmd = ("%s router-create externalRouter") % config.network_type output = osi._execCommand(cmd) EXTERNAL_ROUTER_ID = osi._getValueByPropertyName(output, 'id') cmd = ("%s router-gateway-set externalRouter " + PUBLIC_NET_ID) % config.network_type output = osi._execCommand(cmd) cmd = ("%s router-interface-add externalRouter " + MGMT_SUBNET_ID) % config.network_type output = osi._execCommand(cmd) if config.openstack_type == "juno": print "Sending public net id to the network node.\n" cmd = "ssh gram@" + net_node_addr + " echo " + PUBLIC_NET_ID + " > /home/gram/neutron_public_net" output = osi._execCommand(cmd) print "Sending external router id to the network node.\n" cmd = "ssh gram@" + net_node_addr + " echo " + EXTERNAL_ROUTER_ID + " > /home/gram/neutron_ext_router" output = osi._execCommand(cmd) print "Rewriting network node neutron l3 agent config files.\n" cmd = "ssh gram@" + net_node_addr + " sudo /home/gram/gram/juno/install/network_files/synch_control_network.sh" osi._execCommand(cmd) else: osi._execCommand("service neutron-l3-agent restart") mgmt_ns = _getMgmtNamespace() if mgmt_ns: if conf_mgmt_ns and conf_mgmt_ns == mgmt_ns: print "Found management namespace and it matches config" elif conf_mgmt_ns: print "WARNING: Found management namespace but it does not match config" print "Rewriting config value" _setField('mgmt_ns',mgmt_ns) osi._execCommand("service gram-am restart")