Saltstack virt module Creating virtual Machine Analysis II

Source: Internet
Author: User
Tags saltstack

That's the 2nd one today. The command execution format is as follows:

Salt ' kvm.tiancity.com ' virt.init web20 4 nic=nics Disk=system


Here, we need to be aware that the KVM/QEMU is not allowed to use the profile, we need to change the virt.py code:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/56/AB/wKioL1SKgY2yWdXzAAGs9K0sV2Q276.jpg "title=" Pass.png "alt=" Wkiol1skgy2ywdxzaags9k0sv2q276.jpg "/>

In this way, my test environment is allowed.


My idea is that my virtual machine image files are stored in the
/var/lib/libvirt/images/web20/system.raw, look at how I construct the data structure of the disk.

diskp=[{' system ': {' size ': ' 8192 ', ' format ': ' Raw ', ' model ': ' Virtio ', ' pool ': '/var/lib/libvirt/images '}]

From the analysis code,

default = [
{' System ':
{' Size ': ' 8192 '}
}
]

Elif hypervisor in [' Qemu ', ' KVM ']:
Overlay = {' format ': ' Qcow2 ',
' Model ': ' Virtio ',
' Pool ': __salt__[' config.option ' (' virt.images ')
}

Disklist = __salt__[' Config.get '] (' Virt:disk ', {}). Get (profile, default)

No, in the absence of disk profile, we use the default data and then use

For key, Val in Overlay.items ():
For I, disks in Enumerate (disklist):
For disk in disks:
If key not in Disks[disk]:
Disklist[i][disk][key] = val

You'll get to disklist=.

[{' System ': {' format ': ' Qcow2 ',
' Model ': ' Virtio ',
' Pool ': '/srv/salt-images ',
' Size ': ' 8192 '}}]


I need to change pool here, so what's my whole thing? I can use Grains,pillar to set.

[Email protected]:/srv/salt/_grains# more virt_disk_nic.py
Def disk_profile ():
Grains = {}
grains[' virt ']={' disk ': {}}
grains[' virt ' [' Disk '] [' System ']={}
grains[' virt ' [' Disk '] [' System ']=[{' system ': {' format ': ' Raw ', ' pool ': '/var/lib/libvirt/images '}]
return grains

Sync Grains

[Email protected]:/srv/salt/_grains# Salt ' kvm.tiancity.com ' Saltutil.sync_all
Kvm.tiancity.com:
----------
Grains
-Grains.virt_disk_nic
Modules
Outputters:
Renderers:
Returners:
States:

Test:
[email protected]:/srv/salt/_grains# salt ' kvm.tiancity.com ' config.get virt:disk--output=json
{
    "kvm.tiancity.com": {
        "system": [
             {
                 "System": {
                     "Pool": "/var/lib/libvirt/images",
                     " Format ":" Raw "
               }
           }
       ]
   }
}

Then the corresponding profile name is system, so if you want to use an alternative profile name, you only need to modify the

grains[' virt ' [' Disk '] [' System (Profile name) ']={}


Next, we'll construct the network card structure.

default = [{' eth0 ': {}}]

Kvm_overlay = {' type ': ' Bridge ', ' source ': ' br0 ', ' model ': ' Virtio '}

Config_data = __salt__[' Config.get '] (' Virt:nic ', {}). Get (
Profile_name, default
)

Interfaces=[]

Elif isinstance (Config_data, list):
For interface in Config_data:
If Isinstance (interface, dict):
If Len (Interface.keys ()) = = 1:
Append_dict_profile_to_interface_list (interface)
Else
Interfaces.append (interface)

The above is the addition of interface NIC related attribute information to the interfaces list.

interfaces=[{' name ': ' eth0 ', ' type ': ' Bridge ', ' source ': ' Br0 ', ' mac ': ' Ac:de:48:5d:9c:b4 ', ' model ': ' Virtio '}]

Then the network card and disk construction:

Def disk_nic ():
Grains = {}
grains[' virt ']={' disk ': {}, ' Nic ': {}}
grains[' virt ' [' Disk '] [' System ']={}
grains[' Virt ' [' Nic '] [' NICs ']=[{' eth0 ': {' bridge ': ' Br0 '}}]
grains[' virt ' [' Disk '] [' System ']=[{' system ': {' format ': ' Raw ', ' pool ': '/var/lib/libvirt/images '}]
return grains

Test:

[Email protected]:/srv/salt/_grains# Salt ' kvm.tiancity.com ' config.get virt:nic--output=json
{
"Kvm.tiancity.com": {
"NICs": [
{
"Eth0": {
"Bridge": "Br0"
}
}
]
}
}

Well, all of our things have been constructed, so let's do it and see if I can start my virtual machine web20 properly, and of course the image file has been put into/var/lib/libvirt/images/web20/system.raw.

Start executing ...

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/56/AF/wKiom1SKnL6xTuXbAABQt9OYuNk924.jpg "title=" Salt.png "alt=" Wkiom1sknl6xtuxbaabqt9oyunk924.jpg "/>

Seconds to open ....

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/56/AD/wKioL1SKnDaCtYhsAAB3pw8XvqA218.jpg "title=" Virshlist.png "alt=" Wkiol1skndactyhsaab3pw8xvqa218.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/56/AD/wKioL1SKnFLyVTlbAABY6q_24U0911.jpg "title=" Web20.png "alt=" Wkiol1sknflyvtlbaaby6q_24u0911.jpg "/>

Ha ha. Next time, I'll try again, add a piece of data disk and add a NIC.


Then see if you can start normally.

This article is from the "Bad Boy" blog, make sure to keep this source http://5ydycm.blog.51cto.com/115934/1589346

Saltstack virt module Creating virtual Machine Analysis II

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.