Skip to content

Commit

Permalink
Rd 626 support create if missing (#190)
Browse files Browse the repository at this point in the history
* add create if missing for webapp and plan

* use resource factory to check if resource exist

* use function in order to save common info in runtime props

* remove logs

* use function to save external resource details

* fix plan tests and add external resouce and create if missing tests

* add genereate cloud error function, add tests for webapp with create if missing and refactor tests structure

* fix plan delete

* use function to get azure config and create loadbalancer backend puul resource in sdk

* implement get load balancer backend pool in sdk

* add create if missing for load balancer backend pool

* remove uneccesary inputs from example blueprint

* flake8

* add loadbalancer probe sdk

* fix load balancer probe bug and add create if missing to lb probes

* remove comments

* fix lb rule bug

* add create if missing for loadbalancer rule

* add create if missing for inbound nat rule

* flake8 fixes

* Rd 626 support create if missing neteork resources (#191)

* some refactoring for the network resources

* fix subnet params bug

* Rd 626 support create if missing storage resources (#192)

* add file share sdk and task

* clean storage account

* more refactoring for storage account

* change mapping

* add delete operation for fileshare

* add storage account runtime property

* Rd 626 support create if missing compute resources (#193)

* add create if missing for managed cluster

* add operation for aks

* map aks store kubeconfig operation

* delete comments

* delete one more comment

* bump version
  • Loading branch information
AdarShaked authored May 23, 2021
1 parent 26b7794 commit b7dc1ce
Show file tree
Hide file tree
Showing 31 changed files with 926 additions and 832 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
3.3.0: Add create_if_missing for all azure resources.
3.2.1: Fix bug, fail if trying to use external resource that doesn't exist.
3.2.0: Add pull operation for Azure ARM deployment.
3.1.0: Support create if missing/use if exists logic.
Expand Down
14 changes: 7 additions & 7 deletions azure_sdk/resources/app_service/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ def get(self, group_name, plan_name):
self.logger.info("Get plan...{0}".format(plan_name))
plan = self.client.app_service_plans.get(
resource_group_name=group_name,
name=plan_name
).as_dict()
self.logger.info(
'Get plan result: {0}'.format(
utils.secure_logging_content(plan)))
name=plan_name)
if plan:
plan = plan.as_dict()
self.logger.info(
'Get plan result: {0}'.format(
utils.secure_logging_content(plan)))
return plan

def create_or_update(self, group_name, plan_name, params):
Expand All @@ -56,10 +57,9 @@ def create_or_update(self, group_name, plan_name, params):

def delete(self, group_name, plan_name):
self.logger.info("Deleting plan...{0}".format(plan_name))
delete_async_operation = self.client.app_service_plans.delete(
self.client.app_service_plans.delete(
resource_group_name=group_name,
name=plan_name
)
delete_async_operation.wait()
self.logger.debug(
'Deleted plan {0}'.format(plan_name))
14 changes: 7 additions & 7 deletions azure_sdk/resources/app_service/web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ def get(self, group_name, web_app_name):
self.logger.info("Get web_app...{0}".format(web_app_name))
web_app = self.client.web_apps.get(
resource_group_name=group_name,
name=web_app_name
).as_dict()
self.logger.info(
'Get web_app result: {0}'.format(
utils.secure_logging_content(web_app)))
name=web_app_name)
if web_app:
web_app = web_app.as_dict()
self.logger.info(
'Get web_app result: {0}'.format(
utils.secure_logging_content(web_app)))
return web_app

def create_or_update(self, group_name, web_app_name, params):
Expand All @@ -55,10 +56,9 @@ def create_or_update(self, group_name, web_app_name, params):

def delete(self, group_name, web_app_name):
self.logger.info("Deleting web_app...{0}".format(web_app_name))
delete_async_operation = self.client.web_apps.delete(
self.client.web_apps.delete(
resource_group_name=group_name,
name=web_app_name
)
delete_async_operation.wait()
self.logger.debug(
'Deleted web_app {0}'.format(web_app_name))
96 changes: 96 additions & 0 deletions azure_sdk/resources/network/load_balancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,99 @@ def delete(self, group_name, load_balancer_name):
delete_async_operation.wait()
self.logger.debug(
'Deleted load_balancer {0}'.format(load_balancer_name))


class LoadBalancerBackendAddressPool(AzureResource):

def __init__(self, azure_config, logger,
api_version=constants.API_VER_NETWORK_LB_BACKEND_PROBES):
super(LoadBalancerBackendAddressPool, self).__init__(azure_config)
self.logger = logger
self.client = \
NetworkManagementClient(self.credentials, self.subscription_id,
api_version=api_version)

def get(self, group_name, load_balancer_name, backend_address_pool_name):
self.logger.info("Get load balancer backend address pool...{0}".format(
backend_address_pool_name))
backend_pool = self.client.load_balancer_backend_address_pools.get(
resource_group_name=group_name,
load_balancer_name=load_balancer_name,
backend_address_pool_name=backend_address_pool_name).as_dict()
self.logger.info(
"Get load balancer backend address pool: {0}".format(
utils.secure_logging_content(backend_pool))
)
return backend_pool


class LoadBalancerProbe(AzureResource):

def __init__(self, azure_config, logger,
api_version=constants.API_VER_NETWORK_LB_BACKEND_PROBES):
super(LoadBalancerProbe, self).__init__(azure_config)
self.logger = logger
self.client = \
NetworkManagementClient(self.credentials, self.subscription_id,
api_version=api_version)

def get(self, group_name, load_balancer_name, probe_name):
self.logger.info("Get load balancer probe...{0}".format(
probe_name))
probe = self.client.load_balancer_probes.get(
resource_group_name=group_name,
load_balancer_name=load_balancer_name,
probe_name=probe_name).as_dict()
self.logger.info(
"Get load balancer probe result: {0}".format(
utils.secure_logging_content(probe))
)
return probe


class LoadBalancerLoadBalancingRule(AzureResource):

def __init__(self, azure_config, logger,
api_version=constants.API_VER_NETWORK_LB_BACKEND_PROBES):
super(LoadBalancerLoadBalancingRule, self).__init__(azure_config)
self.logger = logger
self.client = \
NetworkManagementClient(self.credentials, self.subscription_id,
api_version=api_version)

def get(self, group_name, load_balancer_name, load_balancing_rule_name):
self.logger.info("Get load balancer rule...{0}".format(
load_balancing_rule_name))
rule = self.client.load_balancer_load_balancing_rules.get(
resource_group_name=group_name,
load_balancer_name=load_balancer_name,
load_balancing_rule_name=load_balancing_rule_name).as_dict()
self.logger.info(
"Get load balancer rule result: {0}".format(
utils.secure_logging_content(rule))
)
return rule


class LoadBalancerInboundNatRule(AzureResource):

def __init__(self, azure_config, logger,
api_version=constants.API_VER_NETWORK_LB_BACKEND_PROBES):
super(LoadBalancerInboundNatRule, self).__init__(azure_config)
self.logger = logger
self.client = \
NetworkManagementClient(self.credentials, self.subscription_id,
api_version=api_version)

def get(self, group_name, load_balancer_name, inbound_nat_rule_name):
self.logger.info("Get load balancer inbound nat rule...{0}".format(
inbound_nat_rule_name))
rule = self.client.inbound_nat_rules.get(
resource_group_name=group_name,
load_balancer_name=load_balancer_name,
inbound_nat_rule_name=inbound_nat_rule_name).as_dict()
self.logger.info(
"Get load balancer inbound nat rule result: {0}".format(
utils.secure_logging_content(rule))
)
return rule
57 changes: 57 additions & 0 deletions azure_sdk/resources/storage/file_share.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from azure.mgmt.storage import StorageManagementClient

from cloudify_azure import (constants, utils)
from azure_sdk.common import AzureResource


class FileShare(AzureResource):

def __init__(self, azure_config, logger,
api_version=constants.API_VER_STORAGE_FILE_SHARE):
super(FileShare, self).__init__(azure_config)
self.logger = logger
self.client = \
StorageManagementClient(self.credentials, self.subscription_id,
api_version=api_version)

def get(self, group_name, account_name, share_name):
self.logger.info("Get File Share...{0}".format(share_name))
file_share = self.client.file_shares.get(
resource_group_name=group_name,
account_name=account_name,
share_name=share_name
).as_dict()
self.logger.info(
'Get File Share result: {0}'.format(
utils.secure_logging_content(file_share)))
return file_share

def create(self,
group_name,
account_name,
share_name,
metadata=None,
share_quota=None):
self.logger.info(
"Create File Share...{0}".format(share_name))
file_share = self.client.file_shares.create(
resource_group_name=group_name,
account_name=account_name,
share_name=share_name,
metadata=metadata,
share_quota=share_quota,
).as_dict()
self.logger.info(
'Create File Share result : {0}'.format(
utils.secure_logging_content(file_share)))
return file_share

def delete(self, group_name, account_name, share_name):
self.logger.info("Deleting File Share...{0}".format(share_name))
self.client.file_shares.delete(
resource_group_name=group_name,
account_name=account_name,
share_name=share_name
)
self.logger.debug(
'Deleted File Share {0}'.format(share_name))
2 changes: 2 additions & 0 deletions cloudify_azure/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
# Each service has its own API version independent of any other services
API_VER_RESOURCES = '2017-05-10'
API_VER_STORAGE = '2015-06-15'
API_VER_STORAGE_FILE_SHARE = '2019-06-01'
API_VER_NETWORK = '2016-09-01'
API_VER_NETWORK_LB_BACKEND_PROBES = '2020-03-01'
API_VER_COMPUTE = '2016-03-30'
API_VER_STORAGE_BLOB = '2015-12-11'
API_VER_CONTAINER = '2017-07-01'
Expand Down
Loading

0 comments on commit b7dc1ce

Please sign in to comment.