Examples of ServiceInstance


Examples of com.vmware.vim25.mo.ServiceInstance

    String password = args[2];
    String vm1_oid = "vm-26"; // The reference ID for VM 1
    String vm2_oid = "vm-28"; // The reference ID for VM 2
   
    // initialize the system, set up web services
    ServiceInstance si = new ServiceInstance(url, username, password, true);
   
    // create a new VirtualMachineConfigSpec for VM1
    VirtualMachineConfigSpec vmcs1 = new VirtualMachineConfigSpec();
    ResourceAllocationInfo rai1 = new ResourceAllocationInfo();
    SharesInfo si1 = new SharesInfo();
    si1.setLevel(SharesLevel.custom);
    si1.setShares(1333);
    rai1.setShares(si1);
    vmcs1.setCpuAllocation(rai1);

    // do the same for VM2
    VirtualMachineConfigSpec vmcs2 = new VirtualMachineConfigSpec();
    ResourceAllocationInfo rai2 = new ResourceAllocationInfo();
    SharesInfo si2 = new SharesInfo();
    si2.setLevel(SharesLevel.high);
    rai2.setShares(si2);
    vmcs2.setCpuAllocation(rai2);
   
    ManagedObjectReference vm1_mor = createMOR("VirtualMachine", vm1_oid);
    ManagedObjectReference vm2_mor = createMOR("VirtualMachine", vm2_oid);
    VirtualMachine vm1 = (VirtualMachine) MorUtil.createExactManagedEntity(si.getServerConnection(), vm1_mor);
    VirtualMachine vm2 = (VirtualMachine) MorUtil.createExactManagedEntity(si.getServerConnection(), vm2_mor);
   
    // make a web service call to set the configuration.
    vm1.reconfigVM_Task(vmcs1);
    vm2.reconfigVM_Task(vmcs2);     

    // log out from web service
    si.getServerConnection().logout();
    System.out.println("Done with setting VM CPU shares.");
  }
View Full Code Here

Examples of com.vmware.vim25.mo.ServiceInstance

      System.out.println("Usage: java AddNIC <url> "
          + "<username> <password>");
      return;
    }

    ServiceInstance si = new ServiceInstance(
        new URL(args[0]), args[1], args[2], true);

    String hostname = "dev.acme.com";
    String portGroupName = "ViMaster PortGroup";
    String switchName = "ViMaster Switch";

    Folder rootFolder = si.getRootFolder();
    HostSystem host = null;
    host = (HostSystem) new InventoryNavigator(
        rootFolder).searchManagedEntity("HostSystem", hostname);

    HostNetworkSystem hns = host.getHostNetworkSystem();

    // add a virtual switch
    HostVirtualSwitchSpec spec = new HostVirtualSwitchSpec();
    spec.setNumPorts(8);
    hns.addVirtualSwitch(switchName, spec);
   
    // add a port group
    HostPortGroupSpec hpgs = new HostPortGroupSpec();
    hpgs.setName(portGroupName);
    hpgs.setVlanId(0); // not associated with a VLAN
    hpgs.setVswitchName(switchName);
    hpgs.setPolicy(new HostNetworkPolicy());
    hns.addPortGroup(hpgs);
   
    // add a virtual NIC to VMKernel
    HostVirtualNicSpec hvns = new HostVirtualNicSpec();
    hvns.setMac("00:50:56:7d:5e:0b");
    HostIpConfig hic = new HostIpConfig();
    hic.setDhcp(false);
    hic.setIpAddress("10.20.143.204");
    hic.setSubnetMask("255.255.252.0");
    hvns.setIp(hic);
    String result = hns.addVirtualNic("VMKernel", hvns);
    System.out.println(result);
   
    si.getServerConnection().logout();
  }
View Full Code Here

