Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ The client here will eventually be released as "spython" (and eventually to
singularity on pypi), and the versions here will coincide with these releases.

## [master](https://github.com/singularityhub/singularity-cli/tree/master)
- Fixing bug with instance not having name when not started (0.0.56)
- instance start has been moved to non-private
- Added ability for exec and run to return the full output and message (0.0.55)
- By default, oci commands (pause, resume, kill) return the return value
- Added support and tests for OCI image command group (0.0.54)
Expand Down
22 changes: 17 additions & 5 deletions spython/instance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class Instance(ImageBase):

def __init__(self, image, start=True, **kwargs):
def __init__(self, image, start=True, name=None, **kwargs):
'''An instance is an image running as an instance with services.
This class has functions appended under cmd/__init__ and is
instantiated when the user calls Client.
Expand All @@ -19,10 +19,12 @@ def __init__(self, image, start=True, **kwargs):
==========
image: the Singularity image uri to parse (required)
start: boolean to start the instance (default is True)

name: a name for the instance (will generate RobotName
if not provided)
'''
super(ImageBase, self).__init__()
self.parse_image_name(image)
self.generate_name(name)

# Update metadats from arguments
self._update_metadata(kwargs)
Expand All @@ -31,10 +33,20 @@ def __init__(self, image, start=True, **kwargs):

# Start the instance
if start is True:
self._start(**kwargs)
self.start(**kwargs)

# Unique resource identifier

def generate_name(self, name=None):
'''generate a Robot Name for the instance to use, if the user doesn't
supply one.
'''
# If no name provided, use robot name
if name == None:
name = self.RobotNamer.generate()
self.name = name.replace('-','_')


def parse_image_name(self, image):
'''
simply split the uri from the image. Singularity handles
Expand Down Expand Up @@ -62,7 +74,7 @@ def _update_metadata(self, kwargs=None):
'''

# If not given metadata, use instance.list to get it for container
if kwargs is None:
if kwargs == None and hasattr(self, 'name'):
kwargs = self._list(self.name, quiet=True, return_json=True)

# Add acceptable arguments
Expand All @@ -79,7 +91,7 @@ def _update_metadata(self, kwargs=None):


def __str__(self):
if hasattr(self, 'uri'):
if hasattr(self, 'name'):
if self.uri:
return "%s%s" %(self.uri, self.name)
return os.path.basename(self._image)
Expand Down
2 changes: 1 addition & 1 deletion spython/instance/cmd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def generate_instance_commands():
Instance._run_command = run_command
Instance._list = instances # list command is used to get metadata
Instance._println = println
Instance._start = start # intended to be called on init, not by user
Instance.start = start # intended to be called on init, not by user
Instance.stop = stop

# Give an instance the ability to breed :)
Expand Down
7 changes: 3 additions & 4 deletions spython/instance/cmd/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ def start(self, image=None, name=None, args=None, sudo=False, options=[], captur
check_install )
check_install()

# If no name provided, give it an excellent one!
if name is None:
name = self.RobotNamer.generate()
self.name = name.replace('-','_')
# If name provided, over write robot (default)
if name != None:
self.name = name

# If an image isn't provided, we have an initialized instance
if image is None:
Expand Down
2 changes: 1 addition & 1 deletion spython/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# with this file, You can obtain one at http://mozilla.org/MPL/2.0/.


__version__ = "0.0.55"
__version__ = "0.0.56"
AUTHOR = 'Vanessa Sochat'
AUTHOR_EMAIL = 'vsochat@stanford.edu'
NAME = 'spython'
Expand Down