Yograj_YC Absent Member.
Absent Member.
667 views

HPE OneView REST API Help – Error while creating a SAN profile using REST API

Hi,

I am facing issues with OneView profile creation on our TBird setup. Can anyone help me on this ?

Chassis/OneView Details : T-Bird

OneView firmware version :“3.00.00-0259499”.

Blade : Synergy 480 Gen9

Mezz 1: HPE Synergy 3530C 16G Host Bus Adapter

I am trying to create a OneView profile using REST API with SAN storage configuration. As per the REST API reference I found the below format :

Create an advanced Profile with SAN storage settings

Request

   POST https://{appl}/rest/server-profiles

 

   auth=abcdefghijklmnopqrstuvwxyz012345

   X-Api-Version: 300

   {

       "type": "ServerProfileV6",

       "name": "Profile101",

       "serverHardwareUri": "/rest/server-hardware/{serverUUID}",

       "affinity": "Bay",

       "macType": "Virtual",

       "serialNumberType": "Virtual",

       "wwnType": "Virtual",

       "hideUnusedFlexNics":false,

       "connections": [{

           "id": 1,

           "name":"connection1",

           "functionType": "FibreChannel",

           "portId": "Auto",

           "requestedMbps": 2500,

           "networkUri": "/rest/fc-networks/{fcNetworkID}"

       },

       {

           "id": 2,

           "name":"connection2",

           "functionType": "FibreChannel",

           "portId": "Auto",

           "requestedMbps": 2500,

           "wwpnType": "UserDefined",

           "wwnn": "10:00:1C:11:00:00:00:00",

           "wwpn": "10:00:1C:11:00:00:00:01",

           "macType": "UserDefined",

           "mac": "12:11:11:00:00:00",

           "networkUri": "/rest/fc-networks/{fcNetworkID}"

       }],

       "sanStorage": {

           "hostOSType": "Windows 2012 / WS2012 R2",

           "manageSanStorage": true,

           "volumeAttachments": [{

               "id": 1,

               "lunType": "Auto",

               "volumeUri": "/rest/storage-volumes/{volumeID}",

               "volumeStoragePoolUri": "/rest/storage-pools/{poolID}",

               "volumeStorageSystemUri": "/rest/storage-systems/{systemID}",

               "storagePaths": [{

                   "storageTargetType": "TargetPorts",

                   "storageTargets": ["{WWPN1}", "{WWPN2}"],

                   "connectionId": 1,

                   "isEnabled": true

               }]

           },

           {

               "id": 2,

               "lunType": "Manual",

               "lun": "1",

               "volumeUri": "/rest/storage-volumes/{volumeID}",

               "volumeStoragePoolUri": "/rest/storage-pools/{poolID}",

               "volumeStorageSystemUri": "/rest/storage-systems/{systemID}",

               "storagePaths": [{

                   "storageTargetType": "Auto",

                   "storageTargets": [],

                   "connectionId": 1,

                   "isEnabled": true

               }]

           }]

       }

   }

#############

I am using the REST APIs for getting the UUIDs required for ‘serverHardwareUri’,‘networkUri’,’ volumeUri’,’ volumeStoragePoolUri’ and’ volumeStorageSystemUri’ ;

 

But when I am sending this request to OneView, I am getting the response as “URI must be absolute”. Why is this? How can I resolve this error?

 

If I try to create a simple connectionless profile, it is successful. The error is encountered when we add the connection/SAN details.

 

I am also attaching the perl code that I am using to create a profile.

 

Regards,

yograj

 

######################    CODE    #####################################

#!/user/bin/perl
use LWP::UserAgent;
use Net::SSL;
use JSON;
use Data::Dumper;

############## USE BAY 9 for trying profile creation #####################

my $filename = 'OneViewJSON.log';
open(my $fh, '>', $filename) or die "Could not open file '$filename' $!";
my $auth; my $ua;
my $oneviewURL = "https://x.x.x.x";
my %OVProfile = ();
my $profileStr = ();
my $SUTbay = '9';
my $serverHwType = '';
my $enclGrpType = '';

{   #####Authentication for REST API invocation ################
    $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0,}) or die;
    my $server_endpoint = "$oneviewURL/rest/login-sessions";
    # set custom HTTP request header fields
    my $req = HTTP::Request->new(POST => $server_endpoint);
    $req->header('content-type' => 'application/json');
    $req->header('X-Api-Version' => '300');
    # add POST data to HTTP request body
    my $post_data = '{ "userName": "Administrator", "password": "Password1" }';
    $req->content($post_data);
    my $resp = $ua->request($req);
    print $fh "$req\n";
    if ($resp->is_success) {
        my $message = $resp->decoded_content;
        print $fh "\n\nReceived reply: $message\n";
        if ($message =~ m/(.*)\:\"(.*)\"/) {
            $auth = $2;
        }
    } else {
        print $fh "HTTP POST error code: ", $resp->code, "HTTP POST error message: ", $resp->message, "\n";
    }
}

