Skip to content

Commit 2d308d2

Browse files
author
greyhoundforty
committed
Php block storage example
1 parent bb9fc9b commit 2d308d2

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

content/php/storage_credentials.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: "Get storage credentials for Block Storage"
3+
description: "Retrieving the username and password for Performance/Endurance Block storage"
4+
date: "2016-08-10"
5+
classes: ["SoftLayer_Network_Storage_Iscsi"]
6+
tags:
7+
- "iscsi"
8+
- "blockStorage"
9+
- "objectMask"
10+
---
11+
12+
13+
The following script allows you retrieve the username and password for Performance/Endurance Block storage if you have authorized hosts against the storage.
14+
15+
```php
16+
<?php
17+
18+
/* You can use the getenv() module to pull your exported Username
19+
and API key to keep from having to store them in your files */
20+
21+
require_once './vendor/autoload.php';
22+
$apiUsername = getenv('SOFTLAYER_USERNAME');
23+
$apiKey = getenv('SOFTLAYER_API_KEY');
24+
$storageid = '123456';
25+
26+
try {
27+
$client = \SoftLayer\SoapClient::getClient('SoftLayer_Network_Storage_Iscsi', $storageid, $apiUsername, $apiKey);
28+
$objectMask = new \SoftLayer\Common\ObjectMask();
29+
$objectMask->allowedHardware->allowedHost->credential;
30+
$objectMask->allowedVirtualGuests->allowedHost->credential;
31+
$client->setObjectMask($objectMask);
32+
33+
$response = $client->getObject();
34+
35+
print_r($response);
36+
37+
} catch(Exception $e) {
38+
echo 'Unable to get Storage credentials: ' . $e->getMessage();
39+
}
40+
?>
41+
```

0 commit comments

Comments
 (0)