When we publish image services programmatically, only a few of the metadata fields can be populated during the creation of a service definition. We would like to have a programmatic approach for updating the rest of the metadata fields (it appears that only description and tags can be populated in the CreateImageSDDraft command).
I tried using the arcpy metadata module, but it seems to treat the item as read-only. I am able to manually edit the metadata fields in the Server Manager in the Item Description section of the service, and also to edit it in ArcGIS Pro via an ags connection in the Catalog pane without any problems. Is this just not supported in the metadata module, or am I doing something wrong?
I tried a few different paths, and both of the URL-based options returned the expected service description (I added a few test print statements before the conditional). The path using the ags returned 'None', so that option may not have been hitting the right target. I thought this might be the best option, as the ags file contains credentials, but that doesn't help if it doesn't find the right target.
I tried setting the service to allow "Edit" functionality, but I expect that's not really referencing the metadata. Is there another setting somewhere that needs to be adjusted?
I suspect this might have to do with credentials. I tried running the script directly from the server, and got the same result, but maybe even there I'd need to provide some sort of credential. Any ideas where I'd add that in, or if that's truly the issue?
import arcpy
from arcpy import metadata as md
# Create a new Metadata object and add some content to it
new_md = md.Metadata()
new_md.title = 'My new title'
new_md.tags = 'tag1, tag2'
new_md.summary = 'summary language'
new_md.description = 'description language'
new_md.credits = 'credit statement'
new_md.accessConstraints = 'under construction'
# Assign the Metadata object's content to a target item
# hand_path = r'C:\Users\__\Documents\ImageServer\ImageServices\arcgis on gis-test.xyz.xyz.ags\Folder\ServiceName' # this path doesn't return expected description
# hand_path = r'https://gis-test.xyz.xyz/arcgis/rest/services/Folder/ServiceName/ImageServer/info/metadata' # this path returns expected description
hand_path = r'https://gis-test.xyz.xyz/arcgis/rest/services/Folder/ServiceName/ImageServer' # this path also returns expected description
tgt_item_md = md.Metadata(hand_path)
print('is read only: %s' % tgt_item_md.isReadOnly) # verify that the target is, indeed, read only
print(tgt_item_md.description) # verify that it's hitting the right target
if not tgt_item_md.isReadOnly:
tgt_item_md.copy(new_md)
print('copied new metadata')
tgt_item_md.save()
print('new metadata saved')
else:
print('item is read only')
This is what I see as output when running the script:
is read only: True
Expected existing description for the image service
item is read only
Process finished with exit code 0