def _get_client(handler): """ Get the clients using newer methods from the CloudBolt main repo if this CB is running a version greater than 9.2.2. These internal methods implicitly take care of much of the other features in CloudBolt such as proxy and ssl verification. Otherwise, manually instantiate clients without support for those other CloudBolt settings. """ import settings from common.methods import is_version_newer cb_version = settings.VERSION_INFO["VERSION"] if is_version_newer(cb_version, "9.2.2"): wrapper = handler.get_api_wrapper() storage_client = wrapper.storage_client else: # TODO: Remove once versions <= 9.2.2 are no longer supported. credentials = ServicePrincipalCredentials(client_id=handler.client_id, secret=handler.secret, tenant=handler.tenant_id) storage_client = storage.StorageManagementClient( credentials, handler.serviceaccount) set_progress("Connection to Azure established") return storage_client
def _get_clients(handler): """ Get the clients using newer methods from the CloudBolt main repo if this CB is running a version greater than 9.2.1. These internal methods implicitly take care of much of the other features in CloudBolt such as proxy and ssl verification. Otherwise, manually instantiate clients without support for those other CloudBolt settings. :param handler: :return: """ import settings from common.methods import is_version_newer set_progress("Connecting To Azure...") cb_version = settings.VERSION_INFO["VERSION"] if is_version_newer(cb_version, "9.2.1"): from resourcehandlers.azure_arm.azure_wrapper import configure_arm_client wrapper = handler.get_api_wrapper() web_client = configure_arm_client(wrapper, WebSiteManagementClient) resource_client = wrapper.resource_client else: # TODO: Remove once versions <= 9.2.1 are no longer supported. credentials = ServicePrincipalCredentials( client_id=handler.client_id, secret=handler.secret, tenant=handler.tenant_id, ) web_client = WebSiteManagementClient(credentials, handler.serviceaccount) resource_client = ResourceManagementClient(credentials, handler.serviceaccount) set_progress("Connection to Azure established") return web_client, resource_client
""" Creates an Azure Storage account. """ import settings from azure.common.credentials import ServicePrincipalCredentials import azure.mgmt.storage as storage import azure.mgmt.storage.v2018_02_01.models as models from common.methods import is_version_newer, set_progress from infrastructure.models import CustomField from infrastructure.models import Environment cb_version = settings.VERSION_INFO["VERSION"] CB_VERSION_93_PLUS = is_version_newer(cb_version, "9.2.2") def generate_options_for_env_id(server=None, **kwargs): envs = Environment.objects.filter( resource_handler__resource_technology__name="Azure") options = [(env.id, env.name) for env in envs] return options def generate_options_for_resource_group(control_value=None, **kwargs): """Dynamically generate options for resource group form field based on the user's selection for Environment. This method requires the user to set the resource_group parameter as dependent on environment. """ if control_value is None: return []