in deploy/ansible/action_plugins/public_api.py [0:0]
def run(self, tmp=None, task_vars=None):
result = super(ActionModule, self).run(tmp, task_vars)
# Get parameters from task arguments
method = self._task.args.get("method")
output_directory = self._task.args.get("outputDirectoryPath", "/tmp")
output_file = self._task.args.get("outputFile", "output.txt")
azure_arg_mapping = {
"calKeyvaultId": "vault_url",
"clientId": "client_id",
"clientSecret": "secret",
"tenantId": "tenant",
}
# Extract relevant arguments and map them to AzureKeyVaultManager constructor argument names
azure_args = {
azure_arg_mapping[key]: value
for key, value in self._task.args.items()
if key in azure_arg_mapping
}
# Retrieve secrets from Azure Key Vault
azure_mngr = AzureKeyVaultManager(**azure_args)
api_secrets = azure_mngr.get_secrets(
["apiEndpoint", "clientCertificate", "clientPrivateKey", "oauthServerUrl"]
)
apiEndPoint, clientCertificate, clientPrivateKey, oathUrl = api_secrets
# Create certificate files
azure_mngr.create_certificates_files(clientCertificate, clientPrivateKey)
conn = Connection("", output_directory, output_file)
if method == "get_product":
validation_result, new_module_args = self.validate_argument_spec(
method_spec_product, required_together=required_together
)
conn.login(oathUrl, apiEndPoint)
status, _, data = conn.get("/solutions/v1/products")
result.update(status=status, response=str(data))
elif method == "get_progress":
validation_result, new_module_args = self.validate_argument_spec(
method_spec_progress, required_together=required_together
)
conn.login(oathUrl, apiEndPoint)
system_id = new_module_args.get("systemId")
status, _, data = conn.get(
"/workloads/v1/systems/" + system_id + "/provisioningProgress"
)
result.update(status=status, response=str(data))
elif method == "deployment":
validation_result, new_module_args = self.validate_argument_spec(
method_spec_deployment, required_together=required_together
)
conn.login(oathUrl, apiEndPoint)
status, _, data = conn.get("/solutions/v1/products")
if data is not None:
products_dict = {p["productId"]: p for p in data.get("products")}
product = products_dict.get(new_module_args.get("productId"))
product_constraints = [
item
for item in product.get("availableProviders")
if "Microsoft Azure" in item["name"]
][0]
if not product:
raise AnsibleActionFail(
"Product not found. Choose from the available products' list %s"
% products_dict
)
method_spec_deployment.get("infrastructureParameterSet").get("options").get(
"operatingSystem"
).update({"choices": product_constraints.get("availableOperatingSystems")})
method_spec_deployment.get("infrastructureParameterSet").get("options").get(
"hanaVmSize"
).update({"choices": product_constraints.get("availableHanaVmSizes")})
method_spec_deployment.get("infrastructureParameterSet").get("options").get(
"centralServicesVmSize"
).update(
{"choices": product_constraints.get("availableCentralServicesVmSizes")}
)
method_spec_deployment.get("infrastructureParameterSet").get("options").get(
"enqueueReplicationServerVmSize"
).update(
{
"choices": product_constraints.get(
"availableEnqueueReplicationServerVmSizes"
)
}
)
method_spec_deployment.get("infrastructureParameterSet").get("options").get(
"applicationServerVmSize"
).update(
{
"choices": product_constraints.get(
"availableApplicationServerVmSizes"
)
}
)
method_spec_deployment.get("infrastructureParameterSet").get("options").get(
"webDispatcherVmSize"
).update(
{"choices": product_constraints.get("availableWebDispatcherVmSizes")}
)
validation_result, new_module_args = self.validate_argument_spec(
method_spec_deployment
)
system = SAPsystem(new_module_args)
system_request = system.get_props()
status, _, data = conn.post(
"/workloads/v1/systems/provisioning", payload=system_request
)
result.update(status=status, response=str(data))
elif method == "software_provisioning":
conn.login(oathUrl, apiEndPoint)
validation_result, new_module_args = self.validate_argument_spec(
method_spec_provisioning, required_together=required_together
)
system = SAPsystem(new_module_args)
system_request = system.get_props()
status, _, data = conn.post(
"/workloads/v1/systems/softwareProvisioning", payload=system_request
)
result.update(
status=status, response=str(data)
) # Write response to output file
result["changed"] = True
return result