Examples of com.vmware.vim25.mo.ServiceInstance

      System.out.println("Usage: java CopyFile "
        + "<url> <username> <password>");
      return;
    }

    ServiceInstance si = new ServiceInstance(
      new URL(args[0]), args[1], args[2], true);

    Datacenter dc = (Datacenter)new InventoryNavigator(
        si.getRootFolder()).searchManagedEntity(
            "Datacenter", "ha-datacenter");
    FileManager fileMgr = si.getFileManager();
    if(fileMgr==null)
    {
      System.out.println("FileManager not available.");
      si.getServerConnection().logout();
      return;
    }
   
    String basePath = "[storage1 (2)] Nostalgia011";
    String dirPath = basePath + "/" + "testDir";
    // create parent directories if needed - true
    fileMgr.makeDirectory(dirPath, dc, true);
   
    String srcPath = basePath + "/Nostalgia011.vmdk";
    String dstPath = dirPath + "/copy of Nostalgia011.vmdk";
    Task cTask = fileMgr.copyDatastoreFile_Task(srcPath, dc,
        dstPath, dc, true);

    if(cTask.waitForMe()==Task.SUCCESS)
    {
      System.out.println("File copied successfully!");
    }
    else
    {
      System.out.println("File copy failed!");
      return;
    }
    Thread.sleep(30*1000);
   
    fileMgr.deleteDatastoreFile_Task(dstPath, dc);
    fileMgr.deleteDatastoreFile_Task(dirPath, dc);
    si.getServerConnection().logout();
  }
View Full Code Here

Examples of com.vmware.vim25.mo.ServiceInstance

      System.out.println("Usage: java CreateScheduledTasks "
      + "<url> <username> <password> <vmname>");
    return;
    }
   
    ServiceInstance si = new ServiceInstance(
                new URL(args[0]), args[1], args[2], true);
    Folder rootFolder = si.getRootFolder();
   
    InventoryNavigator inv = new InventoryNavigator(rootFolder);
    String vmname = args[3];
    VirtualMachine vm = (VirtualMachine)inv.searchManagedEntity(
            "VirtualMachine", vmname);
  if(vm==null)
  {
    System.out.println("Cannot find the VM " + vmname
      + "\nExisting...");
    si.getServerConnection().logout();
    return;
  }

    ScheduledTaskManager stm = si.getScheduledTaskManager();
    if(stm!=null)
    {
      //to save space, we just check one name here
      if(taskNameExists(stm, "ViMaster_OneTime"))
      {
        si.getServerConnection().logout();
        return;
      }
     
      // Note: the time should be fetched from server,
      // just to make sure it's synchronized.
      ScheduledTaskSpec oneSpec = createOneTimeSchedulerSpec(
          "ViMaster_OneTime", si.currentTime());
     
      ScheduledTaskSpec weekSpec = createWeeklySchedulerSpec(
          "ViMaster_Weekly");

      ScheduledTask st = stm.createScheduledTask(vm, oneSpec);
      ScheduledTask st1 = stm.createScheduledTask(vm, weekSpec);
    // sleep two minutes before deleting
    // the one time scheduled task.
      // An one time scheduled task has not to be deleted after
      // it's run. It can be run any time again by calling the
      // runScheduledTask() method.
      Thread.sleep(2*60*1000);
      st.removeScheduledTask();
    }
    else
    {
      System.out.println("SchduledTaskManager is not "
        + "available on this target.");
    }
   
  si.getServerConnection().logout();
   }
View Full Code Here

Examples of com.vmware.vim25.mo.ServiceInstance

      System.out.println("Usage: java TurnOnFirewallPolicy " +
          "<url> <username> <password> <hostname>");
      return;
    }

    ServiceInstance si = new ServiceInstance(
        new URL(args[0]), args[1], args[2], true);

    String hostname = args[3];
    Folder rootFolder = si.getRootFolder();
    HostSystem host = null;
    host = (HostSystem) new InventoryNavigator(
        rootFolder).searchManagedEntity("HostSystem", hostname);

    if(host==null)
    {
      System.out.println("Cannot find the host:" + hostname);
      si.getServerConnection().logout();
      return;
    }
   
    HostFirewallSystem hss = host.getHostFirewallSystem();
   
View Full Code Here

