Revision 6bf572d7

View differences:

src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb
64 64
                 when "chmod"        then self.chmod_octet(action_hash['params'])
65 65
                 when "attachdisk"   then self.attachdisk(action_hash['params'])
66 66
                 when "detachdisk"   then self.detachdisk(action_hash['params'])
67
                 when "attachnic"    then self.attachnic(action_hash['params'])
68
                 when "detachnic"    then self.detachnic(action_hash['params'])
67 69
                 when "update"       then self.update(action_hash['params'])
68 70
                 when "rename"       then self.rename(action_hash['params'])
69 71
                 else
......
111 113
            super(params['disk_id'].to_i)
112 114
        end
113 115

  
116
        def attachnic(params=Hash.new)
117
            template_json = params['nic_template']
118
            template = template_to_str(template_json)
119
            super(template)
120
        end
121

  
122
        def detachnic(params=Hash.new)
123
            super(params['nic_id'].to_i)
124
        end
125

  
114 126
        def update(params=Hash.new)
115 127
            super(params['template_raw'])
116 128
        end
src/sunstone/public/js/opennebula.js
744 744
            OpenNebula.Action.simple_action(params,OpenNebula.VM.resource,
745 745
                                            "detachdisk",action_obj);
746 746
        },
747
        "attachnic" : function(params){
748
            var action_obj = {"nic_template": params.data.extra_param};
749
            OpenNebula.Action.simple_action(params,OpenNebula.VM.resource,
750
                                            "attachnic",action_obj);
751
        },
752
        "detachnic" : function(params){
753
            var action_obj = {"nic_id": params.data.extra_param};
754
            OpenNebula.Action.simple_action(params,OpenNebula.VM.resource,
755
                                            "detachnic",action_obj);
756
        },
747 757
        "rename" : function(params){
748 758
            var action_obj = params.data.extra_param;
749 759
            OpenNebula.Action.simple_action(params,
src/sunstone/public/js/plugins/templates-tab.js
829 829
    //$('button',disk_section).button();
830 830
}
831 831

  
832

  
833

  
834

  
835

  
836

  
837

  
838

  
839
function generate_nic_tab_content(str_nic_tab_id, str_datatable_id){
840
  var html = '<div class="row">'+
841
    '<div class="five columns push-seven">'+
842
      '<input id="'+str_nic_tab_id+'_search" type="text" placeholder="Search"/>'+
843
    '</div>'+
844
  '</div>'+
845
    '<table id="'+str_datatable_id+'" class="datatable twelve">'+
846
      '<thead>'+
847
        '<tr>'+
848
          '<th class="check"><input type="checkbox" class="check_all" value=""></input></th>'+
849
          '<th>'+tr("ID")+'</th>'+
850
          '<th>'+tr("Owner")+'</th>'+
851
          '<th>'+tr("Group")+'</th>'+
852
          '<th>'+tr("Name")+'</th>'+
853
          '<th>'+tr("Cluster")+'</th>'+
854
          '<th>'+tr("Type")+'</th>'+
855
          '<th>'+tr("Bridge")+'</th>'+
856
          '<th>'+tr("Leases")+'</th>'+
857
        '</tr>'+
858
      '</thead>'+
859
      '<tbody id="tbodynetworks">'+
860
      '</tbody>'+
861
    '</table>'+
862
    '<br>'+
863
    '<div class="vm_param kvm_opt xen_opt vmware_opt">'+
864
      '<span id="select_network" class="radius secondary label">'+tr("Please select an network from the list")+'</span>'+
865
      '<span id="network_selected" class="radius secondary label hidden">You selected the following image: '+
866
      '</span>'+
867
      '<span class="radius label" type="text" id="NETWORK" name="network"></span>'+
868
      '<input type="hidden" id="NETWORK_ID" name="network_id" size="2"/>'+
869
    '</div>'+
870
  '<hr>'+
871
    '<div class="show_hide" id="advanced">'+
872
          '<h4><small><i class=" icon-plus-sign-alt"/> '+tr("Advanced options")+'<a id="add_os_boot_opts" class="icon_left" href="#"></a></small></h4>'+
873
    '</div>'+
874
    '<div class="advanced">'+
875
      '<div class="row">'+
876
        '<div class="six columns">'+
877
          '<div class="row">'+
878
            '<div class="four columns">'+
879
              '<label class="right inline" for="IP">'+tr("IP")+':</label>'+
880
            '</div>'+
881
            '<div class="six columns">'+
882
              '<input type="text" id="IP" name="IP" size="3" />'+
883
            '</div>'+
884
            '<div class="two columns">'+
885
              '<div class="tip">'+tr("Request an specific IP from the Network")+'</div>'+
886
            '</div>'+
887
          '</div>'+
888
        '</div>'+
889
        '<div class="six columns">'+
890
          '<div class="row">'+
891
            '<div class="four columns">'+
892
                '<label class="right inline" for="MODEL">'+tr("MODEL")+':</label>'+
893
            '</div>'+
894
            '<div class="six columns">'+
895
              '<input type="text" id="MODEL" name="MODEL" />'+
896
            '</div>'+
897
            '<div class="two columns">'+
898
              '<div class="tip">'+tr("Hardware that will emulate this network interface. With Xen this is the type attribute of the vif.")+'</div>'+
899
            '</div>'+
900
          '</div>'+
901
        '</div>'+
902
      '</div>'+
903
    '<div class="row">'+
904
    '<div class="six columns">'+
905
      '<fieldset>'+
906
        '<legend>'+tr("TCP Firewall")+'</legend>'+
907
        '<div class="row">'+
908
          '<div class="four columns push-two">'+
909
            '<input type="radio" name="tcp_type" id="tcp_type" value="WHITE_PORTS_TCP"> Whitelist '+
910
          '</div>'+
911
          '<div class="four columns pull-two">'+
912
            '<input type="radio" name="tcp_type" id="tcp_type" value="BLACK_PORTS_TCP"> Blacklist'+
913
          '</div>'+
914
        '</div>'+
915
        '<br>'+
916
        '<div class="row">'+
917
          '<div class="four columns">'+
918
            '<label class="right inline" for="TCP_PORTS">'+tr("PORTS")+':</label>'+
919
          '</div>'+
920
          '<div class="six columns">'+
921
              '<input type="text" id="TCP_PORTS" name="ports" />'+
922
          '</div>'+
923
          '<div class="two columns">'+
924
              '<div class="tip">'+tr("A list of ports separated by commas or a ranges separated by semilocolons, e.g.: 22,80,5900:6000")+'</div>'+
925
          '</div>'+
926
        '</div>'+
927
      '</fieldset>'+
928
    '</div>'+
929
    '<div class="six columns">'+
930
      '<fieldset>'+
931
        '<legend>'+tr("UDP Firewall")+'</legend>'+
932
        '<div class="row">'+
933
          '<div class="four columns push-two">'+
934
            '<input type="radio" name="udp_type" id="udp_type" value="WHITE_PORTS_UDP"> Whitelist '+
935
          '</div>'+
936
          '<div class="four columns pull-two">'+
937
            '<input type="radio" name="udp_type" id="udp_type" value="BLACK_PORTS_UDP"> Blacklist'+
938
          '</div>'+
939
        '</div>'+
940
        '<br>'+
941
        '<div class="row">'+
942
          '<div class="four columns">'+
943
            '<label class="right inline" for="UDP_PORTS">'+tr("PORTS")+':</label>'+
944
          '</div>'+
945
          '<div class="six columns">'+
946
              '<input type="text" id="UDP_PORTS" name="ports" />'+
947
          '</div>'+
948
          '<div class="two columns">'+
949
              '<div class="tip">'+tr("A list of ports separated by commas or a ranges separated by semilocolons, e.g.: 22,80,5900:6000")+'</div>'+
950
          '</div>'+
951
        '</div>'+
952
      '</fieldset>'+
953
    '</div>'+
954
    '</div>'+
955
      '<div class="row">'+
956
        '<div class="six columns">'+
957
          '<div class="row">'+
958
            '<div class="four columns">'+
959
            '</div>'+
960
            '<div class="six columns">'+
961
              '<label for="icmp_type"><input type="checkbox" name="icmp_type" value="ICMP" id="icmp_type"> '+ tr("Drop ICMP")+'</label>'+
962
            '</div>'+
963
            '<div class="two columns">'+
964
            '</div>'+
965
          '</div>'+
966
        '</div>'+
967
      '</div>'+
968
    '</div>';
969

  
970
    return html;
971
}
972

  
973
function setup_nic_tab_content(nic_section, str_nic_tab_id, str_datatable_id) {
974
    var dataTable_template_networks = $('#'+str_datatable_id, nic_section).dataTable({
975
              "bSortClasses": false,
976
              "bAutoWidth":false,
977
              "iDisplayLength": 4,
978
              "sDom" : '<"H">t<"F"p>',
979
              "oColVis": {
980
                  "aiExclude": [ 0 ]
981
              },
982
              "aoColumnDefs": [
983
                  { "bSortable": false, "aTargets": ["check"] },
984
                  { "sWidth": "60px", "aTargets": [0,6,7,8] },
985
                  { "sWidth": "35px", "aTargets": [1] },
986
                  { "sWidth": "100px", "aTargets": [2,3,5] },
987
                  { "bVisible": false, "aTargets": [0, 7]}
988
              ],
989
              "oLanguage": (datatable_lang != "") ?
990
                  {
991
                      sUrl: "locale/"+lang+"/"+datatable_lang
992
                  } : ""
993
            });
994

  
995
    //addElement([spinner,'','','','','','','',''],dataTable_template_networks);
996

  
997
    // Retrieve the networks to fill the datatable
998
    OpenNebula.Network.list({
999
      timeout: true,
1000
      success: function (request, networks_list){
1001
          var network_list_array = [];
1002

  
1003
          $.each(networks_list,function(){
1004
             network_list_array.push(vNetworkElementArray(this));
1005
          });
1006

  
1007
          updateView(network_list_array, dataTable_template_networks);
1008
      },
1009
      error: onError
1010
    });
1011

  
1012

  
1013

  
1014
    $('#'+str_nic_tab_id+'_search', nic_section).keyup(function(){
1015
      dataTable_template_networks.fnFilter( $(this).val() );
1016
    })
1017

  
1018
  // TBD Add refresh button for the datatable
1019

  
1020
  // When a row is selected the background color is updated. If a previous row
1021
  // was selected (previous_row) the background color is removed.
1022
  // #IMAGE and #IMAGE_ID inputs are updated using the row information
1023
  if (typeof previous_row === 'undefined') {
1024
      var previous_row = 0;
1025
  }
1026

  
1027
  $('#'+str_datatable_id + '  tbody', nic_section).delegate("tr", "click", function(e){
1028
      if ($(e.target).is('input') ||
1029
          $(e.target).is('select') ||
1030
          $(e.target).is('option')) return true;
1031

  
1032
      var aData = dataTable_template_networks.fnGetData(this);
1033

  
1034
    if (previous_row) {
1035
        $("td:first", previous_row).parent().children().each(function(){$(this).removeClass('markrow');});
1036
    }
1037
    else {
1038
        $('#network_selected',  nic_section).toggle();
1039
        $('#select_network',  nic_section).hide();
1040
    }
1041

  
1042
        $('.alert-box', nic_section).hide();
1043

  
1044
      previous_row = this;
1045
      $("td:first", this).parent().children().each(function(){$(this).addClass('markrow');});
1046

  
1047
      $('#NETWORK', nic_section).text(aData[4]);
1048
      $('#NETWORK_ID', nic_section).val(aData[1]);
1049
      return false;
1050
  });
1051

  
1052

  
1053
  $('.advanced', nic_section).hide();
1054

  
1055
  $('#advanced', nic_section).click(function(){
1056
      $('.advanced', nic_section).toggle();
1057
      return false;
1058
  });
1059

  
1060
  setupTips(nic_section);
1061
}
1062

  
1063

  
1064

  
1065

  
1066

  
1067

  
832 1068
// Callback to update the information panel tabs and pop it up
833 1069
function updateTemplateInfo(request,template){
834 1070
    var template_info = template.VMTEMPLATE;
......
1463 1699
      var str_datatable_id = 'datatable_template_networks' + number_of_nics;
1464 1700

  
1465 1701
      var html_tab_content = '<li id="'+str_nic_tab_id+'Tab" class="nic wizard_internal_tab">'+
1466
        '<div class="row">'+
1467
          '<div class="five columns push-seven">'+
1468
            '<input id="'+str_nic_tab_id+'_search" type="text" placeholder="Search"/>'+
1469
          '</div>'+
1470
        '</div>'+
1471
          '<table id="'+str_datatable_id+'" class="datatable twelve">'+
1472
            '<thead>'+
1473
              '<tr>'+
1474
                '<th class="check"><input type="checkbox" class="check_all" value=""></input></th>'+
1475
                '<th>'+tr("ID")+'</th>'+
1476
                '<th>'+tr("Owner")+'</th>'+
1477
                '<th>'+tr("Group")+'</th>'+
1478
                '<th>'+tr("Name")+'</th>'+
1479
                '<th>'+tr("Cluster")+'</th>'+
1480
                '<th>'+tr("Type")+'</th>'+
1481
                '<th>'+tr("Bridge")+'</th>'+
1482
                '<th>'+tr("Leases")+'</th>'+
1483
              '</tr>'+
1484
            '</thead>'+
1485
            '<tbody id="tbodynetworks">'+
1486
            '</tbody>'+
1487
          '</table>'+
1488
          '<br>'+
1489
          '<div class="vm_param kvm_opt xen_opt vmware_opt">'+
1490
            '<span id="select_network" class="radius secondary label">'+tr("Please select an network from the list")+'</span>'+
1491
            '<span id="network_selected" class="radius secondary label hidden">You selected the following image: '+
1492
            '</span>'+
1493
            '<span class="radius label" type="text" id="NETWORK" name="network"></span>'+
1494
            '<input type="hidden" id="NETWORK_ID" name="network_id" size="2"/>'+
1495
          '</div>'+
1496
        '<hr>'+
1497
          '<div class="show_hide" id="advanced">'+
1498
                '<h4><small><i class=" icon-plus-sign-alt"/> '+tr("Advanced options")+'<a id="add_os_boot_opts" class="icon_left" href="#"></a></small></h4>'+
1499
          '</div>'+
1500
          '<div class="advanced">'+
1501
            '<div class="row">'+
1502
              '<div class="six columns">'+
1503
                '<div class="row">'+
1504
                  '<div class="four columns">'+
1505
                    '<label class="right inline" for="IP">'+tr("IP")+':</label>'+
1506
                  '</div>'+
1507
                  '<div class="six columns">'+
1508
                    '<input type="text" id="IP" name="IP" size="3" />'+
1509
                  '</div>'+
1510
                  '<div class="two columns">'+
1511
                    '<div class="tip">'+tr("Request an specific IP from the Network")+'</div>'+
1512
                  '</div>'+
1513
                '</div>'+
1514
              '</div>'+
1515
              '<div class="six columns">'+
1516
                '<div class="row">'+
1517
                  '<div class="four columns">'+
1518
                      '<label class="right inline" for="MODEL">'+tr("MODEL")+':</label>'+
1519
                  '</div>'+
1520
                  '<div class="six columns">'+
1521
                    '<input type="text" id="MODEL" name="MODEL" />'+
1522
                  '</div>'+
1523
                  '<div class="two columns">'+
1524
                    '<div class="tip">'+tr("Hardware that will emulate this network interface. With Xen this is the type attribute of the vif.")+'</div>'+
1525
                  '</div>'+
1526
                '</div>'+
1527
              '</div>'+
1528
            '</div>'+
1529
          '<div class="row">'+
1530
          '<div class="six columns">'+
1531
            '<fieldset>'+
1532
              '<legend>'+tr("TCP Firewall")+'</legend>'+
1533
              '<div class="row">'+
1534
                '<div class="four columns push-two">'+
1535
                  '<input type="radio" name="tcp_type" id="tcp_type" value="WHITE_PORTS_TCP"> Whitelist '+
1536
                '</div>'+
1537
                '<div class="four columns pull-two">'+
1538
                  '<input type="radio" name="tcp_type" id="tcp_type" value="BLACK_PORTS_TCP"> Blacklist'+
1539
                '</div>'+
1540
              '</div>'+
1541
              '<br>'+
1542
              '<div class="row">'+
1543
                '<div class="four columns">'+
1544
                  '<label class="right inline" for="TCP_PORTS">'+tr("PORTS")+':</label>'+
1545
                '</div>'+
1546
                '<div class="six columns">'+
1547
                    '<input type="text" id="TCP_PORTS" name="ports" />'+
1548
                '</div>'+
1549
                '<div class="two columns">'+
1550
                    '<div class="tip">'+tr("A list of ports separated by commas or a ranges separated by semilocolons, e.g.: 22,80,5900:6000")+'</div>'+
1551
                '</div>'+
1552
              '</div>'+
1553
            '</fieldset>'+
1554
          '</div>'+
1555
          '<div class="six columns">'+
1556
            '<fieldset>'+
1557
              '<legend>'+tr("UDP Firewall")+'</legend>'+
1558
              '<div class="row">'+
1559
                '<div class="four columns push-two">'+
1560
                  '<input type="radio" name="udp_type" id="udp_type" value="WHITE_PORTS_UDP"> Whitelist '+
1561
                '</div>'+
1562
                '<div class="four columns pull-two">'+
1563
                  '<input type="radio" name="udp_type" id="udp_type" value="BLACK_PORTS_UDP"> Blacklist'+
1564
                '</div>'+
1565
              '</div>'+
1566
              '<br>'+
1567
              '<div class="row">'+
1568
                '<div class="four columns">'+
1569
                  '<label class="right inline" for="UDP_PORTS">'+tr("PORTS")+':</label>'+
1570
                '</div>'+
1571
                '<div class="six columns">'+
1572
                    '<input type="text" id="UDP_PORTS" name="ports" />'+
1573
                '</div>'+
1574
                '<div class="two columns">'+
1575
                    '<div class="tip">'+tr("A list of ports separated by commas or a ranges separated by semilocolons, e.g.: 22,80,5900:6000")+'</div>'+
1576
                '</div>'+
1577
              '</div>'+
1578
            '</fieldset>'+
1579
          '</div>'+
1580
          '</div>'+
1581
            '<div class="row">'+
1582
              '<div class="six columns">'+
1583
                '<div class="row">'+
1584
                  '<div class="four columns">'+
1585
                  '</div>'+
1586
                  '<div class="six columns">'+
1587
                    '<label for="icmp_type"><input type="checkbox" name="icmp_type" value="ICMP" id="icmp_type"> '+ tr("Drop ICMP")+'</label>'+
1588
                  '</div>'+
1589
                  '<div class="two columns">'+
1590
                  '</div>'+
1591
                '</div>'+
1592
              '</div>'+
1593
            '</div>'+
1594
          '</div>'+
1702
          generate_nic_tab_content(str_nic_tab_id, str_datatable_id) + 
1595 1703
        '</li>'
1596 1704

  
1597
        // Append the new div containing the tab and add the tab to the list
1598
        var a = $("<dd><a href='#"+str_nic_tab_id+"'>NIC <i class='icon-remove-sign remove-tab'></i></a></dd>").appendTo($("dl#template_create_network_tabs"));
1599

  
1600
        $(html_tab_content).appendTo($("ul#template_create_network_tabs_content"));
1601

  
1602
        $(document).foundationTabs("set_tab", a);
1603

  
1604

  
1605
        var nic_section = $('li#' + str_nic_tab_id + 'Tab', dialog);
1606

  
1607
        var dataTable_template_networks = $('#'+str_datatable_id, dialog).dataTable({
1608
          "bSortClasses": false,
1609
          "bAutoWidth":false,
1610
          "iDisplayLength": 4,
1611
          "sDom" : '<"H">t<"F"p>',
1612
          "oColVis": {
1613
              "aiExclude": [ 0 ]
1614
          },
1615
          "aoColumnDefs": [
1616
              { "bSortable": false, "aTargets": ["check"] },
1617
              { "sWidth": "60px", "aTargets": [0,6,7,8] },
1618
              { "sWidth": "35px", "aTargets": [1] },
1619
              { "sWidth": "100px", "aTargets": [2,3,5] },
1620
              { "bVisible": false, "aTargets": [0, 7]}
1621
          ],
1622
          "oLanguage": (datatable_lang != "") ?
1623
              {
1624
                  sUrl: "locale/"+lang+"/"+datatable_lang
1625
              } : ""
1626
        });
1627

  
1628
        //addElement([spinner,'','','','','','','',''],dataTable_template_networks);
1629

  
1630
        // Retrieve the networks to fill the datatable
1631
        OpenNebula.Network.list({
1632
          timeout: true,
1633
          success: function (request, networks_list){
1634
              var network_list_array = [];
1635

  
1636
              $.each(networks_list,function(){
1637
                 network_list_array.push(vNetworkElementArray(this));
1638
              });
1639

  
1640
              updateView(network_list_array, dataTable_template_networks);
1641
          },
1642
          error: onError
1643
        });
1644

  
1645

  
1646

  
1647
        $('#'+str_nic_tab_id+'_search', nic_section).keyup(function(){
1648
          dataTable_template_networks.fnFilter( $(this).val() );
1649
        })
1650

  
1651
      // TBD Add refresh button for the datatable
1652

  
1653
      // When a row is selected the background color is updated. If a previous row
1654
      // was selected (previous_row) the background color is removed.
1655
      // #IMAGE and #IMAGE_ID inputs are updated using the row information
1656
      if (typeof previous_row === 'undefined') {
1657
          var previous_row = 0;
1658
      }
1659

  
1660
      $('#'+str_datatable_id + '  tbody', dialog).delegate("tr", "click", function(e){
1661
          if ($(e.target).is('input') ||
1662
              $(e.target).is('select') ||
1663
              $(e.target).is('option')) return true;
1664

  
1665
          var aData = dataTable_template_networks.fnGetData(this);
1666

  
1667
        if (previous_row) {
1668
            $("td:first", previous_row).parent().children().each(function(){$(this).removeClass('markrow');});
1669
        }
1670
        else {
1671
            $('#network_selected',  nic_section).toggle();
1672
            $('#select_network',  nic_section).hide();
1673
        }
1674

  
1675
            $('.alert-box', nic_section).hide();
1676

  
1677
          previous_row = this;
1678
          $("td:first", this).parent().children().each(function(){$(this).addClass('markrow');});
1679

  
1680
          $('#NETWORK', nic_section).text(aData[4]);
1681
          $('#NETWORK_ID', nic_section).val(aData[1]);
1682
          return false;
1683
      });
1705
      // Append the new div containing the tab and add the tab to the list
1706
      var a = $("<dd><a href='#"+str_nic_tab_id+"'>NIC <i class='icon-remove-sign remove-tab'></i></a></dd>").appendTo($("dl#template_create_network_tabs"));
1684 1707

  
1708
      $(html_tab_content).appendTo($("ul#template_create_network_tabs_content"));
1685 1709

  
1686
      $('.advanced', nic_section).hide();
1710
      $(document).foundationTabs("set_tab", a);
1687 1711

  
1688
      $('#advanced', nic_section).click(function(){
1689
          $('.advanced', nic_section).toggle();
1690
          return false;
1691
      });
1692 1712

  
1693
      setupTips(nic_section);
1713
      var nic_section = $('li#' + str_nic_tab_id + 'Tab', dialog);
1714
      setup_nic_tab_content(nic_section, str_nic_tab_id, str_datatable_id)
1694 1715

  
1695 1716
      number_of_nics++;
1696 1717
      nics_index++;
src/sunstone/public/js/plugins/vms-tab.js
203 203
        error: onError
204 204
    },
205 205

  
206
    "VM.shownics" : {
207
        type: "single",
208
        call: OpenNebula.VM.show,
209
        callback: function(request, vm){
210
          updateVMachineElement(request, vm);
211
          updateVMNicsInfo(request, vm);
212
        },
213
        error: onError
214
    },
206 215
    "VM.refresh" : {
207 216
        type: "custom",
208 217
        call : function (){
......
550 559
        error: onError,
551 560
        notify: true
552 561
    },
562
    "VM.attachnic" : {
563
        type: "single",
564
        call: OpenNebula.VM.attachnic,
565
        callback: function(request) {
566
            Sunstone.runAction("VM.shownics", request.request.data[0]);
567
        },
568
        error: onError,
569
        notify: true
570
    },
571
    "VM.detachnic" : {
572
        type: "single",
573
        call: OpenNebula.VM.detachnic,
574
        callback: function(request) {
575
            Sunstone.runAction("VM.shownics", request.request.data[0]);
576
        },
577
        error: onError,
578
        notify: true
579
    },
553 580
    "VM.help" : {
554 581
        type: "custom",
555 582
        call: function() {
......
966 993
    var id = vm_json.VM.ID;
967 994
    var element = vMachineElementArray(vm_json);
968 995
    updateSingleElement(element,dataTable_vMachines,'#vm_'+id)
969

  
970
    //we update this too, even if it is not shown.
971
    var $hotplugging_tab = $('div#vm_info_panel div#vm_hotplugging_tab');
972
    $('#hotplugging_form',$hotplugging_tab).replaceWith(printDisks(vm_json.VM));
973
    $('tr.at_volatile',$hotplugging_tab).hide();
974 996
}
975 997

  
976 998
// Callback to delete a single element from the list
......
1217 1239
        content: printDisks(vm_info)
1218 1240
    };
1219 1241

  
1242
    var network_tab = {
1243
        title: tr("Network"),
1244
        content: printNics(vm_info)
1245
    };
1246

  
1220 1247
    var template_tab = {
1221 1248
        title: tr("VM Template"),
1222 1249
        content:
......
1343 1370

  
1344 1371
    Sunstone.updateInfoPanelTab("vm_info_panel","vm_info_tab",info_tab);
1345 1372
    Sunstone.updateInfoPanelTab("vm_info_panel","vm_hotplugging_tab",hotplugging_tab);
1373
    Sunstone.updateInfoPanelTab("vm_info_panel","vm_network_tab",network_tab);
1346 1374
    Sunstone.updateInfoPanelTab("vm_info_panel","vm_template_tab",template_tab);
1347 1375
    Sunstone.updateInfoPanelTab("vm_info_panel","vm_log_tab",log_tab);
1348 1376
    Sunstone.updateInfoPanelTab("vm_info_panel","vm_history_tab",history_tab);
......
1378 1406
        <div id="datatable_cluster_vnets_info_div columns twelve">\
1379 1407
           <form id="hotplugging_form" vmid="'+vm_info.ID+'" >\
1380 1408
              <div class="twelve columns">\
1381
                <div id="refresh_disk" class="button small secondary radius" ><i class="icon-refresh"/></div>\
1382
                  '
1409
                <div id="refresh_disk" class="button small secondary radius" ><i class="icon-refresh"/></div>'
1383 1410

  
1384 1411
    // If VM is not RUNNING, then we forget about the attach disk form.
1385
    if (vm_info.STATE == "3"){
1412
    if (vm_info.STATE == "3" && vm_info.LCM_STATE == "3"){
1386 1413
      html += '\
1387 1414
         <div id="attach_disk" class="button small secondary radius" >' + tr("Attach new disk") +'</div>'
1388 1415
    }
......
1426 1453
            var disk = disks[i];
1427 1454

  
1428 1455
            var save_as;
1429
            if (vm_info.STATE == "3" && vm_info.LCM_STATE == "26") {
1456
            // Snapshot deferred
1457
            if ( 
1458
               ( // ACTIVE
1459
                vm_info.STATE == "3") && 
1460
               ( // HOTPLUG_SAVEAS HOTPLUG_SAVEAS_POWEROFF HOTPLUG_SAVEAS_SUSPENDED
1461
                vm_info.LCM_STATE == "26" || vm_info.LCM_STATE == "27" || vm_info.LCM_STATE == "28") && 
1462
               ( // 
1463
                disk.SAVE_AS_ACTIVE == "YES")
1464
               ) {
1430 1465
              save_as = "in progress";
1431
            } else {
1466
              actions = 'deferred snapshot in progress'
1467
            } 
1468
            // Snapshot Hot
1469
            else if ( 
1470
               ( // ACTIVE
1471
                vm_info.STATE == "3") && 
1472
               ( // HOTPLUG_SAVEAS HOTPLUG_SAVEAS_POWEROFF HOTPLUG_SAVEAS_SUSPENDED
1473
                vm_info.LCM_STATE == "26" || vm_info.LCM_STATE == "27" || vm_info.LCM_STATE == "28") && 
1474
               ( // 
1475
                disk.HOTPLUG_SAVE_AS_ACTIVE == "YES")
1476
               ) {
1477
              save_as = (disk.SAVE_AS ? disk.SAVE_AS : '-');
1478
              actions = 'hot snapshot in progress'
1479
            }
1480
            // Attach / Detach
1481
            else if ( 
1482
               ( // ACTIVE
1483
                vm_info.STATE == "3") && 
1484
               ( // HOTPLUG_SAVEAS HOTPLUG_SAVEAS_POWEROFF HOTPLUG_SAVEAS_SUSPENDED
1485
                vm_info.LCM_STATE == "17") && 
1486
               ( // 
1487
                disk.ATTACH = "YES")
1488
               ) { 
1432 1489
              save_as = (disk.SAVE_AS ? disk.SAVE_AS : '-');
1490
              actions = 'attach/detach in progress'
1491
            }
1492
            else {
1493
              save_as = (disk.SAVE_AS ? disk.SAVE_AS : '-');
1494

  
1495
              actions = '';
1496
              
1497
              if ((vm_info.STATE == "3" && vm_info.LCM_STATE == "3") || vm_info.STATE == "5" || vm_info.STATE == "8") {
1498
                actions += '<a href="VM.saveas" class="saveas" ><i class="icon-save"/>'+tr("Snapshot")+'</a> &emsp;'
1499
              }
1500

  
1501
              if (vm_info.STATE == "3" && vm_info.LCM_STATE == "3") {
1502
                actions += '<a href="VM.detachdisk" class="detachdisk" ><i class="icon-remove"/>'+tr("Detach")+'</a>'
1503
              }
1433 1504
            }
1434 1505

  
1435 1506
            html += '\
1436 1507
              <tr disk_id="'+(disk.DISK_ID)+'">\
1437 1508
                <td>' + disk.DISK_ID + '</td>\
1438 1509
                <td>' + disk.TARGET + '</td>\
1439
                <td>' + (disk.IMAGE ? disk.IMAGE : (disk.FORMAT ? (disk.FORMAT + ' - ') : + humanize_size_from_mb(disk.SIZE))) + '</td>\
1510
                <td>' + (disk.IMAGE ? disk.IMAGE : (humanize_size_from_mb(disk.SIZE) + (disk.FORMAT ? (' - ' + disk.FORMAT) : '') )) + '</td>\
1440 1511
                <td>' + ((disk.SAVE && disk.SAVE == 'YES' )? tr('YES') : tr('NO')) + '</td>\
1441 1512
                <td>' + save_as + '</td>\
1442
                <td>\
1443
                  <a href="VM.saveas" class="saveas" ><i class="icon-save"/>'+tr("Snapshot")+'</a> &emsp;\
1444
                  <a href="VM.detachdisk" class="detachdisk" ><i class="icon-remove"/>'+tr("Detach")+'</a>\
1445
                </td>\
1513
                <td>' + actions + '</td>\
1446 1514
            </tr>';
1447 1515
        }
1448 1516
    }
......
1663 1731

  
1664 1732
        return false;
1665 1733
    }); 
1734
}
1666 1735

  
1667
    $('select#attach_disk_type').live('change',function(){
1668
        var context = $(this).parents('form');
1669
        switch ($(this).val()){
1670
        case "image":
1671
            $('tr.at_volatile',context).hide();
1672
            $('tr.at_image',context).show();
1673
            break;
1674
        case "volatile":
1675
            $('tr.at_image',context).hide();
1676
            $('tr.at_volatile',context).show();
1677
            break;
1678
        };
1679
    });
