Visualizzazione post con etichetta vcloud. Mostra tutti i post
Visualizzazione post con etichetta vcloud. Mostra tutti i post

lunedì 12 maggio 2014

VMware: vCloud tenants reports using jQuery Mobile and PowerCLI

In this post we will create a simple HTML report using PowerCLI for Tenants and jQuery Mobile. jQuery Mobile provides an HTML5 user interface designed to allow the creation of web pages specifically suited for mobile devices with smaller screen compared to classic desktop/laptop PCs.

From PowerCLI perspective the following script is really simple, it retrieve some data from the vCloud environment then generates the HTML report by iterating HTML code (precisely <li> blocks) in order to create vApps list then finally it outputs the result as a single HTML by concatenating the composing elements.

As for jQuery Mobile perspective this is not complex at all, the resulting page structure is linear. In the header section there is the declaration of jQuery Mobile usage:

 <head>  
 <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" />  
 <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>  
 <script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>  
 </head>  

The body is constructed in a block approach: several blocks with different functions while the body block is the main elements that is filled by different informations regarding cloud organization:

 <div data-role="page" id="home"> --Page  
   <div data-role="header">  
     HEADER BLOCK  
   </div>  
   <div data-role="content">  
     CONTENT BLOCK  
   </div>  
   <div data-role="footer">  
     FOOTER BLOCK  
   </div>  
 </div>  

The PowerCLI script is intended to be run by vCloud tenants, having enough privileges on the organization they manage, against a vCloud Director server. The expected output will be an HTML page that can be consumed by any HTML5 capable browser, but, as previously said, jQuery Mobile does its best when used on a mobile device like a tablet or a smartphone.

Results will be similar to these:



The PowerCLI code to create this report is the following. As usual you can also find it in my GitHub repository: Tenants Mobile Reports.ps1



That's all!!

mercoledì 30 aprile 2014

VMware: PowerCLI for vCloud Tenants 101

PowerCLI for Tenants is a great way to offer scripting capabilities to your cloud users. It works identically to the "classic" PowerCLI but it offers a limited set of cmdlets specifically designed to provide tenants control over their cloud organizations.

This is an introductory post regarding PowerCLI for tenants in which I will explore some of the many useful cmdlets that allow users to control a cloud organization through PowerCLI.

First step is to install PowerCLI for Tenants. At this time version 5.1 release 2 is the latest available and can be downloaded here. If you already have the "classic" vSphere PowerCLI installed on your machine you need to remove it first in order to install the tenants version.

As usual, when dealing with PowerCLI, official documentation comes in handy.

In PowerCLI for tenants every user (tenant) connects to a vCloud Director server in order to run cmdlets against an organization the user is entitled to interact with. This means, for example, that different tenants can be connected at the same time to the same vCloud Director server interacting with different organizations.



Connection to an organization is performed using the following command:

Connect-CIServer -Server 192.168.243.50 -User User1 -Password MyPassword0! -Org HostileCoding

 Name              User              Org  
 ----              ----              ---  
 192.168.243.50         User1             HostileCoding  

where -Server is the vCloud Director server IP or FQDN and -Org is the organization name to connect to.

To retrieve an organization's details Get-Org cmdlet is used.

 Enabled     : True  
 CanPublish   : False  
 DeployedVMQuota : 8  
 StoredVMQuota  : 10  
 VdcCount    : 1  
 CatalogCount  : 1  
 VAppCount    : 1  
 Href      : https://192.168.243.50/api/admin/org/a3314e21-f6b8-4c53-9690-b44e96141b56  
 FullName    : HostileCoding  
 ExtensionData  : VMware.VimAutomation.Cloud.Views.AdminOrg  
 Description   : Organization Cloud  
 Id       : urn:vcloud:org:a3314e21-f6b8-4c53-9690-b44e96141b56  
 Name      : HostileCoding  

DeployedVMQuota and StoredVMQuota respectively count the maximum number of virtual machines that can be deployed and stored simultaneously by a member of this organization.

While Get-OrgVdc retrieves details about an organization:

 Href          : https://192.168.243.50/api/vdc/9fa21642-32a8-46b3-91ac-aedfc42a2937  
 AllocationModel     : ReservationPool  
 Enabled         : True  
 CpuUsedGhz       : 0  
 CpuLimitGhz       : 3  
 CpuAllocationGhz    : 3  
 CpuOverheadGhz     : 0  
 MemoryUsedGB      : 0.119140625  
 MemoryLimitGB      : 2  
 MemoryAllocationGB   : 2  
 MemoryOverheadGB    : 0  
 StorageUsedGB      : 10.25  
 StorageLimitGB     : 19.193359375  
 StorageAllocationGB   : -1  
 StorageOverheadGB    : -1  
 VAppCount        : 1  
 Status         : Ready  
 NetworkMaxCount     : 2  
 VMMaxCount       :  
 NicMaxCount       :  
 MemoryGuaranteedPercent :  
 CpuGuaranteedPercent  :  
 VMCpuCoreMHz      :  
 ThinProvisioned     :  
 UseFastProvisioning   :  
 ExtensionData      : VMware.VimAutomation.Cloud.Views.Vdc  
 Description       : Customer1 Virtual DataCenter  
 Id           : urn:vcloud:vdc:9fa21642-32a8-46b3-91ac-aedfc42a2937  
 Name          : VDC-Customer1  

