remove test function from flavors.py and minors changes:
authorPaul Tonelli <paul.tonelli@logilab.fr>
Thu, 28 Feb 2013 16:01:03 +0100
changeset 7 123e86b7f5f7
parent 6 7fc32398ed73
child 8 c6acd24fb4f4
remove test function from flavors.py and minors changes: - update visualization svg. - cleaning code and comments in openstack_client.py and vm_create.py - remove test function in flavors.py
_modules/openstack_client.py
_modules/vm_create.py
_states/flavors.py
others/fonctionnement.svg
--- a/_modules/openstack_client.py	Tue Mar 05 15:17:53 2013 +0100
+++ b/_modules/openstack_client.py	Thu Feb 28 16:01:03 2013 +0100
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 '''
-this module replaces temporarely the glance script from salt (unavailable due to 
-glanceclient not being available in debian)
+this module replaces temporarely the glance script from salt 
+(unavailable due to glanceclient not being available in debian)
 
 it also relies on the nova script (which works)
 '''
@@ -56,7 +56,8 @@
      
     CLI Example::
       
-        salt '*'  openstack_client.delete_image 00000000-0000-0000-0000-000000000000
+        salt '*'  openstack_client.delete_image\
+                00000000-0000-0000-0000-000000000000
     '''
     print __salt__['cmd.run']("glance delete " + id_image)
 
@@ -132,13 +133,24 @@
         #    }
     return ret
 
-def force_running_container(image_id,flavor=_FLAVOR): #should be used in state
-    '''if a container is active, use it, else create it '''
+def check_running_container(human_id, image_id=None, flavor=None): #should be used in state
+    '''
+    if a container is active, use it, else create it
+
+    CLI Example::
+
+        salt '*' nova.check_running_container "ami-creator"
+    '''
+
     nt_ks = _auth_nova()
     matching_instances = [machine for machine in nt_ks.servers.list() 
-            if item.nk.servers.list()[0].image['id'] == image_id]
+            if item.nk.servers.list()[0].human_id == human_id]
     if len(matching_instances) == 1:
         machine = matching_instances[0]
+        if (image_id!=None):
+            assert machine.image['id'] == image_d
+        if flavor!=None
+            assert nt_ks.flavors.get(machine.flavor['id']) == image_d
         if machine.status == 'PAUSED':
             machine.unpause()
         if machine.status == 'SUSPENDED':
--- a/_modules/vm_create.py	Tue Mar 05 15:17:53 2013 +0100
+++ b/_modules/vm_create.py	Thu Feb 28 16:01:03 2013 +0100
@@ -107,8 +107,8 @@
     assert archive_name.split('.')[-1] == 'gz'
     remove_images(path)
     assert len(_get_images(path)) == 0
-    print __salt__['cmd.run']('tar xzf ' + path + '/' + archive_name + ' --wildcards -C ' 
-            + path + ' "*.img" ')
+    print __salt__['cmd.run']('tar xzf ' + path + '/' + archive_name 
+            + ' --wildcards -C ' + path + ' "*.img" ')
     images = _get_images(path)
     assert len(images) == 1
     image_name = images[0]
@@ -176,7 +176,8 @@
         return_files.append(myfile)
     return tuple(return_files)
 
-def create_flavor(archive_name, flavor_filename, path=DEFAULT_PATH, upload_to_glance=True):
+def create_flavor(archive_name, flavor_filename, path=DEFAULT_PATH,
+        upload_to_glance=True):
     '''
     complete function to create the new flavor from a virtual machine
 
@@ -192,14 +193,15 @@
     resize_and_check(path, image_name)
     if upload_to_glance:
         print 'will now upload to glance server'
