Exemple #1
0
    create, validate = False, False
    if options.validate:
        validate = True
    elif options.create:
        validate, create = True, True
    else:
        parser.print_help()
        exit(1)
    if len(args) != 1:
        parser.print_help()
        exit(1)

    filename = args[0]
    if not os.path.isfile(filename):
        log.fail("Can not find xml file: %s, please check it.", filename)
        exit(1)
    schema_file = os.path.join(os.path.dirname(__file__), "../etc/schema.xsd")
    if not xml_utils.validate(schema_file, filename):
        log.fail("XML file '%s' did not validate with the schema.xsd!",
                 filename)
        exit(1)

    # start to create via xml
    parsed_xml = xml_utils.parse_xml(filename)
    # [{'passwd': '123456', 'host': '192.168.1.10', 'user': '******', 'vms': []}]

    # 1. validate xml items
    iplist = []
    for server in parsed_xml:
        hostname, user, passwd = server['host'], server['user'], server[
Exemple #2
0
    parser.add_option("--list-bridge",
                      dest="list_bridge",
                      action="store_true",
                      help="List the bridge/switch names in the host")
    parser.add_option("--list-SR",
                      dest="list_sr",
                      action="store_true",
                      help="List the storage repository infor in the host")

    (options, args) = parser.parse_args()
    log.debug("options:%s, args:%s", str(options), str(args))

    if options.host is not None and (options.user is None
                                     or options.passwd is None):
        log.fail(
            "Please specify a user-name and passward for the given host:%s",
            options.host)
        exit(1)

    host_name = options.host
    user = options.user if options.user else "root"
    passwd = str(options.passwd).replace('\\', '') if options.passwd else ""

    virthost = VirtHostDomain(host_name, user, passwd)
    if not virthost:
        log.fail(
            "Can not connect to virtual driver or DB driver, initial VirtHostDomain failed."
        )
        exit(1)

    vnet_driver = virthost.vnet_driver
Exemple #3
0
    parser.add_option("--list-bridge",
                      dest="list_bridge",
                      action="store_true",
                      help="List the bridge/switch names in the host")
    parser.add_option("--list-SR",
                      dest="list_sr",
                      action="store_true",
                      help="List the storage repository infor in the host")

    (options, args) = parser.parse_args()
    log.debug("options:%s, args:%s", str(options), str(args))

    if options.host is not None and (options.user is None
                                     or options.passwd is None):
        log.fail(
            "Please specify a user-name and passward for the given host:%s",
            options.host)
        exit(1)
    host_name = options.host
    user = options.user if options.user else "root"
    passwd = str(options.passwd).replace('\\', '') if options.passwd else ""

    if not options.list_vif and not options.list_pif and not options.list_sr and not options.list_network and \
            not options.list_bridge and \
            (not options.vif_index and not options.del_index and not options.add_index and
             not options.disk_size and not options.cpu_cores and not options.max_cores and
             not options.memory_size and not options.min_memory and not options.max_memory):
        parser.print_help()
        exit(1)

    virthost = VirtHostDomain(host_name, user, passwd)
Exemple #4
0
    parser.add_option("--list-pif",
                      dest="list_pif",
                      action="store_true",
                      help="List all the interface information")
    parser.add_option("--list-bond",
                      dest="list_bond",
                      action="store_true",
                      help="List all the bond information")

    (options, args) = parser.parse_args()
    log.debug("options:%s, args:%s", str(options), str(args))

    if options.host is not None and (options.user is None
                                     or options.passwd is None):
        log.fail(
            "Please specify a user-name and passward for the given host:%s",
            options.host)
        exit(1)
    host_name = options.host
    user = options.user if options.user else "root"
    passwd = str(options.passwd).replace('\\', '') if options.passwd else ""

    serverDomain = ServerDomain(host_name, user, passwd)
    if not serverDomain:
        log.fail(
            "Can not connect to virtual driver or DB driver, initial serverDomain failed."
        )
        exit(1)

    if options.list_sr:
        log.info("Host Storage informations:")
Exemple #5
0
    parser.add_option("-p",
                      "--pwd",
                      dest="passwd",
                      help="Passward for host server")
    parser.add_option(
        "--vm",
        dest="vm",
        help="Delete an unused VM in server, the disk will not be deleted")

    (options, args) = parser.parse_args()
    log.debug("options:%s, args:%s", str(options), str(args))

    if options.host is not None and (options.user is None
                                     or options.passwd is None):
        log.fail(
            "Please specify a user-name and passward for the given host:%s",
            options.host)
        exit(1)
    host_name = options.host
    user = options.user if options.user else "root"
    passwd = str(options.passwd).replace('\\', '') if options.passwd else ""

    virthost = VirtHostDomain(host_name, user, passwd)
    if not virthost:
        log.fail(
            "Can not connect to virtual driver or DB driver, initial VirtHostDomain failed."
        )
        exit(1)

    virt_driver = virthost.virt_driver
Exemple #6
0
        return False
    cpu_cores = vm_record['VCPUs_live']
    sn = vm_record['uuid']

    return db_driver.update(sn=sn, data={"cpu_cores": cpu_cores})


if __name__ == "__main__":
    from optparse import OptionParser

    parser = OptionParser()
    parser.add_option("--host", dest="host", help="IP for host server")
    parser.add_option("-u", "--user", dest="user", help="User name for host server")
    parser.add_option("-p", "--pwd", dest="passwd", help="Passward for host server")
    parser.add_option("--create", dest="create", help="Create VM record in database")
    parser.add_option("--delete", dest="delete", help="Delete record from database")

    (options, args) = parser.parse_args()
    log.debug("options:%s, args:%s", str(options), str(args))

    if options.host is not None and (options.user is None or options.passwd is None):
        log.fail("Please specify a user-name and passward for the given host:%s", options.host)
        exit(1)

    if options.create:
        print create_vm_database_info(inst_name=options.create, host=options.host, user=options.user, passwd=options.passwd)
    elif options.delete:
        print delete_vm_database_info(inst_name=options.delete)
    else:
        parser.print_help()
Exemple #7
0
                      "--pwd",
                      dest="passwd",
                      help="Passward for host server")

    parser.add_option("--all",
                      dest="all",
                      action="store_true",
                      help="Power off all VMs in server")

    (options, args) = parser.parse_args()
    log.debug("options:%s, args:%s", str(options), str(args))

    if options.host is not None and (options.user is None
                                     or options.passwd is None):
        log.fail(
            "Please specify a user-name and passward for the given host:%s",
            options.host)
        exit(1)
    host_name = options.host
    user = options.user if options.user else "root"
    passwd = str(options.passwd).replace('\\', '') if options.passwd else ""

    virthost = VirtHostDomain(host_name, user, passwd)
    if not virthost:
        log.fail(
            "Can not connect to virtual driver or DB driver, initial VirtHostDomain failed."
        )
        exit(1)

    virt_driver = virthost.virt_driver
