Пример #1
0
def attach_remote(
    name,
    address,
    ssh_port,
    username,
    password='',
    private_key_file='',
    private_key_passphrase='',
    workspace_name=None,
    resource_group_name=None,
):
    workspace = get_workspace_or_default(workspace_name=workspace_name,
                                         resource_group=resource_group_name)

    print('Attaching compute resource...')
    attach_config = RemoteCompute.attach_configuration(
        username=username,
        address=address,
        ssh_port=ssh_port,
        password=password,
        private_key_file=private_key_file,
        private_key_passphrase=private_key_passphrase)
    ComputeTarget.attach(workspace, name, attach_config)
    print('Resource attach submitted successfully.')
    print('To see if your compute target is ready to use, run:')
    print('  az ml computetarget show -n {}'.format(name))
Пример #2
0
    def attach(self, compute_name, username, password, address):
        compute_target = self.__get_if_exist_compute_target(compute_name)

        if (compute_target is None):
            compute_target = RemoteCompute.attach(self.__workspace,
                                                  name=compute_name,
                                                  username=params['username'],
                                                  address=params['address'],
                                                  password=params['password'])
            compute_target.wait_for_completion(show_output=True)

        return compute_target
Пример #3
0
def create_compute_instance():
    try:
        ws=_establish_connection_to_aml_workspace()
    except Exception as e:
        raise e
    try:
        compute_target_name='testConfDSVM'
        attach_config=RemoteCompute.attach_configuration(
            # resource_id="/subscriptions/e4da59ca-11b0-454e-a89a-cd711dea9094/resourceGroups/Barrys-ConfidentialML-Test/providers/Microsoft.Compute/virtualMachines/Barrys-ConfidentialML-TestComputeTarget",
            resource_id="/subscriptions/e4da59ca-11b0-454e-a89a-cd711dea9094/resourcegroups/Barrys-ConfidentialML-Test/providers/Microsoft.Compute/virtualMachines/BarrysTestConfidentialDSVM",
            ssh_port=22,
            username="******",
            password="******"
        )
        compute=ComputeTarget.attach(ws,compute_target_name,attach_config)
        compute.wait_for_completion(show_output=True)
    except Exception as e:
        raise e
ws = Workspace.from_config(auth=cli_auth)

# Read the New VM Config
with open("aml_config/security_config.json") as f:
    config = json.load(f)

remote_vm_name = config["remote_vm_name"]
remote_vm_username = config["remote_vm_username"]
remote_vm_password = config["remote_vm_password"]
remote_vm_ip = config["remote_vm_ip"]

try:
    dsvm_compute = RemoteCompute.attach(
        ws,
        name=remote_vm_name,
        username=remote_vm_username,
        address=remote_vm_ip,
        ssh_port=22,
        password=remote_vm_password,
    )
    dsvm_compute.wait_for_completion(show_output=True)

except Exception as e:
    print("Caught = {}".format(e.message))
    print("Compute config already attached.")

## Create VM if not available
# compute_target_name = remote_vm_name

# try:
#     dsvm_compute = DsvmCompute(workspace=ws, name=compute_target_name)
#     print('found existing:', dsvm_compute.name)
Пример #5
0
    "remotecompute"]

# Get workspace
print("Loading Workspace")
cli_auth = AzureCliAuthentication()
config_file_path = os.environ.get("GITHUB_WORKSPACE", default="aml_service")
config_file_name = "aml_arm_config.json"
ws = Workspace.from_config(path=config_file_path,
                           auth=cli_auth,
                           _file_name=config_file_name)
print(ws.name, ws.resource_group, ws.location, ws.subscription_id, sep='\n')

try:
    # Loading remote compute
    print("Loading existing and attached compute resource")
    remote_compute = RemoteCompute(workspace=ws,
                                   name=remotecompute_settings["name"])
    print("Found existing VM")
except ComputeTargetException:
    print("Loading failed")
    print("Trying to attach existing compute")

    # Create the compute config
    attach_config = RemoteCompute.attach_configuration(
        address=remotecompute_settings["address"],
        ssh_port=remotecompute_settings["ssh_port"],
        username=remotecompute_settings["address"])
    if remotecompute_settings["use_ssh_auth"]:
        # use ssh authentication
        attach_config.password = None
        attach_config.private_key_file = remotecompute_settings[
            "private_key_file"]
