def get(self, subscription_id, resource_group_name, workspace_name, compute_instance_name): """Retrieve Compute Instance object. :param subscription_id: Subscription ID to use :type subscription_id: str :param resource_group_name: Resource Group name to use :type resource_group_name: str :param workspace_name: Azure ML workspace name to use :type workspace_name: str :param compute_instance_name: Azure ML Compute Instance name to use :type compute_instance_name: str :return: Compute Instance object that is retrieve by specified parameters. :rtype: azureml.core.compute.computeinstance.ComputeInstance """ compute_instance = None try: ws = Workspace(subscription_id=subscription_id, resource_group=resource_group_name, workspace_name=workspace_name, auth=msi_auth) compute_instance = ComputeInstance(ws, name=compute_instance_name) except ProjectSystemException as ex: print("ProjectSystemException: {}".format(ex.message)) except ComputeTargetException as ex: print("ComputeTargetException: {}".format(ex.message)) except Exception as ex: print("Error caught at: {}\n{}".format(self, exception_to_string(ex))) return compute_instance
def delete(self, subscription_id, resource_group_name, workspace_name, compute_instance_name): """Deletes the Compute Instance :param subscription_id: Subscription ID to use :type subscription_id: str :param resource_group_name: Resource Group name to use :type resource_group_name: str :param workspace_name: Azure ML workspace name to use :type workspace_name: str :param compute_instance_name: Azure ML Compute Instance name to use :type compute_instance_name: str """ try: ws = Workspace(subscription_id=subscription_id, resource_group=resource_group_name, workspace_name=workspace_name, auth=msi_auth) ComputeInstance(ws, name=compute_instance_name).delete() except ProjectSystemException as ex: print("ProjectSystemException: {}".format(ex.message)) except ComputeTargetException as ex: print("ComputeTargetException: {}".format(ex.message)) except Exception as ex: print("Error caught at: {}\n{}".format(self, exception_to_string(ex)))
def report(self, subscription_id, resource_group_name, workspace_name, compute_instance_name, summary=False): """Reports current status of Compute Instance :param subscription_id: Subscription ID to use :type subscription_id: str :param resource_group_name: Resource Group name to use :type resource_group_name: str :param workspace_name: Azure ML workspace name to use :type workspace_name: str :param compute_instance_name: Azure ML Compute Instance name to use :type compute_instance_name: str :param summary: [TODO], defaults to False :type summary: bool, optional :return: [TODO] :rtype: [TODO] """ ws = None ci = None status = None try: ws = Workspace(subscription_id=subscription_id, resource_group=resource_group_name, workspace_name=workspace_name, auth=msi_auth) ci = ComputeInstance(ws, name=compute_instance_name).get() if summary == False: status = ci else: properties = ci['properties']['properties'] id_split = ci['id'].split('/') resource_group_name = id_split[4] workspace_name = id_split[8] status = "rg_name: {}, ws_name: {}. ci_name: {}, state: {}, vm_size: {}, ssh_admin_user_name: {}, ssh_public_access: {}, public_ip_address: {}, error: {}".format( resource_group_name, workspace_name, ci['name'], properties['state'], properties['vmSize'], properties['sshSettings']['adminUserName'], properties['sshSettings']['sshPublicAccess'], properties['connectivityEndpoints']['publicIpAddress'], properties['errors']) except ProjectSystemException as ex: print("ProjectSystemException: {}".format(ex.message)) except ComputeTargetException as ex: print("ComputeTargetException: {}".format(ex.message)) except Exception as ex: print("Error caught at: {}\n{}".format(self, exception_to_string(ex))) return status
def create(self, subscription_id, resource_group_name, workspace_name, compute_instance_name, vm_size, ssh_public_access, admin_user_ssh_public_key): """Create Compute Instance under specified Azure ML workspace. :param subscription_id: Subscription ID to use :type subscription_id: str :param resource_group_name: Resource Group name to use :type resource_group_name: str :param workspace_name: Azure ML workspace name to use :type workspace_name: str :param compute_instance_name: Azure ML Compute Instance name to use :type compute_instance_name: str :param vm_size: VM size to use :type vm_size: str :param ssh_public_access: Whether to allow SSH Public Access :type ssh_public_access: boolean :param admin_user_ssh_public_key: SSH Public Key to use for the Compute Instance :type admin_user_ssh_public_key: str :return: Created Compute Instance object :rtype: azureml.core.compute.computeinstance.ComputeInstance """ compute_instance = None try: ws = Workspace(subscription_id=subscription_id, resource_group=resource_group_name, workspace_name=workspace_name, auth=msi_auth) # print(ws.name, ws.location) provision_config = ComputeInstance.provisioning_configuration( vm_size=vm_size, ssh_public_access=ssh_public_access, admin_user_ssh_public_key=admin_user_ssh_public_key) compute_instance = ComputeInstance.create(ws, compute_instance_name, provision_config) except ProjectSystemException as ex: print("ProjectSystemException: {}".format(ex.message)) except ComputeTargetException as ex: print("ComputeTargetException: {}".format(ex.message)) except Exception as ex: print("Error caught at: {}\n{}".format(self, exception_to_string(ex))) return compute_instance