def validate_azure_job(job_doc): """ Validate job. And update target_account_info for given job doc. """ validate_job(job_doc) cloud_account = get_azure_account(job_doc['cloud_account'], job_doc['requesting_user']) attrs = ('region', 'source_container', 'source_resource_group', 'source_storage_account') publish_args = ('label', 'offer_id', 'publisher_id', 'sku') for attr in attrs: if attr not in job_doc: job_doc[attr] = cloud_account[attr] services = get_services_by_last_service(job_doc['last_service']) if 'publish' in services: for arg in publish_args: if arg not in job_doc: raise MashJobException( 'Azure publishing jobs require a(n) ' ' {arg} argument in the job document.'.format(arg=arg)) return job_doc
def test_validate_job(): # use_build_time missing {date} job = { 'last_service': 'test', 'use_build_time': True, 'cloud_image_name': 'Fake image' } with raises(Exception): validate_job(job)
def validate_oci_job(job_doc): """ Update target_account_info for given job doc. """ job_doc = validate_job(job_doc) user_id = job_doc['requesting_user'] cloud_account = get_oci_account(job_doc['cloud_account'], user_id) attrs = [ 'region', 'bucket', 'availability_domain', 'compartment_id', 'oci_user_id', 'tenancy', ] create_args = ['operating_system', 'operating_system_version'] for attr in attrs: if attr not in job_doc: job_doc[attr] = cloud_account[attr] services = get_services_by_last_service(job_doc['last_service']) if 'create' in services: for arg in create_args: if arg not in job_doc: raise MashJobException( 'OCI jobs that create an image require an ' ' {arg} argument in the job document.'.format(arg=arg)) return job_doc
def validate_ec2_job(job_doc): """ Validate job. Update target_account_info for given job doc. Once accounts dictionary is built remove cloud_groups and cloud_accounts keys from job_doc. """ job_doc = validate_job(job_doc) user_id = job_doc['requesting_user'] helper_images = get_ec2_helper_images() cloud_accounts = convert_account_dict(job_doc.get('cloud_accounts', [])) accounts = {} target_accounts = [] if job_doc.get('cloud_account'): account_name = job_doc['cloud_account'] cloud_account = get_ec2_account(account_name, user_id) target_accounts.append(cloud_account) for group_name in job_doc.get('cloud_groups', []): group_accounts = get_accounts_in_ec2_group(group_name, user_id) target_accounts += group_accounts for account_name in cloud_accounts: cloud_account = get_ec2_account(account_name, user_id) target_accounts.append(cloud_account) for account in target_accounts: if account['name'] not in accounts: add_target_ec2_account( account, accounts, cloud_accounts, helper_images, job_doc.get('use_root_swap'), job_doc.get('skip_replication', False) ) if 'cloud_groups' in job_doc: del job_doc['cloud_groups'] if 'cloud_account' in job_doc: del job_doc['cloud_account'] if 'cloud_accounts' in job_doc: del job_doc['cloud_accounts'] job_doc['target_account_info'] = accounts return job_doc
def validate_aliyun_job(job_doc): """ Validate job. And update target_account_info for given job doc. """ job_doc = validate_job(job_doc) cloud_account = get_aliyun_account(job_doc['cloud_account'], job_doc['requesting_user']) attrs = ['region', 'bucket', 'security_group_id', 'vswitch_id'] for attr in attrs: if attr not in job_doc: job_doc[attr] = cloud_account.get(attr) return job_doc
def validate_gce_job(job_doc): """ Validate job. And update target_account_info for given job doc. """ job_doc = validate_job(job_doc) cloud_account = get_gce_account(job_doc['cloud_account'], job_doc['requesting_user']) attrs = ['region', 'bucket', 'testing_account'] for attr in attrs: if attr not in job_doc: job_doc[attr] = cloud_account.get(attr) services = get_services_by_last_service(job_doc['last_service']) if 'create' in services: if cloud_account['is_publishing_account'] and not job_doc.get( 'family'): raise MashJobException( 'Jobs using a GCE publishing account require a family.') if 'test' in services: if cloud_account['is_publishing_account'] and not job_doc.get( 'testing_account'): raise MashJobException( 'Jobs using a GCE publishing account require' ' the use of a test account.') if cloud_account['is_publishing_account'] and not job_doc.get( 'image_project'): raise MashJobException( 'Jobs using a GCE publishing account require an image_project.' ) return job_doc