def processWorkflow(args): if not os.path.exists(args['inputfile']): logger.error('Input File "{0:s}" does not exist.'.format( args['inputfile'])) elif os.path.exists( args['inputfile']) and not os.path.isfile(args['inputfile']): logger.error( 'Input File Name "{0:s}" exists but is not a file.'.format( args['inputfile'])) elif os.path.exists( args['outputfile']) and not os.path.isfile(args['outputfile']): logger.error( 'Output File Name "{0:s}" exists but is not a file.'.format( args['outputfile'])) elif args['outputfile'] is None or len(args['outputfile']) == 0: logger.error('Output File Name must be specified.') else: oci_json = None if args["source"] == 'drawio': input_parser = OCIDrawIoXMLParser(args['inputfile']) input_parser.parse() oci_json = input_parser.getJson() logger.debug(oci_json) logJson(oci_json) else: logger.warn( 'Unsupported source {0:s}. Supported source type {1:s}'.format( args['source'], ','.join(supported_sources))) if oci_json is not None: validateVisualiserJson(oci_json) writeJsonFile(oci_json, args['outputfile']) return
def ociRegion(): query_string = request.query_string parsed_query_string = urllib.parse.unquote(query_string.decode()) query_json = json.loads(parsed_query_string) logJson(query_json) config_profile = query_json.get('config_profile', 'DEFAULT') logger.info('Using Profile : {0!s:s}'.format(config_profile)) oci_regions = OCIRegions(profile=config_profile) regions = oci_regions.list() logger.debug(">>>>>>>>> Regions: {0!s:s}".format(regions)) return json.dumps(regions, sort_keys=False, indent=2, separators=(',', ': '))
def handle_exception(error): message = [str(x) for x in error.args] status_code = 500 success = False response = { 'success': success, 'error': { 'type': error.__class__.__name__, 'message': message } } logger.exception(error) logJson(response) return jsonify(response), status_code
def list(self, compartment_id=None, filter=None): if compartment_id is None and self.compartment_id is None: compartment_id = self.config['tenancy'] elif compartment_id is None: compartment_id = self.compartment_id # Add filter if filter is None: filter = {} shapes = oci.pagination.list_call_get_all_results( self.client.list_shapes, compartment_id=compartment_id).data logger.debug( '============================== Shapes Raw ==============================' ) logger.debug(str(shapes)) # Convert to Json object shapes_json = self.toJson(shapes) logJson(shapes_json) # De-Duplicate seen = [] deduplicated = [] for shape in shapes_json: if shape['shape'] not in seen: shape['sort_key'] = shape['shape'] if 'ocpus' in shape: split_shape = shape['shape'].split('.') shape['sort_key'] = "{0:s}-{1:s}-{2:03n}-{3:03n}".format( split_shape[0], split_shape[1], shape['ocpus'], shape['memory_in_gbs']) deduplicated.append(shape) seen.append(shape['shape']) logger.debug( '============================== Shapes De-Duplicate ==============================' ) logJson(deduplicated) shapes_json = deduplicated # Filter results self.shapes_json = self.filterJsonObjectList(shapes_json, filter) logger.debug( '============================== Shapes ==============================' ) logger.debug(str(self.shapes_json)) return self.shapes_json
def list(self, compartment_id=None, filter=None): if compartment_id is None: compartment_id = self.compartment_id # Get Namespace namespace = str(self.client.get_namespace().data) logger.debug('Namespace : {0!s:s}'.format(namespace)) # Add filter to only return AVAILABLE Compartments if filter is None: filter = {} object_storage_buckets_summary = oci.pagination.list_call_get_all_results( self.client.list_buckets, namespace_name=namespace, compartment_id=compartment_id).data # Convert to Json object object_storage_buckets_summary_json = self.toJson( object_storage_buckets_summary) logger.debug(str(object_storage_buckets_summary_json)) # Filter results self.object_storage_buckets_json = self.filterJsonObjectList( object_storage_buckets_summary_json, filter) logger.debug(str(self.object_storage_buckets_json)) # Convert Bucket Summary to Details object_storage_buckets_json = [] for bucket_summary in self.object_storage_buckets_json: bucket = self.client.get_bucket(bucket_summary['namespace'], bucket_summary['name']).data object_storage_buckets_json.append(self.toJson(bucket)) object_storage_buckets_json[-1][ 'id'] = object_storage_buckets_json[-1].get( 'id', '{0!s:s}-{1!s:s}'.format(bucket_summary['namespace'], bucket_summary['name'])) self.object_storage_buckets_json = object_storage_buckets_json logger.debug(str(self.object_storage_buckets_json)) logJson(self.object_storage_buckets_json) return self.object_storage_buckets_json
def ociQuery(): if request.method == 'GET': query_string = request.query_string parsed_query_string = urllib.parse.unquote(query_string.decode()) query_json = standardiseIds(json.loads(parsed_query_string), from_char='-', to_char='.') logger.debug( '===================================== Query Json =====================================' ) logJson(query_json) logger.debug( '======================================================================================' ) config_profile = query_json.get('config_profile', 'DEFAULT') logger.info('Using Profile : {0!s:s}'.format(config_profile)) response_json = {} config = {'region': query_json['region']} else: return '404'
def ociCompartment(): query_string = request.query_string parsed_query_string = urllib.parse.unquote(query_string.decode()) query_json = standardiseIds(json.loads(parsed_query_string), from_char='-', to_char='.') logJson(query_json) config_profile = query_json.get('config_profile', 'DEFAULT') logger.info('Using Profile : {0!s:s}'.format(config_profile)) oci_tenancies = OCITenancies(profile=config_profile) tenancy = oci_tenancies.listCompartments() compartments = [{ 'display_name': c['display_name'], 'id': c['id'], 'home_region_key': tenancy['home_region_key'] } for c in tenancy['compartments']] compartments.sort(key=lambda x: x['display_name']) logger.debug("Compartments: {0!s:s}".format(compartments)) return json.dumps(compartments, sort_keys=False, indent=2, separators=(',', ': '))
def list(self, filter={}): regions = oci.pagination.list_call_get_all_results( self.client.list_regions).data # Convert to Json object regions_json = self.toJson(regions) logger.debug(str(regions_json)) # Filter results self.regions_json = self.filterJsonObjectList(regions_json, filter) logger.debug(str(self.regions_json)) logJson(self.regions_json) # Build List of Region Objects that have methods for getting VCN / Security Lists / Route Tables etc self.regions_obj = [] for region in self.regions_json: name_parts = region['name'].split('-') region['display_name'] = '{0!s:s} {1!s:s}'.format( name_parts[0].upper(), name_parts[1].capitalize()) region['id'] = region['name'] self.regions_obj.append( OCIRegion(self.config, self.configfile, self.profile, region)) return sorted(self.regions_json, key=lambda k: k['display_name'], reverse=True)
def executeQuery(request_json={}, **kwargs): response_json = {} logger.info('Request JSON : {0:s}'.format(str(request_json))) compartment_id = request_json['compartment_id'] filter = request_json.get('virtual_cloud_network_filter', None) if filter == '': filter = None oci_compartments = OCICompartments() compartment_json = oci_compartments.get(compartment_id=compartment_id) oci_compartment = oci_compartments.compartments_obj[0] # Build OKIT Response json add compartment information response_json['compartments'] = [compartment_json] logger.info('Compartment: {0!s:s}'.format(oci_compartment.data['name'])) # Query all Virtual Cloud Networks oci_virtual_cloud_networks = oci_compartment.getVirtualCloudNetworkClients( ) response_json["virtual_cloud_networks"] = oci_virtual_cloud_networks.list( filter=filter) # Loop through resulting json for oci_virtual_cloud_network in oci_virtual_cloud_networks.virtual_cloud_networks_obj: logger.info('\tVirtual Cloud Network : {0!s:s}'.format( oci_virtual_cloud_network.data['display_name'])) # Internet Gateways oci_internet_gateways = oci_virtual_cloud_network.getInternetGatewayClients( ) response_json['internet_gateways'] = oci_internet_gateways.list() for oci_internet_gateway in oci_internet_gateways.internet_gateways_obj: logger.info('\t\tInternet Gateway : {0!s:s}'.format( oci_internet_gateway.data['display_name'])) # Route Tables oci_route_tables = oci_virtual_cloud_network.getRouteTableClients() response_json['route_tables'] = oci_route_tables.list() for oci_route_table in oci_route_tables.route_tables_obj: logger.info('\t\tRoute Table : {0!s:s}'.format( oci_route_table.data['display_name'])) # Security Lists security_lists = oci_virtual_cloud_network.getSecurityListClients() response_json['security_lists'] = security_lists.list() for security_list in security_lists.security_lists_obj: logger.info('\t\tSecurity List : {0!s:s}'.format( security_list.data['display_name'])) # Subnets subnets = oci_virtual_cloud_network.getSubnetClients() response_json['subnets'] = subnets.list() for subnet in subnets.subnets_obj: logger.info('\t\tSubnet : {0!s:s}'.format( subnet.data['display_name'])) # Query all Instances oci_instances = oci_compartment.getInstanceClients() response_json['instances'] = oci_instances.list(filter=filter) oci_instance_vnics = oci_compartment.getInstanceVnicClients() for instance in response_json['instances']: instance['vnics'] = oci_instance_vnics.list(instance_id=instance['id']) instance['subnet_id'] = instance['vnics'][0]['subnet_id'] # Query all Load Balancers oci_load_balancers = oci_compartment.getLoadBalancerClients() response_json['load_balancers'] = oci_load_balancers.list(filter=filter) logger.debug('Response : {0:s}'.format(str(response_json))) logJson(response_json) response_json = standardiseJson(response_json) logJson(response_json) return response_json
def standardiseJson(json_data={}, **kwargs): logJson(json_data) json_data = standardiseIds(json_data) logJson(json_data) return json_data
def ociArtifacts(artifact): logger.info('Artifact : {0:s}'.format(str(artifact))) query_string = request.query_string parsed_query_string = urllib.parse.unquote(query_string.decode()) query_json = standardiseIds(json.loads(parsed_query_string), from_char='-', to_char='.') logger.debug( '===================================== Query Json =====================================' ) logJson(query_json) logger.debug( '======================================================================================' ) config_profile = query_json.get('config_profile', 'DEFAULT') logger.info('Using Profile : {0!s:s}'.format(config_profile)) response_json = {} config = {'region': query_json['region']} if artifact == 'Compartment': logger.info('---- Processing Compartment') oci_compartments = OCICompartments(config=config, profile=config_profile) response_json = oci_compartments.get( compartment_id=query_json['compartment_id']) elif artifact == 'AutonomousDatabase': logger.info('---- Processing Autonomous Databases') oci_autonomous_databases = OCIAutonomousDatabases( config=config, profile=config_profile, compartment_id=query_json['compartment_id']) response_json = oci_autonomous_databases.list( filter=query_json.get('autonomous_database_filter', None)) elif artifact == 'BlockStorageVolume': logger.info('---- Processing Block Storage Volumes') oci_block_storage_volumes = OCIBlockStorageVolumes( config=config, profile=config_profile, compartment_id=query_json['compartment_id']) response_json = oci_block_storage_volumes.list( filter=query_json.get('block_storage_volume_filter', None)) elif artifact == 'Compartments': logger.info('---- Processing Compartments') oci_compartments = OCICompartments( config=config, profile=config_profile, compartment_id=query_json['compartment_id']) response_json = oci_compartments.list( filter=query_json.get('compartment_filter', None)) elif artifact == 'DynamicRoutingGateway': logger.info('---- Processing Dynamic Routing Gateways') oci_dynamic_routing_gateways = OCIDynamicRoutingGateways( config=config, profile=config_profile, compartment_id=query_json['compartment_id']) response_json = oci_dynamic_routing_gateways.list( filter=query_json.get('dynamic_routing_gateway_filter', None)) elif artifact == 'FastConnect': logger.info('---- Processing FastConnects') oci_fast_connects = OCIFastConnects( config=config, profile=config_profile, compartment_id=query_json['compartment_id']) response_json = oci_fast_connects.list( filter=query_json.get('fast_connect_filter', None)) elif artifact == 'FileStorageSystem': logger.info('---- Processing File Storage Systems') oci_file_storage_systems = OCIFileStorageSystems( config=config, profile=config_profile, compartment_id=query_json['compartment_id']) response_json = oci_file_storage_systems.list( filter=query_json.get('file_storage_system_filter', None)) elif artifact == 'Instance': logger.info('---- Processing Instances') oci_instances = OCIInstances( config=config, profile=config_profile, compartment_id=query_json['compartment_id']) response_json = oci_instances.list( filter=query_json.get('instance_filter', None)) elif artifact == 'InternetGateway': logger.info('---- Processing Internet Gateways') oci_internet_gateways = OCIInternetGateways( config=config, profile=config_profile, compartment_id=query_json['compartment_id'], vcn_id=query_json['vcn_id']) response_json = oci_internet_gateways.list( filter=query_json.get('internet_gateway_filter', None)) elif artifact == 'LoadBalancer': logger.info('---- Processing Load Balancers') oci_load_balancers = OCILoadBalancers( config=config, profile=config_profile, compartment_id=query_json['compartment_id']) response_json = oci_load_balancers.list( filter=query_json.get('load_balancer_filter', None)) response_json = [ lb for lb in response_json if query_json['subnet_id'] in lb['subnet_ids'] ] elif artifact == 'LocalPeeringGateway': logger.info('---- Processing LocalPeeringGateways') oci_local_peering_gateways = OCILocalPeeringGateways( config=config, profile=config_profile, compartment_id=query_json['compartment_id'], vcn_id=query_json['vcn_id']) response_json = oci_local_peering_gateways.list( filter=query_json.get('local_peering_gateway_filter', None)) elif artifact == 'NATGateway': logger.info('---- Processing NAT Gateways') oci_nat_gateways = OCINATGateways( config=config, profile=config_profile, compartment_id=query_json['compartment_id'], vcn_id=query_json['vcn_id']) response_json = oci_nat_gateways.list( filter=query_json.get('nat_gateway_filter', None)) elif artifact == 'NetworkSecurityGroup': logger.info('---- Processing Network Security Groups') oci_network_security_groups = OCINetworkSecurityGroups( config=config, profile=config_profile, compartment_id=query_json['compartment_id'], vcn_id=query_json['vcn_id']) response_json = oci_network_security_groups.list( filter=query_json.get('network_security_group_filter', None)) elif artifact == 'ObjectStorageBucket': logger.info('---- Processing Object Storage Buckets') oci_object_storage_buckets = OCIObjectStorageBuckets( config=config, profile=config_profile, compartment_id=query_json['compartment_id']) response_json = oci_object_storage_buckets.list( filter=query_json.get('object_storage_bucket_filter', None)) elif artifact == 'RouteTable': logger.info('---- Processing Route Tables') oci_route_tables = OCIRouteTables( config=config, profile=config_profile, compartment_id=query_json['compartment_id'], vcn_id=query_json['vcn_id']) response_json = oci_route_tables.list( filter=query_json.get('route_table_filter', None)) elif artifact == 'SecurityList': logger.info('---- Processing Security Lists') oci_security_lists = OCISecurityLists( config=config, profile=config_profile, compartment_id=query_json['compartment_id'], vcn_id=query_json['vcn_id']) response_json = oci_security_lists.list( filter=query_json.get('security_list_filter', None)) elif artifact == 'ServiceGateway': logger.info('---- Processing Service Gateways') oci_service_gateways = OCIServiceGateways( config=config, profile=config_profile, compartment_id=query_json['compartment_id'], vcn_id=query_json['vcn_id']) response_json = oci_service_gateways.list( filter=query_json.get('service_gateway_filter', None)) elif artifact == 'Subnet': logger.info('---- Processing Subnets') oci_subnets = OCISubnets(config=config, profile=config_profile, compartment_id=query_json['compartment_id'], vcn_id=query_json['vcn_id']) response_json = oci_subnets.list( filter=query_json.get('subnet_filter', None)) elif artifact == 'VirtualCloudNetwork': logger.info('---- Processing Virtual Cloud Networks') oci_virtual_cloud_networks = OCIVirtualCloudNetworks( config=config, profile=config_profile, compartment_id=query_json['compartment_id']) response_json = oci_virtual_cloud_networks.list( filter=query_json.get('virtual_cloud_network_filter', None)) else: logger.warn('---- Unknown Artifact : {0:s}'.format(str(artifact))) return '404' logger.debug( json.dumps(response_json, sort_keys=True, indent=2, separators=(',', ': '))) return json.dumps(standardiseIds(response_json), sort_keys=True)
def designer(): # Read Artifact Specific JavaScript Files oci_assets_js = sorted( os.listdir(os.path.join(bp.static_folder, 'js', 'oci_artefacts'))) # Get Palette Icon Groups / Icons svg_files = [] svg_icon_groups = {} # Read Files for (dirpath, dirnames, filenames) in os.walk(os.path.join(bp.static_folder, 'palette')): logger.debug('dirpath : {0!s:s}'.format(dirpath)) logger.debug('dirnames : {0!s:s}'.format(dirnames)) logger.debug('filenames : {0!s:s}'.format(filenames)) if os.path.basename(dirpath) != 'palette': svg_files.extend([ os.path.join(os.path.basename(dirpath), f) for f in filenames ]) svg_icon_groups[os.path.basename(dirpath)] = filenames else: svg_files.extend(filenames) logger.debug('Files Walk : {0!s:s}'.format(svg_files)) logger.debug('SVG Icon Groups {0!s:s}'.format(svg_icon_groups)) palette_icon_groups = [] for key in sorted(svg_icon_groups.keys()): palette_icon_group = {'name': str(key).title(), 'icons': []} for palette_svg in sorted(svg_icon_groups[key]): palette_icon = { 'svg': os.path.join(key, palette_svg), 'title': os.path.basename(palette_svg).split('.')[0].replace('_', ' ') } palette_icon_group['icons'].append(palette_icon) palette_icon_groups.append(palette_icon_group) logger.debug('Palette Icon Groups : {0!s:s}'.format(palette_icon_groups)) logJson(palette_icon_groups) # Read Fragment Files fragment_files = os.listdir( os.path.join(bp.static_folder, 'fragments', 'svg')) fragment_icons = [] for fragment_svg in sorted(fragment_files): logger.info('Fragment : {0!s:s}'.format(fragment_svg)) logger.info('Fragment full : {0!s:s}'.format( os.path.join(bp.static_folder, 'fragments', 'svg', fragment_svg))) fragment_icon = { 'svg': fragment_svg, 'title': os.path.basename(fragment_svg).split('.')[0].replace('_', ' ').title() } logger.info('Icon : {0!s:s}'.format(fragment_icon)) fragment_icons.append(fragment_icon) # Walk Template directory Structure template_files = [] template_dirs = {} logger.debug('Walking the template directories') rootdir = os.path.join(bp.static_folder, 'templates') for (dirpath, dirnames, filenames) in os.walk(rootdir): logger.debug('dirpath : {0!s:s}'.format(dirpath)) logger.debug('dirnames : {0!s:s}'.format(dirnames)) logger.debug('filenames : {0!s:s}'.format(filenames)) relpath = os.path.relpath(dirpath, rootdir) logger.debug('Relative Path : {0!s:s}'.format(relpath)) template_files.extend([os.path.join(relpath, f) for f in filenames]) template_dirs[relpath] = filenames logger.debug('Files Walk : {0!s:s}'.format(template_files)) logger.debug('Template Dirs {0!s:s}'.format(template_dirs)) template_groups = [] for key in sorted(template_dirs.keys()): template_group = { 'name': str(key).replace('_', ' ').title(), 'templates': [] } for template_file in sorted(template_dirs[key]): try: okit_template = { 'json': os.path.join(key, template_file), 'id': template_file.replace('.', '_') } filename = os.path.join(bp.static_folder, 'templates', key, template_file) template_json = readJsonFile(filename) logger.debug('Template Json : {0!s:s}'.format(template_json)) okit_template['title'] = template_json['title'] okit_template['description'] = template_json.get( 'description', template_json['title']) template_group['templates'].append(okit_template) except Exception as e: logger.debug(e) template_groups.append(template_group) logger.debug('Template Groups {0!s:s}'.format(template_groups)) logJson(template_groups) #Render The Template return render_template('okit/okit_designer.html', oci_assets_js=oci_assets_js, palette_icon_groups=palette_icon_groups, fragment_icons=fragment_icons, okit_templates_groups=template_groups)