Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return wrapper
return wrap
TEST_DATA_CONFIG = {
"AWSCloudProvider": {
# Match the ami value with entry in custom_amis.json for use with moto
"image": cb_helpers.get_env('CB_IMAGE_AWS', 'ami-aa2ea6d0'),
"vm_type": cb_helpers.get_env('CB_VM_TYPE_AWS', 't2.nano'),
"placement": cb_helpers.get_env('CB_PLACEMENT_AWS', 'us-east-1a'),
"placement_cfg_key": "aws_zone_name"
},
'OpenStackCloudProvider': {
'image': cb_helpers.get_env('CB_IMAGE_OS',
'c66bdfa1-62b1-43be-8964-e9ce208ac6a5'),
"vm_type": cb_helpers.get_env('CB_VM_TYPE_OS', 'm1.tiny'),
"placement": cb_helpers.get_env('CB_PLACEMENT_OS', 'nova'),
"placement_cfg_key": "os_zone_name"
},
'GCPCloudProvider': {
'image': cb_helpers.get_env(
'CB_IMAGE_GCP',
'https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/'
'global/images/ubuntu-1710-artful-v20180126'),
'vm_type': cb_helpers.get_env('CB_VM_TYPE_GCP', 'f1-micro'),
'placement': cb_helpers.get_env('GCP_ZONE_NAME', 'us-central1-a'),
"placement_cfg_key": "gcp_zone_name"
},
"AzureCloudProvider": {
"image":
cb_helpers.get_env('CB_IMAGE_AZURE',
'Canonical:UbuntuServer:16.04.0-LTS:latest'),
"vm_type": cb_helpers.get_env('CB_VM_TYPE_OS', 'm1.tiny'),
"placement": cb_helpers.get_env('CB_PLACEMENT_OS', 'nova'),
"placement_cfg_key": "os_zone_name"
},
'GCPCloudProvider': {
'image': cb_helpers.get_env(
'CB_IMAGE_GCP',
'https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/'
'global/images/ubuntu-1710-artful-v20180126'),
'vm_type': cb_helpers.get_env('CB_VM_TYPE_GCP', 'f1-micro'),
'placement': cb_helpers.get_env('GCP_ZONE_NAME', 'us-central1-a'),
"placement_cfg_key": "gcp_zone_name"
},
"AzureCloudProvider": {
"image":
cb_helpers.get_env('CB_IMAGE_AZURE',
'Canonical:UbuntuServer:16.04.0-LTS:latest'),
"vm_type": cb_helpers.get_env('CB_VM_TYPE_AZURE', 'Basic_A2'),
"placement": cb_helpers.get_env('CB_PLACEMENT_AZURE', 'eastus'),
"placement_cfg_key": "azure_zone_name"
}
}
def get_provider_test_data(provider, key):
provider_id = (provider.PROVIDER_ID if isinstance(provider, CloudProvider)
else provider)
if "aws" == provider_id:
return TEST_DATA_CONFIG.get("AWSCloudProvider").get(key)
if "mock" == provider_id:
return TEST_DATA_CONFIG.get("AWSCloudProvider").get(key)
elif "openstack" == provider_id:
"placement_cfg_key": "os_zone_name"
},
'GCPCloudProvider': {
'image': cb_helpers.get_env(
'CB_IMAGE_GCP',
'https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/'
'global/images/ubuntu-1710-artful-v20180126'),
'vm_type': cb_helpers.get_env('CB_VM_TYPE_GCP', 'f1-micro'),
'placement': cb_helpers.get_env('GCP_ZONE_NAME', 'us-central1-a'),
"placement_cfg_key": "gcp_zone_name"
},
"AzureCloudProvider": {
"image":
cb_helpers.get_env('CB_IMAGE_AZURE',
'Canonical:UbuntuServer:16.04.0-LTS:latest'),
"vm_type": cb_helpers.get_env('CB_VM_TYPE_AZURE', 'Basic_A2'),
"placement": cb_helpers.get_env('CB_PLACEMENT_AZURE', 'eastus'),
"placement_cfg_key": "azure_zone_name"
}
}
def get_provider_test_data(provider, key):
provider_id = (provider.PROVIDER_ID if isinstance(provider, CloudProvider)
else provider)
if "aws" == provider_id:
return TEST_DATA_CONFIG.get("AWSCloudProvider").get(key)
if "mock" == provider_id:
return TEST_DATA_CONFIG.get("AWSCloudProvider").get(key)
elif "openstack" == provider_id:
return TEST_DATA_CONFIG.get("OpenStackCloudProvider").get(key)
elif "gcp" == provider_id:
def create_provider_instance(self):
provider_name = cb_helpers.get_env("CB_TEST_PROVIDER", "aws")
zone_cfg_key = get_provider_test_data(provider_name,
'placement_cfg_key')
factory = CloudProviderFactory()
provider_class = factory.get_provider_class(provider_name)
config = {
'default_wait_interval': self.get_provider_wait_interval(
provider_class),
'default_result_limit': 5,
zone_cfg_key: get_provider_test_data(provider_name, 'placement')
}
return provider_class(config)
# having the same resource group name do not have the same SA name.
self.storage_account = self._get_config_value(
'azure_storage_account',
get_env(
'AZURE_STORAGE_ACCOUNT',
'storacc' + self.subscription_id[-6:] +
str(uuid.uuid5(uuid.NAMESPACE_OID,
str(self.resource_group)))[-6:]))
self.vm_default_user_name = self._get_config_value(
'azure_vm_default_username', get_env(
'AZURE_VM_DEFAULT_USERNAME')) \
or self.__get_deprecated_username('cbuser')
self.public_key_storage_table_name = self._get_config_value(
'azure_public_key_storage_table_name', get_env(
'AZURE_PUBLIC_KEY_STORAGE_TABLE_NAME', 'cbcerts'))
self._azure_client = None
self._security = AzureSecurityService(self)
self._storage = AzureStorageService(self)
self._compute = AzureComputeService(self)
self._networking = AzureNetworkingService(self)
'azure_access_token', get_env('AZURE_ACCESS_TOKEN'))
self._region_name = self._get_config_value(
'azure_region_name', get_env('AZURE_REGION_NAME', 'eastus'))
self._zone_name = self._get_config_value(
'azure_zone_name', get_env('AZURE_ZONE_NAME'))
self.resource_group = self._get_config_value(
'azure_resource_group', get_env('AZURE_RESOURCE_GROUP',
'cloudbridge'))
# Storage account name is limited to a max length of 24 alphanum chars
# and unique across all of Azure. Thus, a uuid is used to generate a
# unique name for the Storage Account based on the resource group,
# while also using the subscription ID to ensure that different users
# having the same resource group name do not have the same SA name.
self.storage_account = self._get_config_value(
'azure_storage_account',
get_env(
'AZURE_STORAGE_ACCOUNT',
'storacc' + self.subscription_id[-6:] +
str(uuid.uuid5(uuid.NAMESPACE_OID,
str(self.resource_group)))[-6:]))
self.vm_default_user_name = self._get_config_value(
'azure_vm_default_username', get_env(
'AZURE_VM_DEFAULT_USERNAME')) \
or self.__get_deprecated_username('cbuser')
self.public_key_storage_table_name = self._get_config_value(
'azure_public_key_storage_table_name', get_env(
'AZURE_PUBLIC_KEY_STORAGE_TABLE_NAME', 'cbcerts'))
self._azure_client = None
# mandatory config values
self.subscription_id = self._get_config_value(
'azure_subscription_id', get_env('AZURE_SUBSCRIPTION_ID'))
self.client_id = self._get_config_value(
'azure_client_id', get_env('AZURE_CLIENT_ID'))
self.secret = self._get_config_value(
'azure_secret', get_env('AZURE_SECRET'))
self.tenant = self._get_config_value(
'azure_tenant', get_env('AZURE_TENANT'))
# optional config values
self.access_token = self._get_config_value(
'azure_access_token', get_env('AZURE_ACCESS_TOKEN'))
self._region_name = self._get_config_value(
'azure_region_name', get_env('AZURE_REGION_NAME', 'eastus'))
self._zone_name = self._get_config_value(
'azure_zone_name', get_env('AZURE_ZONE_NAME'))
self.resource_group = self._get_config_value(
'azure_resource_group', get_env('AZURE_RESOURCE_GROUP',
'cloudbridge'))
# Storage account name is limited to a max length of 24 alphanum chars
# and unique across all of Azure. Thus, a uuid is used to generate a
# unique name for the Storage Account based on the resource group,
# while also using the subscription ID to ensure that different users
# having the same resource group name do not have the same SA name.
self.storage_account = self._get_config_value(
'azure_storage_account',
get_env(
'AZURE_STORAGE_ACCOUNT',
'storacc' + self.subscription_id[-6:] +
str(uuid.uuid5(uuid.NAMESPACE_OID,
self.client_id = self._get_config_value(
'azure_client_id', get_env('AZURE_CLIENT_ID'))
self.secret = self._get_config_value(
'azure_secret', get_env('AZURE_SECRET'))
self.tenant = self._get_config_value(
'azure_tenant', get_env('AZURE_TENANT'))
# optional config values
self.access_token = self._get_config_value(
'azure_access_token', get_env('AZURE_ACCESS_TOKEN'))
self._region_name = self._get_config_value(
'azure_region_name', get_env('AZURE_REGION_NAME', 'eastus'))
self._zone_name = self._get_config_value(
'azure_zone_name', get_env('AZURE_ZONE_NAME'))
self.resource_group = self._get_config_value(
'azure_resource_group', get_env('AZURE_RESOURCE_GROUP',
'cloudbridge'))
# Storage account name is limited to a max length of 24 alphanum chars
# and unique across all of Azure. Thus, a uuid is used to generate a
# unique name for the Storage Account based on the resource group,
# while also using the subscription ID to ensure that different users
# having the same resource group name do not have the same SA name.
self.storage_account = self._get_config_value(
'azure_storage_account',
get_env(
'AZURE_STORAGE_ACCOUNT',
'storacc' + self.subscription_id[-6:] +
str(uuid.uuid5(uuid.NAMESPACE_OID,
str(self.resource_group)))[-6:]))
self.vm_default_user_name = self._get_config_value(
'azure_vm_default_username', get_env(
def __init__(self, config):
super(AzureCloudProvider, self).__init__(config)
# mandatory config values
self.subscription_id = self._get_config_value(
'azure_subscription_id', get_env('AZURE_SUBSCRIPTION_ID'))
self.client_id = self._get_config_value(
'azure_client_id', get_env('AZURE_CLIENT_ID'))
self.secret = self._get_config_value(
'azure_secret', get_env('AZURE_SECRET'))
self.tenant = self._get_config_value(
'azure_tenant', get_env('AZURE_TENANT'))
# optional config values
self.access_token = self._get_config_value(
'azure_access_token', get_env('AZURE_ACCESS_TOKEN'))
self._region_name = self._get_config_value(
'azure_region_name', get_env('AZURE_REGION_NAME', 'eastus'))
self._zone_name = self._get_config_value(
'azure_zone_name', get_env('AZURE_ZONE_NAME'))
self.resource_group = self._get_config_value(
'azure_resource_group', get_env('AZURE_RESOURCE_GROUP',
'cloudbridge'))
# Storage account name is limited to a max length of 24 alphanum chars
# and unique across all of Azure. Thus, a uuid is used to generate a
# unique name for the Storage Account based on the resource group,
# while also using the subscription ID to ensure that different users
# having the same resource group name do not have the same SA name.
self.storage_account = self._get_config_value(
'azure_storage_account',
get_env(
'AZURE_STORAGE_ACCOUNT',
def __init__(self, config):
super(AzureCloudProvider, self).__init__(config)
# mandatory config values
self.subscription_id = self._get_config_value(
'azure_subscription_id', get_env('AZURE_SUBSCRIPTION_ID'))
self.client_id = self._get_config_value(
'azure_client_id', get_env('AZURE_CLIENT_ID'))
self.secret = self._get_config_value(
'azure_secret', get_env('AZURE_SECRET'))
self.tenant = self._get_config_value(
'azure_tenant', get_env('AZURE_TENANT'))
# optional config values
self.access_token = self._get_config_value(
'azure_access_token', get_env('AZURE_ACCESS_TOKEN'))
self._region_name = self._get_config_value(
'azure_region_name', get_env('AZURE_REGION_NAME', 'eastus'))
self._zone_name = self._get_config_value(
'azure_zone_name', get_env('AZURE_ZONE_NAME'))
self.resource_group = self._get_config_value(
'azure_resource_group', get_env('AZURE_RESOURCE_GROUP',
'cloudbridge'))
# Storage account name is limited to a max length of 24 alphanum chars
# and unique across all of Azure. Thus, a uuid is used to generate a
# unique name for the Storage Account based on the resource group,
# while also using the subscription ID to ensure that different users
# having the same resource group name do not have the same SA name.