Guest User

naveen/classes_python

a guest
Jan 18th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. naveen@ol4:>vi second.py
  2. naveen@ol4:>clear
  3.  
  4. naveen@ol4:>cat second.py
  5. #!/usr/bin/env python
  6. import paramiko
  7. class Servers(object):
  8. def __init__(self,hostname,cmd):
  9. self.hostname=hostname
  10. ssh=paramiko.SSHClient()
  11. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  12. ssh.connect(hostname,username="root",password="redhat")
  13. stdin,stdout,stderr=ssh.exec_command(cmd)
  14. print stdout.readlines()
  15. ssh.close()
  16.  
  17. naveen@ol4:>python
  18. Python 2.7.5 (default, Sep 5 2016, 02:30:38)
  19. [GCC 4.8.5 20150623 (Red Hat 4.8.5-9)] on linux2
  20. Type "help", "copyright", "credits" or "license" for more information.
  21. >>> import second
  22. >>> a=second.Servers('puppet','hostname')
  23. [u'puppet.localdomain\n']
  24. >>> a=second.Servers('puppet','cat /etc/hosts')
  25. [u'# HEADER: This file was autogenerated at 2016-12-17 09:41:55 +0530\n', u'# HEADER: by puppet. While it can still be managed manually, it\n', u'# HEADER: is definitely not recommended.\n', u'127.0.0.1\tlocalhost\tlocalhost.localdomain localhost4 localhost4.localdomain4\n', u'::1\tlocalhost\tlocalhost.localdomain localhost6 localhost6.localdomain6\n', u'10.0.2.24\tpuppet\tpuppet.localdomain\n', u'10.0.2.9\trhel1\trhel1.localdomain\n', u'10.0.2.21 ol4 ol4.localdomain\n', u'10.0.2.37\tol1\tol1.localdomain\n']
  26. >>> a=second.Servers('puppet','facter fqdn')
  27. [u'puppet.localdomain\n']
  28. >>> hostlist=['rhel1','puppet','jenkins']
  29. >>> for host in hostlist:
  30. ... a=second.Servers(host,'hostname')
  31. ...
  32.  
  33. naveen@ol4:>vi second.py
  34. naveen@ol4:>clear
  35.  
  36. naveen@ol4:>cat second.py
  37. #!/usr/bin/env python
  38. import paramiko
  39. class Servers(object):
  40. def __init__(self,hostname,cmd):
  41. self.hostname=hostname
  42. ssh=paramiko.SSHClient()
  43. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  44. ssh.connect(hostname,username="root",password="redhat")
  45. stdin,stdout,stderr=ssh.exec_command(cmd)
  46. print stdout.readlines()
  47. ssh.close()
  48.  
  49. naveen@ol4:>python
  50. Python 2.7.5 (default, Sep 5 2016, 02:30:38)
  51. [GCC 4.8.5 20150623 (Red Hat 4.8.5-9)] on linux2
  52. Type "help", "copyright", "credits" or "license" for more information.
  53. >>> import second
  54. >>> a=second.Servers('puppet','hostname')
  55. [u'puppet.localdomain\n']
  56. >>> a=second.Servers('puppet','cat /etc/hosts')
  57. [u'# HEADER: This file was autogenerated at 2016-12-17 09:41:55 +0530\n', u'# HEADER: by puppet. While it can still be managed manually, it\n', u'# HEADER: is definitely not recommended.\n', u'127.0.0.1\tlocalhost\tlocalhost.localdomain localhost4 localhost4.localdomain4\n', u'::1\tlocalhost\tlocalhost.localdomain localhost6 localhost6.localdomain6\n', u'10.0.2.24\tpuppet\tpuppet.localdomain\n', u'10.0.2.9\trhel1\trhel1.localdomain\n', u'10.0.2.21 ol4 ol4.localdomain\n', u'10.0.2.37\tol1\tol1.localdomain\n']
  58. >>> a=second.Servers('puppet','facter fqdn')
  59. [u'puppet.localdomain\n']
  60. >>> hostlist=['rhel1','puppet','jenkins']
  61. >>> for host in hostlist:
  62. ... a=second.Servers(host,'hostname')
  63. ...
Add Comment
Please, Sign In to add comment