示例#1
0
class RemoteRepositoryMixin(object):
    def setUp(self):
        self.client = ModelsRepositoryClient()
        self.client_type = REMOTE_REPO

    def tearDown(self):
        self.client.close()
示例#2
0
class LocalRepositoryMixin(object):
    def setUp(self):
        test_dir = os.path.dirname(os.path.abspath(__file__))
        local_repo = os.path.join(test_dir, "local_repository")
        self.client = ModelsRepositoryClient(repository_location=local_repo)
        self.client_type = LOCAL_REPO

    def tearDown(self):
        self.client.close()
def get_model():
    # This API call will return a dictionary mapping DTMI to its corresponding model from
    # a DTDL document at the specified endpoint
    # i.e. https://devicemodels.azure.com/dtmi/com/example/temperaturecontroller-1.json
    with ModelsRepositoryClient() as client:
        model_map = client.get_models(dtmi)
        pprint.pprint(model_map)
def get_model_and_dependencies():
    # This API call will return a dictionary mapping the specified DTMI to its corresponding model,
    # from a DTDL document at the specified endpoint, as well as the DTMIs and models for all
    # dependencies on components and interfaces
    # i.e. https://devicemodels.azure.com/dtmi/com/example/temperaturecontroller-1.json
    with ModelsRepositoryClient() as client:
        model_map = client.get_models(dtmis=[dtmi], dependency_resolution=DEPENDENCY_MODE_ENABLED)
        pprint.pprint(model_map)
def get_model_expanded_dtdl():
    # This API call will return a dictionary mapping DTMIs to corresponding models for all elements
    # of an expanded DTDL document at the specified endpoint
    # i.e. https://devicemodels.azure.com/dtmi/com/example/temperaturecontroller-1.expanded.json
    with ModelsRepositoryClient() as client:
        model_map = client.get_models(
            dtmis=[dtmi], dependency_resolution=DEPENDENCY_MODE_TRY_FROM_EXPANDED
        )
        pprint.pprint(model_map)
def get_model_error_handling():
    # Various errors that can be raised when fetching models
    try:
        with ModelsRepositoryClient() as client:
            model_map = client.get_models(dtmi)
            pprint.pprint(model_map)
    except ResourceNotFoundError as e:
        print("The model could not be found")
        print("{}".format(e.message))
    except ServiceRequestError as e:
        print("There was an error sending the request")
        print("{}".format(e.message))
    except ServiceResponseError as e:
        print("No response was received")
        print("{}".format(e.message))
    except HttpResponseError as e:
        print("HTTP Error Response received")
        print("{}".format(e.message))
 def setUp(self):
     test_dir = os.path.dirname(os.path.abspath(__file__))
     local_repo = os.path.join(test_dir, "local_repository")
     self.client = ModelsRepositoryClient(repository_location=local_repo)
     self.client_type = LOCAL_REPO
     super(LocalRepositoryMixin, self).setUp()
 def setUp(self):
     self.client = ModelsRepositoryClient()
     self.client_type = REMOTE_REPO
     super(RemoteRepositoryMixin, self).setUp()
示例#9
0
 def setUp(self):
     self.client = ModelsRepositoryClient()
     self.client_type = REMOTE_REPO
def use_local_repository():
    # You can also specify a custom local filesystem path where your Models Repository is located.
    # Paths can be specified as relative or absolute, as well as in URI format
    client = ModelsRepositoryClient(
        repository_location="file:///home/fake/myrepository")
def use_remote_repository():
    # You can specify a custom remote endpoint where your Models Repository is located
    client = ModelsRepositoryClient(
        repository_location="https://fake.myrepository.com/")
def default_client():
    # By default, this client will be configured for the Azure Device Models Repository
    # i.e. https://devicemodels.azure.com/
    client = ModelsRepositoryClient()