forked from NREL/buildstockbatch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request NREL#409 from rewiringamerica/refactor
Small refactor to simplify adding a GCP implementation
- Loading branch information
Showing
4 changed files
with
65 additions
and
39 deletions.
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
Empty file.
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,45 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
buildstockbatch.docker_base | ||
~~~~~~~~~~~~~~~ | ||
This is the base class mixed into classes that deploy using a docker container. | ||
:author: Natalie Weires | ||
:license: BSD-3 | ||
""" | ||
import docker | ||
import logging | ||
|
||
from buildstockbatch.base import BuildStockBatchBase | ||
from buildstockbatch.utils import ContainerRuntime | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class DockerBatchBase(BuildStockBatchBase): | ||
"""Base class for implementations that run in Docker containers.""" | ||
|
||
CONTAINER_RUNTIME = ContainerRuntime.DOCKER | ||
|
||
def __init__(self, project_filename): | ||
super().__init__(project_filename) | ||
|
||
self.docker_client = docker.DockerClient.from_env() | ||
try: | ||
self.docker_client.ping() | ||
except: # noqa: E722 (allow bare except in this case because error can be a weird non-class Windows API error) | ||
logger.error("The docker server did not respond, make sure Docker Desktop is started then retry.") | ||
raise RuntimeError("The docker server did not respond, make sure Docker Desktop is started then retry.") | ||
|
||
@staticmethod | ||
def validate_project(project_file): | ||
super(DockerBatchBase, DockerBatchBase).validate_project(project_file) | ||
|
||
@property | ||
def docker_image(self): | ||
return "nrel/openstudio:{}".format(self.os_version) | ||
|
||
@property | ||
def weather_dir(self): | ||
return self._weather_dir |
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