OpenStack虚拟机的用户客制化方法(User Data)



  • Gzip Compressed Content
    content found to be gzip compressed will be uncompressed.
    Theuncompressed data will then be used as if it were not
    compressed.Compression of data is useful because user-data is
    limited to 16384bytes1
  • Mime Multi Part archive
    This list of rules is applied to each part ofthis multi-part
    file. Using a mime-multi part file, the user canspecify more than
    one type of data. For example, both a user datascript and a
    cloud-config type could be specified.
  • User-Data Script
    begins with: “#!” or”Content-Type: text/x-shellscript”
    script will be executed at “rc.local-like” level during first boot.rc.local-like means “very late in the boot sequence”
  • Include File
    begins with “#include” or”Content-Type: text/x-include-url”
    This content is a “include” file. The file contains a list of urls,one per line. Each of the URLs will be read, and their content willbe passed through this same set of rules. Ie, the content read fromthe URL can be gzipped, mime-multi-part, or plain text
  • Cloud Config Data
    begins with “#cloud-config” or”Content-Type: text/cloud-config”
    This content is “cloud-config” data. See the examples for acommented example of supported config formats.
  • Upstart Job
    begins with “#upstart-job” or”Content-Type: text/upstart-job”
    Content is placed into a file in /etc/init, and will be consumed byupstart as any other upstart job.
  • Cloud Boothook
    begins with “#cloud-boothook” or”Content-Type: text/cloud-boothook”
    This content is “boothook” data. It is stored in a file under/var/lib/cloud and then executed immediately.
    This is the earliest “hook” available. Note, that there is nomechanism provided for running only once. The boothook must takecare of this itself. It is provided with the instance id in theenvironment variable “INSTANCE_ID”. This could be made use of toprovide a ‘once-per-instance’
    Only available in 10.10 or later (cloud-init 0.5.12 andlater)
  • Part Handler
    begins with “#part-handler” or”Content-Type: text/part-handler”
    This is a ‘part-handler’. It will be written to a file in/var/lib/cloud/data based on its filename. This must be python codethat contains a list_types method and a handle_type method.
    Oncethe section is read the ‘list_types’ method will be called. It mustreturn a list of mime-types that this part-handler handlers.
    The ‘handle_type’ method must be like:
    def handle_part(data,ctype,filename,payload):
    # data = the cloudinit object
    # ctype = "__begin__", "__end__", or the mime-type of the part that is
    # being handled.
    # filename = the filename of the part (or a generated filename if none is
    # present in mime data)# payload = the parts' content

  这里主要关注User-Data Script,其使用的就是常用的shell脚本,我们只要在dashboard创建虚拟机的时候讲脚本写入user data输入框中即可。
user-data sample