Search in sources :

Example 1 with Network

use of org.ovirt.engine.sdk4.types.Network in project ovirt-engine-sdk-java by oVirt.

the class AddVmNic 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 virtual machines service and use it to find the virtual machine:
    VmsService vmsService = connection.systemService().vmsService();
    Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
    // In order to specify the network that the new interface will be connected to, we need to specify the
    // identifier of the virtual network interface profile, so we need to find it:
    VnicProfilesService profilesService = connection.systemService().vnicProfilesService();
    String profileId = null;
    List<VnicProfile> profiles = profilesService.list().send().profiles();
    for (VnicProfile profile : profiles) {
        if (Objects.equals(profile.name(), "mynetwork")) {
            profileId = profile.id();
            break;
        }
    }
    // Locate the service that manages the NICs of the virtual machine:
    VmNicsService nicsService = vmsService.vmService(vm.id()).nicsService();
    // Use the "add" method of the disks service to add the disk:
    nicsService.add().nic(nic().name("mynic").description("My network interface card").vnicProfile(vnicProfile().id(profileId))).send();
    // Close the connection to the server:
    connection.close();
}
Also used : VnicProfilesService(org.ovirt.engine.sdk4.services.VnicProfilesService) Vm(org.ovirt.engine.sdk4.types.Vm) Connection(org.ovirt.engine.sdk4.Connection) VnicProfile(org.ovirt.engine.sdk4.types.VnicProfile) VmsService(org.ovirt.engine.sdk4.services.VmsService) VmNicsService(org.ovirt.engine.sdk4.services.VmNicsService)

Example 2 with Network

use of org.ovirt.engine.sdk4.types.Network 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 3 with Network

use of org.ovirt.engine.sdk4.types.Network in project ovirt-engine-sdk-java by oVirt.

the class StartVmWithCloudInit 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();
    // Find the virtual machine:
    VmsService vmsService = connection.systemService().vmsService();
    Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
    // Find the service that manages the virtual machine:
    VmService vmService = vmsService.vmService(vm.id());
    // Create cloud-init script, which you want to execute in deployed virtual machine, please note that
    // the script must be properly formatted and indented as it's using YAML.
    String myScript = "write_files:\n" + "  - content: |\n" + "      Hello, world!\n" + "    path: /tmp/greeting.txt\n" + "    permissions: '0644'\n";
    // Start the virtual machine enabling cloud-init and providing the password for the `root` user and the network
    // configuration:
    vmService.start().useCloudInit(true).vm(vm().initialization(initialization().userName("root").rootPassword("redhat123").hostName("myvm.example.com").nicConfigurations(nicConfiguration().name("eth0").onBoot(true).bootProtocol(BootProtocol.STATIC).ip(ip().version(IpVersion.V4).address("192.168.0.100").netmask("255.255.255.0").gateway("192.168.0.1"))).dnsServers("192.168.0.1 192.168.0.2 192.168.0.3").dnsSearch("example.com").customScript(myScript))).send();
    // Close the connection to the server:
    connection.close();
}
Also used : Vm(org.ovirt.engine.sdk4.types.Vm) VmService(org.ovirt.engine.sdk4.services.VmService) Connection(org.ovirt.engine.sdk4.Connection) VmsService(org.ovirt.engine.sdk4.services.VmsService)

Example 4 with Network

use of org.ovirt.engine.sdk4.types.Network in project ovirt-engine-sdk-java by oVirt.

the class AddBond method main.

public static void main(String[] args) throws Exception {
    // Create the connection to the server:
    Connection connection = connection().url("https://engine42.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").insecure(true).build();
    // Find the service that manages the collection of hosts:
    HostsService hostsService = connection.systemService().hostsService();
    // Find the host:
    Host host = hostsService.list().search("name=myhost").send().hosts().get(0);
    // Find the service that manages the host:
    HostService hostService = hostsService.hostService(host.id());
    // Configure the host adding a bond with two slaves, and attaching it to a network with an static IP address:
    hostService.setupNetworks().modifiedBonds(hostNic().name("bond0").bonding(bonding().options(option().name("mode").value("1"), option().name("miimon").value("100")).slaves(hostNic().name("eth0"), hostNic().name("eth1")))).modifiedNetworkAttachments(networkAttachment().network(network().name("mynetwork")).ipAddressAssignments(ipAddressAssignment().assignmentMethod(BootProtocol.STATIC).ip(ip().address("192.168.122.100").netmask("255.255.255.0")))).send();
    // After modifying the network configuration it is very important to make it persistent:
    hostService.commitNetConfig().send();
    // Close the connection to the server:
    connection.close();
}
Also used : HostService(org.ovirt.engine.sdk4.services.HostService) Connection(org.ovirt.engine.sdk4.Connection) HostsService(org.ovirt.engine.sdk4.services.HostsService) Host(org.ovirt.engine.sdk4.types.Host)

Example 5 with Network

use of org.ovirt.engine.sdk4.types.Network 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)5 NetworksService (org.ovirt.engine.sdk4.services.NetworksService)2 VmsService (org.ovirt.engine.sdk4.services.VmsService)2 Vm (org.ovirt.engine.sdk4.types.Vm)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 HostService (org.ovirt.engine.sdk4.services.HostService)1 HostsService (org.ovirt.engine.sdk4.services.HostsService)1 VmNicsService (org.ovirt.engine.sdk4.services.VmNicsService)1 VmService (org.ovirt.engine.sdk4.services.VmService)1 VnicProfilesService (org.ovirt.engine.sdk4.services.VnicProfilesService)1 Cluster (org.ovirt.engine.sdk4.types.Cluster)1 Host (org.ovirt.engine.sdk4.types.Host)1 Network (org.ovirt.engine.sdk4.types.Network)1 VnicProfile (org.ovirt.engine.sdk4.types.VnicProfile)1