Skip to content

Commit

Permalink
Fix toc generation for api docs (#9655)
Browse files Browse the repository at this point in the history
* Fix toc generation for api docs

* Apply suggestions from code review

Co-authored-by: dahn <daan.hoogland@gmail.com>

---------

Co-authored-by: dahn <daan.hoogland@gmail.com>
  • Loading branch information
vishesh92 and DaanHoogland authored Sep 17, 2024
1 parent 5f80778 commit aa64476
Showing 1 changed file with 40 additions and 68 deletions.
108 changes: 40 additions & 68 deletions tools/apidoc/gen_toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
# specific language governing permissions and limitations
# under the License.

import os
import os.path
import sys
from xml.dom import minidom
from xml.parsers.expat import ExpatError
import difflib


ROOT_ADMIN = 'r'
Expand Down Expand Up @@ -51,7 +51,9 @@
'VirtualMachine': 'Virtual Machine',
'VM': 'Virtual Machine',
'Vnf': 'Virtual Network Functions',
'VnfTemplate': 'Virtual Network Functions',
'GuestSubnet': 'Routing',
'HypervisorGuestOsNames': 'Guest OS',
'Domain': 'Domain',
'Template': 'Template',
'Iso': 'ISO',
Expand All @@ -63,83 +65,46 @@
'StaticNat': 'NAT',
'IpForwarding': 'NAT',
'Host': 'Host',
'OutOfBand': 'Out-of-band Management',
'HostTags': 'Host',
'OutOfBandManagement': 'Out-of-band Management',
'Cluster': 'Cluster',
'Account': 'Account',
'Role': 'Role',
'Snapshot': 'Snapshot',
'User': 'User',
'UserData': 'User Data',
'Os': 'Guest OS',
'ServiceOffering': 'Service Offering',
'DiskOffering': 'Disk Offering',
'LoadBalancer': 'Load Balancer',
'SslCert': 'Load Balancer',
'SslCert': 'SSL Certificates',
'Router': 'Router',
'SystemVm': 'System VM',
'Configuration': 'Configuration',
'Capabilities': 'Configuration',
'Pod': 'Pod',
'ManagementNetworkIpRange': 'Pod',
'PublicIpRange': 'Network',
'Zone': 'Zone',
'Vmware' : 'Zone',
'NetworkOffering': 'Network Offering',
'NetworkACL': 'Network ACL',
'NetworkAclItem': 'Network ACL',
'Network': 'Network',
'CiscoNexus': 'Network',
'OpenDaylight': 'Network',
'createServiceInstance': 'Network',
'addGloboDnsHost': 'Network',
'createTungstenFabricProvider': 'Tungsten',
'listTungstenFabricProviders': 'Tungsten',
'configTungstenFabricService': 'Tungsten',
'createTungstenFabricPublicNetwork': 'Tungsten',
'synchronizeTungstenFabricData': 'Tungsten',
'addTungstenFabricPolicyRule': 'Tungsten',
'createTungstenFabricPolicy': 'Tungsten',
'deleteTungstenFabricPolicy': 'Tungsten',
'removeTungstenFabricPolicyRule': 'Tungsten',
'listTungstenFabricTag': 'Tungsten',
'listTungstenFabricTagType': 'Tungsten',
'listTungstenFabricPolicy': 'Tungsten',
'listTungstenFabricPolicyRule': 'Tungsten',
'listTungstenFabricNetwork': 'Tungsten',
'listTungstenFabricVm': 'Tungsten',
'listTungstenFabricNic': 'Tungsten',
'createTungstenFabricTag': 'Tungsten',
'createTungstenFabricTagType': 'Tungsten',
'deleteTungstenFabricTag': 'Tungsten',
'deleteTungstenFabricTagType': 'Tungsten',
'applyTungstenFabricPolicy': 'Tungsten',
'applyTungstenFabricTag': 'Tungsten',
'removeTungstenFabricTag': 'Tungsten',
'removeTungstenFabricPolicy': 'Tungsten',
'createTungstenFabricApplicationPolicySet': 'Tungsten',
'createTungstenFabricFirewallPolicy': 'Tungsten',
'createTungstenFabricFirewallRule': 'Tungsten',
'createTungstenFabricServiceGroup': 'Tungsten',
'createTungstenFabricAddressGroup': 'Tungsten',
'createTungstenFabricLogicalRouter': 'Tungsten',
'addTungstenFabricNetworkGatewayToLogicalRouter': 'Tungsten',
'listTungstenFabricApplicationPolicySet': 'Tungsten',
'listTungstenFabricFirewallPolicy': 'Tungsten',
'listTungstenFabricFirewallRule': 'Tungsten',
'listTungstenFabricServiceGroup': 'Tungsten',
'listTungstenFabricAddressGroup': 'Tungsten',
'listTungstenFabricLogicalRouter': 'Tungsten',
'deleteTungstenFabricApplicationPolicySet': 'Tungsten',
'deleteTungstenFabricFirewallPolicy': 'Tungsten',
'deleteTungstenFabricFirewallRule': 'Tungsten',
'deleteTungstenFabricAddressGroup': 'Tungsten',
'deleteTungstenFabricServiceGroup': 'Tungsten',
'deleteTungstenFabricLogicalRouter': 'Tungsten',
'removeTungstenFabricNetworkGatewayFromLogicalRouter': 'Tungsten',
'updateTungstenFabricLBHealthMonitor': 'Tungsten',
'listTungstenFabricLBHealthMonitor': 'Tungsten',
'TungstenFabric': 'Tungsten',
'listNsxControllers': 'NSX',
'addNsxController': 'NSX',
'deleteNsxController': 'NSX',
'Vpn': 'VPN',
'Limit': 'Limit',
'Limit': 'Resource Limit',
'Netscaler': 'Netscaler',
'NetscalerControlCenter': 'Netscaler',
'NetscalerLoadBalancer': 'Netscaler',
'SolidFire': 'SolidFire',
'PaloAlto': 'Palo Alto',
'ResourceCount': 'Limit',
'CloudIdentifier': 'Cloud Identifier',
'InstanceGroup': 'VM Group',
Expand All @@ -150,10 +115,9 @@
'updateStorageCapabilities' : 'Storage Pool',
'SecurityGroup': 'Security Group',
'SSH': 'SSH',
'register': 'Registration',
'AsyncJob': 'Async job',
'Certificate': 'Certificate',
'Hypervisor': 'Hypervisor',
'Hypervisor': 'Configuration',
'Alert': 'Alert',
'Event': 'Event',
'login': 'Authentication',
Expand All @@ -175,19 +139,20 @@
'ExternalLoadBalancer': 'Ext Load Balancer',
'ExternalFirewall': 'Ext Firewall',
'Usage': 'Usage',
'TrafficMonitor': 'Usage',
'TrafficType': 'Usage',
'TrafficMonitor': 'Network',
'TrafficType': 'Network',
'Product': 'Product',
'LB': 'Load Balancer',
'ldap': 'LDAP',
'Ldap': 'LDAP',
'Swift': 'Swift',
'Swift': 'Image Store',
'S3' : 'S3',
'SecondaryStorage': 'Host',
'SecondaryStorage': 'Image Store',
'Project': 'Project',
'Lun': 'Storage',
'Pool': 'Pool',
'VPC': 'VPC',
'VPCOffering': 'VPC Offering',
'PrivateGateway': 'VPC',
'migrateVpc': 'VPC',
'Simulator': 'simulator',
Expand All @@ -201,13 +166,15 @@
'Counter': 'AutoScale',
'Condition': 'AutoScale',
'Api': 'API Discovery',
'ApiLimit': 'Configuration',
'Region': 'Region',
'Detail': 'Resource metadata',
'addIpToNic': 'Nic',
'removeIpFromNic': 'Nic',
'updateVmNicIp': 'Nic',
'listNics':'Nic',
'AffinityGroup': 'Affinity Group',
'AffinityGroup': 'Affinity Group',
'ImageStore': 'Image Store',
'addImageStore': 'Image Store',
'listImageStore': 'Image Store',
'deleteImageStore': 'Image Store',
Expand All @@ -228,15 +195,16 @@
'CacheStores' : 'Cache Stores',
'CacheStore' : 'Cache Store',
'OvsElement' : 'Ovs Element',
'StratosphereSsp' : ' Stratosphere SSP',
'StratosphereSsp' : 'Misc Network Service Providers',
'Metrics' : 'Metrics',
'listClustersMetrics': 'Cluster',
'VpnUser': 'VPN',
'listZonesMetrics': 'Metrics',
'Infrastructure' : 'Metrics',
'listNetscalerControlCenter' : 'Load Balancer',
'listRegisteredServicePackages': 'Load Balancer',
'listNsVpx' : 'Load Balancer',
'destroyNsVPx': 'Load Balancer',
'deployNetscalerVpx' : 'Load Balancer',
'deleteNetscalerControlCenter' : 'Load Balancer',
'stopNetScalerVpx' : 'Load Balancer',
'deleteServicePackageOffering' : 'Load Balancer',
'destroyNsVpx' : 'Load Balancer',
Expand All @@ -256,17 +224,16 @@
'UnmanagedInstance': 'Virtual Machine',
'KubernetesSupportedVersion': 'Kubernetes Service',
'KubernetesCluster': 'Kubernetes Service',
'UnmanagedInstance': 'Virtual Machine',
'Rolling': 'Rolling Maintenance',
'importVsphereStoragePolicies' : 'vSphere storage policies',
'listVsphereStoragePolicies' : 'vSphere storage policies',
'ConsoleEndpoint': 'Console Endpoint',
'Shutdown': 'Shutdown',
'importVm': 'Virtual Machine',
'revertToVMSnapshot': 'Virtual Machine',
'listQuarantinedIp': 'IP Quarantine',
'updateQuarantinedIp': 'IP Quarantine',
'removeQuarantinedIp': 'IP Quarantine',
'Shutdown': 'Shutdown',
'Shutdown': 'Management',
'addObjectStoragePool': 'Object Store',
'listObjectStoragePools': 'Object Store',
'deleteObjectStoragePool': 'Object Store',
Expand All @@ -276,7 +243,6 @@
'deleteBucket': 'Object Store',
'listBuckets': 'Object Store',
'listVmsForImport': 'Virtual Machine',
'importVm': 'Virtual Machine',
'SharedFS': 'Shared FileSystem',
'SharedFileSystem': 'Shared FileSystem',
'Webhook': 'Webhook',
Expand All @@ -297,12 +263,19 @@


def choose_category(fn):
possible_known_categories = []
for k, v in known_categories.items():
if k in fn:
return v
possible_known_categories.append(k)

if len(possible_known_categories) > 0:
close_matches = difflib.get_close_matches(fn, possible_known_categories, n=1, cutoff=0.1)
if len(close_matches) > 0:
return known_categories[close_matches[0]]
else:
return known_categories[possible_known_categories[0]]
raise Exception('Need to add a category for %s to %s:known_categories' %
(fn, __file__))
sys.exit(1)


for f in sys.argv:
Expand Down Expand Up @@ -353,7 +326,6 @@ def xml_for(command):
def write_xml(out, user):
with open(out, 'w') as f:
cat_strings = []

for category in categories.keys():
strings = []
for command in categories[category]:
Expand Down

0 comments on commit aa64476

Please sign in to comment.