Examples of com.vmware.vim25.mo.ServiceInstance

      System.out.println("Usage: java AddDatastore "
        + "<url> <username> <password>");
      return;
    }

    ServiceInstance si = new ServiceInstance(
      new URL(args[0]), args[1], args[2], true);
   
    String hostname = "sjin-dev1.eng.vmware.com";

    Folder rootFolder = si.getRootFolder();
    HostSystem host = null;

    host = (HostSystem) new InventoryNavigator(
        rootFolder).searchManagedEntity("HostSystem", hostname);
 
    if(host==null)
    {
      System.out.println("Host not found");
      si.getServerConnection().logout();
      return;
    }
   
    HostDatastoreSystem hds = host.getHostDatastoreSystem();
   
    HostNasVolumeSpec hnvs = new HostNasVolumeSpec();
    hnvs.setRemoteHost("10.20.140.25");
    hnvs.setRemotePath("/home/vm_share");
    hnvs.setLocalPath("VM_Share");
    hnvs.setAccessMode("readWrite"); // or, "readOnly"
   
    Datastore ds = hds.createNasDatastore(hnvs);
    DatastoreInfo di = ds.getInfo();
   
    System.out.println("Name:" + di.getName());
    System.out.println("FreeSpace:" + di.getFreeSpace());
   
    si.getServerConnection().logout();
  }
View Full Code Here

Examples of com.vmware.vim25.mo.ServiceInstance

      System.out.println("Usage: java QueryHistoricalEvents "
        + "<url> <username> <password>");
      return;
    }

    ServiceInstance si = new ServiceInstance(
      new URL(args[0]), args[1], args[2], true);

    EventManager evtMgr = si.getEventManager();

    if(evtMgr!=null)
    {
      EventFilterSpec eventFilter = new EventFilterSpec();
      EventHistoryCollector ehc =
        evtMgr.createCollectorForEvents(eventFilter);
     
      int total = 0;
     
      Event[] latestEvts = ehc.getLatestPage();
      printEvents(latestEvts, 0);
      total += latestEvts==null? 0 : latestEvts.length;
     
      System.out.println("\nBefore Latest Page:");
      ehc.resetCollector();
      while(true)
      {
        Event[] events = ehc.readPreviousEvents(50);
        if(events==null)
        {
          break;
        }
        printEvents(events, total);
        total += events.length;
      }
    }
    si.getServerConnection().logout();
  }
View Full Code Here

