HewlettPackard / oneview-python

Python library for HPE OneView
https://github.com/HewlettPackard/oneview-python/wiki
Apache License 2.0
28 stars 27 forks source link

How can I enroll new iLO inside oneview programtically using python SDK? #172

Closed zeshan1977 closed 3 years ago

zeshan1977 commented 3 years ago

What infrmation would i need iloip,svr profile ,svr profilr template. What is the api call that I would be usging , Cna someone throw a aample code in here? What is the Generation if ilo that cqan be managed by oneview appliance. iLO5- YES ilo4 - YES ilo3 - ? ilo2- ? ilo1- ? I have 2500 unmanged ilo that are going to be enrolled in OneView

yuvirani commented 3 years ago

@zeshan1977, We have an attribute called "managementProcessor" as part of server profile/server profile template resources which helps us to configure iLO settings.

You can use either POST or PUT API calls for creating/updating SP/SPT with iLO settings. There are 5 setting types supported as of now. I'm giving an example for the setting type "LocalAccounts". This way iLO settings getting managed in Oneview appliance.

Here is the code to update existing Server Profile with iLO Settings:

# Get existing SP by uri
print("\nGet a server profile by uri")
profile = server_profiles.get_by_uri(profile.data['uri'])
pprint(profile.data)

# Update iLO settings
ilo_settings = {
          "manageMp": True,
          "mpSettings": [
             {
                "settingType": "LocalAccounts",
                "args": {
                   "localAccounts": [
                      {
                         "userName": "user1",
                         "displayName": "One",
                         "password": "password1",
                         "userConfigPriv": True,
                         "remoteConsolePriv": True,
                         "virtualMediaPriv": True,
                         "virtualPowerAndResetPriv": True,
                         "iLOConfigPriv": True
                      },
                   ]
                }
             }]
             }

print("\n update iLO settings")
if profile:
    profile_ilo = profile.data.copy()
    profile_ilo["managementProcessor"] = ilo_settings
    profile.update(profile_ilo)
    pprint(profile.data)

Please let us know if you need any help.

zeshan1977 commented 3 years ago

How do I add an ilo to oneview via python SDK? for the first time?.

Whatis the minimum info required? and how do you do it? Please include a code snippet

yuvirani commented 3 years ago

@zeshan1977,

You can add iLO settings to Oneview through Server Profile/Server Profile Template resources while creating the profile. Since you mentioned that you have unmanaged iLO, give them in management processor settings below.

The minimum info required here is username, displayname and password of the type you like to configure. If any permissions needed, you have the option to add them too(as mentioned above iLOConfigPriv, remoteConsolePriv).

This is the python code you can copy and run from examples folder:

from pprint import pprint

from config_loader import try_load_from_file
from hpeOneView.oneview_client import OneViewClient

config = {
    "ip": "<oneview_ip>",
    "credentials": {
        "userName": "<username>",
        "password": "<password>",
    },
    "api_version": "<api_version>"
}

# Try load config from a file (if there is a config file)
config = try_load_from_file(config)
oneview_client = OneViewClient(config)
server_profiles = oneview_client.server_profiles

basic_profile_options = {
       "name": "Profile101",
       "serverHardwareTypeUri": "/rest/server-hardware-types/0EB0955A-65F5-417E-A95E-575D8C71102C",
       "enclosureGroupUri": "/rest/enclosure-groups/214579e4-bd49-4e86-ac11-9d7962b3bf2c",
       "managementProcessor": {
          "manageMp": True,
          "mpSettings": [
             {
                "settingType": "LocalAccounts",
                "args": {
                   "localAccounts": [
                      {
                         "userName": "user1",
                         "displayName": "User",
                         "password": "password1",
                      }
                ]}
        }]}
}

# Create a server profile with iLO settings
print("\nCreate server profile with iLo")
profile = server_profiles.create(basic_profile_options)
pprint(profile.data)

Also, could you help me with iLO setting type you would like to configure in Oneview? So that, I will come up with detailed solution. Setting type can be Directory Group, Directory, iLO hostname, Key Manager.

zeshan1977 commented 3 years ago

I dont understand. I do not have any uri information. all I have is : a) ONeView (Monitior mode) IP : admin level credentials b) ilo ip, admin creds to the ilo

How do I add /enroll b to a

VenkateshRavula commented 3 years ago

Please use the below piece of code from server_hardware resource example.

  1. You need to provide your OneView ip and creds in config.json file (https://github.com/HewlettPackard/oneview-python/blob/master/examples/config-rename.json). Refer the README for more info.
  2. Provide your iLO ip and credentials in the below dictionary (https://github.com/HewlettPackard/oneview-python/blob/master/examples/server_hardware.py#L35-L41)
  3. Run the below code to add the iLO to your oneview. (https://github.com/HewlettPackard/oneview-python/blob/master/examples/server_hardware.py#L57-L58)
options = {
    "hostname": "<iLO_ip>",
    "username": "<iLO_user>",
    "password": "<iLO_password>",
    "licensingIntent": "OneView",
    "configurationState": "Managed"
}

server_hardwares = oneview_client.server_hardware
server = server_hardwares.add(options)
print("Added rack mount server '%s'.\n  uri = '%s'" % (server.data['name'], server.data['uri']))

I hope this helps you. Please close this issue if this works.

zeshan1977 commented 3 years ago

Works!, Thanks suggestion in your examples folder add a enroll_svr_hdwre.py or add_server_hardware.py. PS Since my requirement is that they configurations date needs to be monitored so I added that specific key value pair in the dictionary