コード例 #1
0
    def createResource(self, resource_type, resource_name, status, description=None,
                       external_system=None, location=None, department=None, owner=None, **add_params):
        """
        Create resource object and save it into database
        @return created resource object
        """
        resource = Resource(specification_name=resource_type, resource_name=resource_name, resource_status=status,
                            description=description, external_system=external_system, location=location,
                            department=department, owner=owner, additional_parameters=add_params)
        resource.validate()

        self.db_conn.connect()
        res_id = self.db_conn.save_entity(CommonDatabaseAPI.ET_RESOURCE, resource.to_dict())
        self.db_conn.close()

        resource.set__id(res_id)

        return resource
コード例 #2
0
    def updateResource(self, resource_id, resource_name=None, status=None, description=None, external_system=None,
                       location=None, department=None, owner=None, **add_params):
        """
        Update resource information
        Find resource in database by ID and update all non-None passed attributes
        """
        self.db_conn.connect()
        raw_resource = self.db_conn.get_entity(CommonDatabaseAPI.ET_RESOURCE, resource_id)
        resource = Resource(raw_resource)

        if resource_name is not None:
            resource.set_resource_name(resource_name)
        if status is not None:
            resource.set_resource_status(status)
        if description is not None:
            resource.set_description(description)
        if external_system is not None:
            resource.set_external_system(external_system)
        if location is not None:
            resource.set_location(location)
        if department is not None:
            resource.set_department(department)
        if owner is not None:
            resource.set_owner(owner)

        for param_name, param_value in add_params.iteritems():
            resource.set_attribute(param_name, param_value)

        resource.validate()
        self.db_conn.save_entity(CommonDatabaseAPI.ET_RESOURCE, resource.to_dict())
        self.db_conn.close()

        return resource