vsphere API - searchManagedEntity function always returns null - virtualization

The searchManagedEntity function always returns null, I've tried many solutions on the web but unfortunately none of them worked.
Here's a snippet of my code:
ServiceInstance serviceInstance = authentification.connexionExsi();
Folder rootFolder = serviceInstance.getRootFolder();
System.out.println("Host" + (HostSystem) new InventoryNavigator(rootFolder).searchManagedEntity("HostSystem","192.168.1.44"));
Thank you in advance for your help <3

i've finally found the solution to this problem, you must use the name of ESXI host instead of the IP (ESXI Name = ESXI Hostname + Domain Name):
code:
ServiceInstance serviceInstance = authentification.connexionExsi();
Folder rootFolder = serviceInstance.getRootFolder();
System.out.println("Host"+new InventoryNavigator(rootFolder).searchManagedEntity("HostSystem","rabatos.Home").getName());
you can find the host & domain name in Dns & Routing, as depicted in the picture below:
Esxi Name

Related

How to resolve issue :: file_get_contents(http://localhost:8085/assets/data/test.txt): Failed to open stream: HTTP request failed

By using CodeIgniter 4 framework, I've developed RESTful api and there I need to access file (.json and .txt) to get content. But not able to access php inbuilt function file_get_contents().
For more details, pls check attached screenshot API_curl_file_get_content_error.PNG
And test.txt file is also accessible with same file path. For more details pls check screenshot Input-txt-file-content.png
NOTE : 1) test.txt file and respective directories have full permission.
2) Development environment :
<---->Apache/2.4.47 (Win64) OpenSSL/1.1.1k PHP/8.1.2
<---->Database client version: libmysql - mysqlnd 8.1.2
<---->PHP version: 8.1.2
<---->CodeIgniter 4
Product.php (index method)
<?php
namespace App\Controllers;
use CodeIgniter\RESTful\ResourceController;
class Product extends ResourceController
{
use \CodeIgniter\API\ResponseTrait;
public function index()
{
helper("filesystem");
ini_set('max_execution_time', 300);
$data['msg'] = "Product Index wizard";
$data['status'] = 200;
$file_path = base_url() . '/assets/data/test.txt'; // Read JSON
$json = file_get_contents($file_path, true);
$json_data = json_decode($json, true);
return $this->respond($data);
}
}
Explanation:
Remember that "http://localhost:8085/" most likely points to the document root of the project, which is usually the /public path. So, unless the "assets" folder resides in the /public path, file_get_contents("http://localhost:8085/assets/data/test.txt"); will fail to find the requested server resource.
Solution:
Since your file resource (test.txt) is on the local filesystem,
Instead of:
file_get_contents("http://localhost:8085/assets/data/test.txt");
Use this:
constant ROOTPATH
The path to the project root directory. Just above APPPATH.
file_get_contents(ROOTPATH . "assets/data/test.txt");
Addendum:
I believe you also forgot to add the $json_data output to the returned $data variable in the Product::index resource controller method.

How to get the computers domain name in matlab?

I tried getting domain name in c# as below,
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
Console.WriteLine("Domain name: {0}", properties.DomainName);
I have searched similar kind of approach in matlab for finding domain name. But I am not successful. Could anyone help me out like how we can get the domain name matlab(The domain name looks like yyy.xxxxx.com).
I got to know how to get computer name as below:
cc=getenv('computername');
How about this:
[s,cout] = system('net config workstation | findstr /C:"Full Computer name"');
FQDN= strtrim(strrep(cout,'Full Computer name',''))
FQDN=
XXXX.YYYY.com
This returns the fully qualified domain name (FQDN) of the computer . Where XXXX is your PC Name and YYYY is the domain.
Similarly if you just want the domain name:
[s,cout] = system('systeminfo | findstr /C:"Domain:"');
Domain = strtrim(strrep(cout,'Domain:',''))
Domain =
YYYY.com
EDIT: You can also get the FQDN using java in matlab like this:
FQDN = java.net.InetAddress.getLocalHost.getCanonicalHostName
FQDN =
XXXX.YYYY.com
You can read from the environment variable:
getenv('USERDOMAIN')

Owncloud "Add as trusted domain" button fails

The 'Add as a trusted domain' button didn't do anything before now it takes me to an 'Error 404' page.
I can set the domain on the owncloud box by editing the file config.php and have done so but I still do not understand why the button doesn't work.
you can manually override this button:
go to your installation folder in the config directory
open config.php and add a line like this:
'trusted_domains' =>
array (
0 => 'localhost',
1 => 'yourdomain.com'
),
Just started working with ownCloud myself and happened upon a similar issue when I reboot my BananaPi. The BPi got assigned a new IP on my network and the only Trusted IP was the original IP. I wanted to see how I could allow more trusted domains or IPs. Quick search shows no wildcard options. Since I often add and remove devices from my network, I wanted to add a range, like 192.168.0.1 to 192.168.0.254.
Since config.php is simply included and can still run code, versus just being XML or something, we can build an array really quickly.
config.php
<?php
$local_ips = array();
$base = "192.168.0.";
for($i = 1; $i < 255; $i++){
array_push($local_ips, $base . $i);
}
$CONFIG = array(
// Other config items ...
'trusted_domains' => $local_ips,
// More config items...
);
This will create an array of IPs that can then be used as Trusted Domains. $base is the first 4 octets of your Private IP Subnet. If you use 192.168.0.0/24 or 10.0.1.0/24, the $base would be 192.168.0. or 10.0.1. The for() loop will want to have a limit based on your network size.
You must to include http or https before the domain. The general form is:
http://domain:port
or
https://domain:port
This is an example example:
http://10.0.0.1:8000
or
https://10.0.0.1:8000

How to Update DNS Records Programatically