Пример #6
0
ws = Workspace.from_config(auth=cli_auth)

# Read the New VM Config
with open("aml_config/security_config.json") as f:
    config = json.load(f)

remote_vm_name = config["remote_vm_name"]
remote_vm_username = config["remote_vm_username"]
remote_vm_password = config["remote_vm_password"]
remote_vm_ip = config["remote_vm_ip"]

try:
    dsvm_compute = RemoteCompute.attach_configuration(
        vm_name=remote_vm_name,
        username=remote_vm_username,
        address=remote_vm_ip,
        ssh_port=22,
        password=remote_vm_password,
    )
    dsvm_compute.wait_for_completion(show_output=True)

except Exception as e:
    print("Caught = {}".format(e.message))
    print("Compute config already attached.")

## Create VM if not available
# compute_target_name = remote_vm_name

# try:
#     dsvm_compute = DsvmCompute(workspace=ws, name=compute_target_name)
#     print('found existing:', dsvm_compute.name)
Пример #7
0
output, error = proc_cr.communicate()

# Get dynamic IP address of VM
ip_cmd = "az vm list-ip-addresses -n {} -g {}".format(vm_name, rg)
print("Getting IP address using command: ", ip_cmd)
proc_ip = subprocess.Popen(ip_cmd, shell=True, stdout=subprocess.PIPE)
output, error = proc_ip.communicate()
output = json.loads(output.decode("ascii"))

ipAddress = str(output[0]["virtualMachine"]["network"]["publicIpAddresses"][0]
                ["ipAddress"])

# Attach VM to Workspace

print("Attaching DSVM with IP address ", ipAddress)

attach_config = RemoteCompute.attach_configuration(
    username=admin,
    address=ipAddress,
    private_key_file=os.path.join(str(Path.home()), ".ssh/id_rsa"))

dsvm = DsvmCompute.attach(workspace=ws,
                          name=vm_name,
                          attach_configuration=attach_config)

dsvm.wait_for_completion(show_output=True)
status = dsvm.get_status()

if status != "Succeeded":
    raise Exception('Failed to provision DSVM')
Пример #8
0
from azureml.core.compute import RemoteCompute, ComputeTarget

# Create the compute config 
compute_target_name = "attach-dsvm"

attach_config = RemoteCompute.attach_configuration(
												#resource_id='<resource_id>',
                                                #ssh_port=22,
                                                #username='******',
                                                #password="******")

# If you authenticate with SSH keys instead, use this code:
                                                  ssh_port=22,
                                                  username='******',
                                                  password=None,
                                                  private_key_file="/Users/ra312/.ssh/id_rsa",
#                                                 private_key_passphrase="<passphrase>")

# Attach the compute
compute = ComputeTarget.attach(ws, compute_target_name, attach_config)

compute.wait_for_completion(show_output=True)
script_folder = './aml-run'  # this is the folder that we are going to send to the remote vm
os.makedirs(script_folder, exist_ok=True)
shutil.copy('./train.py', os.path.join(script_folder, 'train.py'))
shutil.copy('./myfucs.py', os.path.join(script_folder, 'myfucs.py'))

#%%
""" 02d-1 -- Configuration (Compute - DSVM)
"""
from azureml.core.compute import RemoteCompute, ComputeTarget
from azureml.core.compute_target import ComputeTargetException

dsvm_name = "vm-1"
target_compuate = "attach-vm-1"
try:
    target_compuate = RemoteCompute(workspace=ws, name=target_compuate)
    print('found existing:', target_compuate.name)
except ComputeTargetException:
    vm_username = os.environ.get("vm_user_name", default='ting')
    vm_password = os.environ.get("vm_password", default='Password123!')
    attach_config = RemoteCompute.attach_configuration(
        resource_id='/subscriptions/' + ws.subscription_id +
        '/resourceGroups/' + ws.resource_group +
        '/providers/Microsoft.Compute/virtualMachines/' + dsvm_name,
        ssh_port=22,
        username=vm_username,
        password=vm_password)
    target_compuate = ComputeTarget.attach(workspace=ws,
                                           name=target_compuate,
                                           attach_configuration=attach_config)
    target_compuate.wait_for_completion(show_output=True)