-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Joe Stubbs
committed
Jul 15, 2015
1 parent
db5274e
commit 42bae6f
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import docker | ||
from models import Actor | ||
from stores import actors_store | ||
|
||
class ActorError(Exception): | ||
def __init__(self, message): | ||
Exception.__init__(self, message) | ||
self.message = message | ||
|
||
|
||
|
||
def pull_image(actor_id): | ||
""" | ||
Update the local registry with an actor's image. | ||
:param actor_id: | ||
:return: | ||
""" | ||
try: | ||
actor = Actor.from_db(actors_store[actor_id]) | ||
except KeyError: | ||
raise ActorError("Unable to pull image -- actor {} not found.".format(actor_id)) | ||
image = actor.image | ||
cli = docker.AutoVersionClient(base_url='unix://var/run/docker.sock') | ||
try: | ||
rsp = cli.pull(repository=image) | ||
except Exception as e: | ||
raise ActorError("Error pulling image for actor {} - exception: {} ".format(actor_id, str(e))) | ||
return rsp | ||
|
||
def execute_actor(image, msg): | ||
cli = docker.AutoVersionClient(base_url='unix://var/run/docker.sock') | ||
container = cli.create_container(image=image, environment={'message': msg}) | ||
cli.start(container=container.get('Id')) | ||
cli.wait(container=container.get('Id')) | ||
|
||
|
||
if __name__ == "__main__": | ||
rsp = pull_image("foo_1") | ||
print("Image pulled. Response: {}".format(str(rsp))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
flask==0.10.1 | ||
Flask-RESTful==0.3.3 | ||
redis==2.10.3 | ||
pika==0.9.13 | ||
pika==0.9.13 | ||
docker-py |