Ejemplo n.º 1
0
class DigitalTwinsProvider(object):
    def __init__(self, cmd, name, rg=None):
        assert cmd
        assert name

        self.cmd = cmd
        self.name = name
        self.rg = rg
        self.resource_id = DIGITALTWINS_RESOURCE_ID
        self.rp = ResourceProvider(self.cmd)

    def _get_endpoint(self):
        host_name = None
        https_prefix = "https://"
        http_prefix = "http://"

        if self.name.lower().startswith(https_prefix):
            self.name = self.name[len(https_prefix):]
        elif self.name.lower().startswith(http_prefix):
            self.name = self.name[len(http_prefix):]

        if not all([valid_hostname(self.name), "." in self.name]):
            instance = self.rp.find_instance(name=self.name, resource_group_name=self.rg)
            host_name = instance.host_name
            if not host_name:
                raise CLIError("Instance has invalid hostName. Aborting operation...")
        else:
            host_name = self.name

        return "https://{}".format(host_name)

    def get_sdk(self):
        creds = DigitalTwinAuthentication(cmd=self.cmd, resource_id=self.resource_id)
        return AzureDigitalTwinsAPI(base_url=self._get_endpoint(), credentials=creds)
Ejemplo n.º 2
0
class DigitalTwinsProvider(object):
    def __init__(self, cmd, name, rg=None):
        assert cmd
        assert name

        self.cmd = cmd
        self.name = name
        self.rg = rg
        self.resource_id = DIGITALTWINS_RESOURCE_ID
        self.rp = ResourceProvider(self.cmd)

    def _get_endpoint(self):
        host_name = None
        https_prefix = "https://"
        http_prefix = "http://"

        if self.name.lower().startswith(https_prefix):
            self.name = self.name[len(https_prefix):]
        elif self.name.lower().startswith(http_prefix):
            self.name = self.name[len(http_prefix):]

        if not all([valid_hostname(self.name), "." in self.name]):
            instance = self.rp.find_instance(name=self.name,
                                             resource_group_name=self.rg)
            host_name = instance.host_name
            if not host_name:
                raise CLIError(
                    "Instance has invalid hostName. Aborting operation...")
        else:
            host_name = self.name

        return "https://{}".format(host_name)

    def get_sdk(self):
        from azure.cli.core.commands.client_factory import get_mgmt_service_client

        client = get_mgmt_service_client(
            cli_ctx=self.cmd.cli_ctx,
            client_or_resource_type=AzureDigitalTwinsAPI,
            base_url=self._get_endpoint(),
            resource=self.resource_id,
            subscription_bound=False,
            base_url_bound=False,
        )

        client.config.add_user_agent(USER_AGENT)
        return client
Ejemplo n.º 3
0
class DigitalTwinsProvider(object):
    def __init__(self, cmd, name, rg=None):
        assert cmd
        assert name

        self.cmd = cmd
        self.name = name
        self.rg = rg
        self.resource_id = DIGITALTWINS_RESOURCE_ID
        self.rp = ResourceProvider(self.cmd)

    def _get_endpoint(self):
        instance = self.rp.find_instance(name=self.name, resource_group_name=self.rg)
        host_name = instance.host_name
        if not host_name:
            raise CLIError("Retrieved hostName was null which is invalid.")
        return "https://{}".format(instance.host_name)

    def get_sdk(self):
        creds = DigitalTwinAuthentication(cmd=self.cmd, resource_id=self.resource_id)
        return AzureDigitalTwinsAPI(base_url=self._get_endpoint(), credentials=creds)
def show_instance(cmd, name, resource_group_name=None):
    rp = ResourceProvider(cmd)
    return rp.find_instance(name=name, resource_group_name=resource_group_name)
Ejemplo n.º 5
0
def wait_instance(cmd, name, resource_group_name=None):
    rp = ResourceProvider(cmd)
    return rp.find_instance(name=name,
                            resource_group_name=resource_group_name,
                            wait=True)