Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Release btpsa-v1.5.0 #434

Merged
merged 10 commits into from
Feb 21, 2023
Prev Previous commit
Next Next commit
Revert "add check for provisioningMethod"
This reverts commit a80fd3c.
rui1610 committed Feb 20, 2023
commit 026fa12b7e886ef70bf7a77183dbd41f3f86411d
40 changes: 1 addition & 39 deletions libs/python/btp_cli.py
Original file line number Diff line number Diff line change
@@ -1780,59 +1780,21 @@ def doAllEntitlements(btpUsecase: BTPUSECASE, allItems):
assign_entitlement(btpUsecase, service)


def getListOfAvailableServicesAndAppsInSubaccount(btpUsecase):
accountMetadata = btpUsecase.accountMetadata
subaccountid = accountMetadata["subaccountid"]

command = (
"btp --format json list accounts/entitlement --subaccount '"
+ subaccountid
+ "'"
)
message = (
"Get list of available services and app subsciptions for defined subaccount >"
+ subaccountid
+ "<"
)
result = runCommandAndGetJsonResult(btpUsecase, command, "INFO", message)

return result


def isProvisioningRequired(service, allEntitlements):
for entitlement in allEntitlements.get("quotas"):
if entitlement.get("service") == service.name and entitlement.get("plan") == service.plan:
if entitlement.get("provisioningMethod") == "NONE_REQUIRED":
return False
if entitlement.get("provisioningMethod") == "SERVICE_BROKER":
return True

return None


def initiateAppSubscriptions(btpUsecase: BTPUSECASE):
if (
btpUsecase.definedAppSubscriptions is not None
and len(btpUsecase.definedAppSubscriptions) > 0
):

log.header("Initiate subscriptions to apps")
entitlements = getListOfAvailableServicesAndAppsInSubaccount(btpUsecase)

# Now do all the subscriptions
for appSubscription in btpUsecase.definedAppSubscriptions:
appName = appSubscription.name
appPlan = appSubscription.plan
parameters = appSubscription.parameters
if appSubscription.entitleonly is False:
provisioningRequired = isProvisioningRequired(appSubscription, allEntitlements=entitlements)
if provisioningRequired is True:
subscribe_app_to_subaccount(btpUsecase, appName, appPlan, parameters)
if isProvisioningRequired(appSubscription, allEntitlements=entitlements) is False:
log.warning("Creation of subscription not required for app >" + appSubscription.name + "< and plan >" + appSubscription.plan + "<. Skipping.")
if isProvisioningRequired(appSubscription, allEntitlements=entitlements) is None:
log.error("Something wrong with entitlement for app >" + appSubscription.name + "< and plan >" + appSubscription.plan + "<. Please cross-check!")
sys.exit(os.EX_DATAERR)
subscribe_app_to_subaccount(btpUsecase, appName, appPlan, parameters)


def get_subscription_deletion_status(btpUsecase: BTPUSECASE, app):
47 changes: 2 additions & 45 deletions libs/python/helperServiceInstances.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from libs.python.helperCommandExecution import runShellCommand, runCommandAndGetJsonResult
from libs.python.helperCommandExecution import runShellCommand
from libs.python.helperGeneric import (
getServiceByServiceName,
createInstanceName,
@@ -27,7 +27,6 @@
deleteBtpServiceInstance,
getBtpServiceDeletionStatus,
)

from libs.python.helperEnvKyma import (
createKymaServiceBinding,
deleteKymaServiceBindingAndWait,
@@ -230,17 +229,6 @@ def checkIfAllServiceInstancesCreated(btpUsecase, checkIntervalInSeconds):
return allServicesCreated


def isProvisioningRequired(service, allEntitlements):
for entitlement in allEntitlements.get("quotas"):
if entitlement.get("service") == service.name and entitlement.get("plan") == service.plan:
if entitlement.get("provisioningMethod") == "NONE_REQUIRED":
return False
if entitlement.get("provisioningMethod") == "SERVICE_BROKER":
return True

return None


def initiateCreationOfServiceInstances(btpUsecase):
createServiceInstances = (
btpUsecase.definedServices is not None and len(btpUsecase.definedServices) > 0
@@ -249,8 +237,6 @@ def initiateCreationOfServiceInstances(btpUsecase):
if createServiceInstances is True:
log.header("Initiate creation of service instances")



# First add all instance names to the services
for service in btpUsecase.definedServices:
instancename = createInstanceName(btpUsecase, service)
@@ -273,23 +259,12 @@ def initiateCreationOfServiceInstances(btpUsecase):
)
sys.exit(os.EX_DATAERR)

entitlements = getListOfAvailableServicesAndAppsInSubaccount(btpUsecase)

serviceInstancesToBeCreated = []
# Restrict the creation of service instances to those
# that have been set to entitleOnly to False (default)
for service in btpUsecase.definedServices:

# Check whether the creation of a service instance is required at all
provisioningRequired = isProvisioningRequired(service, allEntitlements=entitlements)
if service.entitleonly is False:
if isProvisioningRequired(service, allEntitlements=entitlements) is True:
serviceInstancesToBeCreated.append(service)
if isProvisioningRequired(service, allEntitlements=entitlements) is False:
log.warning("Creation of service instance not required for service >" + service.name + "< and plan >" + service.plan + "<. Skipping.")
if isProvisioningRequired(service, allEntitlements=entitlements) is None:
log.error("Something wrong with entitlement for service >" + service.name + "< and plan >" + service.plan + "<. Please cross-check!")
sys.exit(os.EX_DATAERR)
serviceInstancesToBeCreated.append(service)

# Now create all the service instances
for service in serviceInstancesToBeCreated:
@@ -386,24 +361,6 @@ def get_service_status(btpUsecase, service, targetEnvironment):
return status


def getListOfAvailableServicesAndAppsInSubaccount(btpUsecase):
accountMetadata = btpUsecase.accountMetadata
subaccountid = accountMetadata["subaccountid"]

command = (
"btp --format json list accounts/entitlement --subaccount '"
+ subaccountid
+ "'"
)
message = (
"Get list of available services and app subsciptions for defined subaccount >"
+ subaccountid
+ "<"
)
result = runCommandAndGetJsonResult(btpUsecase, command, "INFO", message)

return result

def createServiceInstance(btpUsecase, service, targetEnvironment, serviceCategory):
if targetEnvironment == "cloudfoundry":
if serviceCategory == "SERVICE" or service.category == "ELASTIC_SERVICE":