def execute( cls, client: GraphqlClient, input: EditEquipmentPortInput ) -> EditEquipmentPortMutationData.EquipmentPort: # fmt: off variables = {"input": input} try: network_start = perf_counter() response_text = client.call(''.join(set(QUERY)), variables=variables) decode_start = perf_counter() res = cls.from_json(response_text).data decode_time = perf_counter() - decode_start network_time = decode_start - network_start client.reporter.log_successful_operation( "EditEquipmentPortMutation", variables, network_time, decode_time) return res.editEquipmentPort except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, "EditEquipmentPortMutation", variables, )
def execute( cls, client: GraphqlClient ) -> Optional[LocationTypesQueryData.LocationTypeConnection]: # fmt: off variables: Dict[str, Any] = {} try: network_start = perf_counter() response_text = client.call(''.join(set(QUERY)), variables=variables) decode_start = perf_counter() res = cls.from_json(response_text).data decode_time = perf_counter() - decode_start network_time = decode_start - network_start client.reporter.log_successful_operation("LocationTypesQuery", variables, network_time, decode_time) return res.locationTypes except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, "LocationTypesQuery", variables, )
def execute( cls, client: GraphqlClient, data: ServiceTypeCreateData ) -> AddServiceTypeMutationData.ServiceType: # fmt: off variables: Dict[str, Any] = {"data": data} try: network_start = perf_counter() response_text = client.call(''.join(set(QUERY)), variables=variables) decode_start = perf_counter() res = cls.from_json(response_text).data decode_time = perf_counter() - decode_start network_time = decode_start - network_start client.reporter.log_successful_operation("AddServiceTypeMutation", variables, network_time, decode_time) return res.addServiceType except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, "AddServiceTypeMutation", variables, )
def execute(cls, client: GraphqlClient, id: str, workOrderId: Optional[str] = None) -> str: # fmt: off variables: Dict[str, Any] = {"id": id, "workOrderId": workOrderId} try: network_start = perf_counter() response_text = client.call(''.join(set(QUERY)), variables=variables) decode_start = perf_counter() res = cls.from_json(response_text).data decode_time = perf_counter() - decode_start network_time = decode_start - network_start client.reporter.log_successful_operation("RemoveEquipmentMutation", variables, network_time, decode_time) return res.removeEquipment except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, "RemoveEquipmentMutation", variables, )
def execute( cls, client: GraphqlClient, locationID: str, parentLocationID: Optional[str] = None ) -> MoveLocationMutationData.Location: # fmt: off variables = { "locationID": locationID, "parentLocationID": parentLocationID } try: network_start = perf_counter() response_text = client.call(''.join(set(QUERY)), variables=variables) decode_start = perf_counter() res = cls.from_json(response_text).data decode_time = perf_counter() - decode_start network_time = decode_start - network_start client.reporter.log_successful_operation("MoveLocationMutation", variables, network_time, decode_time) return res.moveLocation except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, "MoveLocationMutation", variables, )
def execute( cls, client: GraphqlClient, after: Optional[str] = None, first: Optional[int] = None ) -> PortsQueryData.EquipmentPortConnection: # fmt: off variables: Dict[str, Any] = {"after": after, "first": first} try: network_start = perf_counter() response_text = client.call(''.join(set(QUERY)), variables=variables) decode_start = perf_counter() res = cls.from_json(response_text).data decode_time = perf_counter() - decode_start network_time = decode_start - network_start client.reporter.log_successful_operation("PortsQuery", variables, network_time, decode_time) return res.equipmentPorts except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, "PortsQuery", variables, )
def edit_equipment( client: SymphonyClient, equipment: Equipment, new_name: Optional[str] = None, new_properties: Optional[Dict[str, PropertyValue]] = None, ) -> Equipment: """Edit existing equipment. Args: equipment (pyinventory.consts.Equipment object): equipment object new_name (Optional[str]): equipment new name new_properties (Optional[Dict[str, pyinventory.consts.PropertyValue]]): Dict, where str - property name PropertyValue - new value of the same type for this property Returns: pyinventory.consts.Equipment object Raises: FailedOperationException: internal inventory error Example: ``` location = client.get_location({("Country", "LS_IND_Prod_Copy")}) equipment = client.get_equipment("indProdCpy1_AIO", location) edited_equipment = client.edit_equipment(equipment=equipment, new_name="new_name", new_properties={"Z AIO - Number": 123}) ``` """ properties = [] property_types = client.equipmentTypes[ equipment.equipment_type_name].property_types if new_properties: properties = get_graphql_property_inputs(property_types, new_properties) edit_equipment_input = EditEquipmentInput( id=equipment.id, name=new_name if new_name else equipment.name, properties=properties, ) try: result = EditEquipmentMutation.execute( client, edit_equipment_input).__dict__[EDIT_EQUIPMENT_MUTATION_NAME] client.reporter.log_successful_operation(EDIT_EQUIPMENT_MUTATION_NAME, edit_equipment_input.__dict__) except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, EDIT_EQUIPMENT_MUTATION_NAME, edit_equipment_input.__dict__, ) return Equipment(id=result.id, name=result.name, equipment_type_name=result.equipmentType.name)
def add_equipment_type( client: SymphonyClient, name: str, category: str, properties: List[Tuple[str, str, Optional[PropertyValue], Optional[bool]]], ports_dict: Dict[str, str], position_list: List[str], ) -> EquipmentType: new_property_types = format_properties(properties) port_definitions = [{"name": name} for name, _ in ports_dict.items()] position_definitions = [{"name": position} for position in position_list] add_equipment_type_variables = { "name": name, "category": category, "positionDefinitions": position_definitions, "portDefinitions": port_definitions, "properties": new_property_types, } try: equipment_type = _add_equipment_type( client, name, category, new_property_types, position_definitions, port_definitions, ) client.reporter.log_successful_operation( ADD_EQUIPMENT_TYPE_MUTATION_NAME, add_equipment_type_variables) except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, ADD_EQUIPMENT_TYPE_MUTATION_NAME, add_equipment_type_variables, ) equipment_type = EquipmentType( name=equipment_type.name, category=equipment_type.category, id=equipment_type.id, propertyTypes=list( map(lambda p: asdict(p), equipment_type.propertyTypes)), positionDefinitions=list( map(lambda p: asdict(p), equipment_type.positionDefinitions)), portDefinitions=list( map(lambda p: asdict(p), equipment_type.portDefinitions)), ) client.equipmentTypes[equipment_type.name] = equipment_type return equipment_type
def edit_location( client: SymphonyClient, location: Location, new_name: Optional[str] = None, new_lat: Optional[float] = None, new_long: Optional[float] = None, new_external_id: Optional[str] = None, new_properties: Optional[Dict[str, Any]] = None, ) -> Location: properties = [] location_type = location.locationTypeName property_types = client.locationTypes[location_type].propertyTypes if new_properties: properties = get_graphql_property_inputs(property_types, new_properties) if new_external_id is None: new_external_id = location.externalId edit_location_input = EditLocationInput( id=location.id, name=new_name if new_name is not None else location.name, latitude=new_lat if new_lat is not None else location.latitude, longitude=new_long if new_long is not None else location.longitude, properties=properties, externalID=new_external_id, ) try: result = EditLocationMutation.execute( client, edit_location_input).__dict__[EDIT_LOCATION_MUTATION_NAME] client.reporter.log_successful_operation(EDIT_LOCATION_MUTATION_NAME, edit_location_input.__dict__) return Location( name=result.name, id=result.id, latitude=result.latitude, longitude=result.longitude, externalId=result.externalId, locationTypeName=result.locationType.name, ) except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, EDIT_LOCATION_MUTATION_NAME, edit_location_input.__dict__, ) return None
def _update_equipment_type( client: SymphonyClient, equipment_type_id: str, name: str, category: Optional[str], properties: List[PropertyTypeInput], position_definitions: List[EquipmentPositionInput], port_definitions: List[EquipmentPortInput], ) -> EquipmentType: edit_equipment_type_variables = { "name": name, "category": category, "positionDefinitions": position_definitions, "portDefinitions": port_definitions, "properties": properties, } try: equipment_type = _edit_equipment_type( client=client, equipment_type_id=equipment_type_id, name=name, category=category, properties=properties, position_definitions=position_definitions, port_definitions=port_definitions, ) client.reporter.log_successful_operation( EDIT_EQUIPMENT_TYPE_MUTATION_NAME, edit_equipment_type_variables) except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, EDIT_EQUIPMENT_TYPE_MUTATION_NAME, edit_equipment_type_variables, ) equipment_type = EquipmentType( name=equipment_type.name, category=equipment_type.category, id=equipment_type.id, property_types=equipment_type.propertyTypes, position_definitions=equipment_type.positionDefinitions, port_definitions=equipment_type.portDefinitions, ) client.equipmentTypes[name] = equipment_type return equipment_type
def add_location_type( client: SymphonyClient, name: str, properties: List[Tuple[str, str, Optional[PropertyValue], Optional[bool]]], map_zoom_level: int = 8, ) -> LocationType: new_property_types = format_properties(properties) add_location_type_variables = { "name": name, "mapZoomLevel": map_zoom_level, "properties": new_property_types, } try: result = AddLocationTypeMutation.execute( client, AddLocationTypeInput( name=name, mapZoomLevel=map_zoom_level, properties=[ from_dict( data_class=PropertyTypeInput, data=p, config=Config(strict=True) ) for p in new_property_types ], surveyTemplateCategories=[], ), ).__dict__[ADD_LOCATION_TYPE_MUTATION_NAME] client.reporter.log_successful_operation( ADD_LOCATION_TYPE_MUTATION_NAME, add_location_type_variables ) except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, ADD_LOCATION_TYPE_MUTATION_NAME, add_location_type_variables, ) location_type = LocationType( name=result.name, id=result.id, propertyTypes=[asdict(p) for p in result.propertyTypes], ) client.locationTypes[result.name] = location_type return location_type
def execute(cls, client: GraphqlClient, data: SurveyCreateData) -> str: # fmt: off variables = {"data": data} try: start_time = perf_counter() response_text = client.call(''.join(set(QUERY)), variables=variables) res = cls.from_json(response_text).data elapsed_time = perf_counter() - start_time client.reporter.log_successful_operation("CreateSurveyMutation", variables, elapsed_time) return res.createSurvey except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, "CreateSurveyMutation", variables, )
def execute(cls, client: GraphqlClient, id: str) -> Optional[LocationDepsQueryData.Node]: # fmt: off variables = {"id": id} try: start_time = perf_counter() response_text = client.call(''.join(set(QUERY)), variables=variables) res = cls.from_json(response_text).data elapsed_time = perf_counter() - start_time client.reporter.log_successful_operation("LocationDepsQuery", variables, elapsed_time) return res.location except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, "LocationDepsQuery", variables, )
def execute(cls, client: GraphqlClient, filters: List[EquipmentFilterInput] = [], limit: Optional[int] = None) -> EquipmentSearchQueryData.EquipmentSearchResult: # fmt: off variables = {"filters": filters, "limit": limit} try: start_time = perf_counter() response_text = client.call(''.join(set(QUERY)), variables=variables) res = cls.from_json(response_text).data elapsed_time = perf_counter() - start_time client.reporter.log_successful_operation("EquipmentSearchQuery", variables, elapsed_time) return res.equipmentSearch except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, "EquipmentSearchQuery", variables, )
def execute(cls, client: GraphqlClient, authID: str) -> Optional[UserQueryData.User]: # fmt: off variables = {"authID": authID} try: start_time = perf_counter() response_text = client.call(''.join(set(QUERY)), variables=variables) res = cls.from_json(response_text).data elapsed_time = perf_counter() - start_time client.reporter.log_successful_operation("UserQuery", variables, elapsed_time) return res.user except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, "UserQuery", variables, )
def execute(cls, client: GraphqlClient, entityType: ImageEntity, entityId: str, id: str) -> DeleteImageMutationData.File: # fmt: off variables = {"entityType": entityType, "entityId": entityId, "id": id} try: start_time = perf_counter() response_text = client.call(''.join(set(QUERY)), variables=variables) res = cls.from_json(response_text).data elapsed_time = perf_counter() - start_time client.reporter.log_successful_operation("DeleteImageMutation", variables, elapsed_time) return res.deleteImage except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, "DeleteImageMutation", variables, )
def execute(cls, client: GraphqlClient, input: AddLocationTypeInput) -> AddLocationTypeMutationData.LocationType: # fmt: off variables = {"input": input} try: start_time = perf_counter() response_text = client.call(''.join(set(QUERY)), variables=variables) res = cls.from_json(response_text).data elapsed_time = perf_counter() - start_time client.reporter.log_successful_operation("AddLocationTypeMutation", variables, elapsed_time) return res.addLocationType except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, "AddLocationTypeMutation", variables, )
def execute(cls, client: GraphqlClient) -> Optional[LatestPythonPackageQueryData.LatestPythonPackageResult]: # fmt: off variables = {} try: start_time = perf_counter() response_text = client.call(''.join(set(QUERY)), variables=variables) res = cls.from_json(response_text).data elapsed_time = perf_counter() - start_time client.reporter.log_successful_operation("LatestPythonPackageQuery", variables, elapsed_time) return res.latestPythonPackage except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, "LatestPythonPackageQuery", variables, )
def execute(cls, client: GraphqlClient, id: str) -> str: # fmt: off variables = {"id": id} try: start_time = perf_counter() response_text = client.call(''.join(set(QUERY)), variables=variables) res = cls.from_json(response_text).data elapsed_time = perf_counter() - start_time client.reporter.log_successful_operation("RemoveEquipmentPortTypeMutation", variables, elapsed_time) return res.removeEquipmentPortType except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, "RemoveEquipmentPortTypeMutation", variables, )
def execute(cls, client: GraphqlClient) -> EquipmentPortTypesQueryData.EquipmentPortTypeConnection: # fmt: off variables = {} try: start_time = perf_counter() response_text = client.call(''.join(set(QUERY)), variables=variables) res = cls.from_json(response_text).data elapsed_time = perf_counter() - start_time client.reporter.log_successful_operation("EquipmentPortTypesQuery", variables, elapsed_time) return res.equipmentPortTypes except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, "EquipmentPortTypesQuery", variables, )
def move_location( client: SymphonyClient, location_id: str, new_parent_id: Optional[str] ) -> Location: """This function moves existing location to another existing parent location. Args: location_id (str): existing location ID to be moved new_parent_id (Optional[str]): new existing parent location ID Returns: `pyinventory.consts.Location` object Raises: FailedOperationException: for internal inventory error Example: ``` # this call will fail if there is Bletchley Park in two cities location = client.get_location(location_hirerchy=[("Site", "Bletchley Park")]) moved_location = client.move_locatoin( location_id=location.id, new_parent_id="12345" ) ``` """ params = {"locationID": location_id, "parentLocationID": new_parent_id} try: result = MoveLocationMutation.execute( client, locationID=location_id, parentLocationID=new_parent_id ).__dict__[MOVE_LOCATION_MUTATION_NAME] client.reporter.log_successful_operation(MOVE_LOCATION_MUTATION_NAME, params) return Location( name=result.name, id=result.id, latitude=result.latitude, longitude=result.longitude, externalId=result.externalId, locationTypeName=result.locationType.name, ) except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, MOVE_LOCATION_MUTATION_NAME, params )
def execute(cls, client: GraphqlClient, id: str) -> Optional[ServiceEndpointsQueryData.Node]: # fmt: off variables: Dict[str, Any] = {"id": id} try: network_start = perf_counter() response_text = client.call(''.join(set(QUERY)), variables=variables) decode_start = perf_counter() res = cls.from_json(response_text).data decode_time = perf_counter() - decode_start network_time = decode_start - network_start client.reporter.log_successful_operation("ServiceEndpointsQuery", variables, network_time, decode_time) return res.service except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, "ServiceEndpointsQuery", variables, )
def execute(cls, client: GraphqlClient, id: str, linkId: str) -> AddServiceLinkMutationData.Service: # fmt: off variables = {"id": id, "linkId": linkId} try: network_start = perf_counter() response_text = client.call(''.join(set(QUERY)), variables=variables) decode_start = perf_counter() res = cls.from_json(response_text).data decode_time = perf_counter() - decode_start network_time = decode_start - network_start client.reporter.log_successful_operation("AddServiceLinkMutation", variables, network_time, decode_time) return res.addServiceLink except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, "AddServiceLinkMutation", variables, )
def execute(cls, client: GraphqlClient, name: str, after: Optional[str] = None, first: Optional[int] = 10, before: Optional[str] = None, last: Optional[int] = None) -> SearchQueryData.SearchNodesConnection: # fmt: off variables = {"name": name, "after": after, "first": first, "before": before, "last": last} try: network_start = perf_counter() response_text = client.call(''.join(set(QUERY)), variables=variables) decode_start = perf_counter() res = cls.from_json(response_text).data decode_time = perf_counter() - decode_start network_time = decode_start - network_start client.reporter.log_successful_operation("SearchQuery", variables, network_time, decode_time) return res.searchForNode except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, "SearchQuery", variables, )
def move_location(client: SymphonyClient, location_id: str, new_parent_id: Optional[str]) -> Location: params = {"locationID": location_id, "parentLocationID": new_parent_id} try: result = MoveLocationMutation.execute( client, locationID=location_id, parentLocationID=new_parent_id ).__dict__[MOVE_LOCATION_MUTATION_NAME] client.reporter.log_successful_operation(MOVE_LOCATION_MUTATION_NAME, params) return Location( name=result.name, id=result.id, latitude=result.latitude, longitude=result.longitude, externalId=result.externalId, locationTypeName=result.locationType.name, ) except OperationException as e: raise FailedOperationException(client.reporter, e.err_msg, e.err_id, MOVE_LOCATION_MUTATION_NAME, params)
def execute(cls, client: GraphqlClient, input: AddCustomerInput) -> AddCustomerMutationData.Customer: # fmt: off variables: Dict[str, Any] = {"input": input} try: network_start = perf_counter() response_text = client.call(''.join(set(QUERY)), variables=variables) decode_start = perf_counter() res = cls.from_json(response_text).data decode_time = perf_counter() - decode_start network_time = decode_start - network_start client.reporter.log_successful_operation("AddCustomerMutation", variables, network_time, decode_time) return res.addCustomer except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, "AddCustomerMutation", variables, )
def add_equipment_to_position( client: SymphonyClient, name: str, equipment_type: str, existing_equipment: Equipment, position_name: str, properties_dict: Dict[str, PropertyValue], ) -> Equipment: """Create a new equipment inside a given positionName of the given existingEquipment. The equipment will be of the given equipment type, with the given name and with the given properties. If equipment with his name in this position already exists the existing equipment is returned Args: name (str): new equipment name equipment_type (str): equipment type name existing_equipment (pyinventory.consts.Equipment object): could be retrieved from - `pyinventory.api.equipment.get_equipment` - `pyinventory.api.equipment.get_equipment_in_position` - `pyinventory.api.equipment.add_equipment` - `pyinventory.api.equipment.add_equipment_to_position` position_name (str): position name in the equipment type. properties_dict (Dict[str, PropertyValue]): dict of property name to property value - str - property name - PropertyValue - new value of the same type for this property Returns: pyinventory.consts.Equipment object: You can use the ID to access the equipment from the UI: https://{}.thesymphony.cloud/inventory/inventory?equipment={} Raises: AssertionException: if parent equipment has more than one position with the given name or if property value in propertiesDict does not match the property type FailedOperationException: for internal inventory error `pyinventory.exceptions.EntityNotFoundError`: if existing_equipment does not exist Example: ``` from datetime import date equipment = client.addEquipmentToPosition( "Card Y123", "Card", equipment, "Pos 1", { 'Date Property ': date.today(), 'Lat/Lng Property: ': (-1.23,9.232), 'E-mail Property ': "*****@*****.**", 'Number Property ': 11, 'String Property ': "aa", 'Float Property': 1.23 }) ``` """ position_definition_id, _ = _find_position_definition_id( client, existing_equipment, position_name) property_types = client.equipmentTypes[equipment_type].property_types properties = get_graphql_property_inputs(property_types, properties_dict) add_equipment_input = AddEquipmentInput( name=name, type=client.equipmentTypes[equipment_type].id, parent=existing_equipment.id, positionDefinition=position_definition_id, properties=properties, ) try: equipment = AddEquipmentMutation.execute( client, add_equipment_input).__dict__[ADD_EQUIPMENT_MUTATION_NAME] client.reporter.log_successful_operation( ADD_EQUIPMENT_TO_POSITION_MUTATION_NAME, add_equipment_input.__dict__) except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, ADD_EQUIPMENT_TO_POSITION_MUTATION_NAME, add_equipment_input.__dict__, ) return Equipment( id=equipment.id, name=equipment.name, equipment_type_name=equipment.equipmentType.name, )
def edit_link_properties( client: SymphonyClient, equipment: Equipment, port_name: str, new_link_properties: Dict[str, PropertyValue], ) -> EquipmentPort: """This function returns edited port in equipment based on its name. Args: equipment ( `pyinventory.consts.Equipment` ): existing equipment object port_name (str): existing port name new_link_properties (Dict[str, PropertyValue]) - str - link property name - PropertyValue - new value of the same type for this property Returns: `pyinventory.consts.EquipmentPort` object Raises: `pyinventory.exceptions.EntityNotFoundError`: when `pyinventory.consts.EquipmentPortDefinition.port_type_name` is None, there are no properties FailedOperationException: on operation failure Example: ``` location = client.get_location(location_hirerchy=[("Country", "LS_IND_Prod_Copy")]) equipment = client.get_equipment(name="indProdCpy1_AIO", location=location) edited_port = client.edit_link_properties( equipment=equipment, port_name="Z AIO - Port 1", new_link_properties={"Link Property 1": 98765}, ) ``` """ port = get_port(client, equipment, port_name) link = port.link if link is None: raise EntityNotFoundError(entity=Entity.Link, entity_name=port_name) definition_port_type_name = "" if port.definition.port_type_name is None: raise EntityNotFoundError( entity=Entity.Property, msg=f"Not possible to edit link properties in '{port.definition.name}' port with undefined PortType", ) else: definition_port_type_name = port.definition.port_type_name new_link_property_inputs = [] if new_link_properties and definition_port_type_name: link_property_types = client.portTypes[ definition_port_type_name ].link_property_types new_link_property_inputs = get_graphql_property_inputs( link_property_types, new_link_properties ) edit_link_input = { "id": link.id, "properties": new_link_property_inputs, "serviceIds": link.service_ids, } try: result = EditLinkMutation.execute( client, EditLinkInput( id=link.id, properties=new_link_property_inputs, serviceIds=link.service_ids, ), ).__dict__[EDIT_LINK_MUTATION_NAME] client.reporter.log_successful_operation( EDIT_LINK_MUTATION_NAME, edit_link_input ) except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, EDIT_LINK_MUTATION_NAME, edit_link_input, ) return EquipmentPort( id=port.id, properties=port.properties, definition=EquipmentPortDefinition( id=port.definition.id, name=port.definition.name, port_type_name=port.definition.port_type_name, ), link=Link( id=result.id, properties=result.properties, service_ids=[s.id for s in result.services], ) if result else None, )
def add_equipment( client: SymphonyClient, name: str, equipment_type: str, location: Location, properties_dict: Dict[str, PropertyValue], ) -> Equipment: """Create a new equipment in a given location. The equipment will be of the given equipment type, with the given name and with the given properties. If equipment with his name in this location already exists, the existing equipment is returned Args: name (str): new equipment name equipment_type (str): equipment type name location (pyinventory.consts.Location object): location object could be retrieved from - `pyinventory.api.location.get_location` - `pyinventory.api.location.add_location` properties_dict (Dict[str, PropertyValue]): dict of property name to property value - str - property name - PropertyValue - new value of the same type for this property Returns: pyinventory.consts.Equipment object: You can use the ID to access the equipment from the UI: https://{}.thesymphony.cloud/inventory/inventory?equipment={} Raises: AssertionException: location contains more than one equipments with the same name or if property value in properties_dict does not match the property type FailedOperationException: internal inventory error Example: ``` from datetime import date equipment = client.addEquipment( "Router X123", "Router", location, { 'Date Property ': date.today(), 'Lat/Lng Property: ': (-1.23,9.232), 'E-mail Property ': "*****@*****.**", 'Number Property ': 11, 'String Property ': "aa", 'Float Property': 1.23 }) ``` """ property_types = client.equipmentTypes[equipment_type].property_types properties = get_graphql_property_inputs(property_types, properties_dict) add_equipment_input = AddEquipmentInput( name=name, type=client.equipmentTypes[equipment_type].id, location=location.id, properties=properties, ) try: equipment = AddEquipmentMutation.execute( client, add_equipment_input).__dict__[ADD_EQUIPMENT_MUTATION_NAME] client.reporter.log_successful_operation(ADD_EQUIPMENT_MUTATION_NAME, add_equipment_input.__dict__) except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, ADD_EQUIPMENT_MUTATION_NAME, add_equipment_input.__dict__, ) return Equipment( id=equipment.id, name=equipment.name, equipment_type_name=equipment.equipmentType.name, )
def edit_port_properties( client: SymphonyClient, equipment: Equipment, port_name: str, new_properties: Dict[str, PropertyValue], ) -> EquipmentPort: """This function returns edited port in equipment based on its name. Args: equipment ( `pyinventory.consts.Equipment` ): existing equipment object port_name (str): existing port name new_properties (Dict[str, PropertyValue]): Dict, where - str - property name - PropertyValue - new value of the same type for this property Returns: `pyinventory.consts.EquipmentPort` object Raises: `pyinventory.exceptions.EntityNotFoundError`: when `pyinventory.consts.EquipmentPortDefinition.port_type_name` is None, there are no properties or if there any unknown property name in properties_dict keys FailedOperationException: on operation failure Example: ``` location = client.get_location(location_hirerchy=[("Country", "LS_IND_Prod_Copy")]) equipment = client.get_equipment(name="indProdCpy1_AIO", location=location) edited_port = client.edit_port_properties( equipment=equipment, port_name="Z AIO - Port 1", new_properties={"Port Property 2": "test_it"}, ) ``` """ port = get_port(client, equipment, port_name) new_property_inputs = [] if new_properties: port_type_name = port.definition.port_type_name if port_type_name is None: raise EntityNotFoundError( entity=Entity.Property, msg=f"Not possible to edit properties in '{port.definition.name}' port with undefined PortType", ) property_types = client.portTypes[port_type_name].property_types new_property_inputs = get_graphql_property_inputs( property_types, new_properties ) edit_equipment_port_input = { "side": LinkSide(equipment=equipment.id, port=port.definition.id), "properties": new_property_inputs, } try: result = EditEquipmentPortMutation.execute( client, EditEquipmentPortInput( side=LinkSide(equipment=equipment.id, port=port.definition.id), properties=new_property_inputs, ), ).__dict__[EDIT_EQUIPMENT_PORT_MUTATION_NAME] client.reporter.log_successful_operation( EDIT_EQUIPMENT_PORT_MUTATION_NAME, edit_equipment_port_input ) except OperationException as e: raise FailedOperationException( client.reporter, e.err_msg, e.err_id, EDIT_EQUIPMENT_PORT_MUTATION_NAME, edit_equipment_port_input, ) return EquipmentPort( id=result.id, properties=result.properties, definition=EquipmentPortDefinition( id=result.definition.id, name=result.definition.name, port_type_name=result.definition.portType.name, ), link=Link( id=result.link.id, properties=result.link.properties, service_ids=[s.id for s in result.link.services], ) if result.link else None, )