def push_yaml_to_node(host, src_path, dst_file_name): (out, err) = ssh_connect2(host, 'test -d /etc/hiera || mkdir /etc/hiera') if err == '': LOG.debug('Push %s to node %s .' % (src_path, host)) scp_connect(host, src_path, '/etc/hiera/%s' % dst_file_name) else: LOG.error('Can not create "/etc/hiera/" on node %s .' % host)
def init_node_list_file(): # generate node-list file LOG.info('Generate node-list file ...') file_path = '/.eayunstack/node-list' if not os.path.exists(os.path.dirname(file_path)): os.mkdir(os.path.dirname(file_path)) if os.path.exists(file_path): os.remove(file_path) logging.disable(logging.CRITICAL) rep = APIClient.get_request("nodes/") logging.disable(logging.NOTSET) ips = [] for node in rep: fqdn = node['fqdn'] ip = node['ip'] ips.append(ip) roles = ','.join(node['roles']) if not roles: continue host = fqdn.split('.')[0] mac = node['mac'].replace(':', '.') idrac_addr = get_idrac_addr(ip) entry = fqdn + ':' + host + ':' + ip + ':' + roles + ':' + mac + ':' + idrac_addr + '\n' output = open(file_path, 'a') output.write(entry) output.close() # scp node-list file to all nodes LOG.info('Copy node-list file to all nodes ...') for ip in ips: LOG.info(' To node %s ...' % ip) scp_connect(ip, file_path, file_path)
def push_repo_file_to_node(host, plugin_name, src_path, backup=False): LOG.debug('Push %s to node %s .' % (src_path, host)) if backup: ssh_connect2(host, 'test -e /etc/yum.repos.d/bak || mkdir /etc/yum.repos.d/bak/') (out, err) = ssh_connect2(host, 'mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/') if err == '': scp_connect(host, src_path, '/etc/yum.repos.d/%s.repo' % plugin_name) else: LOG.error('Can not backup "/etc/yum.repos.d/*.repo" on node %s .') else: scp_connect(host, src_path, '/etc/yum.repos.d/%s.repo' % plugin_name)
def push_repo_file_to_node(host, plugin_name, src_path, backup=False): LOG.debug('Push %s to node %s .' % (src_path, host)) if backup: ssh_connect2( host, 'test -e /etc/yum.repos.d/bak || mkdir /etc/yum.repos.d/bak/') (out, err) = ssh_connect2( host, 'mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/') if err == '': scp_connect(host, src_path, '/etc/yum.repos.d/%s.repo' % plugin_name) else: LOG.error('Can not backup "/etc/yum.repos.d/*.repo" on node %s .') else: scp_connect(host, src_path, '/etc/yum.repos.d/%s.repo' % plugin_name)
def setup_nodes(myip): repo_content = """ [eayunstack] name=eayunstack baseurl=http://{ip}:8080/eayunstack/repo gpgcheck=0 """ tmp_repo_file = '/tmp/eayunstack.repo' target_repo_file = '/etc/yum.repos.d/eayunstack.repo' with open(tmp_repo_file, 'wb') as f: f.write(repo_content.format(ip=myip)) setup_command = 'mkdir -p /var/lib/eayunstack/{upgrade,puppet}' for node in NODE_ROLE.nodes: scp_connect(node['ip'], tmp_repo_file, target_repo_file) ssh_connect2(node['ip'], setup_command) os.unlink(tmp_repo_file)
def init_node_role_file(): file_path = '/.eayunstack/node-role' tmp_path = ('/tmp/node-role') # init local node-role file LOG.info('Generate node-role file for fuel node ...') output = open(file_path, 'w') output.write('fuel\n') output.close() # init openstack node node-role file LOG.info('Generate node-role file for openstack node ...') logging.disable(logging.CRITICAL) rep = APIClient.get_request("nodes/") logging.disable(logging.NOTSET) for node in rep: ip = node['ip'] if os.path.exists(tmp_path): os.remove(tmp_path) output = open(tmp_path, 'a') for role in node['roles']: output.write(role + '\n') output.close() LOG.info(' To node %s ...' % ip) scp_connect(ip, tmp_path, file_path)
def init_node_role_file(): file_path = '/.eayunstack/node-role' tmp_path = ('/tmp/node-role') # init local node-role file LOG.info('Generate node-role file for fuel node ...') output = open(file_path,'w') output.write('fuel\n') output.close() # init openstack node node-role file LOG.info('Generate node-role file for openstack node ...') logging.disable(logging.CRITICAL) rep = APIClient.get_request("nodes/") logging.disable(logging.NOTSET) for node in rep: ip = node['ip'] if os.path.exists(tmp_path): os.remove(tmp_path) output = open(tmp_path,'a') for role in node['roles']: output.write(role + '\n') output.close() LOG.info(' To node %s ...' % ip) scp_connect(ip, tmp_path, file_path)
def init_node_role_file(): file_path = "/.eayunstack/node-role" tmp_path = "/tmp/node-role" # init local node-role file LOG.info("Generate node-role file for fuel node ...") output = open(file_path, "w") output.write("fuel\n") output.close() # init openstack node node-role file LOG.info("Generate node-role file for openstack node ...") logging.disable(logging.CRITICAL) rep = APIClient.get_request("nodes/") logging.disable(logging.NOTSET) for node in rep: ip = node["ip"] if os.path.exists(tmp_path): os.remove(tmp_path) output = open(tmp_path, "a") for role in node["roles"]: output.write(role + "\n") output.close() LOG.info(" To node %s ..." % ip) scp_connect(ip, tmp_path, file_path)
def init_node_list_file(): # generate node-list file LOG.info('Generate node-list file ...') file_path = '/.eayunstack/node-list' if not os.path.exists(os.path.dirname(file_path)): os.mkdir(os.path.dirname(file_path)) if os.path.exists(file_path): os.remove(file_path) logging.disable(logging.CRITICAL) rep = APIClient.get_request("nodes/") logging.disable(logging.NOTSET) ips = [] for node in rep: fqdn = node['fqdn'] ip = node['ip'] ips.append(ip) roles = '' if len(node['roles']) > 1: for n in node['roles']: if not roles: roles = roles + n else: roles = roles + ',' + n else: roles = node['roles'][0] host = fqdn.split('.')[0] mac = node['mac'].replace(':', '.') idrac_addr = get_idrac_addr(ip) entry = fqdn + ':' + host + ':' + ip + ':' + roles + ':' + mac + ':' + idrac_addr + '\n' output = open(file_path,'a') output.write(entry) output.close() # scp node-list file to all nodes LOG.info('Copy node-list file to all nodes ...') for ip in ips: LOG.info(' To node %s ...' % ip) scp_connect(ip, file_path, file_path)
def init_node_list_file(): # generate node-list file LOG.info("Generate node-list file ...") file_path = "/.eayunstack/node-list" if not os.path.exists(os.path.dirname(file_path)): os.mkdir(os.path.dirname(file_path)) if os.path.exists(file_path): os.remove(file_path) logging.disable(logging.CRITICAL) rep = APIClient.get_request("nodes/") logging.disable(logging.NOTSET) ips = [] for node in rep: fqdn = node["fqdn"] ip = node["ip"] ips.append(ip) roles = "" if len(node["roles"]) > 1: for n in node["roles"]: if not roles: roles = roles + n else: roles = roles + "," + n else: roles = node["roles"][0] host = fqdn.split(".")[0] mac = node["mac"].replace(":", ".") idrac_addr = get_idrac_addr(ip) entry = fqdn + ":" + host + ":" + ip + ":" + roles + ":" + mac + ":" + idrac_addr + "\n" output = open(file_path, "a") output.write(entry) output.close() # scp node-list file to all nodes LOG.info("Copy node-list file to all nodes ...") for ip in ips: LOG.info(" To node %s ..." % ip) scp_connect(ip, file_path, file_path)
def push_hiera_yaml_to_node(host, src_path): LOG.debug('Push %s to node %s .' % (src_path, host)) scp_connect(host, src_path, '/etc/puppet/hiera.yaml')