def destroy(args):
    vc = _get_vc()
    vm_lists = utils.get_items(args.vm_names)
    vms = []
    if args.path is None:
        vms = vc.get_vms_by_regex(vm_lists)
    else:
        items = utils.get_items(args.path, '/')
        len_path = len(items)
        dc = vc.get_datacenter_by_name(items[0])
        if dc is None:
            exit(1)
        if len_path == 1:
            vms = dc.get_vms_by_regex(vm_lists)
        elif len_path == 2:
            cluster = dc.get_cluster_by_name(items[1])
            if cluster is None:
                exit(1)
            hosts = cluster.get_hosts()
            for host in hosts:
                vms.extend(host.get_vms_by_regex(vm_lists))
        elif len_path == 3:
            cluster = dc.get_cluster_by_name(items[1])
            if cluster is None:
                exit(1)
            rp = cluster.get_resourcepool_by_name(items[2])
            if rp is None:
                exit(1)
            vms.extend(rp.get_vms_by_regex(vm_lists))
    for vm in vms:
        print 'Delete vm ' + vm.name()
        vm.destroy()
Exemple #2
0
def destroy(args):
    vc = _get_vc()
    vm_lists = utils.get_items(args.vm_names)
    vms = []
    if args.path is None:
        vms = vc.get_vms_by_regex(vm_lists)
    else:
        items = utils.get_items(args.path, '/')
        len_path = len(items)
        dc = vc.get_datacenter_by_name(items[0])
        if dc is None:
            exit(1)
        if len_path == 1:
            vms = dc.get_vms_by_regex(vm_lists)
        elif len_path == 2:
            cluster = dc.get_cluster_by_name(items[1])
            if cluster is None:
                exit(1)
            hosts = cluster.get_hosts()
            for host in hosts:
                vms.extend(host.get_vms_by_regex(vm_lists))
        elif len_path == 3:
            cluster = dc.get_cluster_by_name(items[1])
            if cluster is None:
                exit(1)
            rp = cluster.get_resourcepool_by_name(items[2])
            if rp is None:
                exit(1)
            vms.extend(rp.get_vms_by_regex(vm_lists))
    for vm in vms:
        print 'Delete vm ' + vm.name()
        vm.destroy()
 def init_resource(self):
     sections = self.cf.sections()
     for section in sections:
         if section.startswith(self.cf_item):
             regulars = utils.get_items(self.cf.get(section, 'targets'))
             vm_list = self.vc.get_vms_by_regex(regulars)
             self.item_dict[section] = vm_list
 def init_resource(self):
     sections = self.cf.sections()
     for section in sections:
         if section.startswith(self.cf_item):
             regulars = utils.get_items(self.cf.get(section, 'targets'))
             vm_list = self.vc.get_vms_by_regex(regulars)
             self.item_dict[section] = vm_list
def power_vapp(args):
    vc = _get_vc()
    regular_list = utils.get_items(args.vapp_names)
    vapps = vc.get_vapps_by_regex(regular_list)
    for vapp in vapps:
        if args.action == 'on':
            vapp.poweron()
        else:
            vapp.poweroff()
Exemple #6
0
 def init_resource(self):
     sections = self.cf.sections()
     for section in sections:
         if section.startswith(self.cf_item):
             hosts = []
             host_names = utils.get_items(self.cf.get(section, 'targets'))
             for item in host_names:
                 hosts.extend(operations.get_host_list(item))
             all_hosts = self.vc.get_hosts()
             host_list = [host for host in all_hosts if host.name() in hosts]
             self.item_dict[section] = host_list
Exemple #7
0
 def planner(self):
     plan = []
     sections = self.cf.sections()
     for section in sections:
         if section.startswith(self.cf_item):
             actions = utils.get_items(self.cf.get(section, "actions"))
             if actions is None:
                 continue
             number_str = self.cf.get(section, "target_number")
             number = len(self.item_dict) if "" == number_str else int(number_str)
             policy = self.cf.get(section, "policy").strip().lower()
             plan.extend(self.get_plan(policy, section, actions, number))
     return plan
Exemple #8
0
 def planner(self):
     plan = []
     sections = self.cf.sections()
     for section in sections:
         if section.startswith(self.cf_item):
             actions = utils.get_items(self.cf.get(section, 'actions'))
             if actions is None:
                 continue
             number_str = self.cf.get(section, 'target_number')
             number = len(
                 self.item_dict) if '' == number_str else int(number_str)
             policy = self.cf.get(section, 'policy').strip().lower()
             plan.extend(self.get_plan(policy, section, actions, number))
     return plan
def delete_file(args):
    vc = _get_vc()
    vm_name = args.vm_name.strip()
    vm = None
    if args.vm_path is not None:
        items = utils.get_items(args.vm_path, '/')
        dc = vc.get_datacenter_by_name(items[0])
        if dc:
            cluster = dc.get_cluster_by_name(items[1])
            if cluster:
                vm = cluster.get_vm_by_name(vm_name)
        if vm is None:
            print 'VM {} not exist under the path {}'.format(vm_name, args.vm_path)
            exit(1)
    else:
        vm = vc.get_vm_by_name(vm_name)
    if vm:
        if vm.search_file(args.file_name):
            vm.delete_file(args.file_name)
        exit(0)
    else:
        print 'File {} not exist on VM {}'.format(args.file_name, vm_name)
        exit(1)
Exemple #10
0
def delete_file(args):
    vc = _get_vc()
    vm_name = args.vm_name.strip()
    vm = None
    if args.vm_path is not None:
        items = utils.get_items(args.vm_path, '/')
        dc = vc.get_datacenter_by_name(items[0])
        if dc:
            cluster = dc.get_cluster_by_name(items[1])
            if cluster:
                vm = cluster.get_vm_by_name(vm_name)
        if vm is None:
            print 'VM {} not exist under the path {}'.format(
                vm_name, args.vm_path)
            exit(1)
    else:
        vm = vc.get_vm_by_name(vm_name)
    if vm:
        if vm.search_file(args.file_name):
            vm.delete_file(args.file_name)
        exit(0)
    else:
        print 'File {} not exist on VM {}'.format(args.file_name, vm_name)
        exit(1)
Exemple #11
0
def power(args):
    vc = _get_vc()
    vm_names = utils.get_items(args.vm_names)
    vms = vc.get_vms_by_regex(vm_names, args.folder)
    for vm in vms:
        vm.power(args.action)
def destroy_vapp(args):
    vc = _get_vc()
    regular_list = utils.get_items(args.vapp_names)
    vapps = vc.get_vapps_by_regex(regular_list)
    for vapp in vapps:
        vapp.destroy()
def power(args):
    vc = _get_vc()
    vm_names = utils.get_items(args.vm_names)
    vms = vc.get_vms_by_regex(vm_names, args.folder)
    for vm in vms:
        vm.power(args.action)