Examples of com.vmware.vim25.mo.ServiceInstance

        System.out.println("java ExportOvfToLocal <SdkUrl> <username> <password> <VappOrVmName> <hostip> <VirtualMachine|VirtualApp> <localDir>");
        System.out.println("java ExportOvfToLocal https://10.20.152.74/sdk root password NewVM1 10.20.152.74 VirtualMachine C:\\Temp\\ovf\\");
        return;
      }
     
      ServiceInstance si = new ServiceInstance(new URL(args[0]), args[1], args[2], true);

      String vAppOrVmName = args[3];
      String hostip = args[4];
      String entityType = args[5];
      String targetDir = args[6];

      HostSystem host = (HostSystem) si.getSearchIndex().findByIp(null, hostip, false);
       
      System.out.println("Host Name : " + host.getName());
      System.out.println("Network : " + host.getNetworks()[0].getName());
      System.out.println("Datastore : " + host.getDatastores()[0].getName());

      InventoryNavigator iv = new InventoryNavigator(si.getRootFolder());
     
      HttpNfcLease hnLease = null;
     
      ManagedEntity me = null;
      if (entityType.equals("VirtualApp"))
      {
        me = iv.searchManagedEntity("VirtualApp", vAppOrVmName);
        hnLease = ((VirtualApp)me).exportVApp();
      }
      else
      {
        me = iv.searchManagedEntity("VirtualMachine", vAppOrVmName);
        hnLease = ((VirtualMachine)me).exportVm();
      }
       
      // Wait until the HttpNfcLeaseState is ready
      HttpNfcLeaseState hls;
      for(;;)
      {
        hls = hnLease.getState();
        if(hls == HttpNfcLeaseState.ready)
        {
          break;
        }
        if(hls == HttpNfcLeaseState.error)
        {
          si.getServerConnection().logout();
          return;
        }
      }
     
      System.out.println("HttpNfcLeaseState: ready ");
      HttpNfcLeaseInfo httpNfcLeaseInfo = hnLease.getInfo();
      httpNfcLeaseInfo.setLeaseTimeout(300*1000*1000);
      printHttpNfcLeaseInfo(httpNfcLeaseInfo);

      //Note: the diskCapacityInByte could be many time bigger than
      //the total size of VMDK files downloaded.
      //As a result, the progress calculated could be much less than reality.
      long diskCapacityInByte = (httpNfcLeaseInfo.getTotalDiskCapacityInKB()) * 1024;

      leaseProgUpdater = new LeaseProgressUpdater(hnLease, 5000);
      leaseProgUpdater.start();

      long alredyWrittenBytes = 0;
      HttpNfcLeaseDeviceUrl[] deviceUrls = httpNfcLeaseInfo.getDeviceUrl();
      if (deviceUrls != null)
      {
        OvfFile[] ovfFiles = new OvfFile[deviceUrls.length];
        System.out.println("Downloading Files:");
        for (int i = 0; i < deviceUrls.length; i++)
        {
          String deviceId = deviceUrls[i].getKey();
          String deviceUrlStr = deviceUrls[i].getUrl();
          String diskFileName = deviceUrlStr.substring(deviceUrlStr.lastIndexOf("/") + 1);
          String diskUrlStr = deviceUrlStr.replace("*", hostip);
          String diskLocalPath = targetDir + diskFileName;
          System.out.println("File Name: " + diskFileName);
          System.out.println("VMDK URL: " + diskUrlStr);
          String cookie = si.getServerConnection().getVimService().getWsc().getCookie();
          long lengthOfDiskFile = writeVMDKFile(diskLocalPath, diskUrlStr, cookie, alredyWrittenBytes, diskCapacityInByte);
          alredyWrittenBytes += lengthOfDiskFile;
          OvfFile ovfFile = new OvfFile();
          ovfFile.setPath(diskFileName);
          ovfFile.setDeviceId(deviceId);
          ovfFile.setSize(lengthOfDiskFile);
          ovfFiles[i] = ovfFile;
        }
       
        OvfCreateDescriptorParams ovfDescParams = new OvfCreateDescriptorParams();
        ovfDescParams.setOvfFiles(ovfFiles);
        OvfCreateDescriptorResult ovfCreateDescriptorResult =
          si.getOvfManager().createDescriptor(me, ovfDescParams);

        String ovfPath = targetDir + vAppOrVmName + ".ovf";
        FileWriter out = new FileWriter(ovfPath);
        out.write(ovfCreateDescriptorResult.getOvfDescriptor());
        out.close();
        System.out.println("OVF Desriptor Written to file: " + ovfPath);
      }
     
      System.out.println("Completed Downloading the files");
      leaseProgUpdater.interrupt();
      hnLease.httpNfcLeaseProgress(100);
      hnLease.httpNfcLeaseComplete();

      si.getServerConnection().logout();
    }
View Full Code Here

Examples of net.juniper.contrail.api.types.ServiceInstance

            throw new CloudRuntimeException(ex);
        }

        s_logger.debug("service-instance object created");

        ServiceInstance siObj;
        try {
            _manager.getDatabase().getServiceInstances().add(serviceModel);
            siObj = serviceModel.getServiceInstance();
        } catch (Exception ex) {
            s_logger.warn("DB add", ex);
View Full Code Here

Examples of net.juniper.contrail.api.types.ServiceInstance

    private void buildServiceInstance(ModelController controller, String serviceUuid) {
        ContrailManager manager = controller.getManager();
        ApiConnector api = controller.getApiAccessor();
        _serviceUuid = serviceUuid;

        ServiceInstance siObj;
        try {
            siObj = (ServiceInstance) api.findById(ServiceInstance.class, serviceUuid);
        } catch (IOException ex) {
            s_logger.warn("service-instance read", ex);
            throw new CloudRuntimeException("Unable to read service-instance object", ex);
        }

        ServiceInstanceModel siModel;
        String fqn = StringUtils.join(siObj.getQualifiedName(), ':');
        siModel = manager.getDatabase().lookupServiceInstance(fqn);
        if (siModel == null) {
            siModel = new ServiceInstanceModel(serviceUuid);
            siModel.build(controller, siObj);
            manager.getDatabase().getServiceInstances().add(siModel);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.