示例#1
0
def do_slurm_suspend(args):
    log.debug(f"reading config file ({args.config_file})")

    c = azconfig.ConfigFile()
    c.open(args.config_file)
    config = c.preprocess()

    log.info(f"slurm suspend for {args.nodes}")
    _, resource_list = _nodelist_expand(args.nodes)
    log.debug("suspend list expanded to: " + ",".join(resource_list))
    subscription_id = azutil.get_subscription_id()
    resource_group = config["resource_group"]

    vm_ids = []
    nic_ids = []
    disk_ids = []
    for resource in resource_list:
        vm_ids.append(
            f"/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.Compute/virtualMachines/{resource}"
        )
        nic_ids.append(
            f"/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.Network/networkInterfaces/{resource}_nic"
        )
        disk_ids.append(
            f"/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.Compute/disks/{resource}_osdisk"
        )

    # delete vms
    log.debug("deleting vms: " + ",".join(vm_ids))
    azutil.delete_resources(vm_ids)
    # delete nics and disks
    log.debug("deleting nics and disks: " + ",".join(nic_ids + disk_ids))
    azutil.delete_resources(nic_ids + disk_ids)
    log.debug("exiting do_slurm_suspend")
示例#2
0
def do_slurm_suspend(args):
    log.debug(f"reading config file ({args.config_file})")

    c = azconfig.ConfigFile()
    c.open(args.config_file)
    config = c.preprocess()

    log.info(f"slurm suspend for {args.nodes}")
    # first get the resource name
    all_resources = config.get("resources", [])
    resource_name, brackets = re.search(r'([^[]*)\[?([\d\-\,]*)\]?',
                                        args.nodes).groups(0)
    resource_list = []
    if bool(brackets):
        for part in brackets.split(","):
            if "-" in part:
                lo, hi = part.split("-")
                assert len(lo) == 4, "expecting number width of 4"
                assert len(hi) == 4, "expecting number width of 4"
                for i in range(int(lo), int(hi) + 1):
                    resource_list.append(f"{resource_name}{i:04d}")
            else:
                assert len(part) == 4, "expecting number width of 4"
                resource_list.append(f"{resource_name}{part}")
    else:
        resource_list.append(resource_name)
        resource_name = resource_name[:-4]

    subscription_id = azutil.get_subscription_id()
    resource_group = config["resource_group"]

    vm_ids = []
    nic_ids = []
    disk_ids = []
    for resource in resource_list:
        vm_ids.append(
            f"/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.Compute/virtualMachines/{resource}"
        )
        nic_ids.append(
            f"/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.Network/networkInterfaces/{resource}_nic"
        )
        disk_ids.append(
            f"/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.Compute/disks/{resource}_osdisk"
        )

    # delete vms
    log.debug("deleting vms: " + ",".join(vm_ids))
    azutil.delete_resources(vm_ids)
    # delete nics and disks
    log.debug("deleting nics and disks: " + ",".join(nic_ids + disk_ids))
    azutil.delete_resources(nic_ids + disk_ids)
    log.debug("exiting do_slurm_suspend")