Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run_scripts(self):
scripts = config.get('Pyami', 'scripts')
if scripts:
for script in scripts.split(','):
script = script.strip(" ")
try:
pos = script.rfind('.')
if pos > 0:
mod_name = script[0:pos]
cls_name = script[pos+1:]
cls = find_class(mod_name, cls_name)
boto.log.info('Running Script: %s' % script)
s = cls()
s.main()
else:
boto.log.warning('Trouble parsing script: %s' % script)
except Exception, e:
boto.log.exception('Problem Running Script: %s. Startup process halting.' % script)
raise e
def wait(self):
if self.server == None:
raise ValueError('server attribute must be set to run this command')
with closing(self.server.get_cmdshell()) as cmd:
# wait for the volume device to appear
cmd = self.server.get_cmdshell()
while not cmd.exists(self.device):
boto.log.info('%s still does not exist, waiting 10 seconds' % self.device)
time.sleep(10)
def handle_mount_point(self):
boto.log.info('handle_mount_point')
if not os.path.isdir(self.mount_point):
boto.log.info('making directory')
# mount directory doesn't exist so create it
self.run("mkdir %s" % self.mount_point)
else:
boto.log.info('directory exists already')
self.run('mount -l')
lines = self.last_command.output.split('\n')
for line in lines:
t = line.split()
if t and t[2] == self.mount_point:
# something is already mounted at the mount point
# unmount that and mount it as /tmp
if t[0] != self.device:
self.run('umount %s' % self.mount_point)
self.run('mount %s /tmp' % t[0])
break
self.run('chmod 777 /tmp')
def mount(self):
if self.server == None:
raise ValueError('server attribute must be set to run this command')
boto.log.info('handle_mount_point')
with closing(self.server.get_cmdshell()) as cmd:
cmd = self.server.get_cmdshell()
if not cmd.isdir(self.mount_point):
boto.log.info('making directory')
# mount directory doesn't exist so create it
cmd.run("mkdir %s" % self.mount_point)
else:
boto.log.info('directory exists already')
status = cmd.run('mount -l')
lines = status[1].split('\n')
for line in lines:
t = line.split()
if t and t[2] == self.mount_point:
# something is already mounted at the mount point
# unmount that and mount it as /tmp
if t[0] != self.device:
def mount(self):
if self.server == None:
raise ValueError, 'server attribute must be set to run this command'
boto.log.info('handle_mount_point')
with closing(self.server.get_cmdshell()) as cmd:
cmd = self.server.get_cmdshell()
if not cmd.isdir(self.mount_point):
boto.log.info('making directory')
# mount directory doesn't exist so create it
cmd.run("mkdir %s" % self.mount_point)
else:
boto.log.info('directory exists already')
status = cmd.run('mount -l')
lines = status[1].split('\n')
for line in lines:
t = line.split()
if t and t[2] == self.mount_point:
# something is already mounted at the mount point
# unmount that and mount it as /tmp
if t[0] != self.device:
cmd.run('umount %s' % self.mount_point)
cmd.run('mount %s /tmp' % t[0])
cmd.run('chmod 777 /tmp')
break
# Mount up our new EBS volume onto mount_point
cmd.run("mount %s %s" % (self.device, self.mount_point))
cmd.run('xfs_growfs %s' % self.mount_point)
def run(self):
boto.log.info('running:%s' % self.command)
log_fp = StringIO.StringIO()
process = subprocess.Popen(self.command, shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while process.poll() == None:
time.sleep(1)
t = process.communicate()
log_fp.write(t[0])
log_fp.write(t[1])
boto.log.info(log_fp.getvalue())
boto.log.info('output: %s' % log_fp.getvalue())
self.last_status = process.returncode
self.last_output = log_fp.getvalue()[0:1023]
def handle_unprocessed(self, resp):
if len(resp.get('UnprocessedItems', [])):
table_name = self.table.table_name
unprocessed = resp['UnprocessedItems'].get(table_name, [])
# Some items have not been processed. Stow them for now &
# re-attempt processing on ``__exit__``.
msg = "%s items were unprocessed. Storing for later."
boto.log.info(msg % len(unprocessed))
self._unprocessed.extend(unprocessed)
def run(self):
boto.log.info('running:%s' % self.command)
self.process = subprocess.Popen(self.command, shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if(self.wait):
while self.process.poll() == None:
time.sleep(1)
t = self.process.communicate()
self.log_fp.write(t[0])
self.log_fp.write(t[1])
boto.log.info(self.log_fp.getvalue())
self.exit_code = self.process.returncode
return self.exit_code
def handle_unprocessed(self, resp):
if len(resp.get('UnprocessedItems', [])):
table_name = self.table.table_name
unprocessed = resp['UnprocessedItems'].get(table_name, [])
# Some items have not been processed. Stow them for now &
# re-attempt processing on ``__exit__``.
msg = "%s items were unprocessed. Storing for later."
boto.log.info(msg % len(unprocessed))
self._unprocessed.extend(unprocessed)
def read_message(self):
boto.log.info('read_message')
message = self.input_queue.read(self.processing_time)
if message:
boto.log.info(message.get_body())
key = 'Service-Read'
message[key] = get_ts()
return message