Categories
ceph storage virtualization

OpenStack使用ceph存储时,glance 上传镜像输出

[root@node2 ~(keystone_admin)]# glance image-create --name bc_win2012 --disk-format qcow2 --container-format ovf --f /meta/iso/bc_win2012.qcow2 
+------------------+----------------------------------------------------------------------------------+
| Property         | Value                                                                            |
+------------------+----------------------------------------------------------------------------------+
| checksum         | 13422230096bef83fade0418d64e9890                                                 |
| container_format | ovf                                                                              |
| created_at       | 2020-02-26T12:03:58Z                                                             |
| direct_url       | rbd://d484bdf2-c9ba-4e1f-a69f-86586e0dc8ad/images/b9168a42-244f-4642-b08f-       |
|                  | 3e6fdc05645e/snap                                                                |
| disk_format      | qcow2                                                                            |
| id               | b9168a42-244f-4642-b08f-3e6fdc05645e                                             |
| min_disk         | 0                                                                                |
| min_ram          | 0                                                                                |
| name             | bc_win2012                                                                       |
| os_hash_algo     | sha512                                                                           |
| os_hash_value    | 30025e558627c60e7cd88aab01f193c2ca38fb73454c4fcd8c5bfc9b38cd23e963fa33aac3089f55 |
|                  | 8de746524a290d3c9e2dd87a1e919c60928fa51b9646e18d                                 |
| os_hidden        | False                                                                            |
| owner            | 504fb6fa98c443899288ec9e35b487a8                                                 |
| protected        | False                                                                            |
| size             | 8959033344                                                                       |
| status           | active                                                                           |
| tags             | []                                                                               |
| updated_at       | 2020-02-26T12:10:15Z                                                             |
| virtual_size     | Not available                                                                    |
| visibility       | shared                                                                           |
+------------------+----------------------------------------------------------------------------------+

Categories
poem

使用virsh执行qemu-monitor命令

virsh 可以发送命令给qemu-monitor

virsh # help  qemu-monitor-command host
  NAME
    qemu-monitor-command - QEMU Monitor Command

  SYNOPSIS
    qemu-monitor-command <domain> [--hmp] [--pretty] {[--cmd] <string>}...

  DESCRIPTION
    QEMU Monitor Command

  OPTIONS
    [--domain] <string>  domain name, id or uuid
    --hmp            command is in human monitor protocol
    --pretty         pretty-print any qemu monitor protocol output
    [--cmd] <string>  command

Categories
py

做新旧命令兼容的一种方式

将无法解析的命令
1. catch parse异常.
2. 错误输出直接重定向/dev/null.避免干扰output

#!/usr/bin/env python

import sys
import os
import subprocess
from optparse import OptionParser

class redirect_stdout_stderr(object):
    def __init__(self, stream):
        # Save the old std streams
        self.old_stream = sys.stdout
        self.old_error_stream = sys.stderr
        self.fstream = stream

    def __enter__(self):
        # Change the std streams to your streams when entering
        sys.stdout = self.fstream
        sys.stderr = self.fstream

    def __exit__(self, exc_type, exc_value, exc_traceback):
        # Change the std streams back to the original streams while exiting
        sys.stdout = self.old_stream
        sys.stderr = self.old_error_stream

if __name__ == "__main__":
    usage = "mdfscli [options]"
    parser = OptionParser(usage)
    #需要兼容的旧命令
    parser.add_option("--build-info", action="store_true", dest="cmd_build_info", \
                      default=False, help="Show build information")
    newappcli = ""
    try:
        # parse command line arguments
        with redirect_stdout_stderr(open(os.devnull, 'w')):
            (options, args) = parser.parse_args()
    except:
        newappcli = "/usr/share/yourapp/newappcli %s" % (" ".join(sys.argv[1:]))
    else:
        if options.cmd_build_info:
            newappcli = "/usr/share/yourapp/newappcli --build-info"
        else:
          newappcli = "/usr/share/yourapp/newappcli %s" % (" ".join(sys.argv[1:]))

    cmd = subprocess.Popen(newappcli, shell=True, stdout=sys.stdout, stderr=sys.stderr, close_fds=True)
    sys.exit(cmd.wait())