cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
789
Views
0
Helpful
3
Replies

Script to export list of all service profiles/ user labels associated with all servers in multiple UCS domains to an excel sheet.

codejunkie19479
Level 1
Level 1

Trying to put together a script to export list of all service profiles/ user labels associated with all servers in multiple UCS domains to an excel sheet.

Any input is appreciated !!

3 Replies 3

Sergiu.Daniluk
VIP Alumni
VIP Alumni

Hi @codejunkie19479 

Based on your question, I made the following script:

https://github.com/msdaniluk/ucs_tools/tree/master/ucsmsdk_get_sp 

 

1. Download the repository from github

2. Go to the downloaded directory and install requirements (important ones: pandas, ucsmsdk)

pip install -r requirements.txt

3. Edit the domains.py file with your domains information. The info is preserved in a list of dicts, where each element in the list is a domain. Note: the domain name can be anything you define, and it will be used as a name for the xls sheet. Each domain = different excel sheet.

ucs_domains_list = [
    {'name': '',
     'ip': '',
     'username': '',
     'password': ''}
]

4.1 (Optionally) In the service_profile.py, modify the name of the xls file to be generated:

def main():
    for domain in ucs_domains_list:
        sp_list = get_sp_from_domain(domain)
        convert_sp_list_to_excel(sp_list=sp_list, xls_file_name='file.xls', sheet_name=domain['name'])

4.2 (Optionally) In the service_profile.py, uncomment (delete #) print line if you want to also print the SP:

def convert_sp_list_to_excel(sp_list, xls_file_name, sheet_name):
    # convert to Pandas DF and export to excel
    df = pd.DataFrame.from_records(sp_list, columns=['SP Name', 'Type', 'Assigned State', 'Associated State'],)
    # print(df)
    df.to_excel(xls_file_name, sheet_name=sheet_name)

5. Run the script. Note: this is how output looks like if you uncomment the print.

(venv) sd@ubuntu:~$ python service_profile.py
                    SP Name              Type Assigned State Associated State
0  C200-Local-Boot-Template  initial-template     unassigned     unassociated
1      C200-Local-Boot-SRV1          instance       assigned       associated
...

6. File is generated.

 

sp.png

 

Cheers,

Sergiu

 

Thats awesome ! thanks for your response.

Was wondering if this can be done using Cisco UCS Powertool , powershell as well ? 

I just started learning programming languages 

Hello @codejunkie19479 

Welcome to the fascinating world of programmability ^_^

I did not used Powershell for automation so far, so I am not really sure about all of capabilities it has, but most likely there is a way to generate same result.

 

Regards,

Sergiu

 

Review Cisco Networking products for a $25 gift card