def run_powershell(): credentials, subscription_id = credential_helper.get_credentials() resource_group = CONFIG['resource_group'] compute_client = ComputeManagementClient(credentials, subscription_id) machines = [ machine for machine in compute_client.virtual_machines.list(resource_group) ] if not any(machines): return False vm_name = machines[0].name parameters = { 'command_id': 'RunPowerShellScript', 'script': [ 'sqlcmd -S ca-lab-vm -E -Q "use calabs;select TOP 1 * from order_summaries" | SELECT -Last 1' ] } try: poller = compute_client.virtual_machines.run_command( resource_group, vm_name, parameters) result = poller.result() except CloudError as exception: if 'Run command extension execution is in progress. Please wait for completion before invoking a run command.' in exception.message: return False print(exception) raise exception match = re.search("^\((\d+) rows affected\)$", result.value[0].message) return match is not None and int(match.group(1)) > 0
def handler(event, context): credentials = credential_helper.get_credentials(event) project_id = event['environment_params']['project_id'] service = build('compute', 'v1', credentials=credentials) result = service.instances().list(project=project_id, zone='us-central1-a').execute() return True if 'items' in result else False
def handler(event, context): credentials = credential_helper.get_credentials(event) project_id = event['environment_params']['project_id'] service = build('cloudfunctions', 'v1', credentials=credentials) result = service.projects().locations().functions().list( parent='projects/' + project_id + '/locations/-').execute() return True if 'functions' in result and len( result['functions']) >= 1 else False
def list_deploymentslots(): ''' List Azure Web App deployment slots ''' credentials, subscription_id = credential_helper.get_credentials() resource_group = CONFIG['resource_group'] web_client = WebSiteManagementClient(credentials, subscription_id) for webapp in web_client.web_apps.list_by_resource_group(resource_group): if any(web_client.web_apps.list_slots(resource_group, webapp.name)): return True return False
def list_webapps(): ''' List Azure Web Apps ''' credentials, subscription_id = credential_helper.get_credentials() resource_group = CONFIG['resource_group'] web_client = WebSiteManagementClient(credentials, subscription_id) for webapp in web_client.web_apps.list_by_resource_group(resource_group): print(webapp.name) return any(web_client.web_apps.list_by_resource_group(resource_group))
def list_appinsights(): ''' List Application Insights ''' credentials, subscription_id = credential_helper.get_credentials() resource_group = CONFIG['resource_group'] resource_client = ResourceManagementClient(credentials, subscription_id) return any( resource.type == 'microsoft.insights/components' for resource in resource_client.resources.list_by_resource_group( resource_group))
def list_asps(): ''' List Azure App Service Plans ''' credentials, subscription_id = credential_helper.get_credentials() resource_group = CONFIG['resource_group'] resource_client = ResourceManagementClient(credentials, subscription_id) for item in resource_client.resources.list_by_resource_group( resource_group): print(item.name) web_client = WebSiteManagementClient(credentials, subscription_id) for asp in web_client.app_service_plans.list_by_resource_group( resource_group): print(asp.name) return any( web_client.app_service_plans.list_by_resource_group(resource_group))
def list_vms(): credentials, subscription_id = credential_helper.get_credentials() resource_group = CONFIG['resource_group'] resource_client = ResourceManagementClient(credentials, subscription_id) # result_list = resource_client.resource_groups.list() # result_list = list(result_list) # print(json.dumps(result_list)) for item in resource_client.resources.list_by_resource_group( resource_group): print(item.name) compute_client = ComputeManagementClient(credentials, subscription_id) for vm in compute_client.virtual_machines.list(resource_group): print(vm.name) return any(compute_client.virtual_machines.list(resource_group))