OpenStack Glance upload image

Source: Internet
Author: User
OpenStack Glance upload image

Glance is a sub-project that provides mirroring services in OpenStack, this article mainly describes the process of uploading images glance.
The Glance service consists of two services Glance-api and Glance-registry.
The GLANCE-API is responsible for receiving and processing requests and storing the mirrors.
Glance-registry is responsible for saving the meta-information of the image.

Glance image upload operation, involving the client side and the server, this article will be described in detail:
Client side:
Commands to upload images:

OpenStack image Create "Cirros"--file cirros-0.3.4-x86_64-disk.img--disk-format qcow2--container-format bare--public

The above command, OpenStack is a client executable program, image refers to the operation of the resource, create represents the operation of the resource, that is, the creation of a image,–file specified locally to upload the image, –disk-format specify the image Disk format,- CONTAINER-FORMAT Specifies the format of the image container, –public indicates that the image can be accessed publicly.
The source code for OpenStack is as follows:

[Root@console-mitaka ~]# which OpenStack                                                                                                            
/usr/bin/openstack
[Root@console-mitaka ~]# Vim/usr/bin/openstack

Import sys from

openstackclient.shell import main


if __name__ = = "__main__":
    sys.exit (Main ())

As can be seen from the code above, the core code of the client is in the main method of module Openstackclient.shell.

Class Openstackshell: ...
    def run (self, argv):
        ret_val = 1
        #将参数赋值给属性command_options
        self.command_options = argv
        try:
        # Executes the run () method of the parent class
            Ret_val = Super (Openstackshell, self). Run (argv)
            return ret_val
        except Exception as E:
            If not Logging.getlogger ("). Handlers:
                logging.basicconfig ()
            if self.dump_stack_trace:
                Self.log.error (Traceback.format_exc ())
            else:
                self.log.error (' Exception raised: ' + str (e))

            return Ret_val

        finally:
            self.log.info ("END return value:%s", Ret_val)
def main (argv=sys.argv[1:]):
# Sys.argv[1:] In the command line in addition to the executable part of the parameter.
    return Openstackshell (). Run (argv)

With the above code, we call the Run method of the Openstackshell parent class:
Class Openstackshell inheritance and CLIFF.APP.APP class:
Here's the main code for the Run method in the app:
1. Parse the parameters of the parameter, configure log
2. Execute sub-commands.

    def run (self, argv):
        try:
        #解析传入的参数, config log
            self.options, remainder = Self.parser.parse_known_args (argv)
            self.configure_logging ()
            Self.interactive_mode = not remainder ...
            #执行子命令.
            result = Self.run_subcommand (remainder)
        return result

Execute the Sub-command section code:

 def run_subcommand (self, argv): ... subcommand = Self.command_manager.find_comman D (argv) ... cmd_factory, cmd_name, sub_argv = subcommand ... cmd = cmd_factory (self, self.option S, **kwargs) ... self.prepare_to_run_command (cmd) full_name = (Cmd_name i
            F self.interactive_mode Else '. Join ([Self.name, Cmd_name])) Cmd_parser = Cmd.get_parser (full_name) Parsed_args = Cmd_parser.parse_args (sub_argv) result = C Md.run (Parsed_args) ... return result 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.