I am trying to update a DNS Record which is at (I believe) the following path on the server:
ServerName -> Forward Lookup Zones -> domain.com -> test
Where the DNS record is called test, and is of type Host(A).
I downloaded the DNSShell module from here and tried changing the 'Data' column of the DNS record (which contains an IP address) with this command:
Set-DNSRecord -Identity "test.domain.com"
But I got this error:
Cannot validate argument on parameter 'Identity'. The argument "test.domain.com" does not match the "^\\.\root\MicrosoftDNS:MicrosoftDNS_" pattern. Supply an argument that matches "^\\.\root\MicrosoftDNS:MicrosoftDNS_" and try the command again.
So I updated the Identity parameter as follows:
Set-DNSRecord -Identity "\\Servername\root\MicrosoftDNS:MicrosoftDNS_"
But now I am seeing:
Set-DNSRecord : Specified argument was out of the range of the valid values. Parameter name: Path
When I try adding a -Path, it says there is not such parameter! Does anyone know where I need to add the test.domain.com part of the DNS to tell the command which record to update? The documentation on this module is incomplete for this part of it and I can't seem to find any alternatives.
I can call Get-DNSRecord and see the record I need to update, but any attempts to Set are blocked because I have no idea how these paths are built.
Any help is much appreciated.
You can use also default PowerShell module for DNS server from Microsoft, example would then look something like this:
Add-DnsServerResourceRecordA -Name "recordname" -IPv4Address "192.168.0.0" -ZoneName "domain.com" -AllowUpdateAny -AgeRecord
In case you need removal before that something like this should work:
Remove-DnsServerResourceRecord -ZoneName "domain.com" -Name "recordname" -RRType "A" -Force
I managed to overcome this by using ye olde classic CMD command:
dnscmd /RecordAdd domain.com recordname RecordType /Aging /OpenAcl A 192.168.0.0
This adds a new record, and seems to do so even when another record with the same name (but different IP) exists.
So in my case, I will have to use dnscmd to first remove the existing record before adding a new one (as I actually just want to update the IP address of the existing record).
Command for removing dns record :
dnscmd /recorddelete domain.com recordname
More details can be found here.

Modify datasource IP addresses in WebSphere Application Server

I have nearly a hundred data sources in a WebSphere Application Server (WAS) and due to office relocation, the IP of the database servers have changed and I need to update the datasource IP addresses in my WAS too.
Considering it error-prone to update hundred IPs through admin console.
Is there any way that I can make the change by updating config files or running a script? My version of WAS is 7.0.
You should be able to use the WAS Admin Console's built-in "command assistance" to capture simple code snippets for listing datasources and changing them by just completing those operations in the UI once.
Take those snippets and create a new jython script to list and update all of them.
More info on command assistance:
http://www.ibm.com/developerworks/websphere/library/techarticles/0812_rhodes/0812_rhodes.html
wsadmin scripting library:
https://github.com/wsadminlib/wsadminlib
You can achieve this using wsadmin scripting. Covener has the right idea with using the admin console's command assistance to do the update once manually (to get the code) and then dump that into a script that you can automate.
The basic idea is that a datasource has a set of properties nested under it, one of which is the ip address. So you want to write a script that will query for the datasource, find its nested property set, and iterate over the property set looking for the 'ipAddress' property to update.
Here is a function that will update the value of the "ipAddress" property.
import sys
def updateDataSourceIP(dsName, newIP):
ds = AdminConfig.getid('/Server:myServer/JDBCProvider:myProvider/DataSource:' + dsName + '/')
propertySet = AdminConfig.showAttribute(ds, 'propertySet')
propertyList = AdminConfig.list('J2EEResourceProperty', propertySet).splitlines()
for prop in propertyList:
print AdminConfig.showAttribute(prop, 'name')
if (AdminConfig.showAttribute(prop, 'name') == 'ipAddress'):
AdminConfig.modify(prop, '[[value '" + newIP + "']]')
AdminConfig.save();
# Call the function using command line args
updateDataSourceIP(sys.argv[0], sys.argv[1])
To run this script you would invoke the following from the command line:
$WAS_HOME/bin/wsadmin.sh -lang jython -f /path/to/script.py myDataSource 127.0.0.1
**Disclaimer: untested script. I don't know the name of the "ipAddress" property off the top of my head, but if you run this once it will print out all the properties on your ds, so you can get it there
Some useful links:
Basics about jython scripting
Modifying config objects using wsadmin
As an improvement to aguibert's script, to avoid having to provide all 100 datasource names and to update it to correct the containment path of the configuration id, consider this script which will update all datasources, regardless of the scope at which they're defined. As always, backup your configuration before beginning and once you're satisified the script is working as expected, replace the AdminConfig.reset() with save(). Note, these scripts will likely not work properly if you're using connection URLs in your configuration.
import sys
def updateDataSourceIP(newIP):
datasources = AdminConfig.getid('/DataSource:/').splitlines()
for datasource in datasources:
propertySet = AdminConfig.showAttribute(datasource, 'propertySet')
propertyList = AdminConfig.list('J2EEResourceProperty', propertySet).splitlines()
for prop in propertyList:
if (AdminConfig.showAttribute(prop, 'name') == 'serverName'):
oldip = AdminConfig.showAttribute(prop, 'value')
print "Updating serverName attribute of datasource '" + datasource + "' from " + oldip + " to " + sys.argv[0]
AdminConfig.modify(prop, '[[value ' + newIP + ']]')
AdminConfig.reset();
# Call the function using command line arg
updateDataSourceIP(sys.argv[0])
The script should be invoked similarly to the above, but without the datasource parameter, the only parameter is the new hostname or ip address:
$WAS_HOME/bin/wsadmin.sh -lang jython -f /path/to/script.py 127.0.0.1