Exemple #8
0
                      help="Passward for host server")
    parser.add_option("--update",
                      dest="update",
                      action="store_true",
                      help="Update the server's infor to database")
    parser.add_option("--vm",
                      dest="vm_name",
                      help="Sync the VM's infor to database")

    (options, args) = parser.parse_args()
    log.debug("options: %s, args: %s", options, args)

    if options.host is not None and (options.user is None
                                     or options.passwd is None):
        log.fail(
            "Please specify a user-name and passward for the given host:%s",
            options.host)
        exit(1)

    host_name = options.host
    user = options.user if options.user else "root"
    passwd = str(options.passwd).replace('\\', '') if options.passwd else ""

    if options.vm_name:
        virt_host = VirtHostDomain(host_name, user, passwd)
        if not virt_host:
            log.fail(
                "Can not connect to virtual driver or DB driver, initial VirtHostDomain failed."
            )
            exit(1)
        if not virt_host.virt_driver.is_instance_exists(options.vm_name):
Exemple #9
0
thread_log.exception("thread_log test log for exception")

log.info("nohup_orig_log")
nohup_orig_log.debug("test log for debug.")
nohup_orig_log.info("test log for info")
nohup_orig_log.warning("test log for warning")
nohup_orig_log.error("test log for error")
nohup_orig_log.exception("test log for exception")
log.info("nohup log")
nohup_log.debug("nohup test log for debug.")
nohup_log.info("nohup test log for info")
nohup_log.warning("nohup test log for warning")
nohup_log.error("nohup test log for error")
nohup_log.exception("nohup test log for exception")

log.info("rotate_log")
rotate_log.debug("test log for debug.")
rotate_log.info("test log for info")
rotate_log.warning("test log for warning")
rotate_log.error("test log for error")
rotate_log.exception("test log for exception")

log.info("virt console")
log.debug("test log for debug.")
log.info("test log for info")
log.warning("test log for warning")
log.error("test log for error")
log.exception("test log for exception")
log.success("test log for success")
log.fail("test log for fail")
Exemple #10
0
    parser.add_option("--host", dest="hostip", help="IP for the host server.")
    parser.add_option("--ip", dest="vm_ip", help="The ip assigned to the vm")
    parser.add_option("--cluster",
                      dest="cluster",
                      help="The target cluster name, support test|xyz|kvm")
    parser.add_option("--list-roles",
                      dest="list_roles",
                      action="store_true",
                      help="List all supported role names")

    (options, args) = parser.parse_args()
    log.debug("options:%s, args:%s", str(options), str(args))

    if os.getenv("PLATFORM", "Xen") == "Xen":
        log.fail(
            "This script does'n support 'Xen', please use create_vm.py instead."
        )
        exit(1)

    config_dict = template_dict
    try:
        config_file = os.path.join(os.path.dirname(__file__),
                                   "../etc/Nodeconfig.json")
        with open(config_file, "r") as f:
            try:
                config = json.load(f)
                config_dict.update(config)
            except (KeyError, ValueError) as e:
                log.fail("raised exception while load json: %s", e)
                exit(1)
    except IOError as err: