Skip to content

Commit

Permalink
feat(oracle): add config option for region and profile
Browse files Browse the repository at this point in the history
  • Loading branch information
a-dubs authored and aciba90 committed Aug 16, 2024
1 parent e3cc352 commit 3feb7b6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1!7.7.4
1!7.8.0
2 changes: 2 additions & 0 deletions pycloudlib.toml.template
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ domain_name = ""
config_path = "~/.oci/config"
availability_domain = "" # Likely in ~/.oci/oci_cli_rc
compartment_id = "" # Likely in ~/.oci/oci_cli_rc
# region = "us-phoenix-1" # will use region from oci config file if not specified
# profile = "DEFAULT" # will use default profile from oci config file if not specified
# public_key_path = "~/.ssh/id_rsa.pub"
# private_key_path = "" # Defaults to 'public_key_path' without the '.pub'
# key_name = "" # Defaults to your username if not set
Expand Down
24 changes: 20 additions & 4 deletions pycloudlib/oci/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ def __init__(
availability_domain: Optional[str] = None,
compartment_id: Optional[str] = None,
config_path: Optional[str] = None,
config_dict: Optional[str] = None,
config_dict: Optional[dict] = None,
vcn_name: Optional[str] = None,
fault_domain: Optional[str] = None,
):
profile: Optional[str] = None,
region: Optional[str] = None,
): # pylint: disable-msg=too-many-locals
"""
Initialize the connection to OCI.
Expand Down Expand Up @@ -95,6 +97,10 @@ def __init__(
try:
oci.config.validate_config(config_dict)
self.oci_config = config_dict
if profile:
self._log.warning(
"Profile name is ignored when using config_dict"
)
except oci.exceptions.InvalidConfig as e:
raise ValueError(
"Config dict is invalid. Pass a valid config dict. "
Expand All @@ -112,11 +118,21 @@ def __init__(
"{} is not a valid config file. Pass a valid config "
"file.".format(config_path)
)
self.oci_config = oci.config.from_file(config_path)
profile = profile or self.config.get("profile")
if profile:
self.oci_config = oci.config.from_file(
config_path, profile_name=profile
)
else:
self.oci_config = oci.config.from_file(config_path)

self.oci_config["region"] = (
region or self.config.get("region") or self.oci_config["region"]
)
self.region = self.oci_config["region"]

self.vcn_name = vcn_name
self.fault_domain = fault_domain

self._log.debug("Logging into OCI")
self.compute_client = oci.core.ComputeClient(self.oci_config) # noqa: E501
self.network_client = oci.core.VirtualNetworkClient(self.oci_config) # noqa: E501
Expand Down

0 comments on commit 3feb7b6

Please sign in to comment.