Hi Vijay,

I was wondering - if you had a few moments - if you might give me some
pointers on how to translate this code I've written in the VI Java API to
the VI API, which we use in CloudStack?

Below is my createVmfsDatastore method.

Thanks for any time you might be able to spend on this!

 public static void createVmfsDatastore(String url, String username, String
password, String datacenterName, String clusterName,

 String datastoreName, String storageIpAddress, Integer portNumber, String
iqn) throws Exception

{

 ServiceInstance si = new ServiceInstance(new URL(url), username, password,
true);

  ManagedEntity datacenter =
si.getSearchIndex().findByInventoryPath(datacenterName);

  if (datacenter == null)

 {

 throw new Exception("Datacenter '" + datacenterName + "' was not found.");

 }

  InventoryNavigator inventoryNavigator =
newInventoryNavigator(si.getRootFolder());

  ClusterComputeResource cluster =
(ClusterComputeResource)inventoryNavigator.searchManagedEntity(
"ClusterComputeResource", clusterName);

  if (cluster == null)

 {

 throw new Exception("Cluster '" + clusterName + "' was not found.");

 }

  HostSystem[] aHostSystems = cluster.getHosts();

  if (aHostSystems == null || aHostSystems.length == 0)

 {

 throw new Exception("There are no hosts in cluster '" + clusterName + "'."
);

 }

  HostInternetScsiHbaStaticTarget target = newHostInternetScsiHbaStaticTarget();

  target.setAddress(storageIpAddress);

 target.setPort(portNumber);

 target.setIScsiName(iqn);

  HostInternetScsiHbaAuthenticationProperties auth =
newHostInternetScsiHbaAuthenticationProperties();

  String strAuthType = "chapRequired";

  auth.setChapAuthEnabled(true);

 auth.setChapInherited(false);

 auth.setChapAuthenticationType(strAuthType);

 auth.setChapName("admin");

 auth.setChapSecret("solidfire");

 auth.setMutualChapInherited(false);

 auth.setMutualChapAuthenticationType(strAuthType);

 auth.setMutualChapName("admin2");

 auth.setMutualChapSecret("solidfire2");

  target.setAuthenticationProperties(auth);

  HostInternetScsiHbaStaticTarget[] aTargets =
newHostInternetScsiHbaStaticTarget[1];

  aTargets[0] = target;

  for (HostSystem hostSystem : aHostSystems)

 {

 boolean iScsiHbaConfigured = false;

   HostStorageSystem hostStorageSystem = hostSystem.getHostStorageSystem();

   for (HostHostBusAdapter hba :
hostStorageSystem.getStorageDeviceInfo().getHostBusAdapter())

 {

  if (hba instanceof HostInternetScsiHba)

  {

  // just finding an instance of HostInternetScsiHba means that we have
found at least one configured iSCSI HBA

  // at least one iSCSI HBA must be configured before a CloudStack user can
use this host for iSCSI storage

  iScsiHbaConfigured = true;

     String iScsiHbaDevice = hba.getDevice();

     hostStorageSystem.addInternetScsiStaticTargets(iScsiHbaDevice,
aTargets);

     hostStorageSystem.rescanHba(iScsiHbaDevice);

  }

 }

   if (!iScsiHbaConfigured)

 {

  throw new Exception("An iSCSI HBA must be configured before a host can
use iSCSI storage.");

 }

 }

  HostDatastoreSystem hostDatastoreSystem =
aHostSystems[0].getHostDatastoreSystem();

  HostScsiDisk[] aHostScsiDisks =
hostDatastoreSystem.queryAvailableDisksForVmfs(null);

  HostStorageSystem hostStorageSystem =
aHostSystems[0].getHostStorageSystem();

  HostScsiDisk hostScsiDisk =
getHostScsiDisk(hostStorageSystem.getStorageDeviceInfo().getScsiTopology(),
aHostScsiDisks, iqn);

  if (hostScsiDisk == null)

 {

 throw new Exception("A relevant SCSI disk could not be located to use to
create a datastore.");

 }

  // just grab the first instance of VmfsDatastoreOption

 VmfsDatastoreOption vmfsDatastoreOption =
hostDatastoreSystem.queryVmfsDatastoreCreateOptions(hostScsiDisk.getDevicePath())[0];

 VmfsDatastoreCreateSpec vmfsDatastoreCreateSpec =
(VmfsDatastoreCreateSpec)vmfsDatastoreOption.getSpec();

  // set the name of the datastore to be created

 vmfsDatastoreCreateSpec.getVmfs().setVolumeName(datastoreName);

  Datastore datastore =
hostDatastoreSystem.createVmfsDatastore(vmfsDatastoreCreateSpec);

  if (datastore == null)

 {

 throw new Exception ("Datastore '" + datastoreName + "' could not be
created.");

 }

  System.out.println("Datastore '" + datastoreName + "' was successfully
created.");

}


On Wed, May 29, 2013 at 7:50 PM, Mike Tutkowski <
mike.tutkow...@solidfire.com> wrote:

> OK - thanks, Vijay!
>
>
> On Wed, May 29, 2013 at 5:05 PM, Vijayendra Bhamidipati <
> vijayendra.bhamidip...@citrix.com> wrote:
>
>> Hi Mike,
>>
>> Your opensource vi java code will be close to what you would implement
>> using the closed source vi sdk, so though you will have to rewrite some
>> code, it should be possible to reuse much of your core code, especially
>> with spec preparation and the like. Cloudstack code already has useful
>> functions that let you retrieve dynamic properties etc from MORs, so you
>> would need to replace some of your vi java code with those functions. You
>> cannot however mix vi java with vi sdk in cloudstack, which uses only vi
>> sdk. You also won't need to setup the vmware service context, it's already
>> there in Vmwareresource.java, so you can use that.
>>
>> Regards,
>> Vijay
>>
>>
>> -----Original Message-----
>> From: Mike Tutkowski [mailto:mike.tutkow...@solidfire.com]
>> Sent: Wednesday, May 29, 2013 2:40 PM
>> To: dev@cloudstack.apache.org
>> Subject: VMware API Question
>>
>> Hi,
>>
>> I recently completed work in the new storage framework related to
>> XenServer where I dynamically create a storage repository when attaching a
>> newly created volume, if need be.
>>
>> I now need to implement the same concept for VMware.
>>
>> The idea is that I have zone-wide primary storage that is backed by a
>> plug-in (all new in 4.2).
>>
>> When the user creates a volume, we still just add a row to the volumes
>> table that describes this volume.
>>
>> When the user goes to attach this volume to a VM, the storage framework
>> invokes my plug-in and my plug-in goes off to its SAN to create a
>> volume...returning info like IQN.
>>
>> Next the VMware attach logic is invoked. In this dynamic kind of
>> zone-wide storage, I need to detect in this VMware code that we do not yet
>> have a datastore and create this datastore based on the IQN I returned
>> earlier (and other info like IP address).
>>
>> I have this all working for XenServer and am now turning my attention to
>> VMware.
>>
>> My question is simply this:
>>
>> It looks like VmwareResourse is written with VI SDK. Since I have my
>> "create/delete datastore" logic already written in the VI Java API (
>> http://vijava.sourceforge.net/), I was wondering if it's possible to mix
>> these two approaches or if I will have to re-write my code.
>>
>> Thanks!
>>
>> --
>> *Mike Tutkowski*
>> *Senior CloudStack Developer, SolidFire Inc.*
>> e: mike.tutkow...@solidfire.com
>> o: 303.746.7302
>> Advancing the way the world uses the
>> cloud<http://solidfire.com/solution/overview/?video=play>
>> *(tm)*
>>
>
>
>
> --
> *Mike Tutkowski*
> *Senior CloudStack Developer, SolidFire Inc.*
> e: mike.tutkow...@solidfire.com
> o: 303.746.7302
> Advancing the way the world uses the 
> cloud<http://solidfire.com/solution/overview/?video=play>
> *™*
>



-- 
*Mike Tutkowski*
*Senior CloudStack Developer, SolidFire Inc.*
e: mike.tutkow...@solidfire.com
o: 303.746.7302
Advancing the way the world uses the
cloud<http://solidfire.com/solution/overview/?video=play>
*™*

Reply via email to