Skip to content

Commit 671583f

Browse files
committed
need to stop, seems to be issue with docker firewalls
Signed-off-by: Vanessa Sochat <[email protected]>
1 parent 10d4e44 commit 671583f

File tree

4 files changed

+92
-43
lines changed

4 files changed

+92
-43
lines changed

scompose/client/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ def get_parser():
119119
dest='tail', type=int,
120120
help='clip logs to certain number of lines from end')
121121

122+
logs.add_argument('--clear', dest="clear",
123+
help="clear existing logs.",
124+
default=False, action='store_true')
125+
122126
ps = subparsers.add_parser("ps",
123127
help="list instances")
124128

scompose/client/logs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,7 @@ def main(args, parser, extra):
3434
name=args.project_name,
3535
env_file=args.env_file)
3636

37-
# Create instances, and if none specified, create all
38-
project.logs(args.names, args.tail)
37+
if args.clear:
38+
project.clear_logs(args.names)
39+
else:
40+
project.logs(args.names, args.tail)

scompose/project/instance.py

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -290,18 +290,17 @@ def stop(self):
290290
# Networking
291291

292292
def get_address(self):
293-
'''get an ip address of an image. If it's busybox, we can't use
293+
'''get the bridge address of an image. If it's busybox, we can't use
294294
hostname -I.
295295
'''
296296
ip_address = None
297-
298297
if self.sudo:
299298
if self.exists():
300299
result = self.client.execute(image=self.instance.get_uri(),
301-
command=['hostname', '-I'],
302-
return_result=True,
303-
quiet=True,
304-
sudo=self.sudo)
300+
command=['hostname', '-I'],
301+
return_result=True,
302+
quiet=True,
303+
sudo=self.sudo)
305304

306305
# Busybox won't have hostname -I
307306
if result['return_code'] != 0:
@@ -313,8 +312,6 @@ def get_address(self):
313312
sudo=self.sudo)
314313

315314
ip_address = result['message'].strip('\n').strip()
316-
317-
# Clean up busybox output
318315
if "inet" in ip_address:
319316
ip_address = re.match('.+ inet (?P<address>.+)/', ip_address).groups()[0]
320317
else:
@@ -325,9 +322,29 @@ def get_address(self):
325322

326323
# Logs
327324

328-
def logs(self, tail=0):
329-
'''show logs for an instance'''
325+
def clear_logs(self):
326+
'''delete logs for an instance, if they exist.
327+
'''
328+
log_folder = self._get_log_folder()
329+
330+
for ext in ['out', 'err']:
331+
logfile = os.path.join(log_folder, '%s.%s' % (self.name, ext.lower()))
332+
333+
# Use Try/catch to account for not existing.
334+
try:
335+
if not self.sudo:
336+
self.client._run_command(['rm', logfile], quiet=True)
337+
self.client._run_command(['touch', logfile], quiet=True)
338+
else:
339+
self.client._run_command(['sudo', 'rm', logfile], quiet=True)
340+
self.client._run_command(['sudo', 'touch', logfile], quiet=True)
341+
except:
342+
pass
343+
330344

345+
def _get_log_folder(self):
346+
'''get a log folder that includes a user, home, and host
347+
'''
331348
home = get_userhome()
332349
user = os.path.basename(home)
333350

@@ -337,21 +354,21 @@ def logs(self, tail=0):
337354

338355
# Hostname
339356
hostname = platform.node()
357+
return os.path.join(home, '.singularity', 'instances', 'logs', hostname, user)
358+
359+
360+
def logs(self, tail=0):
361+
'''show logs for an instance'''
340362

341-
log_folder = os.path.join(home, '.singularity', 'instances', 'logs', hostname, user)
363+
log_folder = self._get_log_folder()
342364

343365
for ext in ['OUT', 'ERR']:
344366
logfile = os.path.join(log_folder, '%s.%s' % (self.name, ext.lower()))
345367

346368
# Use Try/catch to account for not existing.
347369
try:
348-
if not self.sudo:
349-
result = self.client._run_command(['cat', logfile], quiet=True)
350-
else:
351-
result = self.client._run_command(['sudo', 'cat', logfile], quiet=True)
352-
353-
if result:
354-
370+
result = self.client._run_command(['cat', logfile], quiet=True, sudo=self.sudo)
371+
if result:
355372
# If the user only wants to see certain number
356373
if tail > 0:
357374
result = '\n'.join(result.split('\n')[-tail:])

scompose/project/project.py

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -166,30 +166,46 @@ def parse(self):
166166

167167
# Networking
168168

169+
def get_bridge_address(self, name='sbr0'):
170+
'''get the (named) bridge address on the host. It should be automatically
171+
created by Singularity over 3.0.
172+
'''
173+
command = ["ip", "-4", "--oneline", "address", "show", "up", name]
174+
result = self.client._run_command(command,
175+
return_result=True,
176+
quiet=True,
177+
sudo=self.sudo)['message']
178+
bridge_address = re.match('.+ inet (?P<address>.+)/', result).groups()[0]
179+
return bridge_address
180+
181+
169182
def create_hosts(self, name, depends_on):
170183
'''create a hosts file to bind to all containers, where we define the
171184
correct hostnames to correspond with the ip addresses created.
172185
Note: This function is terrible. Singularity should easily expose
173186
these addresses. See issue here:
174187
https://github.com/sylabs/singularity/issues/3751
188+
189+
Parameters
190+
==========
191+
name: the name of the instance to create
192+
depends_on: the other instances it depends on
175193
'''
176194
template = read_file(get_template('hosts'))
177195
hosts_file = os.path.join(self.working_dir, 'etc.hosts.%s' % name)
178196
hosts_basename = os.path.basename(hosts_file)
179197

198+
# Add an entry for each instance hostname to see the others
180199
for _, instance in self.instances.items():
181-
if instance.name in depends_on:
182-
ip_address = instance.get_address()
183-
if ip_address is not None:
184-
template = ['%s\t%s\n' % (ip_address, instance.name)] + template
185-
186-
# Add to our instance
187-
instance = self.instances.get(name)
188-
189-
if instance:
190-
instance.volumes.append('%s:/etc/hosts' % hosts_basename)
191-
write_file(hosts_file, template)
192-
200+
ip_address = instance.get_address()
201+
if ip_address:
202+
print(ip_address)
203+
template = ['%s\t%s\n' % (ip_address, instance.name)] + template
204+
205+
# Add the host file to be mounted
206+
write_file(hosts_file, template)
207+
return hosts_file
208+
193209

194210
# Commands
195211

@@ -225,18 +241,20 @@ def execute(self, name, commands):
225241
sudo=self.sudo):
226242
print(line, end='')
227243

244+
# Logs
245+
246+
def clear_logs(self, names):
247+
'''clear_logs will remove all old error and output logs.
248+
'''
249+
for instance in self.iter_instances(names):
250+
instance.clear_logs()
251+
228252

229253
def logs(self, names, tail=0):
230254
'''logs will print logs to the screen.
231255
'''
232-
# If no names provided, show all logs
233-
if not names:
234-
names = self.get_instance_names()
235-
236-
# Print logs for each
237-
for name in names:
238-
if name in self.instances:
239-
self.instances[name].logs(tail=tail)
256+
for instance in self.iter_instances(names):
257+
instance.logs(tail=tail)
240258

241259
# Config
242260

@@ -273,7 +291,11 @@ def up(self, names, writable_tmpfs=False):
273291
'''
274292
return self._create(names, command="up", writable_tmpfs=writable_tmpfs)
275293

