Search in sources :

Example 1 with NetworksService

use of org.ovirt.engine.sdk4.services.NetworksService in project ovirt-engine-sdk-java by oVirt.

the class AddLogicalNetwork method main.

public static void main(String[] args) throws Exception {
    // Create the connection to the server:
    Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
    // Get the reference to the "networks" service:
    NetworksService networksService = connection.systemService().networksService();
    // Use the "add" method to create new VM logical network in data center called "mydatacenter", with VLAN tag
    // 100 and MTU 1500.
    networksService.add().network(network().name("mynetwork").description("My logical network").dataCenter(dataCenter().name("mydatacenter")).vlan(vlan().id(100)).usages(Arrays.asList(NetworkUsage.DISPLAY)).mtu(1500)).send();
    // Close the connection to the server:
    connection.close();
}
Also used : Connection(org.ovirt.engine.sdk4.Connection) NetworksService(org.ovirt.engine.sdk4.services.NetworksService)

Example 2 with NetworksService

use of org.ovirt.engine.sdk4.services.NetworksService in project ovirt-engine-sdk-java by oVirt.

the class AssignNetworkToCluster method main.

public static void main(String[] args) throws Exception {
    // Create the connection to the server:
    Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
    // Locate the networks service and use it to find the network:
    NetworksService networksService = connection.systemService().networksService();
    Network network = networksService.list().search("name=mynetwork and datacenter=mydatacenter").send().networks().get(0);
    // Locate the clusters service and use it to find the cluster:
    ClustersService clustersService = connection.systemService().clustersService();
    Cluster cluster = clustersService.list().search("name=mycluster").send().clusters().get(0);
    // Locate the service that manages the networks of the cluster:
    ClusterService clusterService = clustersService.clusterService(cluster.id());
    ClusterNetworksService assignedNetworksService = clusterService.networksService();
    // Use the "add" method to assign network to cluster:
    assignedNetworksService.add().network(network().id(network.id()).required(true)).send();
    // Close the connection to the server:
    connection.close();
}
Also used : ClusterService(org.ovirt.engine.sdk4.services.ClusterService) ClusterNetworksService(org.ovirt.engine.sdk4.services.ClusterNetworksService) Network(org.ovirt.engine.sdk4.types.Network) Connection(org.ovirt.engine.sdk4.Connection) ClustersService(org.ovirt.engine.sdk4.services.ClustersService) NetworksService(org.ovirt.engine.sdk4.services.NetworksService) ClusterNetworksService(org.ovirt.engine.sdk4.services.ClusterNetworksService) Cluster(org.ovirt.engine.sdk4.types.Cluster)

Aggregations

Connection (org.ovirt.engine.sdk4.Connection)2 NetworksService (org.ovirt.engine.sdk4.services.NetworksService)2 ClusterNetworksService (org.ovirt.engine.sdk4.services.ClusterNetworksService)1 ClusterService (org.ovirt.engine.sdk4.services.ClusterService)1 ClustersService (org.ovirt.engine.sdk4.services.ClustersService)1 Cluster (org.ovirt.engine.sdk4.types.Cluster)1 Network (org.ovirt.engine.sdk4.types.Network)1