def DeleteComposedSystem(ident):
rb = g.rest_base
resource_ids={'Processors':[],'Memory':[],'SimpleStorage':[],'EthernetInterfaces':[]}
# Verify if the System exists and if is of type - "SystemType": "Composed"
if ident in members:
if members[ident]['SystemType'] == 'Composed':
# Remove Links to Composed System and change CompositionState (to 'Unused') in associated Resource Blocks
for block in members[ident]['Links']['ResourceBlocks']:
block = block['@odata.id'].replace(rb + 'CompositionService/ResourceBlocks/','')
resource_blocks[block]['Links']['ComputerSystems']
for index, item in enumerate(resource_blocks[block]['Links']['ComputerSystems']):
if resource_blocks[block]['Links']['ComputerSystems'][index]['@odata.id'].replace(rb + 'Systems/','') == ident:
del resource_blocks[block]['Links']['ComputerSystems'][index]
resource_blocks[block]['CompositionStatus']['CompositionState'] = 'Unused'
for device_type in resource_ids.keys():
for device in resource_blocks[block][device_type]:
resource_ids[device_type].append(device)
# Remove links to Processors, Memory, SimpleStorage, etc
for device_type in resource_ids.keys():
for device in resource_ids[device_type]:
if device_type == 'Processors':
device_back = device['@odata.id'].replace(rb + 'CompositionService/ResourceBlocks/','')
del processors[ident][device_back]
if processors[ident]=={}: del processors[ident]
elif device_type == 'Memory':
device_back = device['@odata.id'].replace(rb + 'CompositionService/ResourceBlocks/','')
del memory[ident][device_back]
if memory[ident]=={}: del memory[ident]
elif device_type == 'SimpleStorage':
device_back = device['@odata.id'].replace(rb + 'CompositionService/ResourceBlocks/','')
del simplestorage[ident][device_back]
if simplestorage[ident]=={}: del simplestorage[ident]
elif device_type == 'EthernetInterfaces':
device_back = device['@odata.id'].replace(rb + 'CompositionService/ResourceBlocks/','')
del ethernetinterfaces[ident][device_back]
if ethernetinterfaces[ident]=={}: del ethernetinterfaces[ident]
# Remove Composed System from System list
del members[ident]
resp = 200
else:
# It is not a Composed System and therefore cannot be deleted as such"
return INTERNAL_ERROR
#
return resp
ComputerSystem_api.py 文件源码
python
阅读 14
收藏 0
点赞 0
评论 0
评论列表
文章目录