def Main(): cgiEnv = lib_common.ScriptEnvironment() grph = cgiEnv.GetGraph() subscription_name = cgiEnv.m_entity_id_dict["Subscription"] subscription_id, certificate_path = lib_credentials.GetCredentials( "Azure", subscription_name) sms = ServiceManagementService(subscription_id, certificate_path) subscription_node = subscription.MakeUri(subscription_name) # Some information printed grph.add((subscription_node, lib_common.MakeProp(".requestid"), lib_util.NodeLiteral(sms.requestid))) grph.add((subscription_node, lib_common.MakeProp(".x_ms_version"), lib_util.NodeLiteral(sms.x_ms_version))) prop_disk = lib_common.MakeProp("Disk") prop_disk_label = lib_common.MakeProp("Label") prop_disk_location = lib_common.MakeProp("Location") prop_media_link = lib_common.MakeProp("Media Link") try: lst_disks = sms.list_disks() except Exception as exc: lib_common.ErrorMessageHtml("Unexpected error:" + str(exc)) for dsk in lst_disks: logging.debug("dsk=%s", str(dir(dsk))) node_disk = disk.MakeUri(dsk.name, subscription_name) grph.add((subscription_node, prop_disk, node_disk)) grph.add((node_disk, lib_common.MakeProp("Size"), lib_util.NodeLiteral(dsk.logical_disk_size_in_gb))) url_disk = dsk.media_link grph.add((node_disk, prop_media_link, lib_common.NodeUrl(url_disk))) if dsk.affinity_group: aff_group = dsk.affinity_group grph.add((node_disk, lib_common.MakeProp("Affinity group"), lib_util.NodeLiteral(aff_group))) grph.add((node_disk, lib_common.MakeProp("Source image name"), lib_util.NodeLiteral(dsk.source_image_name))) grph.add((node_disk, lib_util.NodeLiteral("Operating System"), lib_util.NodeLiteral(dsk.os))) # grph.add((node_disk, lib_util.NodeLiteral("Hosted Service Name"), # lib_util.NodeLiteral(dsk.hosted_service_name))) if dsk.is_corrupted: grph.add((node_disk, lib_util.NodeLiteral("Corrupted"), lib_util.NodeLiteral(dsk.is_corrupted))) grph.add((node_disk, lib_util.NodeLiteral("Label"), lib_util.NodeLiteral(dsk.label))) # grph.add((node_disk, lib_common.MakeProp("Affinity group"), lib_util.NodeLiteral("dsk.affinity_group"))) logging.debug("dsk.attached_to=%s",str(dir(dsk.attached_to))) node_location = location.MakeUri(dsk.location, subscription_name) grph.add((node_disk, prop_disk_location, node_location)) # cgiEnv.OutCgiRdf("LAYOUT_RECT",[prop_disk,prop_disk_location,prop_media_link]) # cgiEnv.OutCgiRdf("LAYOUT_RECT",[prop_disk,prop_disk_location]) # cgiEnv.OutCgiRdf("LAYOUT_RECT",[prop_disk]) cgiEnv.OutCgiRdf("LAYOUT_RECT_TB")
def Main(): cgiEnv = lib_common.CgiEnv() # TODO: The subscription will become a parameter with a default value. # serviceName = cgiEnv.GetId() diskName = cgiEnv.m_entity_id_dict["Disk"] # TODO: This should be a parameter. subscriptionName = cgiEnv.m_entity_id_dict["Subscription"] # subscriptionName=Azure.DefaultSubscription() grph = cgiEnv.GetGraph() (subscription_id,certificate_path) = lib_credentials.GetCredentials( "Azure", subscriptionName ) sms = ServiceManagementService(subscription_id, certificate_path) subscriptionNode = subscription.MakeUri( subscriptionName ) dsk = sms.get_disk(diskName) sys.stderr.write("dsk=%s\n"% str(dir(dsk))) diskNode = disk.MakeUri( diskName, subscriptionName ) grph.add( ( subscriptionNode, lib_common.MakeProp("Service"), diskNode ) ) # grph.add( ( diskNode, lib_common.MakeProp("xxx"), lib_common.NodeLiteral(str(dir(dsk))) ) ) grph.add( ( diskNode, lib_common.MakeProp("affinity_group"), lib_common.NodeLiteral(dsk.affinity_group))) # grph.add( ( diskNode, lib_common.MakeProp("attached_to"), lib_common.NodeLiteral(str(dir(dsk.attached_to)))) ) grph.add( ( diskNode, lib_common.MakeProp("has_operating_system"), lib_common.NodeLiteral(dsk.has_operating_system))) grph.add( ( diskNode, lib_common.MakeProp("is_corrupted"), lib_common.NodeLiteral(dsk.is_corrupted)) ) grph.add( ( diskNode, lib_common.MakeProp("label"), lib_common.NodeLiteral(dsk.label)) ) grph.add( ( diskNode, lib_common.MakeProp("Size"), lib_common.NodeLiteral(dsk.logical_disk_size_in_gb))) grph.add( ( diskNode, lib_common.MakeProp("name"), lib_common.NodeLiteral(dsk.name))) grph.add( ( diskNode, lib_common.MakeProp("os"), lib_common.NodeLiteral(dsk.os))) grph.add( ( diskNode, lib_common.MakeProp("source_image_name"), lib_common.NodeLiteral(dsk.source_image_name))) grph.add( ( diskNode, lib_common.MakeProp("media link"), lib_common.NodeUrl(dsk.media_link))) locaNode = location.MakeUri( dsk.location, subscriptionName ) grph.add( ( diskNode, lib_common.MakeProp("Location"), locaNode ) ) srvNode = service.MakeUri( dsk.attached_to.hosted_service_name, subscriptionName ) grph.add( ( srvNode, lib_common.MakeProp("Role"), lib_common.NodeLiteral(dsk.attached_to.role_name) ) ) grph.add( ( srvNode, lib_common.MakeProp("Deployment"), lib_common.NodeLiteral(dsk.attached_to.deployment_name) ) ) grph.add( ( diskNode, lib_common.MakeProp("Service"), srvNode ) ) # media_link cgiEnv.OutCgiRdf("LAYOUT_RECT_TB")
def Main(): cgiEnv = lib_common.ScriptEnvironment() disk_name = cgiEnv.m_entity_id_dict["Disk"] subscription_name = cgiEnv.m_entity_id_dict["Subscription"] # subscription_name=Azure.DefaultSubscription() grph = cgiEnv.GetGraph() subscription_id, certificate_path = lib_credentials.GetCredentials("Azure", subscription_name) sms = ServiceManagementService(subscription_id, certificate_path) subscription_node = subscription.MakeUri(subscription_name) dsk = sms.get_disk(disk_name) logging.debug("dsk=%s", str(dir(dsk))) disk_node = disk.MakeUri(disk_name, subscription_name) grph.add((subscription_node, lib_common.MakeProp("Service"), disk_node)) grph.add((disk_node, lib_common.MakeProp("affinity_group"), lib_util.NodeLiteral(dsk.affinity_group))) # grph.add((disk_node, lib_common.MakeProp("attached_to"), lib_util.NodeLiteral(str(dir(dsk.attached_to))))) grph.add((disk_node, lib_common.MakeProp("has_operating_system"), lib_util.NodeLiteral(dsk.has_operating_system))) grph.add((disk_node, lib_common.MakeProp("is_corrupted"), lib_util.NodeLiteral(dsk.is_corrupted))) grph.add((disk_node, lib_common.MakeProp("label"), lib_util.NodeLiteral(dsk.label))) grph.add((disk_node, lib_common.MakeProp("Size"), lib_util.NodeLiteral(dsk.logical_disk_size_in_gb))) grph.add((disk_node, lib_common.MakeProp("name"), lib_util.NodeLiteral(dsk.name))) grph.add((disk_node, lib_common.MakeProp("os"), lib_util.NodeLiteral(dsk.os))) grph.add((disk_node, lib_common.MakeProp("source_image_name"), lib_util.NodeLiteral(dsk.source_image_name))) grph.add((disk_node, lib_common.MakeProp("media link"), lib_common.NodeUrl(dsk.media_link))) loca_node = location.MakeUri( dsk.location, subscription_name) grph.add((disk_node, lib_common.MakeProp("Location"), loca_node)) srv_node = service.MakeUri( dsk.attached_to.hosted_service_name, subscription_name) grph.add((srv_node, lib_common.MakeProp("Role"), lib_util.NodeLiteral(dsk.attached_to.role_name))) grph.add((srv_node, lib_common.MakeProp("Deployment"), lib_util.NodeLiteral(dsk.attached_to.deployment_name))) grph.add((disk_node, lib_common.MakeProp("Service"), srv_node)) # media_link cgiEnv.OutCgiRdf("LAYOUT_RECT_TB")
def Main(): cgiEnv = lib_common.CgiEnv() grph = cgiEnv.GetGraph() # subscriptionName=Azure.DefaultSubscription() subscriptionName = cgiEnv.m_entity_id_dict["Subscription"] (subscription_id, certificate_path) = lib_credentials.GetCredentials( "Azure", subscriptionName) sms = ServiceManagementService(subscription_id, certificate_path) subscriptionNode = subscription.MakeUri(subscriptionName) # Some information printed grph.add((subscriptionNode, lib_common.MakeProp(".requestid"), lib_common.NodeLiteral(sms.requestid))) grph.add((subscriptionNode, lib_common.MakeProp(".x_ms_version"), lib_common.NodeLiteral(sms.x_ms_version))) propDisk = lib_common.MakeProp("Disk") propDiskLabel = lib_common.MakeProp("Label") propDiskLocation = lib_common.MakeProp("Location") propMediaLink = lib_common.MakeProp("Media Link") try: # This throws when running with Apache. OK with cgiserver.py lstDisks = sms.list_disks() except: lib_common.ErrorMessageHtml("Unexpected error:" + str(sys.exc_info())) for dsk in lstDisks: sys.stderr.write("dsk=%s\n" % str(dir(dsk))) nodeDisk = disk.MakeUri(dsk.name, subscriptionName) grph.add((subscriptionNode, propDisk, nodeDisk)) grph.add((nodeDisk, lib_common.MakeProp("Size"), lib_common.NodeLiteral(dsk.logical_disk_size_in_gb))) # TODO: This www url does not work. WHY ??? urlDisk = dsk.media_link grph.add((nodeDisk, propMediaLink, lib_common.NodeUrl(urlDisk))) if dsk.affinity_group: affGroup = dsk.affinity_group grph.add((nodeDisk, lib_common.MakeProp("Affinity group"), lib_common.NodeLiteral(affGroup))) grph.add((nodeDisk, lib_common.MakeProp("Source image name"), lib_common.NodeLiteral(dsk.source_image_name))) grph.add((nodeDisk, lib_common.NodeLiteral("Operating System"), lib_common.NodeLiteral(dsk.os))) # grph.add( ( nodeDisk, lib_common.NodeLiteral("Hosted Service Name"), lib_common.NodeLiteral(dsk.hosted_service_name)) ) if dsk.is_corrupted: grph.add((nodeDisk, lib_common.NodeLiteral("Corrupted"), lib_common.NodeLiteral(dsk.is_corrupted))) grph.add((nodeDisk, lib_common.NodeLiteral("Label"), lib_common.NodeLiteral(dsk.label))) # grph.add( ( nodeDisk, lib_common.MakeProp("Affinity group"), lib_common.NodeLiteral("dsk.affinity_group")) ) sys.stderr.write("dsk.attached_to=%s\n" % str(dir(dsk.attached_to))) nodeLocation = location.MakeUri(dsk.location, subscriptionName) grph.add((nodeDisk, propDiskLocation, nodeLocation)) # cgiEnv.OutCgiRdf("LAYOUT_RECT",[propDisk,propDiskLocation,propMediaLink]) # cgiEnv.OutCgiRdf("LAYOUT_RECT",[propDisk,propDiskLocation]) # cgiEnv.OutCgiRdf("LAYOUT_RECT",[propDisk]) cgiEnv.OutCgiRdf("LAYOUT_RECT_TB")