Quite important are the resources limitation exposed by the previous command: StorageLimitGB, MemoryLimitGB, CpuLimitGhz, NetworkMaxCount, VMMaxCount indicate how many resources an organization is entitled to use from the cloud provider.

Get-OrgVdc retrieves a great amount of details regarding organizational's datacenter like: adopted allocation model, reservations, limits and resources used.

To retrieve organization's catalog(s) Get-Catalog cmdlet is used.

 Published     : False  
 Shared      : False  
 Created      : 4/28/2014 2:38:05 PM  
 Org        : HostileCoding  
 Owner       : system  
 VAppTemplateCount : 1  
 MediaCount    : 0  
 ExtensionData   : VMware.VimAutomation.Cloud.Views.AdminCatalog  
 Href       : https://192.168.243.50/api/admin/catalog/873e5007-896d-418b-ae0f-67e9131a1eb6  
 Description    :  
 Id        : urn:vcloud:catalog:873e5007-896d-418b-ae0f-67e9131a1eb6  
 Name       : Catalog1  

In vCloud Director user roles are extremely important because they grant certain capabilities to specific tenants. As you know vCD has five predefined user roles (excluding sysadmin role which is the global role of the user installing/managing the global vCD environment):

  • Organization Administrator 
  • Catalog Author
  • vApp Author 
  • vApp User 
  • Console Access Only.

By being in one of these groups a tenant can or cannot perform several tasks. To retrieve to which role, with corresponding permissions, each user has been assigned to the Get-CIRole cmdlet is used:

