本文整理汇总了Python中shell.Shell类的典型用法代码示例。如果您正苦于以下问题:Python Shell类的具体用法?Python Shell怎么用?Python Shell使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Shell类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_interface
def create_interface(self, vip):
try:
vip=vip.split("/",1)[0]
Shell.run('ifconfig lo:1 %s netmask 255.255.255.255 up' % (vip))
logging.debug("Assigned VIP to the loopback interface")
except Exception as ex:
logging.error(ex)
示例2: clear_interface
def clear_interface(self, vip):
try:
vip=vip.split("/",1)[0]
Shell.run('ifconfig lo:1 %s netmask 255.255.255.255 down' % (vip))
logging.debug("Removed VIP from loopback interface due to all backend failures")
except Exception as ex:
logging.error(ex)
示例3: is_ambari_installed
def is_ambari_installed():
sh = Shell()
output = sh.run('which ambari-server')
if len(output[0]) == 0:
return False
else:
return True
示例4: __init__
def __init__(self, basename):
self.print_backtrace = True
self.reader = 0
self.logger = None
Shell.__init__(self, basename)
self.register_commands(self, self.NOCARD_COMMANDS)
self.set_prompt("(No card) ")
示例5: post
def post(self):
sh = Shell()
for line in request.form['code'].split('\n'):
retval = sh.push(line)
return {'retval': retval.strip() }
示例6: namespace_init
def namespace_init(self, daemon):
output = Shell.run('ip netns list')
for line in output.split():
if line == 'ns-' + daemon:
return False
Shell.run('ip netns add ns-%s' % daemon)
return True
示例7: test_chaining
def test_chaining(self):
sh = Shell(has_input=True)
output = sh.run('cat -u').write('Hello, world!').output()
self.assertEqual(output, ['Hello, world!'])
output = shell('cat -u', has_input=True).write('Hello, world!').output()
self.assertEqual(output, ['Hello, world!'])
示例8: test__handle_output_norecord
def test__handle_output_norecord(self):
sh = Shell(record_output=False, record_errors=False)
self.assertEqual(sh._stdout, '')
self.assertEqual(sh._stderr, '')
sh._handle_output('another.txt\n', 'Error: Please supply an arg.')
self.assertEqual(sh._stdout, '')
self.assertEqual(sh._stderr, '')
示例9: is_hdp_select_installed
def is_hdp_select_installed():
sh = Shell()
output = sh.run('which hdp-select')
if len(output[0]) == 0:
return False
else:
return True
示例10: output
def output(self):
for ok in self.messages['ok']:
print(Shell.color(ok, 'white', 'green'))
for warning in self.messages['warning']:
print(Shell.color(warning, 'yellow', 'black'))
for error in self.messages['error']:
print(Shell.color(error, 'white', 'red'))
示例11: run
def run(self):
shell = Shell()
print(self.three_level_dir_repr(), end='')
command = input().strip()
while(command != 'exit'):
ret_msg = shell.process_command(command)
print(ret_msg)
print(self.three_level_dir_repr(), end='')
command = input().strip()
示例12: _get_master_ifname
def _get_master_ifname(self, daemon, ifname_instance):
output = Shell.run('ip netns exec ns-%s ethtool -S %s' %
(daemon, ifname_instance))
m = re.search(r'peer_ifindex: (\d+)', output)
ifindex = m.group(1)
output = Shell.run('ip link list')
expr = '^' + ifindex + ': (\w+): '
regex = re.compile(expr, re.MULTILINE)
m = regex.search(output)
return m.group(1)
示例13: install_nifi
def install_nifi():
logger.info('Attempting to install NiFi to the cluster')
if not is_ambari_installed():
logger.error('Ambari must be installed to install NiFi as well.')
raise EnvironmentError('You must install the demo on the same node as the Ambari server. Install Ambari here or move to another node with Ambari installed before continuing')
if not is_hdp_select_installed():
installed = install_hdp_select()
if not installed:
logger.error('hdp-select must be installed to install NiFi')
raise EnvironmentError('hdp-select could not be installed. Please install it manually and then re-run the setup.')
conf = config.read_config('service-installer.conf')
cmds = json.loads(conf['NIFI']['install-commands'])
sh = Shell()
logger.info('Getting HDP Version')
version = sh.run(cmds[0])
logger.info('HDP Version: ' + version[0])
fixed_copy = cmds[2].replace('$VERSION', str(version[0])).replace('\n', '')
fixed_remove = cmds[1].replace('$VERSION', str(version[0])).replace('\n', '')
logger.info('NiFi Clean Command: ' + fixed_copy)
logger.info('NiFi Copy Command: ' + fixed_remove)
remove = sh.run(fixed_remove)
copy = sh.run(fixed_copy)
logger.info('Attempting to restart Ambari...')
restart = sh.run(cmds[3])
print("Please open the Ambari Interface and manually deploy the NiFi Service.")
raw_input("Press enter twice to continue...")
raw_input("Press enter once to continue...")
# We've copied the necessary files. Once that completes we need to add it to Ambari
logger.info('Waiting for user to install service in Ambari to continue')
print('Checking to make sure service is installed')
ambari = config.read_config('global.conf')['AMBARI']
installed = check_ambari_service_installed('NIFI', ambari)
logger.info('NiFi installed successfully')
cont = ''
if not installed:
print('Unable to contact Ambari Server. Unsure whether or not Zeppelin was installed')
while not (cont == 'y' or cont == 'n'):
cont = raw_input('Continue attempt to set up NiFi for demo?(y/n)')
if not (cont == 'y' or cont == 'n'):
print('Please enter "y" or "n"')
else:
cont = 'y'
if cont == 'n':
return False
elif cont == 'y':
return True
示例14: test__handle_output_simple
def test__handle_output_simple(self):
sh = Shell()
self.assertEqual(sh._stdout, '')
self.assertEqual(sh._stderr, '')
sh._handle_output('another.txt\n', None)
self.assertEqual(sh._stdout, 'another.txt\n')
self.assertEqual(sh._stderr, '')
sh._handle_output('something.txt\n', 'Error: Please supply an arg.\n')
self.assertEqual(sh._stdout, 'another.txt\nsomething.txt\n')
self.assertEqual(sh._stderr, 'Error: Please supply an arg.\n')
示例15: is_hdp_select_installed
def is_hdp_select_installed():
'''Checks if ``hdp-select`` is installed.
Returns:
bool: True if installed (available as shell command), False if not installed'''
sh = Shell()
output = sh.run('which hdp-select')
if len(output[0]) == 0:
return False
else:
return True