-        id_kernel = __salt__['openstack_client.upload_to_glance'](path, kernel_name, 'aki', '', image_dirname)
-        id_ramdisk = __salt__['openstack_client.upload_to_glance'](path, ramdisk_name, 'ari', '', image_dirname)
-        id_image = __salt__['openstack_client.upload_to_glance'](path, image_name, 'ami', 'kernel_id='
+        id_kernel = __salt__['openstack_client.upload_to_glance'](
+                path, kernel_name, 'aki', '', image_dirname)
+        id_ramdisk = __salt__['openstack_client.upload_to_glance'](
+                path, ramdisk_name, 'ari', '', image_dirname)
+        id_image = __salt__['openstack_client.upload_to_glance'](
+                path, image_name, 'ami', 'kernel_id='
                 + id_kernel + ' ramdisk_id=' + id_ramdisk)
     else:
         print 'Done, no upload to do'
     #clean
     revert(path, (kernel_name, ramdisk_name))
     return True
-
-
--- a/_states/flavors.py	Tue Mar 05 15:17:53 2013 +0100
+++ b/_states/flavors.py	Thu Feb 28 16:01:03 2013 +0100
@@ -1,10 +1,3 @@
-
-#def flavor_sls_exist(name, value):
-#    if __opts__['test']:
-#        ret['result'] = True
-#        ret['comment'] = 'State flavor_sls_exist will check if a flavor file for {0} is available'.format(value)
-#        return ret
-#    return True
 
 def created(name, value):
     ret = {'name': name,
--- a/others/fonctionnement.svg	Tue Mar 05 15:17:53 2013 +0100
+++ b/others/fonctionnement.svg	Thu Feb 28 16:01:03 2013 +0100
@@ -14,7 +14,7 @@
    id="svg2"
    version="1.1"
    inkscape:version="0.47 r22583"
-   sodipodi:docname="New document 1">
+   sodipodi:docname="fonctionnement.svg">
   <defs
      id="defs4">
     <marker
@@ -200,6 +200,68 @@
        inkscape:vp_y="0 : 1000 : 0"
        inkscape:vp_x="0 : 0.5 : 1"
        sodipodi:type="inkscape:persp3d" />
+    <inkscape:perspective
+       id="perspective2919"
+       inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
+       inkscape:vp_z="1 : 0.5 : 1"
+       inkscape:vp_y="0 : 1000 : 0"
+       inkscape:vp_x="0 : 0.5 : 1"
+       sodipodi:type="inkscape:persp3d" />
+    <inkscape:perspective
+       id="perspective2962"
+       inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
+       inkscape:vp_z="1 : 0.5 : 1"
+       inkscape:vp_y="0 : 1000 : 0"
+       inkscape:vp_x="0 : 0.5 : 1"
+       sodipodi:type="inkscape:persp3d" />
+    <marker
+       inkscape:stockid="Arrow1Mend"
+       orient="auto"
+       refY="0"
+       refX="0"
+       id="Arrow1Mend-0"
+       style="overflow:visible">
+      <path
+         id="path3727-3"
+         d="M 0,0 5,-5 -12.5,0 5,5 0,0 z"
+         style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;marker-start:none"
+         transform="matrix(-0.4,0,0,-0.4,-4,0)" />
+    </marker>
+    <inkscape:perspective
+       id="perspective2992"
+       inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
+       inkscape:vp_z="1 : 0.5 : 1"
+       inkscape:vp_y="0 : 1000 : 0"
+       inkscape:vp_x="0 : 0.5 : 1"
+       sodipodi:type="inkscape:persp3d" />
+    <inkscape:perspective
+       id="perspective3017"
+       inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
+       inkscape:vp_z="1 : 0.5 : 1"
+       inkscape:vp_y="0 : 1000 : 0"
+       inkscape:vp_x="0 : 0.5 : 1"
+       sodipodi:type="inkscape:persp3d" />
+    <inkscape:perspective
+       id="perspective3039"
+       inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
+       inkscape:vp_z="1 : 0.5 : 1"
+       inkscape:vp_y="0 : 1000 : 0"
+       inkscape:vp_x="0 : 0.5 : 1"
+       sodipodi:type="inkscape:persp3d" />
+    <inkscape:perspective
+       id="perspective3089"
+       inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
+       inkscape:vp_z="1 : 0.5 : 1"
+       inkscape:vp_y="0 : 1000 : 0"
+       inkscape:vp_x="0 : 0.5 : 1"
+       sodipodi:type="inkscape:persp3d" />
+    <inkscape:perspective
+       id="perspective3122"
+       inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
+       inkscape:vp_z="1 : 0.5 : 1"
+       inkscape:vp_y="0 : 1000 : 0"
+       inkscape:vp_x="0 : 0.5 : 1"
+       sodipodi:type="inkscape:persp3d" />
   </defs>
   <sodipodi:namedview
      id="base"
@@ -209,8 +271,8 @@
      inkscape:pageopacity="0.0"
      inkscape:pageshadow="2"
      inkscape:zoom="1.4"
-     inkscape:cx="410.86848"
-     inkscape:cy="855.36997"
+     inkscape:cx="345.86848"
+     inkscape:cy="906.08426"
      inkscape:document-units="px"
      inkscape:current-layer="layer1"
      showgrid="true"
@@ -232,7 +294,7 @@
         <dc:format>image/svg+xml</dc:format>
         <dc:type
            rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
-        <dc:title></dc:title>
+        <dc:title />
       </cc:Work>
     </rdf:RDF>
   </metadata>
@@ -352,7 +414,11 @@
          sodipodi:role="line"
          id="tspan4165"
          x="500"
-         y="242.36218">chroot</tspan></text>
+         y="242.36218">chroot</tspan><tspan
+         sodipodi:role="line"
+         x="500"
+         y="267.36218"
+         id="tspan2982">(flavor)</tspan></text>
     <path
        style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#Arrow1Mend);stroke-miterlimit:4;stroke-dasharray:none"
        d="m 420,92.362183 0,19.999997"
@@ -367,24 +433,24 @@
     <rect
        style="fill:#ff00ff;fill-opacity:0;stroke:#000000;stroke-width:2;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
        id="rect4766"
-       width="70"
+       width="80"
        height="70"
-       x="30"
+       x="20"
        y="42.362183" />
     <text
        xml:space="preserve"
        style="font-size:20px;font-style:normal;font-weight:normal;text-align:center;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
-       x="65.117188"
+       x="55.117188"
        y="72.362183"
        id="text4768"><tspan
          sodipodi:role="line"
-         id="tspan4770"
-         x="65.117188"
-         y="72.362183">Repo</tspan><tspan
+         x="55.117188"
+         y="72.362183"
+         id="tspan4772">HG</tspan><tspan
          sodipodi:role="line"
-         x="65.117188"
+         x="55.117188"
          y="97.362183"
-         id="tspan4772">HG</tspan></text>
+         id="tspan2909">flavors</tspan></text>
     <path
        style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
        d="m 170,62.36218 0,20 110,0 0,-35 -95,0 -15,15 z"
@@ -408,16 +474,16 @@
     <text
        xml:space="preserve"
        style="font-size:20px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
-       x="590"
+       x="620"
        y="242.36218"
        id="text3592-9"><tspan
          sodipodi:role="line"
          id="tspan3594-3"
-         x="590"
+         x="620"
          y="242.36218">Niveau 3</tspan></text>
     <path
        style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
-       d="m 580,232.36218 0,20 110,0 0,-35 -95,0 -15,15 z"
+       d="m 610,232.36218 0,20 110,0 0,-35 -95,0 -15,15 z"
        id="path4776-4"
        sodipodi:nodetypes="cccccc" />
     <flowRoot
@@ -430,19 +496,19 @@
            height="182.85715"
            x="120.71429"
            y="154.50504" /></flowRegion><flowPara
-         id="flowPara4856"></flowPara></flowRoot>    <path
-       style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none;marker-end:url(#Arrow1Mend)"
-       d="m -30,72.362183 60,0"
+         id="flowPara4856" /></flowRoot>    <path
+       style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker-end:url(#Arrow1Mend)"
+       d="m -40,72.362183 60,0"
        id="path4858" />
     <text
        xml:space="preserve"
        style="font-size:20px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
-       x="-80"
+       x="-90"
        y="72.362183"
        id="text5046"><tspan
          sodipodi:role="line"
          id="tspan5048"
-         x="-80"
+         x="-90"
          y="72.362183">push</tspan></text>
     <path
        style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none;marker-end:url(#Arrow1Mend)"
@@ -457,13 +523,13 @@
     <text
        xml:space="preserve"
        style="font-size:20px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
-       x="110.71429"
-       y="61.647896"
+       x="110"
+       y="62.362183"
        id="text5266"><tspan
          sodipodi:role="line"
          id="tspan5268"
-         x="110.71429"
-         y="61.647896">lance</tspan></text>
+         x="110"
+         y="62.362183">hook</tspan></text>
     <text
        xml:space="preserve"
        style="font-size:20px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
@@ -514,22 +580,114 @@
          id="tspan5344">highstate</tspan></text>
     <path
        style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker-end:url(#TriangleOutM)"
-       d="m 700,232.36218 25,0 0,-184.999997 -80,0"
+       d="m 720,232.36218 20,0 0,-184.999994 -95,-3e-6"
        id="path3713-1"
        sodipodi:nodetypes="cccc" />
     <text
        xml:space="preserve"
        style="font-size:20px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
-       x="730"
+       x="750"
        y="122.36218"
        id="text5340-9"><tspan
          sodipodi:role="line"
-         x="730"
+         x="750"
          y="122.36218"
          id="tspan5344-0">upload </tspan><tspan
          sodipodi:role="line"
-         x="730"
+         x="750"
          y="147.36218"
          id="tspan5404">instances</tspan></text>
+    <text
+       xml:space="preserve"
+       style="font-size:20px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
+       x="580"
+       y="282.36218"
+       id="text5340-2"><tspan
+         sodipodi:role="line"
+         id="tspan5342-7"
+         x="580"
+         y="282.36218">salt</tspan><tspan
+         sodipodi:role="line"
+         x="580"
+         y="307.36218"
+         id="tspan5344-7">highstate</tspan></text>
+    <path
+       style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker-end:url(#Arrow1Mend)"
+       d="m 570,232.36218 10,0 30,0"
+       id="path5050-7"
+       sodipodi:nodetypes="ccc" />
+    <text
+       xml:space="preserve"
+       style="font-size:20px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
+       x="430"
+       y="102.36218"
+       id="text5266-7"><tspan
+         sodipodi:role="line"
+         id="tspan5268-8"
+         x="430"
+         y="102.36218">crée/resume/unpause</tspan></text>
+    <text
+       xml:space="preserve"
+       style="font-size:20px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
+       x="-60"
+       y="232.36218"
+       id="text3592-98"><tspan
+         sodipodi:role="line"
+         id="tspan3594-7"
+         x="-60"
+         y="232.36218">Script</tspan></text>
+    <path
+       style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+       d="m -70,222.36218 0,20 110,0 0,-35 -95,0 -15,15 z"
+       id="path4776-8"
+       sodipodi:nodetypes="cccccc" />
+    <rect
+       style="fill:#ff00ff;fill-opacity:0;stroke:#000000;stroke-width:2;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
+       id="rect4766-6"
+       width="130"
+       height="30"
+       x="-90"
+       y="252.36218" />
+    <text
+       xml:space="preserve"
+       style="font-size:20px;font-style:normal;font-weight:normal;text-align:center;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
+       x="-24.882812"
+       y="272.36218"
+       id="text4768-0"><tspan
+         sodipodi:role="line"
+         x="-24.882812"
+         y="272.36218"
+         id="tspan2909-6">Programme</tspan></text>
+    <rect
+       style="fill:#ff00ff;fill-opacity:0;stroke:#000000;stroke-width:2;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
+       id="rect3683-5"
+       width="120"
+       height="10"
+       x="-80"
+       y="322.36218" />
+    <rect
+       style="fill:#ff00ff;fill-opacity:0;stroke:#000000;stroke-width:2;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
+       id="rect3683-7-8"
+       width="100"
+       height="30"
+       x="-70"
+       y="292.36218" />
+    <text
+       xml:space="preserve"
+       style="font-size:20px;font-style:normal;font-weight:normal;text-align:center;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
+       x="-18.105469"
+       y="312.36218"
+       id="text3707-7"><tspan
+         sodipodi:role="line"
+         x="-18.105469"
+         y="312.36218"
+         id="tspan3711-4">Machine</tspan></text>
+    <rect
+       style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+       id="rect3150"
+       width="150"
+       height="150"
+       x="-100"
+       y="192.36218" />
   </g>
 </svg>