Class VirtualNetwork


  • public class VirtualNetwork
    extends PoolElement
    This class represents an OpenNebula virtual network. It also offers static XML-RPC call wrappers.
    • Constructor Detail

      • VirtualNetwork

        public VirtualNetwork​(int id,
                              Client client)
        Creates a new virtual network representation.
        Parameters:
        id - The virtual network id (nid) .
        client - XML-RPC Client.
      • VirtualNetwork

        protected VirtualNetwork​(org.w3c.dom.Node xmlElement,
                                 Client client)
        See Also:
        PoolElement
    • Method Detail

      • allocate

        public static OneResponse allocate​(Client client,
                                           java.lang.String description,
                                           int clusterId)
        Allocates a new virtual network in OpenNebula.
        Parameters:
        client - XML-RPC Client.
        description - A string containing the template of the virtual network.
        clusterId - The cluster ID. If it is -1, this virtual network won't be added to any cluster.
        Returns:
        If successful the message contains the associated id generated for this virtual network.
      • allocate

        public static OneResponse allocate​(Client client,
                                           java.lang.String description)
        Allocates a new virtual network in OpenNebula.
        Parameters:
        client - XML-RPC Client.
        description - A string containing the template of the virtual network.
        Returns:
        If successful the message contains the associated id generated for this virtual network.
      • info

        public static OneResponse info​(Client client,
                                       int id)
        Retrieves the information of the given virtual network
        Parameters:
        client - XML-RPC Client.
        id - the virtual network id (nid) for the network to retrieve the information from.
        Returns:
        If successful the message contains the string with the information returned by OpenNebula.
      • info

        public static OneResponse info​(Client client,
                                       int id,
                                       boolean decrypt)
        Retrieves the information of the given Virtual Network.
        Parameters:
        client - XML-RPC Client.
        id - The Virtual Network id for the Virtual Network to retrieve the information from
        decrypt - If true decrypt sensitive attributes
        Returns:
        If successful the message contains the string with the information returned by OpenNebula.
      • delete

        public static OneResponse delete​(Client client,
                                         int id)
        Deletes a network from OpenNebula.
        Parameters:
        client - XML-RPC Client.
        id - The virtual network id (nid) of the target network.
        Returns:
        A encapsulated response.
      • publish

        public static OneResponse publish​(Client client,
                                          int id,
                                          boolean publish)
        Publishes or unpublishes a virtual network.
        Parameters:
        client - XML-RPC Client.
        id - The virtual network id (nid) of the target network.
        publish - True for publishing, false for unpublishing.
        Returns:
        If successful the message contains the image id.
      • addAr

        public static OneResponse addAr​(Client client,
                                        int id,
                                        java.lang.String template)
        Adds an Address Range to the VirtualNetwork
        Parameters:
        client - XML-RPC Client.
        id - The virtual network id (nid) of the target network.
        template - AR to add, example: AR = [ TYPE = IP4, IP = 192.168.0.5, SIZE = 10 ]
        Returns:
        A encapsulated response.
      • rmAr

        public static OneResponse rmAr​(Client client,
                                       int id,
                                       int arId)
        Removes an Address Range from the VirtualNetwork
        Parameters:
        client - XML-RPC Client.
        id - The virtual network id (nid) of the target network.
        arId - Id of the Address Range to remove
        Returns:
        A encapsulated response.
      • updateAr

        public static OneResponse updateAr​(Client client,
                                           int id,
                                           java.lang.String template)
        Upates an Address Range from the VirtualNetwork
        Parameters:
        client - XML-RPC Client.
        id - The virtual network id (nid) of the target network.
        template - AR to update, example: AR = [ AR_ID = 3, TYPE = IP4, IP = 192.168.0.5, SIZE = 10 ]
        Returns:
        A encapsulated response.
      • hold

        public static OneResponse hold​(Client client,
                                       int id,
                                       java.lang.String template)
        Holds a VirtualNetwork lease, marking it as used
        Parameters:
        client - XML-RPC Client.
        id - The virtual network id (nid) of the target network.
        template - Address to hold, examples:
              LEASES = [ IP = 192.168.0.5 ]
              LEASES = [ MAC = 02:00:0a:00:00:96 ]
              LEASES = [ IP = 192.168.0.5, AR_ID = 3 ]
        
        Returns:
        A encapsulated response.
      • release

        public static OneResponse release​(Client client,
                                          int id,
                                          java.lang.String template)
        Releases a VirtualNetwork lease on hold
        Parameters:
        client - XML-RPC Client.
        id - The virtual network id (nid) of the target network.
        template - Address to release, examples:
              LEASES = [ IP = 192.168.0.5 ]
              LEASES = [ MAC = 02:00:0a:00:00:96 ]
              LEASES = [ IP = 192.168.0.5, AR_ID = 3 ]
        
        Returns:
        A encapsulated response.
      • chown

        public static OneResponse chown​(Client client,
                                        int id,
                                        int uid,
                                        int gid)
        Changes the owner/group
        Parameters:
        client - XML-RPC Client.
        id - The virtual network id (nid) of the target network.
        uid - The new owner user ID. Set it to -1 to leave the current one.
        gid - The new group ID. Set it to -1 to leave the current one.
        Returns:
        If an error occurs the error message contains the reason.
      • chmod

        public static OneResponse chmod​(Client client,
                                        int id,
                                        int owner_u,
                                        int owner_m,
                                        int owner_a,
                                        int group_u,
                                        int group_m,
                                        int group_a,
                                        int other_u,
                                        int other_m,
                                        int other_a)
        Changes the VirtualNetwork permissions
        Parameters:
        client - XML-RPC Client.
        id - The virtual network id (nid) of the target network.
        owner_u - 1 to allow, 0 deny, -1 do not change
        owner_m - 1 to allow, 0 deny, -1 do not change
        owner_a - 1 to allow, 0 deny, -1 do not change
        group_u - 1 to allow, 0 deny, -1 do not change
        group_m - 1 to allow, 0 deny, -1 do not change
        group_a - 1 to allow, 0 deny, -1 do not change
        other_u - 1 to allow, 0 deny, -1 do not change
        other_m - 1 to allow, 0 deny, -1 do not change
        other_a - 1 to allow, 0 deny, -1 do not change
        Returns:
        If an error occurs the error message contains the reason.
      • chmod

        public static OneResponse chmod​(Client client,
                                        int id,
                                        java.lang.String octet)
        Changes the permissions
        Parameters:
        client - XML-RPC Client.
        id - The id of the target object.
        octet - Permissions octed , e.g. 640
        Returns:
        If an error occurs the error message contains the reason.
      • chmod

        public static OneResponse chmod​(Client client,
                                        int id,
                                        int octet)
        Changes the permissions
        Parameters:
        client - XML-RPC Client.
        id - The id of the target object.
        octet - Permissions octed , e.g. 640
        Returns:
        If an error occurs the error message contains the reason.
      • update

        public static OneResponse update​(Client client,
                                         int id,
                                         java.lang.String new_template,
                                         boolean append)
        Replaces the VirtualNetwork template contents.
        Parameters:
        client - XML-RPC Client.
        id - The vnet id of the target vnet we want to modify.
        new_template - New template contents.
        append - True to append new attributes instead of replace the whole template
        Returns:
        If successful the message contains the vnet id.
      • rename

        public static OneResponse rename​(Client client,
                                         int id,
                                         java.lang.String name)
        Renames this VirtualNetwork
        Parameters:
        client - XML-RPC Client.
        id - The VirtualNetwork id of the target VirtualNetwork.
        name - New name for the VirtualNetwork.
        Returns:
        If an error occurs the error message contains the reason.
      • reserve

        public static OneResponse reserve​(Client client,
                                          int id,
                                          java.lang.String template)
        Reserve a set of addresses from this virtual network
        Parameters:
        client - XML-RPC Client.
        id - The virtual network id (nid) of the target network.
        template - of the reservation. Examples:
              SIZE  = 10
        
              SIZE  = 10
              AR_ID = 3
              NAME  = "new_network"
        
              SIZE  = 10
              IP    = 192.168.10.50
              NETWORK_ID = 9
        
        Returns:
        A encapsulated response.
      • free

        public static OneResponse free​(Client client,
                                       int id,
                                       int arId)
        Removes an Address Range from the VirtualNetwork
        Parameters:
        client - XML-RPC Client.
        id - The virtual network id (nid) of the target network.
        arId - Id of the Address Range to remove
        Returns:
        A encapsulated response.
      • lock

        public static OneResponse lock​(Client client,
                                       int id,
                                       int level)
        lock this virtual network
        Parameters:
        client - XML-RPC Client.
        id - The virtual network id (nid)
        level - Lock level.
        Returns:
        If an error occurs the error message contains the reason.
      • unlock

        public static OneResponse unlock​(Client client,
                                         int id)
        Unlock this virtual network
        Parameters:
        client - XML-RPC Client.
        id - The virtual network id (nid)
        Returns:
        If an error occurs the error message contains the reason.
      • recover

        public static OneResponse recover​(Client client,
                                          int id,
                                          int operation)
        Recovers a stuck Virtual Network.
        Parameters:
        client - XML-RPC Client.
        id - The Virtual Network ID of the target instance.
        operation - to recover the VM: (0) failure, (1) success, (2) delete, (3) retry
        Returns:
        If an error occurs the error message contains the reason.
      • info

        public OneResponse info()
        Loads the xml representation of the virtual network. The info is also stored internally.
        See Also:
        info(Client, int)
      • delete

        public OneResponse delete()
        Deletes the network from OpenNebula.
        Returns:
        A encapsulated response.
      • publish

        public OneResponse publish​(boolean publish)
        Publishes or unpublishes the virtual network.
        Parameters:
        publish - True for publishing, false for unpublishing.
        Returns:
        If successful the message contains the image id.
      • publish

        public OneResponse publish()
        Publishes the virtual network.
        Returns:
        If successful the message contains the image id.
      • unpublish

        public OneResponse unpublish()
        Unpublishes the virtual network.
        Returns:
        If successful the message contains the image id.
      • addAr

        public OneResponse addAr​(java.lang.String template)
        Adds an Address Range to the VirtualNetwork
        Parameters:
        template - AR to add, example:
              AR = [
                  TYPE = IP4,
                  IP = 192.168.0.5,
                  SIZE = 10 ]
        
        Returns:
        A encapsulated response.
      • rmAr

        public OneResponse rmAr​(int arId)
        Removes an Address Range from the VirtualNetwork
        Parameters:
        arId - Id of the Address Range to remove
        Returns:
        A encapsulated response.
      • updateAr

        public OneResponse updateAr​(java.lang.String template)
        Upates an Address Range from the VirtualNetwork
        Parameters:
        template - AR to update, example:
              AR = [
                  AR_ID = 3,
                  TYPE  = IP4,
                  IP    = 192.168.0.5,
                  SIZE  = 10 ]
        
        Returns:
        A encapsulated response.
      • hold

        public OneResponse hold​(java.lang.String ip)
        Holds a VirtualNetwork lease, marking it as used
        Parameters:
        ip - IP or MAC to hold, e.g. "192.168.0.5", "02:00:0a:00:00:96"
        Returns:
        A encapsulated response.
      • hold

        public OneResponse hold​(java.lang.String ip,
                                int arId)
        Holds a VirtualNetwork lease, marking it as used
        Parameters:
        ip - IP or MAC to hold, e.g. "192.168.0.5", "02:00:0a:00:00:96"
        arId - Id of the Address Range to hold the lease from
        Returns:
        A encapsulated response.
      • release

        public OneResponse release​(java.lang.String ip)
        Releases a VirtualNetwork lease on hold
        Parameters:
        ip - IP or MAC to hold, e.g. "192.168.0.5", "02:00:0a:00:00:96"
        Returns:
        A encapsulated response.
      • release

        public OneResponse release​(java.lang.String ip,
                                   int arId)
        Releases a VirtualNetwork lease on hold
        Parameters:
        ip - IP or MAC to hold, e.g. "192.168.0.5", "02:00:0a:00:00:96"
        arId - Id of the Address Range to release the lease from
        Returns:
        A encapsulated response.
      • chown

        public OneResponse chown​(int uid,
                                 int gid)
        Changes the owner/group
        Parameters:
        uid - The new owner user ID. Set it to -1 to leave the current one.
        gid - The new group ID. Set it to -1 to leave the current one.
        Returns:
        If an error occurs the error message contains the reason.
      • chown

        public OneResponse chown​(int uid)
        Changes the owner
        Parameters:
        uid - The new owner user ID.
        Returns:
        If an error occurs the error message contains the reason.
      • chgrp

        public OneResponse chgrp​(int gid)
        Changes the group
        Parameters:
        gid - The new group ID.
        Returns:
        If an error occurs the error message contains the reason.
      • chmod

        public OneResponse chmod​(int owner_u,
                                 int owner_m,
                                 int owner_a,
                                 int group_u,
                                 int group_m,
                                 int group_a,
                                 int other_u,
                                 int other_m,
                                 int other_a)
        Changes the VirtualNetwork permissions
        Parameters:
        owner_u - 1 to allow, 0 deny, -1 do not change
        owner_m - 1 to allow, 0 deny, -1 do not change
        owner_a - 1 to allow, 0 deny, -1 do not change
        group_u - 1 to allow, 0 deny, -1 do not change
        group_m - 1 to allow, 0 deny, -1 do not change
        group_a - 1 to allow, 0 deny, -1 do not change
        other_u - 1 to allow, 0 deny, -1 do not change
        other_m - 1 to allow, 0 deny, -1 do not change
        other_a - 1 to allow, 0 deny, -1 do not change
        Returns:
        If an error occurs the error message contains the reason.
      • chmod

        public OneResponse chmod​(java.lang.String octet)
        Changes the permissions
        Parameters:
        octet - Permissions octed , e.g. 640
        Returns:
        If an error occurs the error message contains the reason.
      • chmod

        public OneResponse chmod​(int octet)
        Changes the permissions
        Parameters:
        octet - Permissions octed , e.g. 640
        Returns:
        If an error occurs the error message contains the reason.
      • update

        public OneResponse update​(java.lang.String new_template)
        Replaces the VirtualNetwork template contents.
        Parameters:
        new_template - New template contents.
        Returns:
        If successful the message contains the vnet id.
      • update

        public OneResponse update​(java.lang.String new_template,
                                  boolean append)
        Replaces the VirtualNetwork template contents.
        Parameters:
        new_template - New template contents.
        append - True to append new attributes instead of replace the whole template
        Returns:
        If successful the message contains the vnet id.
      • rename

        public OneResponse rename​(java.lang.String name)
        Renames this VirtualNetwork
        Parameters:
        name - New name for the VirtualNetwork.
        Returns:
        If an error occurs the error message contains the reason.
      • reserve

        public OneResponse reserve​(java.lang.String template)
        Reserve a set of addresses from this virtual network
        Parameters:
        template - of the reservation. Examples:
              SIZE  = 10
        
              SIZE  = 10
              AR_ID = 3
              NAME  = "new_network"
        
              SIZE  = 10
              IP    = 192.168.10.50
              NETWORK_ID = 9
        
        Returns:
        A encapsulated response.
      • free

        public OneResponse free​(int arId)
        Removes an Address Range from the VirtualNetwork
        Parameters:
        arId - Id of the Address Range to remove
        Returns:
        A encapsulated response.
      • lock

        public OneResponse lock​(int level)
        Lock this virtual network
        Parameters:
        level - Lock level.
        Returns:
        If an error occurs the error message contains the reason.
      • unlock

        public OneResponse unlock()
        Unlock this virtual network
        Returns:
        If an error occurs the error message contains the reason.
      • recover

        public OneResponse recover​(int operation)
        Recovers a stuck Virtual Network.
        Parameters:
        operation - to recover the VM: (0) failure, (1) success, (2) delete, (3) retry
        Returns:
        If an error occurs the error message contains the reason.
      • stateString

        public java.lang.String stateString()
        Returns the state of the Virtual Network.
        The method VirtualNetowrk#info() must be called before.
        Returns:
        The state of the Virtual Network.
      • shortStateStr

        public java.lang.String shortStateStr()
        Returns the short string state of the Virtual Network.
        The method VirtualNetowrk#info() must be called before.
        Returns:
        The short string state of the Virtual Network.