Skip to content

Commit

Permalink
Refactor private base config to use BaseConfiguration base class
Browse files Browse the repository at this point in the history
  • Loading branch information
erl-hpe committed Feb 2, 2024
1 parent f95a18c commit 7b93d20
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 108 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
__pycache__
dist
*.egg-info
build
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# vtds-cluster-common

The common vTDS Cluster layer plugin implementation

## Description

This repository contains the implementation of a vTDS Cluster layer
plugin that should be usable by any vTDS configuration to create a
vTDS cluster. The plugin includes an implementation of the vTDS
Expand Down
10 changes: 5 additions & 5 deletions vtds_cluster_common/base_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
"""Public API for the common platform layer base configuration data, this
gives callers access to the Platform's BaseConfig API and prevents
"""Public API for the common cluster layer base configuration data, this
gives callers access to the Cluster's BaseConfig API and prevents
them from seeing the private implementation of the API.
"""
Expand All @@ -31,7 +31,7 @@

class BaseConfig:
"""BaseConfig class presents operations on the base configuration
of the platform layer to callers.
of the cluster layer to callers.
"""
def __init__(self):
Expand All @@ -41,7 +41,7 @@ def __init__(self):
self.private = PrivateBaseConfig()

def get_base_config(self):
"""Retrieve the base configuration for the platform in the
"""Retrieve the base configuration for the cluster in the
form of a python data structure for use in composing and
overall vTDS configuration.
Expand All @@ -59,7 +59,7 @@ def get_base_config_text(self):
def get_test_overlay(self):
"""Retrieve a pre-defined test overlay configuration in the
form of a python data structure for use in composing vTDS
configurations for testing with this platform layer.
configurations for testing with this cluster layer.
"""
return self.private.get_test_overlay()
20 changes: 10 additions & 10 deletions vtds_cluster_common/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
"""Public API module for the GCP provider layer, this gives callers
access to the Provider API and prevents them from seeing the private
GCP specific implementation of the API.
"""Public API module for the common cluster layer, this gives callers
access to the Cluster API and prevents them from seeing the private
implementation of the API.
"""

Expand All @@ -31,15 +31,15 @@


class LayerAPI:
""" Provider class presents the Provider API to callers.
""" Presents the Cluster API to callers.
"""
def __init__(self, stack, config, build_dir):
"""Constructor. Constructs the public API to be used for
building and interacting with a provider layer based on the
building and interacting with a cluster layer based on the
full stack of vTDS layers loaded, the 'config' data structure
provided and an absolute path to the 'build_dir' which is a
scratch area provided by the caller for any provider layer
scratch area provided by the caller for any cluster layer
build activities to take place.
"""
Expand All @@ -52,28 +52,28 @@ def __init__(self, stack, config, build_dir):
self.private = PrivateCluster(stack, cluster_config, build_dir)

def prepare(self):
"""Prepare the provider for deployment.
"""Prepare the cluster for deployment.
"""
self.private.prepare()

def validate(self):
"""Run any configuration validation that may be appropriate
for the provider layer.
for the cluster layer.
"""
self.private.validate()

def deploy(self):
"""Deploy the provider (must call prepare() prior to this
"""Deploy the cluster (must call prepare() prior to this
call.
"""
self.private.deploy()

def remove(self):
"""Remove operation. This will remove all resources
provisioned for the provider layer.
provisioned for the cluster layer.
"""
self.private.remove()
79 changes: 6 additions & 73 deletions vtds_cluster_common/private/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,88 +20,21 @@
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
"""Private layer implementation module for the common cluster layer base
configuration.
"""Private layer implementation module for the layer base configuration.
"""

import os.path
import yaml
from vtds_base import ContextualError
from vtds_base import BaseConfiguration
from . import CONFIG_DIR


class PrivateBaseConfig:
# pylint: disable=too-few-public-methods
class PrivateBaseConfig(BaseConfiguration):
"""BaseConfig class presents operations on the base configuration
of the provider layer to callers.
of the layer to callers.
"""
def __init__(self):
"""Constructor
"""

def get_base_config(self):
"""Retrieve the base configuration for the provider in the
form of a python data structure for use in composing and
overall vTDS configuration.
"""
config = os.path.join(CONFIG_DIR, "config.yaml")
try:
with open(config, 'r', encoding='UTF-8') as config_stream:
return yaml.safe_load(config_stream)
except OSError as err:
raise ContextualError(
"cannot open common cluster base config file '%s' - %s" % (
config, str(err)
)
) from err
except yaml.YAMLError as err:
raise ContextualError(
"error parsing common cluster base config file '%s' - %s" % (
config, str(err)
)
) from err

def get_base_config_text(self):
"""Retrieve the text of the base configuration file as a text
string (UTF-8 encoded) for use in displaying the configuration
to users.
"""
config = os.path.join(CONFIG_DIR, "config.yaml")
try:
with open(config, 'r', encoding='UTF-8') as config_stream:
return config_stream.read()
except OSError as err:
raise ContextualError(
"cannot open common cluster base config file '%s' - %s" % (
config, str(err)
)
) from err

def get_test_overlay(self):
"""Retrieve a pre-defined test overlay configuration in the
form of a python data structure for use in composing vTDS
configurations for testing with this provider layer.
"""
config = os.path.join(CONFIG_DIR, "test_overlay.yaml")
try:
with open(config, 'r', encoding='UTF-8') as config_stream:
return yaml.safe_load(config_stream)
except OSError as err:
raise ContextualError(
"cannot open common cluster test config overlay file "
"'%s' - %s" % (
config, str(err)
)
) from err
except yaml.YAMLError as err:
raise ContextualError(
"error parsing common cluster test config overlay file "
"'%s' - %s" % (
config, str(err)
)
) from err
super().__init__("common cluster", CONFIG_DIR)
19 changes: 0 additions & 19 deletions vtds_cluster_common/private/config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,2 @@
cluster:
source:
# This identifies the python module containing the common platform
# layer for vTDS, its version and the URL of the pip index. Any
# necessary authentication is assumed to be handled by a '.netrc'
# or may be injected using ARTIFACTORY_USER and
# ARTIFACTORY_PASSWORD environments.
#
# This is included in the base configuration not to be used from
# there, but as an example of what it would look like in your
# first system configuration overlay to import this provider layer
# implementation into your vTDS system. You must put something
# like this in the first system configuration overlay your
# deployment uses. Without it there will be no provider layer in
# your vTDS build. The layer sources are the only special pieces
# of the configuration because they are needed to get the process
# going.
index_url: "https://artifactory.algol60.net/artifactory/csm-python-modules/simple"
package: vtds-cluster-common
version: "latest" # Any version or "latest" to take the latest version
nodes: {}
2 changes: 1 addition & 1 deletion vtds_cluster_common/private/private_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
"""Private layer implementation module for the GCP cluster.
"""Private layer implementation module for the common cluster.
"""

Expand Down

0 comments on commit 7b93d20

Please sign in to comment.