Get-CIRole -User User1

 Name              ReadOnly Rights  
 ----              -------- ------  
 Organization Administrator   False  {Organization: Edit Properties, Orga...  

Then to retrieve detailed infos about a specific user:

Get-CIUser -Name User1

 Href      : https://192.168.243.50/api/admin/user/056c48fd-1b7f-4d48-8da6-81cb53ff0af3  
 StoredVMQuota  : 0  
 StoredVMCount  : 0  
 IM       :  
 DeployedVMQuota : 0  
 DeployedVMCount : 0  
 Phone      :  
 Org       : HostileCoding  
 LdapName    : User1  
 Locked     : False  
 IsLDapUser   : False  
 HasGroupRole  : False  
 External    : False  
 Enabled     : True  
 FullName    : User One  
 Email      : user.one@mycompany.com  
 ExtensionData  : VMware.VimAutomation.Cloud.Views.User  
 Name      : user1  
 Id       : urn:vcloud:user:056c48fd-1b7f-4d48-8da6-81cb53ff0af3  
 Description   :  

This informs us regarding the organization the user belongs, if it is enabled or not, as well as how many VMs has deployed or stored.

To retrieve vApps a user is entitled to access/manage the Get-CIVApp cmdlet is used.

 Href        : https://192.168.243.50/api/vApp/vapp-7591186a-1d3d-4a0c-b392-b2bd7d373210  
 ExtensionData   : VMware.VimAutomation.Cloud.Views.VApp  
 Enabled      : True  
 Status       : PoweredOn  
 SizeGB       : 5  
 CpuCount      : 1  
 MemoryAllocationMB : 256  
 MemoryAllocationGB : 0.25  
 InMaintenanceMode : False  
 Owner       : system  
 Org        : HostileCoding  
 Shared       : False  
 StorageLease    : 30.00:00:00  
 RuntimeLease    : 7.00:00:00  
 Description    :  
 Id         : urn:vcloud:vapp:7591186a-1d3d-4a0c-b392-b2bd7d373210  
 Name        : myFirstCloudvApp  

A vApp is, identically to the ones seen in vSphere, a container for one or more VMs. Here the concept is a little broader since a vApp in vCloud can also contain one or more networks to which the VMs in the vApp are connected to. If you have a look at the previous output several other infos are retrieved like the number of vCPUs, the amount of RAM memory, the power status and both the Storage and Runtime lease expressed in days.



To retrieve all VMs belonging to a specified vApp we use the Get-CIVM cmdlet. In this example only one VM is contained inside myFirstCloudvApp (yes I know, I selected wrong OS during initial VM creation)!

Get-CIVM -vApp myFirstCloudvApp

 ExtensionData  : VMware.VimAutomation.Cloud.Views.Vm  
 Status     : PoweredOn  
 Deleted     : False  
 GuestOsFullName : Red Hat Enterprise Linux 6 (64-bit)  
 CpuCount    : 1  
 MemoryMB    : 256  
 MemoryGB    : 0.25  
 OrgVdc     : VDC-Customer1  
 VApp      : myFirstCloudvApp  
 Description   : This is a simple configuration for Ubuntu Server  
 Href      : https://192.168.243.50/api/vApp/vm-e11d8857-6fa5-4fa1-ab52-b9  
          3c91a23c18  
 Id       : urn:vcloud:vm:e11d8857-6fa5-4fa1-ab52-b93c91a23c18  
 Name      : Ubuntu Minimal  



In the following posts I will provide some scripts to offer some useful capabilities to vCloud tenants.

That's all!!

mercoledì 23 aprile 2014

VMware: Automate the manual deployment of vCloud Agent

While creating provider VDCs in vCloud Director sometimes occurs that not every host is being prepared successfully due to various reasons: something configured incorrectly, cannot place host into maintenance mode, cannot communicate with host, etc. This incapability to correctly dialogue with ESXi hosts leads to the missing deployment of vCloud agent on the hosts belonging to a provider VDC.



The best way to solve this is to fix the underlying problem. Let's be clear: when everything is fine vCloud Director agent deployment works smooth but when something is not the host preparation may become quite a pita. A way to fix this is to proceed with a manual deployment of vCloud agent but, as you reckon, this is quite uncomfortable when dealing with a large number of ESXi hosts.

Today's post goal is to provide a PowerCLI script that allows you to automate the manual process of vCloud agent deployment as well as a mass agent upgrade.

The following script will:

-Connect to a vCenter Server
-Download to your local machine the specified vCloud agent version from vCloud Director virtual machine
-For each host on which you need to install vCloud agent script will:
    -Place host into maintenance mode
    -Enable SSH
    -Check whether vCloud agent is installed or not. If already installed uninstall it first
    -Transfer vCloud agent over to ESXi host using Putty Secure Copy
    -Install vCloud agent
    -Disable SSH
    -Exit maintenance mode
   
Once vCloud agent is successfully installed ESXi host is seen as correctly prepared from vCloud Director.



This is the PowerCLI code. As always you can also find it in my GitHub repository. Automate vCloud Agent Deployment.ps1



Code is quite well commented but let me spend a few words on some cmdlets.

Initial part comprises variable declaration. $FileVcloudAgent is the version of vCloud agent that will be downloaded from vCloud Director virtual machine and later installed on all specified ESXi hosts. In the script I use vcloudagent-esx51-5.1.0-799577.zip file. As name states this version is for ESXi 5.1. If you have different ESXi versions you MUST choose the appropriate ones, like vcloudagent-esx55-5.5.0-1280396.zip if you are using ESXi 5.5 (with vCloud Director 5.5) or vcloudagent-esx50-5.1.0-799574.zip in case of ESXi 5.0, etc.

$puttyScpLocation points to the location of Putty Secure Copy (pscp.exe) that can be downloaded from here and must be placed somewhere on your local machine. Putty Secure Copy is used to copy vCloud agent over to /tmp/ folder of each ESXi host.

Copy-VMGuestFile is a PowerCLI cmdlet used to download specified file from vCloud Director virtual machine to your local machine. -GuestToLocal parameter states that we are downloading files from a VM. Au contraire -LocalToGuest would have been used.

Crucial commands of script above are the VIB uninstall/install ones. To perform a VIB installation on an ESXi host you must use esxcli commands using the following syntax:

 $esx=Get-EsxCli -VMHost <ESXi host on which use esxcli>  

esxcli commands can be executed from PowerCLI by exposing the esxcli functionalities. This is done using:

 $esx=Get-EsxCli -VMHost <ESXi host on which use esxcli>  

and later calling esxcli installation command:

 $esx.software.vib.install("/tmp/$($FileVcloudAgent)", $false, $false, $true, $false, $false)  

On which each parameter has the following meaning:

 Value:vim.EsxCLI.software.vib.install.InstallationResult  
    install(string[] depot, boolean dryrun, boolean force,  
    boolean maintenancemode, boolean noliveinstall, boolean  
    nosigcheck, string proxy, string[] vibname, string[]  
    viburl)  

That's all!!

venerdì 3 gennaio 2014

VMware: Configure Oracle DB 12c for vCloud Director

With latest 12c release Oracle radically changed how databases are managed by introducing the concept of Pluggable Database. What's that? A pluggble database, or simply "PDB", is basically a database contained in another database which acts like a root container. This brings-in multitennancy capabilities in database without having to create a different instance for every tennant.

This new concept has slightly changed the way you perform tasks such as creating users, tablespaces and managing roles so I decided to come up with this post exaplaining how to set up an Oracle Database 12c for vCloud Director.

Prior to start please have a look at official vCloud Director Configure an Oracle Database documentation.

vCloud Director requires some tasks to be performed on Oracle Database:

-Create two tablespaces: CLOUD_DATA, CLOUD_INDX
-Create a user which will be using these tablespaces
-Assign certain permissions to this user
-Set up properly database initialization parameters

In Oracle Database 12c Enteprise Manager has been replaced by Enterprise Manager Express. An extremely slimmed-out version of 'ol classic EM.
Enterprise Manager Express is enabled by default only on root container and not on PDBs. After database installation completed a screen reported Enterprise Manager Express URL, which was something similar to this:

https://<IP_Address_or_FQDN>:5500/em

Where the port 5500 can be easily customized. For example in Oracle 11g by default it was port 1158.

Following screen depicts Enterprise Manager Express console for root container:



As you can see Type reports ORCL as single instance database having 1 PDB, furthermore browsing upper screen menu no tablespace item exists. Tablespaces will be created in PDBs.

Despite all commands can be performed using SQL may be conforting having a GUI on which you can check if everything has been created/modified as expected so let's first enable Enterprise Manager Express on PDBs.

This is done issuing a SQL command so open SQLPlus and connect to database as sysdba.

 connect sys/<password>@<container> as sysdba  

SQL> connect sys/mypassword@ORCL as sysdba

Connected

To issue commands directly to PDB and not to root container you need to alter the scope of your SQL session. This can be done with following command:

 alter session set container=<PDB_name>;  

SQL> alter session set container=PDBORCL;

Session altered.


To enable Enterprise Manager Express console for PDB:

 exec dbms_xdb_config.sethttpsport(<EM_Port>);  

SQL> exec dbms_xdb_config.sethttpsport(5501);

PL/SQL procedure completed


EM console is now available even for PDB and as you can see here Tablespace menu item has appeared:



Let's now perform vCloud Director's related configurations as reported in official documentation.

Tablespace creation can be done either via Enterprise Manager Express or by issuing SQL commands. If done via SQL ensure you are in the correct PDB scope:

 alter session set container=<PDB_name>;  

Create CLOUD_DATA and CLOUD_INDX tablespaces.

Edit $ORACLE_HOME variable according to your current home directory which in my case, on a Windows Server, is:

C:\app\Administrator\

 Create Tablespace CLOUD_DATA datafile '$ORACLE_HOME/oradata/cloud_data01.dbf' size 1000M autoextend on;  
 Create Tablespace CLOUD_INDX datafile '$ORACLE_HOME/oradata/cloud_indx01.dbf' size 500M autoextend on;  



Create a new user who will access these tablespaces:

 Create user <vcloud_user> identified by <vcloud_user_password> default tablespace CLOUD_DATA;  

And assign to it the following privileges:

- CONNECT (already granted to default role)
- RESOURCE (already granted to default role)
- CREATE TRIGGER
- CREATE TYPE
- CREATE VIEW
- CREATE MATERIALIZED VIEW
- CREATE PROCEDURE
- CREATE SEQUENCE

This can be done either via SQL or via Enterprise Manager Express.



Since vcloud user relies on default profile and will inherit default profile's attributes it could be a good move to change default password expiration lease of 180 days.



Last but not least we need to size our database parameters according to the ones suggested by VMware in vCloud Director documentation.

- CONNECTIONS = 75*<Number_of_vCloud_Director_Cells>+50
- PROCESSES = CONNECTIONS
- SESSIONS = PROCESSES*1.1+5
- TRANSACTIONS = SESSIONS*1.1
- OPEN_CURSORS = SESSIONS


As usual this is feasible either via SQL or via Enterprise Manager Express.

If done via SQL synthax is the following:

 alter system set <parameter>=<value> scope=<memory_AND/OR_spfile> sid=<sid>  

For example:

alter system set open_cursors=500 scope=both sid='*';

will change open_cursors parameters to 500, this will apply to both memory (changes not consistent across reboots) and spfile (changes consistent across reboots) and will affect all instances, including nested PDBs.

Please bear in mind that some configuration parameters must be edited at root container level and cannot be modified at PDB level.

This is well shown using Enterprise Manager Express, as following image depicts, processes parameter cannot be modified at PDB level.



Editing a parameter at both root DB or PDB using Enterprise Manager Express is really simple. Just go to Configuration -> Parameters, browse for the parameter you need to edit and click Set icon.



That's all!!