Skip to content

Commit

Permalink
fix errors with vm deletion and bump version (#16)
Browse files Browse the repository at this point in the history
* fix errors with vm deletion and bump version

* fix pylint error from object format change in SDK

* salt installation is handled oob from test install
  • Loading branch information
nicholasmhughes authored Sep 26, 2022
1 parent 89f1704 commit ab788ba
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 21 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
- 3.9
- "3.10"
salt-version:
- 3004.1
- 3004.2

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -187,7 +187,7 @@ jobs:
python-version:
- 3.7
salt-version:
- 3004.1
- 3004.2

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -312,7 +312,7 @@ jobs:
- 3.8
- 3.9
salt-version:
- 3004.1
- 3004.2

steps:
- uses: actions/checkout@v2
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ This project uses [Semantic Versioning](https://semver.org/) - MAJOR.MINOR.PATCH

# Changelog

Saltext.Azurerm 2.0.0 (2022-09-26)
=====================================

Added
-----

- Updated all Azure SDK versions to recent releases and updated base code to accommodate changes.


Saltext.Azurerm 1.0.0 (2022-06-21)
=====================================

Expand Down
2 changes: 0 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ setup_requires =
setuptools>=50.3.2
setuptools-declarative-requirements
install_requires =
salt>=3002
jinja2<=3.1.2
azure-batch==12.0.0
azure-common==1.1.28
azure-graphrbac==0.61.1
Expand Down
58 changes: 43 additions & 15 deletions src/saltext/azurerm/clouds/azurerm.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
import azure.mgmt.compute.models as compute_models
import azure.mgmt.network.models as network_models

from azure.storage.blob.blockblobservice import BlockBlobService
from azure.storage.blob import BlobServiceClient, ContainerClient
from msrestazure.azure_exceptions import CloudError

HAS_LIBS = True
Expand Down Expand Up @@ -227,6 +227,7 @@ def get_configured_provider():
__opts__,
_get_active_provider_name() or __virtualname__,
combo,
log_message=False,
)

if provider:
Expand Down Expand Up @@ -1550,9 +1551,6 @@ def _get_block_blob_service(kwargs=None):
resource_group = kwargs.get("resource_group") or config.get_cloud_config_value(
"resource_group", get_configured_provider(), __opts__, search_global=False
)
sas_token = kwargs.get("sas_token") or config.get_cloud_config_value(
"sas_token", get_configured_provider(), __opts__, search_global=False
)
storage_account = kwargs.get("storage_account") or config.get_cloud_config_value(
"storage_account", get_configured_provider(), __opts__, search_global=False
)
Expand All @@ -1572,15 +1570,45 @@ def _get_block_blob_service(kwargs=None):
storage_keys = {v.key_name: v.value for v in storage_keys.keys}
storage_key = next(iter(storage_keys.values()))

cloud_env = _get_cloud_environment()
return BlobServiceClient(
account_url=storage_account,
credential=storage_key,
)


def _get_container_client(kwargs=None):
"""
Get the storage container client.
"""
resource_group = kwargs.get("resource_group") or config.get_cloud_config_value(
"resource_group", get_configured_provider(), __opts__, search_global=False
)
storage_account = kwargs.get("storage_account") or config.get_cloud_config_value(
"storage_account", get_configured_provider(), __opts__, search_global=False
)
container_name = kwargs.get("container_name") or config.get_cloud_config_value(
"container_name", get_configured_provider(), __opts__, search_global=False
)
storage_key = kwargs.get("storage_key") or config.get_cloud_config_value(
"storage_key", get_configured_provider(), __opts__, search_global=False
)

if not resource_group:
raise SaltCloudSystemExit("A resource group must be specified")

if not storage_account:
raise SaltCloudSystemExit("A storage account must be specified")

endpoint_suffix = cloud_env.suffixes.storage_endpoint
if not storage_key:
storconn = get_conn(client_type="storage")
storage_keys = storconn.storage_accounts.list_keys(resource_group, storage_account)
storage_keys = {v.key_name: v.value for v in storage_keys.keys}
storage_key = next(iter(storage_keys.values()))

return BlockBlobService(
storage_account,
storage_key,
sas_token=sas_token,
endpoint_suffix=endpoint_suffix,
return ContainerClient(
account_url=storage_account,
container_name=container_name,
credential=storage_key,
)


Expand All @@ -1594,11 +1622,11 @@ def list_blobs(call=None, kwargs=None): # pylint: disable=unused-argument
if "container" not in kwargs:
raise SaltCloudSystemExit("A container must be specified")

storageservice = _get_block_blob_service(kwargs)
storageservice = _get_container_client(kwargs)

ret = {}
try:
for blob in storageservice.list_blobs(kwargs["container"]).items:
for blob in storageservice.list_blobs(kwargs["container"]):
ret[blob.name] = {
"blob_type": blob.properties.blob_type,
"last_modified": blob.properties.last_modified.isoformat(),
Expand All @@ -1623,7 +1651,7 @@ def delete_blob(call=None, kwargs=None): # pylint: disable=unused-argument
if "blob" not in kwargs:
raise SaltCloudSystemExit("A blob must be specified")

storageservice = _get_block_blob_service(kwargs)
storageservice = _get_container_client(kwargs)

storageservice.delete_blob(kwargs["container"], kwargs["blob"])
return True
Expand All @@ -1637,7 +1665,7 @@ def delete_managed_disk(call=None, kwargs=None): # pylint: disable=unused-argum
compconn = get_conn(client_type="compute")

try:
compconn.disks.delete(kwargs["resource_group"], kwargs["blob"])
compconn.disks.begin_delete(kwargs["resource_group"], kwargs["blob"])
except Exception as exc: # pylint: disable=broad-except
log.error(
"Error deleting managed disk %s - %s",
Expand Down
2 changes: 1 addition & 1 deletion src/saltext/azurerm/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# pylint: disable=missing-module-docstring
__version__ = "1.0.0"
__version__ = "2.0.0"

0 comments on commit ab788ba

Please sign in to comment.