<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 01/08/2014 02:24 AM, Aline Manera
      wrote:<br>
    </div>
    <blockquote cite="mid:52CC4654.8080906@linux.vnet.ibm.com"
      type="cite">On 01/07/2014 06:27 AM, Royce Lv wrote:
      <br>
      <blockquote type="cite">On 2014年01月06日 16:49,
        <a class="moz-txt-link-abbreviated" href="mailto:shaohef@linux.vnet.ibm.com">shaohef@linux.vnet.ibm.com</a> wrote:
        <br>
        <blockquote type="cite">From: ShaoHe Feng
          <a class="moz-txt-link-rfc2396E" href="mailto:shaohef@linux.vnet.ibm.com">&lt;shaohef@linux.vnet.ibm.com&gt;</a>
          <br>
          <br>
          Add vms field for network GET method
          <br>
          update API.md
          <br>
          <br>
          add a function to get all vms attach to a network
          <br>
          update model
          <br>
          <br>
          add vms field for Network Resource property
          <br>
          update controller
          <br>
          <br>
          Now get the info of default network:
          <br>
          $ curl -u &lt;user&gt;:&lt;password&gt; -H 'Content-type:
          application/json' -H 'Accept:
          <br>
          application/json' -X GET
          <a class="moz-txt-link-freetext" href="http://localhost:8000/networks/default">http://localhost:8000/networks/default</a>
          <br>
          {
          <br>
             "subnet":"192.168.122.0/24",
          <br>
             "connection":"nat",
          <br>
             "name":"default",
          <br>
             "autostart":true,
          <br>
             "state":"active",
          <br>
             "interface":"virbr0",
          <br>
             "dhcp":{
          <br>
               "start":"192.168.122.2",
          <br>
               "end":"192.168.122.254"
          <br>
             },
          <br>
             "vms":[
          <br>
               "rhel6",
          <br>
               "opensuse12"
          <br>
             ]
          <br>
          }
          <br>
          we can see, there are two vms attched to this network
          <br>
          <br>
          Signed-off-by: ShaoHe Feng <a class="moz-txt-link-rfc2396E" href="mailto:shaohef@linux.vnet.ibm.com">&lt;shaohef@linux.vnet.ibm.com&gt;</a>
          <br>
          ---
          <br>
            docs/API.md                    |  1 +
          <br>
            src/kimchi/control/networks.py |  1 +
          <br>
            src/kimchi/model.py            | 15 +++++++++++++++
          <br>
            3 files changed, 17 insertions(+)
          <br>
          <br>
          diff --git a/docs/API.md b/docs/API.md
          <br>
          index 0013e86..32045ac 100644
          <br>
          --- a/docs/API.md
          <br>
          +++ b/docs/API.md
          <br>
          @@ -364,6 +364,7 @@ A interface represents available interface
          on host.
          <br>
                    * active: The Network is ready for use
          <br>
                    * inactive: The Network is not available
          <br>
                * autostart: Network autostart onboot
          <br>
          +    * vms: all vms attached to this network
          <br>
                * subnet: Network segment in slash-separated format with
          ip address and prefix
          <br>
                * dhcp: DHCP services on the virtual network is enabled.
          <br>
                    * start: start boundary of a pool of addresses to be
          provided to DHCP clients.
          <br>
          diff --git a/src/kimchi/control/networks.py
          b/src/kimchi/control/networks.py
          <br>
          index ad95d69..f3f0b41 100644
          <br>
          --- a/src/kimchi/control/networks.py
          <br>
          +++ b/src/kimchi/control/networks.py
          <br>
          @@ -40,6 +40,7 @@ class Network(Resource):
          <br>
                @property
          <br>
                def data(self):
          <br>
                    return {'name': self.ident,
          <br>
          +                'vms': self.info['vms'],
          <br>
        </blockquote>
        Shuming suggested to use /vms?network='net1' to query vm
        attatched to a network instead of using /networks/net1/vms
        <br>
        Personally, previous URI is clearer and also can be integrated
        to vm query.
        <br>
        I'd like we have some discussion with guys about which URL is to
        use.
        <br>
      </blockquote>
      <br>
      I also prefer to use /vms?network='net1' to query which vms are
      using network 'net1'
      <br>
    </blockquote>
    yes.<br>
    this patch set is the first step. <br>
    /vms?network='net1' is the next step.   <br>
    let us discuss details of the next step in next sprint as it is an
    advanced feature.
    <br>
    But we will know the network is not a VM's attribute, it is just a
    VM's interface kind.  <br>
    Not sure it is good  as a query param. <br>
    <br>
    step 1:<br>
    I have discussed with Yu Xin before.  And at the beginning, Yu Xin 
    and I think just need to show the numbers of vms.<br>
    it is a quite light-weight field with only numbers of vms there.<br>
    This is the first UI design of network. but for let last release,
    backend do not support VMS numbers, so yuxing remove the it.<br>
--------------------------------------------------------------------------------------------------------------------------------
    <div class="header"> <span class="column column-name">| Network
        Name | VMS |  </span><span class="column column-state">State</span><span
        class="column column-type">    |  Network Type</span><span
        class="column column-interface">  |  Interface</span><span
        class="column column-space">   |     Address Space        |    </span><span
        class="column">Actions  |  <br>
      </span>--------------------------------------------------------------------------------------------------------------------------------

    </div>
    <span class="column column-name cell">|        default       | 254
      |    <font color="#33cc00"> o  </font>     |      </span><span
      class="column column-state cell"><span class="network-state down"></span></span><span
      class="column column-type cell">   NAT          |     </span><span
      class="column column-interface cell">virbr       |    </span><span
      class="column column-space cell">192.168.122.0/24</span><span
      class="column-action">    |    <span aria-disabled="false"
        role="button" class="btn dropdown action-button ui-button
        ui-widget ui-state-default ui-corner-all
        ui-button-text-icon-secondary"><span class="ui-button-text">Actions 
          |</span></span></span><br>
    --------------------------------------------------------------------------------------------------------------------------------

    <br>
    <span class="column column-name cell">|        net1          |  0
          |    <font color="#33cc00"> <font color="#999999">o </font> </font>    
      |      </span><span class="column column-state cell"><span
        class="network-state down"></span></span><span class="column
      column-type cell">   NAT          |     </span><span
      class="column column-interface cell">virbr       |    </span><span
      class="column column-space cell">192.168.122.0/24</span><span
      class="column-action">    |    <span aria-disabled="false"
        role="button" class="btn dropdown action-button ui-button
        ui-widget ui-state-default ui-corner-all
        ui-button-text-icon-secondary"><span class="ui-button-text">Actions 
          |</span></span></span><br>
--------------------------------------------------------------------------------------------------------------------------------<br>
    The number of vms is a quite intuitive view of the network
    environment and user can do some convenient operation directly.<br>
    For example, if a user wants to delete a network, it is easy to do
    his choice by checking the number of this network. <br>
    The vms of net1 is "0", user can delete this network safely. <br>
    Also the vms of <span class="column column-name cell">default</span>
    is "254", if user just can choose net1 attached to his VM. <br>
    <br>
    Also a VMs number greatly decrease complexity at client side and
    improve performance.  <br>
    After add this vms muber filed, UI can just get /networks  once to
    finish network web page.  <br>
    <br>
    step 2:<br>
    we will draw a network topology with a switch in center and vms
    around with all available information(name, interface, ip
    address...) of vm that is helpful.
    <br>
    by this way, user can have a quite intuitive view of the network
    environment and do some convenient operation directly there.
    <br>
    <br>
    ---------           ---------           ---------          
    ---------<br>
    | vm1 |           | vm2 |           | vm3 |           | vm4| <br>
    ---------           ---------           ---------          
    ---------<br>
         |                    |                    
    |                     |<br>
         |                    |                    
    |                     |<br>
    ----------------------------------------------------------------<br>
    |                                                                          
    |<br>
    |                         network1                                  
    |<br>
    |                                                                          
    |<br>
    ----------------------------------------------------------------<br>
         |                    |                    
    |                     |<br>
         |                    |                    
    |                     |<br>
    ---------           ---------           ---------          
    ---------<br>
    | vm5 |           | vm6 |           | vm7 |           | vm8| <br>
    ---------           ---------           ---------          
    ---------<br>
    <br>
    <br>
    And the user click the vm5, the details will display:<br>
    ----------------------------------------------------------------<br>
    | name |    CPUS |  memory  |    status |      ...      |<br>
    ----------------------------------------------------------------<br>
    |  VM1  |      1     |     1G        |      <span class="column
      column-name cell"><font color="#33cc00"> o       </font></span>|     
    ...      |<br>
    ----------------------------------------------------------------<br>
    <br>
    <br>
    summary:<br>
    we can design our URL by: <br>
    a) <br>
    1. get the VMS numbers and  network  topology by:<br>
    <font size="3">get /networks/<br>
      [ <br>
      {''net1": {bridge: brg1, vms: [vm1, vm2]},<br>
      {''net2": {bridge: brg2, vms: [vm3, vm4, vm5]}<br>
      ]</font><br>
    The numbers field is: len(<font size="3">net1.vms)</font><br>
    The  network topology is: <font size="3">net1.vms</font><br>
    2. get the vms info <br>
    <font size="3">get /vms/vm1</font><br>
    <font size="3">get /vms/vm2<br>
      <br>
    </font>b)get the VMS numbers <br>
    1. <br>
    <font size="3">get /networks/<br>
      [ <br>
      {''net1": {bridge: brg1, vms: 2},<br>
      {''net2": {bridge: brg2, vms: 3}<br>
      ]<br>
    </font><br>
    2. get the network topology and vms info:<br>
    /vms?network='net1'<br>
    [<br>
    "vm1": {"CPUS": 1, "memory": 1G,  "status": "running"},<br>
    "vm2": {"CPUS": 1, "memory": 1G,  "status": "running"},<br>
    ]<br>
    the network topology  is net1.keys()<br>
    /vms?network='net2'<br>
    [<br>
    "vm3": {"CPUS": 1, "memory": 1G,  "status": "running"},<br>
    "vm4": {"CPUS": 1, "memory": 1G,  "status": "running"},<br>
    "vm5": {"CPUS": 1, "memory": 1G,  "status": "running"},<br>
    ]<br>
    the network topology  is net2.keys()<br>
    <br>
    But we will know the network is not a VM's attribute, it is just a
    VM's interface kind. <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <blockquote cite="mid:52CC4654.8080906@linux.vnet.ibm.com"
      type="cite">
      <br>
      <blockquote type="cite">
        <br>
        <blockquote type="cite">                  'autostart':
          self.info['autostart'],
          <br>
                            'connection': self.info['connection'],
          <br>
                            'interface': self.info['interface'],
          <br>
          diff --git a/src/kimchi/model.py b/src/kimchi/model.py
          <br>
          index a21fcf7..3e61390 100644
          <br>
          --- a/src/kimchi/model.py
          <br>
          +++ b/src/kimchi/model.py
          <br>
          @@ -547,6 +547,11 @@ class Model(object):
          <br>
                    xpath =
          "/domain/devices/disk[@device='disk']/source/@file"
          <br>
                    return xmlutils.xpath_get_text(xml, xpath)
          <br>
          <br>
          +    def _vm_get_networks(self, dom):
          <br>
          +        xml = dom.XMLDesc(0)
          <br>
          +        xpath =
          "/domain/devices/interface[@type='network']/source/@network"
          <br>
          +        return xmlutils.xpath_get_text(xml, xpath)
          <br>
          +
          <br>
                def vm_delete(self, name):
          <br>
                    if self._vm_exists(name):
          <br>
                        conn = self.conn.get()
          <br>
          @@ -859,6 +864,15 @@ class Model(object):
          <br>
                    conn = self.conn.get()
          <br>
                    return sorted(conn.listNetworks() +
          conn.listDefinedNetworks())
          <br>
          <br>
          +    def _get_vms_attach_to_a_network(self, network):
          <br>
          +        vms = []
          <br>
          +        conn = self.conn.get()
          <br>
          +        for dom in conn.listAllDomains(0):
          <br>
          +            networks = self._vm_get_networks(dom)
          <br>
          +            if network in networks:
          <br>
          +                vms.append(dom.name())
          <br>
          +        return vms
          <br>
          +
          <br>
                def network_lookup(self, name):
          <br>
                    network = self._get_network(name)
          <br>
                    xml = network.XMLDesc(0)
          <br>
          @@ -887,6 +901,7 @@ class Model(object):
          <br>
                            'interface': interface,
          <br>
                            'subnet': subnet,
          <br>
                            'dhcp': dhcp,
          <br>
          +                'vms':
          self._get_vms_attach_to_a_network(name),
          <br>
                            'autostart': network.autostart() == 1,
          <br>
                            'state':  network.isActive() and "active" or
          "inactive"}
          <br>
          <br>
        </blockquote>
        <br>
        _______________________________________________
        <br>
        Kimchi-devel mailing list
        <br>
        <a class="moz-txt-link-abbreviated" href="mailto:Kimchi-devel@ovirt.org">Kimchi-devel@ovirt.org</a>
        <br>
        <a class="moz-txt-link-freetext" href="http://lists.ovirt.org/mailman/listinfo/kimchi-devel">http://lists.ovirt.org/mailman/listinfo/kimchi-devel</a>
        <br>
      </blockquote>
      <br>
      <br>
      <br>
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
Thanks and best regards!

Sheldon Feng(冯少合)<a class="moz-txt-link-rfc2396E" href="mailto:shaohef@linux.vnet.ibm.com">&lt;shaohef@linux.vnet.ibm.com&gt;</a>
IBM Linux Technology Center</pre>
  </body>
</html>