276-
def _create(self, names, command="create", writable_tmpfs=False):
294+
def _create(self,
295+
names,
296+
command="create",
297+
writable_tmpfs=True):
298+
277299
'''create one or more instances. "Command" determines the sub function
278300
to call for the instance, which should be "create" or "up".
279301
If the user provide a list of names, use them, otherwise default
@@ -289,6 +311,8 @@ def _create(self, names, command="create", writable_tmpfs=False):
289311
if not names:
290312
names = self.get_instance_names()
291313

314+
writable_tmpfs = True
315+
292316
# Keep a count to determine if we have circular dependency structure
293317
created = []
294318
count = 0
@@ -309,9 +333,11 @@ def _create(self, names, command="create", writable_tmpfs=False):
309333

310334
if do_create:
311335

312-
# Create a hosts file for the instance based on depends
313-
self.create_hosts(instance.name, created)
336+
# Create a hosts file for the instance based, add as volume
337+
hosts_file = self.create_hosts(instance.name, depends_on)
338+
instance.volumes.append('%s:/etc/hosts' % hosts_file)
314339

340+
print(instance.volumes)
315341
# If we get here, execute command and add to list
316342
getattr(instance, command)(self.working_dir, writable_tmpfs)
317343
created.append(instance.name)

0 commit comments

Comments
 (0)