Monday, July 25, 2022

PowerCli to get all the needed data for a VM

 We are going to migrate one of our classical environments which doesn't have NSX to a new env. which has NSX.

To start doing some analysis, we will need to collect these data :

1. all the VMs in the env.
2. The OS
3. The power status
4. VLAN number 
5. The CPU and memory of the VMs
6. The size of the VM in GB without decimals 
7. Cluster
8. IP address
9. Number of NICs


here in this GUT repo you will find the powercli script The PowerCli Script



























Wednesday, July 13, 2022

GET VRA Tokens

We will get the refresh and access tokens for VRA , I am following the below page but with a small adjustment

https://vdc-download.vmware.com/vmwb-repository/dcr-public/97d1d46c-8846-4c12-85a8-5655d1189825/3873335e-1ec6-4bac-a9c2-2f62636ce19f/GUID-AC1E4407-6139-412A-B4AA-1F102942EA94.html  


Step number zero :-) . you will need to have a linux VM that can reach to VRA on port 443

1. Define your variables

identity_service_url='https://<vRA-HOSTNAME>'
username='<your_username>'
password='<your_password>'

2. Execute the below command
api_token=`curl -k -X POST \
  "$identity_service_url/csp/gateway/am/api/login?access_token" \
  -H 'Content-Type: application/json' \
  -d '{
  "username": "'"$username"'",
  "password": "'"$password"'"
}' | jq -r .refresh_token`

3. Get the refresh token
echo $api_token

to get the access token:

1. Define your variables
identity_service_url='https://<vRA-HOSTNAME>'
username='<your_username>'
password='<your_password>'

2. Execute the below command
access_token=`curl -k -X POST \
  "$identity_service_url/iaas/api/login" \
  -H 'Content-Type: application/json' \
  -s \
  -d '{
  "refreshToken": "'"$api_token"'"
}' | jq -r .token`

3. Get the access token
echo $access_token

Create bulk of VRA deployments with VRA

 How can you deploy bulk of VRA deployments with the minimum effort , the answer will be Terraform 


terraform {
  required_providers {
    vra = {
      source  = "vmware/vra"
      version = "0.5.1"
    }
  }
}

provider "vra" {
  url           = "https://YourVraURL"
# I will explain to you how to get the refresh token in another page
  refresh_token = ""
  insecure      = "false"
}



resource "vra_deployment" "Test_deployment" {
  count = 10
  name  = "Terraform - MAIB.${count.index}"
  #name        = "Terraform - MAIB100"
  description = "Deployment description"

# You can get this information from the service broker page 
# The catalog_item_id you can get it from the URL  
#https://ABC.COM/catalog/#/library/55dc45e8-ba3f-378b-b900-c16a556f7a55
#The project ID can be gotten from the infrastructure and choose the projects and get teh project ID from the URL
#https://ABC.COM/automation-ui/#/provisioning-ui;ash=%2Fprojects%2Fedit%2Fd6437f49-ebf6-41eb-821c-13cabb509fc0

  catalog_item_id      = "55dc45e8-ba3f-378b-b900-c16a556f7a55"
  catalog_item_version = "2021.08.25-01"
  project_id           = "d6437f49-ebf6-41eb-821c-13cabb509fc0"
  

# This inputs will be changable from one customer to another 
  inputs = {
    t_shirt_size    = "small",
    deployment_name = "Terraform - MAIB.${count.index}"
    image              = "Windows 2019"
    Backup             = "No Backup"
    #Patching_Method    = "Automated monthly patching"
    #Patching_Week      = "Fourth"
    #Patching_Day       = "Sunday"
    #Patching_Timeframe = "13:00 - 15:00"

  }

  timeouts {
    create = "30m"
    delete = "30m"
    update = "30m"
  }

# I am using this part because we are migrating from NSX-V to NSX-T and the cloud zone is changed after the migration.

    lifecycle {
    ignore_changes = [
      catalog_item_id,
      catalog_item_version,
      inputs
    ]

  }


}

Tuesday, July 12, 2022

How to make API call on NSX-T with ansible

 We will make execute an ansible playbook to get all the NSX-T segments for us



cat /root/ansible/hosts/hostsNsx.ini
[nsxtdev]
NSX-T.abc.com


cat /root/ansible/playbooks/nsx.yaml
- hosts: nsxtdev
  connection: local
  gather_facts: false
  tasks:
  - name: Get all the NSX-T Segments
    uri:
      url: https://NSX-T/policy/api/v1/infra/segments
      force_basic_auth: yes
      validate_certs: no
      headers:
        Accept: "application/json"
        Content-Type: "application/json"
      user: USERNAME
      password: PASSWORD
      method: GET
      status_code: "200"
      body_format: json


ansible-playbook -i /root/ansible/hosts/hostsNsx.ini /root/ansible/playbooks/nsx.yaml -vvvv


to avoid using  -vvvv and to get the only API call result , you can use the following playbook

 
- hosts: nsxtdev
  connection: local
  gather_facts: false
  tasks:
  - name: Get all the NSX-T Segments
    uri:
      url: https://NSX-T/policy/api/v1/infra/segments
      force_basic_auth: yes
      validate_certs: no
      headers:
        Accept: "application/json"
        Content-Type: "application/json"
      user: USERNAME
      password: PASSWORD
      method: GET
      status_code: "200"
      body_format: json
    register: response
  - debug: var=response.json


ansible-playbook -i /root/ansible/hosts/hostsNsx.ini /root/ansible/playbooks/nsx.yaml

NSX-T (local log in) with VIDM integration

We will explain how to log in with a local account to your NSX-T which integrated with VIDM. We integrated our NSX-T into the VIDM. We had a...