{     #########################REST Get Servers #############################
    $server_url = "$oneviewURL/rest/server-profiles/available-servers";
    $resp = $ua->get($server_url, 'auth' => $auth, 'X-API-Version' => '300');
    print $fh "$server_url\n";
    if ($resp->is_success) {
        $profileStr =  $resp->decoded_content;
        print $fh "Received Servers: ";
        print "Received servers: !!\n";
        # print $fh Dumper($profileStr), "\n\n";
       
        my $parse_perl = from_json($profileStr);
        @OVProfileTgt  = @{$parse_perl};
        print $fh Dumper(@OVProfileTgt);
        for (my $i=0; $i <= $#OVProfileTgt; $i++) {
             my %ServHash = %{$OVProfileTgt[$i]} ;
             if ($ServHash{'name'} =~ m/bay $SUTbay$/i) {
                $serverHwType = $ServHash{'serverHardwareTypeUri'};
                $enclGrpType  = $ServHash{'enclosureGroupUri'};
                last;
             }
             print "HWType = $serverHwType, EncGrp = $enclGrpType\n";
        }
    } else {
        print $fh "HTTP POST error code: ", $resp->code, "  HTTP POST error message: ", $resp->message, "\n";
        print "HTTP POST error code: ", $resp->code, "  HTTP POST error message: ", $resp->message, "\n";
    }
}
}
{   ############# Create Server Profile ########################

    my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0  }) or die;
    my $server_url = '$oneviewURL/rest/server-profiles';
   
    my $req        = HTTP::Request->new(POST => $server_url);
    $req->header('Content-Type' => 'application/json', 'Auth' => $auth, 'X-API-Version' => '300');

    my $fc_nwMz11  = '/rest/fc-networks/78d7c9ad-3aae-4bb4-bfb7-aa324a705957';
    my $fc_nwMz12  = '/rest/fc-networks/9f368b8e-8803-438d-9015-7ceb55319465';
    my $vol_uri    = '/rest/storage-volumes/71E13537-8082-4B11-A64F-125639219190';
    my $pool_uri   = '/rest/storage-pools/1880B0C0-BBB2-4156-B18C-D7C168E4221E';
    my $storage_uri = '/rest/storage-systems/SGH546WE4Y';
   
   
    #write the subroutine to get the server UUID or take it from variable.cfg
    my %post_hash = (    
    "type" =>  "ServerProfileV6",
    "name" =>  "Profile101",
    "serverHardwareTypeUri"=> "$serverHwType",
    "enclosureGroupUri"=> "$enclGrpType",
    "affinity" =>  "Bay",
    "macType" =>  "Physical",
    "serialNumberType" =>  "Physical",
    "wwnType" =>  "Physical",
    "hideUnusedFlexNics" =>  false,
    "connections" =>  [{
            "id" =>  0,
            "name" =>  "connection-fc1",
            "functionType" =>  "FibreChannel",
            "portId" =>  "Mezz 1:1",
            "requestedMbps" =>  "16000",
            "networkUri" =>  "$fc_nwMz11",
        }, {
            "id" =>  0,
            "name" =>  "connection-fc2",
            "functionType" =>  "FibreChannel",
            "portId" =>  "Mezz 1:2",
            "requestedMbps" =>  "16000",
            "networkUri" =>  "$fc_nwMz12"
        }
    ],
    "sanStorage" =>  {
        "hostOSType" =>  "VMware (ESXi)",
        "manageSanStorage" =>  false,
        "volumeAttachments" =>  [{
                "id" =>  "",
                "lunType" =>  "Auto",
                "lun" =>  "0",
                "volumeUri" =>  "$vol_uri",
                "volumeStoragePoolUri"=>  "$pool_uri",
                "volumeStorageSystemUri"=>  "$storage_uri",
                "storagePaths" =>  [{
                        "storageTargetType" =>  "Auto",
                        "storageTargets" =>  [],
                        "connectionId" =>  "0",
                        "isEnabled" =>  "true"
                    }]
            }]
        }
    );
    my $post_data = encode_json(\%post_hash);

    print "POST JSON = $post_data\n";

    $req->content($post_data);
    my $resp = $ua->request($req);
    # print $fh Dumper(\$resp);
    if ($resp->is_success) {
        $profileStr =  $resp->decoded_content;
        print $fh "Profile Template: ";
        print "Received Profile Template: !!\n";
        print $fh Dumper($profileStr), "\n\n";
       
        my $parse_perl = from_json($profileStr);
        @OVProfileTgt  = @{$parse_perl};
        print $fh Dumper(@OVProfileTgt);
    } else {
        print $fh "HTTP POST error code: ", $resp->code, "  HTTP POST error message: ", $resp->message, "\n";
        print "HTTP POST error code: ", $resp->code, "  HTTP POST error message: ", $resp->message, "\n";
    }

}

{    ################################## DELETE SESSION #############################
    my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0 }) or die;
    my $url = "$oneviewURL/rest/login-sessions";
    # set custom HTTP request header fields
    print $fh "DELETE: $url\n";
    my $req = HTTP::Request->new(DELETE => $url);
    $req->header('X-Api-Version' => '300');
    $req->header('Auth' => $auth);
    my $resp = $ua->request($req);
    print $fh "$url\n";
    print $fh "Delete Session: \n";
    print "Delete Session: \n";
    if ($resp->is_success) {
        my $message = $resp->decoded_content;
        print $fh "\n\nDelete reply: $message\n";
        print " Delete pass\n";
    } else {
        print $fh "HTTP POST error code: ", $resp->code, "HTTP POST error message: ", $resp->message, "\n";
        print "HTTP POST error code: ", $resp->code, "HTTP POST error message: ", $resp->message, "\n";
    }
}

close $fh;

 

 

 

 

Labels (2)
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.