Revision 445d7262 lib/rapi/rlib2.py

b/lib/rapi/rlib2.py
70 70
I_FIELDS = ["name", "admin_state", "os",
71 71
            "pnode", "snodes",
72 72
            "disk_template",
73
            "nic.ips", "nic.macs", "nic.modes", "nic.links", "nic.bridges",
73
            "nic.ips", "nic.macs", "nic.modes",
74
            "nic.links", "nic.networks", "nic.bridges",
74 75
            "network_port",
75 76
            "disk.sizes", "disk_usage",
76 77
            "beparams", "hvparams",
......
90 91
            "group.uuid",
91 92
            ] + _COMMON_FIELDS
92 93

  
94
NET_FIELDS = ["name", "network", "gateway",
95
              "network6", "gateway6",
96
              "mac_prefix", "network_type",
97
              "free_count", "reserved_count",
98
              "map", "group_list", "inst_list",
99
              "external_reservations",
100
             ] 
101

  
93 102
G_FIELDS = [
94 103
  "alloc_policy",
95 104
  "name",
......
642 651
      })
643 652

  
644 653

  
654
class R_2_networks(baserlib.OpcodeResource):
655
  """/2/networks resource.
656

  
657
  """
658
  GET_OPCODE = opcodes.OpNetworkQuery
659
  POST_OPCODE = opcodes.OpNetworkAdd
660
  POST_RENAME = {
661
    "name": "network_name",
662
    }
663

  
664
  def GetPostOpInput(self):
665
    """Create a network.
666

  
667
    """
668
    assert not self.items
669
    return (self.request_body, {
670
      "dry_run": self.dryRun(),
671
      })
672

  
673
  def GET(self):
674
    """Returns a list of all networks.
675

  
676
    """
677
    client = self.GetClient()
678

  
679
    if self.useBulk():
680
      bulkdata = client.QueryNetworks([], NET_FIELDS, False)
681
      return baserlib.MapBulkFields(bulkdata, NET_FIELDS)
682
    else:
683
      data = client.QueryNetworks([], ["name"], False)
684
      networknames = [row[0] for row in data]
685
      return baserlib.BuildUriList(networknames, "/2/networks/%s",
686
                                   uri_fields=("name", "uri"))
687

  
688

  
689
class R_2_networks_name(baserlib.OpcodeResource):
690
  """/2/network/[network_name] resource.
691

  
692
  """
693
  DELETE_OPCODE = opcodes.OpNetworkRemove
694

  
695
  def GET(self):
696
    """Send information about a network.
697

  
698
    """
699
    network_name = self.items[0]
700
    client = self.GetClient()
701

  
702
    result = baserlib.HandleItemQueryErrors(client.QueryNetworks,
703
                                            names=[network_name],
704
                                            fields=NET_FIELDS,
705
                                            use_locking=self.useLocking())
706

  
707
    return baserlib.MapFields(NET_FIELDS, result[0])
708

  
709
  def GetDeleteOpInput(self):
710
    """Delete a network.
711

  
712
    """
713
    assert len(self.items) == 1
714
    return (self.request_body, {
715
      "network_name": self.items[0],
716
      "dry_run": self.dryRun(),
717
      })
718

  
719
class R_2_networks_name_connect(baserlib.OpcodeResource):
720
  """/2/network/[network_name]/connect.
721

  
722
  """
723
  PUT_OPCODE = opcodes.OpNetworkConnect
724

  
725
  def GetPutOpInput(self):
726
    """Changes some parameters of node group.
727

  
728
    """
729
    assert self.items
730
    return (self.request_body, {
731
      "network_name": self.items[0],
732
      })
733

  
734
class R_2_networks_name_connectall(baserlib.OpcodeResource):
735
  """/2/network/[network_name]/connectall.
736

  
737
  """
738
  PUT_OPCODE = opcodes.OpNetworkConnectAll
739

  
740
  def GetPutOpInput(self):
741
    """Changes some parameters of node group.
742

  
743
    """
744
    assert self.items
745
    return (self.request_body, {
746
      "network_name": self.items[0]
747
      })
748

  
749
class R_2_networks_name_disconnect(baserlib.OpcodeResource):
750
  """/2/network/[network_name]/disconnect.
751

  
752
  """
753
  PUT_OPCODE = opcodes.OpNetworkDisconnect
754

  
755
  def GetPutOpInput(self):
756
    """Changes some parameters of node group.
757

  
758
    """
759
    assert self.items
760
    return (self.request_body, {
761
      "network_name": self.items[0],
762
      })
763

  
764
class R_2_networks_name_disconnectall(baserlib.OpcodeResource):
765
  """/2/network/[network_name]/disconnectall.
766

  
767
  """
768
  PUT_OPCODE = opcodes.OpNetworkDisconnectAll
769

  
770
  def GetPutOpInput(self):
771
    """Changes some parameters of node group.
772

  
773
    """
774
    assert self.items
775
    return (self.request_body, {
776
      "network_name": self.items[0],
777
      })
778

  
645 779
class R_2_groups(baserlib.OpcodeResource):
646 780
  """/2/groups resource.
647 781

  
......
655 789
  def GetPostOpInput(self):
656 790
    """Create a node group.
657 791

  
792

  
658 793
    """
659 794
    assert not self.items
660 795
    return (self.request_body, {

Also available in: Unified diff