Difference between pages "Extensions.conf" and "Creating VMs"

From Wikislax
(Difference between pages)
Jump to: navigation, search
(Created page with "{{RightTOC}} == Contexts == The '''extensions.conf''' file contains at the beginning a '''[general]''' and a '''[global]''' contexts, that you probably won't need to modify,...")
 
(Creating a PV VM)
 
Line 1: Line 1:
 
{{RightTOC}}
 
{{RightTOC}}
  
== Contexts ==
+
== the xl tool ==
  
The '''extensions.conf''' file contains at the beginning a '''[general]''' and a '''[global]''' contexts, that you probably won't need to modify, and a set of additional contexts - that define how Asterisk handles calls, the '''dialplan'''. All of the instructions placed after a context definition are part of that context, until the next context.
+
There is a variety of tools and commands to handle virtual machines. Here we will use the Xen '''xl''' command.
  
The '''sip.conf''' file affords defining which users and which channels are associated with which contexts, and this affords ensuring who can do what, and specially who can access expensive communication ressources.
+
* '''xl create ''file''''' affords creating a virtual machine based on the configuration in file ''file''. A one-starting sequential domain id is created.
  
== Extensions ==
+
* '''xl destroy ''domid''''' affords destroying a virtual machine with domain id ''domid''. Of course using the system in the VM will be a preferred method to terminate.
  
An extension is a line composed of :
+
* '''xl help''' affords getting more information on other xm commands.
  
exten => name,priority,application()    '''or'''
+
Xen supports paravirtualisation and hardware virtualization. Both can be used at the same time on a single Xen system.
exten => name,priority(label),application()
 
  
* name is generally actually a number, the extension
+
== Creating a PV VM ==
* priority is a sequence number, ex- or implicitely numbered
 
* label is an optional tag you can specify to address a specific line
 
* application is the action performed at this line of the extension processing
 
  
An example of extension processing would be as follows. Priority '''n''' means the next sequence value. The call is answered then extension 1 is dialed and transferred if successful, otherwise return is with busy or unavail string and the call is transferred to the voicemail which gives a b (busy) or u (unavail) message then records :
+
* in paravirtualization (PV) guest operating systems are modified so they are able to interlock with Xen without emulation or virtual emulated hardware. Xen PV guest kernels exist for Linux, NetBSD, FreeBSD, OpenSolaris and Novell Netware. Upstream kernel.org Linux kernels since Linux 2.6.24 include Xen PV guest (domU) support based on the Linux pvops framework, so every upstream Linux kernel can be automatically used as Xen PV guest kernel without any additional patches or modifications.
  
exten => 1,1,Answer()
+
Paravirtualization requires storing the kernel to boot in the dom0 filesystem, and populating the system in a virtual partition. The kernel generated must be able to manage [http://wiki.qemu.org/download/qemu-doc.html#QEMU-PC-System-emulator the QEMU devices] and include the .config file [http://wiki.xen.org/wiki/Mainline_Linux_Kernel_Configs#Configuring_the_kernel domU options]. Here is a minimal example of such a [{{SERVER}}/wikislax/download/config-domU .config domU] file. The swap partition and VM filesystem can be created as below. Don't forget to update the root device in fstab :
exten => 1,n,Dial(SIP/1,20,m)
 
exten => 1,n,GotoIf($["${DIALSTATUS}" = "BUSY"]?busy:unavail)
 
exten => 1,n(unavail),Voicemail(1@default,u)
 
exten => 1,n,Hangup()
 
exten => 1,n(busy),VoiceMail(1@default,b)
 
exten => 1,n,Hangup()
 
  
<u>Special extensions</u>
+
# dd if=/dev/zero of=sl12.swp bs=1024k count=1024
 +
# mkswap sl12.swp
 +
# dd if=/dev/zero of=sl12.img bs=1024k count=16384
 +
# mkfs -t ext3 sl12.img
 +
# mkdir loop
 +
# mount -o loop sl12.img loop
 +
# cp -ax /mnt/sl12/{0,bin,boot,etc,home,initrd*,lib,lib64,media,mnt,opt,root,run,sbin,srv,sys,usr,var,vmlinuz*} loop
 +
# mkdir loop/{dev,proc,tmp}
 +
# chmod 777 loop/tmp
 +
# vi loop/etc/fstab
 +
# umount loop
 +
# dd if=/dev/zero bs=1G count=8 >> sl12.img
 +
# e2fsck -f sl12.img
 +
# resize2fs sl12.img
  
* '''a''' is for when the asterisk key (*) is pressed while recording a voicemail message.
+
Then a PV config file needs to be created. Samples are available from the /etc/xen directory. Here is an [{{SERVER}}/wikislax/download/sl12 example] running in a X window for slackware 12.1 (32 bits). The main config options to modify are :
* '''h''' is for when the call is hung up to execute some cleanup code.
 
* '''i''' is for when the extension entered is not valid in the context.
 
* '''o''' is for when the zero key is pressed while recording a voicemail message.
 
* '''t''' is for when no entension is entered within the TIMEOUT duration.
 
* '''s''' is for when a call enters a context without a specific destination extension.
 
  
== Applications ==
+
# Kernel image file in dom0 filesystem
 +
kernel = "/boot/vmlinuz-3.4.2-domU"
 +
# Not using any optional ramdisk
 +
#ramdisk = "/boot/initrd.gz"
 +
# Initial memory allocation (in megabytes) for the new domain.
 +
memory = 2048
 +
# A name for the new domain. All domains have to have different names,
 +
name = "sl12"
 +
# Number of virtual CPUs
 +
vcpus = 2
 +
# Define network interfaces
 +
vif = [ ' ' ]
 +
# Define disk devices. Note the device names xvda and xvdb
 +
disk = [ 'file:/mnt/xen/sl12.img,xvda1,w', 'file:/mnt/xen/sl12.swap,xvdb,w' ]
 +
# Define frame buffer device. Use sdl to view virtual machine in a window
 +
vfb = [ 'sdl=1' ]
 +
# Set root device.
 +
root = "/dev/xvda1 ro"
 +
# Window resolution additional parameters
 +
extra = "xen-fbfront.video=16,1680,1024"
  
Let's mention a few useful applications :
+
The VM can then be launched with '''xl create ''file''''' :
  
* '''Answer'''() answers a ringing channel.
+
root@inner:/etc/xen# xl create sl12
 +
Parsing config from sl12
 +
root@inner:/etc/xen#
  
* '''Background'''(basename) plays a sound file also listening for input at the same time. If the caller presses keys, the application interrupts and goes to the corresponding extension. basename is absolute or relative from the default sound directory /usr/local/var/lib/asterisk/sounds. Asterisk automatically adds a sub-directory for the language code.
+
== Creating a HVM ==
  
* '''ConfBridge'''(conference,[bridge_profile,[user_profile,[menu]]]) connects to conference optionnally using a bridge profile, user profile and DTMF menu.
+
* in full hardware virtualization (HVM) guests require CPU virtualization extensions from the host CPU (Intel VT-x, AMD-V). Xen uses a modified version of Qemu to emulate full PC hardware, including BIOS, IDE disk controller, VGA graphic adapter, USB controller, network adapter etc for HVM guests. CPU virtualization extensions are used to boost performance of the emulation. Fully virtualized guests do not require kernel support, so for example Windows operating systems can be used as Xen HVM guest. Fully virtualized guests are usually slower than paravirtualized guests, because of the required emulation.
  
* '''Dial'''(channel/user&channel/user,timeout,option,url) rings the specified destinations simultaneously and bridges the inbound call with whichever destination answers the call first. If Dial() can't contact any of the destinations, Asterisk sets a variable called DIALSTATUS with the reason that it couldn't dial, and continues on with the next priority. timeout is in seconds. The m options plays musiconhold.
+
Full hardware virtualization requires only a disk image to execute in. Then a HV config file needs to be created. Samples are available from the /etc/xen directory. Here is an [{{SERVER}}/wikislax/download/win7 example] running in a X window for Windows 7. The main config options to modify are :
  
* '''Goto'''(context,extension,priority) sends the call to another part of the dialplan.
+
# Initial memory allocation (in megabytes) for the new domain.
 +
memory = 2048
 +
# A name for the new domain. All domains have to have different names,
 +
name = "win7"
 +
# Number of virtual CPUs
 +
vcpus = 4
 +
# Define network interfaces
 +
vif = [ 'type=ioemu, bridge=br0' ]
 +
# Define disk devices. Note the device names xvda and xvdb
 +
disk = [ 'file:/mnt/xen/win7.img,hda,w', 'file:/mnt/xen/win7.iso,hdc:cdrom,r' ]
 +
# enable SDL library for graphics, default = 0
 +
sdl=1
 +
# enable VNC library for graphics, default = 1
 +
vnc=0
 +
# set VNC display number, default = domid
 +
vncdisplay=7
  
* '''GotoIf'''(expression?destination1:destination2) sends the call to another part of the dialplan. destination can be a priority, extension:priority, or context:extension:priority.
+
The VM can then be launched with '''xl create ''file''''' :
  
* '''HangUp'''() hangs up.
+
root@inner:/etc/xen# xl create win7
 +
Parsing config from win7
 +
root@inner:/etc/xen#
  
* '''MusicOnHold''' plays music on hold indefinitely.
+
== A little screen shot ==
  
* '''Playback'''(basename) plays a sound file. Input from the caller is ignore. basename is absolute or relative from the default sound directory /usr/local/var/lib/asterisk/sounds. Asterisk automatically adds a sub-directory for the language code.
+
The 3 VMs displayed on this slackware 13.37 dom0 are slackware 12.1, windows 7 and windows 8.  
  
* '''Record'''(file.ext) plays a beep and begins recording audio until you press the hash key (#). It then saves the audio to the file name specified. If you hangup before pressing the hash key the audio is not recorded.
+
[[file:Screenshot.png]]
 
 
* '''VoiceMail'''(mailbox@context,option) sends the caller to the specified mailbox so that she can leave a message. The mailbox should be specified as ''mailbox@context''. The option letters ''b'' or ''u'' can be added to give a busy or unavailable greeting.
 
 
 
* '''VoiceMailMain'''() affords the caller to access her voicemail messages.
 
 
 
* '''WaitExten'''(seconds) waits for the caller to enter DTMF digits and is frequently used directly after Background(). It is possible to specify as first argument a number of seconds to wait otherwise the default TIMEOUT value is used.
 
 
 
== Variables ==
 
 
 
Variables can be defined in the [global] using VARIABLE'''='''value, or in the extensions using '''Set'''(VARIABLE=value) or Set('''GLOBAL'''(VARIABLE)=value. It is also possible to use Linux environment variables thru ${'''ENV'''(VARIABLE)}. The ${'''EXTEN''':start:number} gives back number characters starting at position start of the extension just dialed. ${'''EXTEN''':'''-'''4:4} would start four digits from the end and return four digits.
 
 
 
== Pattern Matching ==
 
 
 
To avoid always giving exact extensions it is possible to specify patterns. When several patterns match Asterisk chooses the more specific.
 
 
 
Patterns always start with an underscore _ then can include any of the below :
 
 
 
* '''X''' matches any single digit from 0 to 9.
 
* '''Z''' matches any single digit from 1 to 9.
 
* '''N''' matches any single digit from 2 to 9.
 
* '''['''15-7''']''' matches any single digit from the range specified. In this case the pattern matches a single 1 5 6  or 7.
 
* '''.''' (period) (wildcard) matches ''one'' or ''more'' characters no matter what they are.
 
* '''!''' (bang) (wildcard) matches ''zero'' or ''more'' characters no matter what they are.
 
 
 
== Example ==
 
 
 
Here is an example of a very simple '''extensions.conf''' file with the following behaviour :
 
 
 
* '''[freephonie]''' includes only the '''[inside]''' context so can access only the inside.
 
* '''[internal]''' includes both '''[inside]''' and '''[outside]''' so can access the inside and the outside.
 
* If the caller presses a sip user extension in LDAP the call is transferred to the corresponding extension.
 
* If the caller presses 7 the call is transferred to the default_bridge conference bridge.
 
* If the caller presses 9 the call is transferred to the voicemail.
 
* If the caller presses a number starting by 0 the call is transferred to the freephonie channel.
 
* Not pressing any key will trigger a timeout message and the call will be hung up.
 
 
 
The users and extensions are loaded from the LDAP directory using '''switch => Realtime/@'''. Which users and extensions are loaded in which context depend on the values in the multivalued '''AstAccountContext''' field. One '''AstAccountContext''' value and the section name must match for the record to be loaded into the section. Having several values affords including the extensions in several contexts. In our example this affords having a different treatment for internal and freephonie users: the latter cannot rebound and call an external number.  
 
 
 
[globals]
 
 
[general]
 
autofallthrough=yes
 
 
[outside]
 
exten => _0.,1,Dial(SIP/freephonie/${EXTEN})
 
exten => _0.,n,Hangup()
 
 
[inside]
 
exten => 7,1,Answer()
 
exten => 7,n,ConfBridge(default_bridge)
 
exten => 7,n,Hangup()
 
 
exten => 9,1,Answer()
 
exten => 9,n,VoiceMailMain()
 
exten => 9,n,Hangup()
 
 
exten => i,1,Playback(pbx-invalid)
 
exten => i,n,Hangup()
 
 
exten => t,1,Playback(vm-goodbye)
 
exten => t,n,Hangup()
 
 
[internal]
 
switch => Realtime/@
 
include => inside
 
include => outside
 
 
[freephonie]
 
exten => s,1,NoOp()
 
exten => s,n,Answer()
 
exten => s,n,Background(enter-ext-of-person)
 
exten => s,n,WaitExten()
 
switch => Realtime/@
 
include => inside
 
  
 
<br/>
 
<br/>
  
{{pFoot|[[Voicemail.conf]]|[[Main Page]]|[[Desktop software]]}}
+
{{pFoot|[[Using Grub2]]|[[Main Page]]|[[OpenSSL]]}}

Revision as of 19:21, 3 August 2018

the xl tool

There is a variety of tools and commands to handle virtual machines. Here we will use the Xen xl command.

  • xl create file affords creating a virtual machine based on the configuration in file file. A one-starting sequential domain id is created.
  • xl destroy domid affords destroying a virtual machine with domain id domid. Of course using the system in the VM will be a preferred method to terminate.
  • xl help affords getting more information on other xm commands.

Xen supports paravirtualisation and hardware virtualization. Both can be used at the same time on a single Xen system.

Creating a PV VM

  • in paravirtualization (PV) guest operating systems are modified so they are able to interlock with Xen without emulation or virtual emulated hardware. Xen PV guest kernels exist for Linux, NetBSD, FreeBSD, OpenSolaris and Novell Netware. Upstream kernel.org Linux kernels since Linux 2.6.24 include Xen PV guest (domU) support based on the Linux pvops framework, so every upstream Linux kernel can be automatically used as Xen PV guest kernel without any additional patches or modifications.

Paravirtualization requires storing the kernel to boot in the dom0 filesystem, and populating the system in a virtual partition. The kernel generated must be able to manage the QEMU devices and include the .config file domU options. Here is a minimal example of such a .config domU file. The swap partition and VM filesystem can be created as below. Don't forget to update the root device in fstab :

# dd if=/dev/zero of=sl12.swp bs=1024k count=1024
# mkswap sl12.swp
# dd if=/dev/zero of=sl12.img bs=1024k count=16384
# mkfs -t ext3 sl12.img
# mkdir loop
# mount -o loop sl12.img loop
# cp -ax /mnt/sl12/{0,bin,boot,etc,home,initrd*,lib,lib64,media,mnt,opt,root,run,sbin,srv,sys,usr,var,vmlinuz*} loop
# mkdir loop/{dev,proc,tmp}
# chmod 777 loop/tmp
# vi loop/etc/fstab
# umount loop
# dd if=/dev/zero bs=1G count=8 >> sl12.img
# e2fsck -f sl12.img
# resize2fs sl12.img

Then a PV config file needs to be created. Samples are available from the /etc/xen directory. Here is an example running in a X window for slackware 12.1 (32 bits). The main config options to modify are :

# Kernel image file in dom0 filesystem
kernel = "/boot/vmlinuz-3.4.2-domU"
# Not using any optional ramdisk
#ramdisk = "/boot/initrd.gz"
# Initial memory allocation (in megabytes) for the new domain.
memory = 2048
# A name for the new domain. All domains have to have different names,
name = "sl12"
# Number of virtual CPUs
vcpus = 2
# Define network interfaces
vif = [ ' ' ]
# Define disk devices. Note the device names xvda and xvdb
disk = [ 'file:/mnt/xen/sl12.img,xvda1,w', 'file:/mnt/xen/sl12.swap,xvdb,w' ]
# Define frame buffer device. Use sdl to view virtual machine in a window
vfb = [ 'sdl=1' ]
# Set root device.
root = "/dev/xvda1 ro"
# Window resolution additional parameters
extra = "xen-fbfront.video=16,1680,1024"

The VM can then be launched with xl create file :

root@inner:/etc/xen# xl create sl12
Parsing config from sl12
root@inner:/etc/xen#

Creating a HVM

  • in full hardware virtualization (HVM) guests require CPU virtualization extensions from the host CPU (Intel VT-x, AMD-V). Xen uses a modified version of Qemu to emulate full PC hardware, including BIOS, IDE disk controller, VGA graphic adapter, USB controller, network adapter etc for HVM guests. CPU virtualization extensions are used to boost performance of the emulation. Fully virtualized guests do not require kernel support, so for example Windows operating systems can be used as Xen HVM guest. Fully virtualized guests are usually slower than paravirtualized guests, because of the required emulation.

Full hardware virtualization requires only a disk image to execute in. Then a HV config file needs to be created. Samples are available from the /etc/xen directory. Here is an example running in a X window for Windows 7. The main config options to modify are :

# Initial memory allocation (in megabytes) for the new domain.
memory = 2048
# A name for the new domain. All domains have to have different names,
name = "win7"
# Number of virtual CPUs
vcpus = 4
# Define network interfaces
vif = [ 'type=ioemu, bridge=br0' ]
# Define disk devices. Note the device names xvda and xvdb
disk = [ 'file:/mnt/xen/win7.img,hda,w', 'file:/mnt/xen/win7.iso,hdc:cdrom,r' ]
# enable SDL library for graphics, default = 0
sdl=1
# enable VNC library for graphics, default = 1
vnc=0
# set VNC display number, default = domid
vncdisplay=7

The VM can then be launched with xl create file :

root@inner:/etc/xen# xl create win7
Parsing config from win7
root@inner:/etc/xen#

A little screen shot

The 3 VMs displayed on this slackware 13.37 dom0 are slackware 12.1, windows 7 and windows 8.

Screenshot.png


Using Grub2 Main Page OpenSSL