1680 1736

  
1681
    $('#hotplugging_form').live('submit',function(){
1682
        var vm_id = $(this).attr('vmid');
1683
        var disk_obj = {};
1684
        switch($('select#attach_disk_type',this).val()){
1685
        case "image":
1686
            var im_id = $('select[name="IMAGE_ID"]',this).val();
1687
            if (!im_id) {
1688
                notifyError(tr("Please select an image to attach"));
1689
                return false;
1737

  
1738

  
1739

  
1740

  
1741

  
1742

  
1743

  
1744

  
1745

  
1746

  
1747

  
1748

  
1749

  
1750

  
1751

  
1752

  
1753

  
1754

  
1755

  
1756

  
1757

  
1758

  
1759

  
1760

  
1761

  
1762

  
1763

  
1764

  
1765

  
1766

  
1767

  
1768

  
1769
function updateVMNicsInfo(request,vm){
1770
  $("li#vm_network_tabTab").html(printNics(vm.VM));
1771
}
1772

  
1773
function printNics(vm_info){
1774
   var html ='\
1775
     <div class="">\
1776
        <div>\
1777
           <form id="tab_network_form" vmid="'+vm_info.ID+'" >\
1778
              <div class="twelve columns">\
1779
                <div id="refresh_nic" class="button small secondary radius" ><i class="icon-refresh"/></div>'
1780

  
1781
    // If VM is not RUNNING, then we forget about the attach nic form.
1782
    if (vm_info.STATE == "3" && vm_info.LCM_STATE == "3"){
1783
      html += '\
1784
         <div id="attach_nic" class="button small secondary radius" >' + tr("Attach new nic") +'</div>'
1785
    }
1786

  
1787
    html += '\
1788
      </div>\
1789
      <br>\
1790
      <br>'
1791

  
1792
    html += '\
1793
      <div class="twelve columns">\
1794
         <table class="info_table twelve extended_table">\
1795
           <thead>\
1796
             <tr>\
1797
                <th>'+tr("ID")+'</th>\
1798
                <th>'+tr("Network")+'</th>\
1799
                <th>'+tr("VLAN")+'</th>\
1800
                <th>'+tr("Bridge")+'</th>\
1801
                <th>'+tr("IP")+'</th>\
1802
                <th>'+tr("MAC")+'</th>\
1803
                <th colspan="">'+tr("Actions")+'</th>\
1804
              </tr>\
1805
           </thead>\
1806
           <tbody>';
1807

  
1808

  
1809
    var nics = []
1810
    if ($.isArray(vm_info.TEMPLATE.NIC))
1811
        nics = vm_info.TEMPLATE.NIC
1812
    else if (!$.isEmptyObject(vm_info.TEMPLATE.NIC))
1813
        nics = [vm_info.TEMPLATE.NIC]
1814

  
1815
    if (!nics.length){
1816
        html += '\
1817
          <tr id="no_nics_tr">\
1818
            <td colspan="6">' + tr("No nics to show") + '</td>\
1819
          </tr>';
1820
    }
1821
    else {
1822

  
1823
        for (var i = 0; i < nics.length; i++){
1824
            var nic = nics[i];
1825

  
1826
            var save_as;
1827
            // Attach / Detach
1828
            if ( 
1829
               ( // ACTIVE
1830
                vm_info.STATE == "3") && 
1831
               ( // HOTPLUG_NIC
1832
                vm_info.LCM_STATE == "25") && 
1833
               ( // 
1834
                nic.ATTACH == "YES")
1835
               ) {
1836
              actions = 'attach/detach in progress'
1837
            }
1838
            else {
1839
              actions = '';
1840

  
1841
              if (vm_info.STATE == "3" && vm_info.LCM_STATE == "3") {
1842
                actions += '<a href="VM.detachnic" class="detachnic" ><i class="icon-remove"/>'+tr("Detach")+'</a>'
1843
              }
1690 1844
            }
1691
            disk_obj.IMAGE_ID = $('select[name="IMAGE_ID"]',this).val();
1692
            disk_obj.DEV_PREFIX = $('input[name="DEV_PREFIX"]',this).val();
1693
            break;
1694
        case "volatile":
1695
            disk_obj.SIZE = $('input[name="SIZE"]',this).val();
1696
            disk_obj.FORMAT = $('input[name="FORMAT"]',this).val();
1697
            disk_obj.TYPE = $('select[name="TYPE"]',this).val();
1698
            disk_obj.DEV_PREFIX = $('input[name="DEV_PREFIX"]',this).val();
1699
//            disk_obj.READONLY = $('select[name="READONLY"]',this).val();
1700
//            disk_obj.SAVE = $('save[name="SAVE"]',this).val();
1701
            break;
1845

  
1846
            html += '\
1847
              <tr nic_id="'+(nic.NIC_ID)+'">\
1848
                <td>' + nic.NIC_ID + '</td>\
1849
                <td>' + nic.NETWORK + '</td>\
1850
                <td>' + nic.VLAN + '</td>\
1851
                <td>' + nic.BRIDGE + '</td>\
1852
                <td>' + nic.IP + '</td>\
1853
                <td>' + nic.MAC + '</td>\
1854
                <td>' + actions + '</td>\
1855
            </tr>';
1702 1856
        }
1857
    }
1858

  
1859
    html += '\
1860
            </tbody>\
1861
          </table>\
1862
        </div>\
1863
      </form>';
1864

  
1865
    return html;
1866
}
1867

  
1868
function setupAttachNicDialog(){
1869
    dialogs_context.append('<div id="attach_nic_dialog"></div>');
1870
    $attach_nic_dialog = $('#attach_nic_dialog',dialogs_context);
1871
    var dialog = $attach_nic_dialog;
1872

  
1873
    dialog.html('<div class="panel">\
1874
      <h3>\
1875
        <small id="">'+tr("Attach new nic")+'</small>\
1876
      </h3>\
1877
    </div>\
1878
    <form id="attach_nic_form" action="">\
1879
          <div class="row centered">\
1880
              <div class="four columns">\
1881
                  <label class="inline right" for="vm_id">'+tr("Virtual Machine ID")+':</label>\
1882
              </div>\
1883
              <div class="seven columns">\
1884
                  <input type="text" name="vm_id" id="vm_id" disabled/>\
1885
              </div>\
1886
              <div class="one columns">\
1887
                  <div class=""></div>\
1888
              </div>\
1889
          </div>' +
1890
          generate_nic_tab_content("attach_nic", "attach_nic") +
1891
          '<hr>\
1892
          <div class="form_buttons">\
1893
              <button class="button radius right success" id="attach_nic_button" type="submit" value="VM.attachnic">'+tr("Attach")+'</button>\
1894
              <button class="close-reveal-modal button secondary radius" type="button" value="close">' + tr("Close") + '</button>\
1895
          </div>\
1896
      <a class="close-reveal-modal">&#215;</a>\
1897
    </form>')
1898

  
1899
    dialog.addClass("reveal-modal large");
1900
    setupTips(dialog);
1901

  
1902
    setup_nic_tab_content(dialog, "attach_nic", "attach_nic")
1903

  
1904
    $('#attach_nic_form',dialog).submit(function(){
1905
        var vm_id = $('#vm_id', this).val();
1906

  
1907
        var data  = {};
1908
        addSectionJSON(data, this);
1909

  
1910
        var obj = {NIC: data}
1911
        Sunstone.runAction('VM.attachnic', vm_id, obj);
1912

  
1913
        $attach_nic_dialog.trigger("reveal:close")
1914
        return false;
1915
    });
1916
};
1917

  
1918
function popUpAttachNicDialog(vm_id){
1919
    $('#vm_id',$attach_nic_dialog).val(vm_id);
1920
    $attach_nic_dialog.reveal();
1921
}
1922

  
1923

  
1924
// Listeners to the nics operations (detach, saveas, attach)
1925
function setup_vm_network_tab(){
1926
    //setupSaveAsDialog();
1927
    setupAttachNicDialog();
1703 1928

  
1704
        var obj = { DISK : disk_obj };
1705
        Sunstone.runAction("VM.attachdisk", vm_id, obj);
1929
    $('a.detachnic').live('click', function(){
1930
        var b = $(this);
1931
        var vm_id = b.parents('form').attr('vmid');
1932
        var nic_id = b.parents('tr').attr('nic_id');
1933

  
1934
        Sunstone.runAction('VM.detachnic', vm_id, nic_id);
1935

  
1936
        //b.html(spinner);
1706 1937
        return false;
1707 1938
    });
1939

  
1940
    $('#attach_nic').live('click', function(){
1941
        var b = $(this);
1942
        var vm_id = b.parents('form').attr('vmid');
1943

  
1944
        popUpAttachNicDialog(vm_id);
1945

  
1946
        //b.html(spinner);
1947
        return false;
1948
    }); 
1949

  
1950
    $('#refresh_nic').live('click', function(){
1951
        var b = $(this);
1952
        var vm_id = b.parents('form').attr('vmid');
1953
        Sunstone.runAction("VM.shownics", vm_id);
1954

  
1955
        return false;
1956
    }); 
1708 1957
}
1709 1958

  
1959

  
1960

  
1961

  
1962

  
1963

  
1964

  
1965

  
1966

  
1967

  
1968

  
1969

  
1970

  
1971

  
1972

  
1973

  
1974

  
1975

  
1976

  
1977

  
1978

  
1979

  
1980

  
1981

  
1710 1982
// Sets up the create-template dialog and all the processing associated to it,
1711 1983
// which is a lot.
1712 1984
function setupCreateVMDialog(){
......
1946 2218
    setVMAutorefresh();
1947 2219
    setupVNC();
1948 2220
    hotpluggingOps();
2221
    setup_vm_network_tab();
1949 2222

  
1950
    setupSaveAsDialog
1951 2223

  
1952 2224
    initCheckAllBoxes(dataTable_vMachines);
1953 2225
    tableCheckboxesListener(dataTable_vMachines);

Also available in: Unified diff