How to find ESXi host serial number using pyvmomi? - esxi

Previously for VCenter software version 6.0.0 I was using vim.host.SystemIdentificationInfo which was giving me the desired value inside identifierValue
But for VCenter software version 6.5.0 vim.host.SystemIdentificationInfo is returning me an empty list
Output:
'hardware': (vim.host.HardwareInfo) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
systemInfo = (vim.host.SystemInfo) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
vendor = 'Cisco Systems Inc',
model = 'UCSB-B200-M4',
uuid = '16fa7876-059e-e711-0000-00000000001f',
otherIdentifyingInfo = (vim.host.SystemIdentificationInfo) []
}
However I am checking from the ESXi host cli I am getting the serial number by using the command:
esxcfg-info | grep "Serial N"
|----Serial Number............................................FLM1950CK2X
So, the value is available but not returned by pyvmomi currently.
Could anyone please help me to find it out?

host.hardware.systemInfo.serialNumber

Related

How should I write a flake.nix in order to use nix develop instead of nix develop github:project#shell

NB: add --extra-experimental-features nix-command --extra-experimental-features flakes if you've allow experimental feature in nix
This repository propose to load a shell this way:
nix develop github:informalsystems/cosmos.nix#cosmos-shell
It seems to work.
In order to see if I've really understood how nix flake works (I haven't) I am trying to write a flake.nix so that I only have to write
nix develop
There is a field devShells in output in flake.nix in this repo. Warning devShells not devShell. This is a collection of shells defined in configuration.nix
my flake.nix :
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; #not useful for this question
cosmos_inform_system.url = github:informalsystems/cosmos.nix;
flake-utils.url = github:numtide/flake-utils;
};
outputs = { self, nixpkgs, cosmos_inform_system, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
shells = cosmos_inform_system.devShells;
in {
devShell.default = shells.cosmos-shell;
});
}
warning: flake output attribute 'devShell' is deprecated; use 'devShells..default' instead
error: attribute 'cosmos-shell' missing
There is cosmos-shell in configuration.nix this a field devShells. Therefore I don't understand the error
In order to remove the warning, I replace this line
devShell = shells.cosmos-shell;
by this line
devShells.${system}.default = shells.cosmos-shell;
error: flake attribute 'devShell.aarch64-linux' is not a derivation
I still have the warning.
Take a look at this flake.nix file for an example of how to do that.
nix flake check
works with that
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
cosmos_inform_system.url = github:informalsystems/cosmos.nix;
flake-utils.url = github:numtide/flake-utils;
};
outputs = { self, nixpkgs, cosmos_inform_system, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
shells = cosmos_inform_system.devShells;
in {
devShells.default = shells.${system}.cosmos-shell;
}
);
}
but
nix develop
error: hash mismatch in fixed-output derivation '/nix/store/yz9kjwjhszzpp7g4wnbxj43zwga1zzsy-ica-go-modules.drv':
specified: sha256-ykGo5TQ+MiFoeQoglflQL3x3VN2CQuyZCIiweP/c9lM=
got: sha256-D31e+G/7KAmF3Gkk4IOmU2g/eLlqkrkpwJa7CEjdaAk=
[1/158 built (1 failed)] building ica-go-modules (installPhase): installing
Nevertheless I have exactly the same problem with nix develop github:informalsystems/cosmos.nix#cosmos-shell
I still think my flake file is the same as nix develop github:informalsystems/cosmos.nix#cosmos-shell

Nix maintain original order of a set

Assumptions:
You have yq and nix installed on your OS running NixOS or some Linux distro.
Question:
Can nix maintain the original ordering of a set? i.e. If I create a sample.nix file:
{pkgs}:
let
dockerComposeConfig = {
version = "1.0";
services = {
srv1 = { name = "srv1"; };
srv2 = { name = "srv2"; };
};
};
in writeTextFile {
name = "docker-compose.json";
text = builtins.toJSON dockerComposeConfig;
}
When I build and convert the output to yaml below I notice is that the set has been alphabetized by Nix. Is there a workaround that keeps my JSON in the same ordering as intended by a Docker user such that the `dockerComposeConfig attrributes remain in the order they are created?
# Cmd1
nix-build -E "with import <nixpkgs> {}; callPackage ./sample.nix {}"
# Cmd2
cat /nix/store/SOMEHASH-docker-compose.json | yq r - --prettyPrint
Nix attribute sets don't have an ordering to their attributes and they are represented as a sorted array in memory. Canonicalizing values helps with reproducibility.
If it's really important you could write a function that turns a list of key value pairs into a JSON object as a Nix string. But that's not going to be easy to use like builtins.toJSON. I'd consider the JSON as "compiled build output" and not worry too much about aesthetics.
Side note: Semantically, they are not even created in any order. The Nix language is declarative: a Nix expression (excluding derivations) describes something that is, not how to create it, although it may be defined in terms of functions.
This is necessary for Nix's laziness to be effective.

Is there a way to specify number of AZs to use when creating a vpc?

When instantiating the vpc object within a stack using the CDK. There is a parameter max_azs which supposedly defaults to 3. However, when I create a vpc no matter what I set that number to, I only ever get 2 AZs.
from aws_cdk import (
core,
aws_ec2 as ec2
)
app = core.App()
subnets = []
subnets.append(ec2.SubnetConfiguration(name = "public", subnet_type = ec2.SubnetType.PUBLIC, cidr_mask = 20))
subnets.append(ec2.SubnetConfiguration(name = "private", subnet_type = ec2.SubnetType.PRIVATE, cidr_mask = 20))
subnets.append(ec2.SubnetConfiguration(name = "isolated", subnet_type = ec2.SubnetType.ISOLATED, cidr_mask = 20))
vpc = ec2.Vpc(app, "MyVpc", subnet_configuration = subnets, max_azs = 3)
print(vpc.availability_zones)
app.synth()
I would expect to see 3 azs used here, but actually only ever get 2. Even if i set the value to 99, which should mean all azs.
Ah yes I came across the same issue myself. What solved it for me was specifying the region and account when creating the stack.
The following examples are for typescript but I'm sure you can write the corresponding python.
new MyStack(app, 'MyStack', {
env: {
region: 'us-east-1',
account: '1234567890',
}
});
In the case of typescript you need to rebuild and synth before you deploy.
$ npm run build
$ cdk synth

Execution failed for task ':buildDB2BotcImage'

System Info : Windows 10 Enterprise
Gradle Version 4.3.1
Docker Version 17.10.0-ce, build f4ffd25
I am getting an issue while doing gradle.build, Error I am getting
Unrecognized field "identitytoken" (class com.github.dockerjava.api.model.AuthConfig), not marked as ignorable (6 known properties: "serveraddress", "username", "auth", "password", "email", "registrytoken"])
at [Source: N/A; line: -1, column: -1] (through reference chain: java.util.LinkedHashMap["auths"]->java.util.LinkedHashMap["registry.au-syd.bluemix.net"]->com.github.dockerjava.api.model.AuthConfig["identitytoken"])
I have done some research and found this https://github.com/bmuschko/gradle-docker-plugin/issues/310 , and done some changes in my build.gradle but still i am getting this error.
The changes I have done in one of the part of build.gradle file :
Previously:
docker {
if (System.properties['os.name'].toLowerCase().contains('windows')) {
url = 'tcp://localhost:2376'
certPath = new File(System.properties['user.home'], '.docker/machine/certs')
}
registryCredentials {
url = 'https://maxrep01.swg.usma.ibm.com/'
username = 'username'
password = 'secret'
}
}
Changed:
docker {
if (System.properties['os.name'].toLowerCase().contains('windows')) {
if (new File("\\\\.\\pipe\\docker_engine").exists()) {
url = 'npipe:////./pipe/docker_engine'
}
else {
url = 'tcp://localhost:2376'
}
certPath = new File(System.properties['user.home'], '.docker/machine/certs')
}
registryCredentials {
url = 'https://maxrep01.swg.usma.ibm.com/'
username = 'username'
password = 'secret'
}
}
This is the only helpful link I am getting, but I am unable to get what is the issue is, my understanding is it is something related to windows 10, but as per the link the changes i have done should resolve the issue.
I am not sure what is wrong here?
Your problem is most likely related to Issue #921 of the docker-java project.
Hello, we got the issue, using latest version of "docker-java" while trying to load and parse DOCKER configuration file ("$HOME/.docker/config.json").
It doesn't accept the field 'identitytoken'. I have noticed that you have 'registrytoken' field, which have been used since DOCKER API v1.22 version for the same purpose. I checked documentation, it was renamed there into --> 'identitytoken' just in the next DOCKER API v1.23 version.
If waiting for a next docker-java version is not acceptable, it might help to tweak config.json to suit your needs.

How to get the most recent ebs snapshot using terraform datasource?

I am trying to get the most recent created snapshot using terraform, don't know how to do it, according to terraform's document, for aws ami, it can be done by:
data "aws_ami" "web" {
filter {
name = "state"
values = ["available"]
}
filter {
name = "tag:Component"
values = ["web"]
}
most_recent = true
}
I am expecting similar things for ebs snapshot like:
data "aws_ebs_snapshot" "latest_snapshot" {
filter {
name = "state"
values = ["available"]
}
most_recent = true
}
But there is no "most_recent" argument at the reference page for data -> "aws_ebs_snapshot" here, so how can I get the most recent created snapshot using terraform? and why cannot we use the similar syntax as what aws_ami has?
Currently not available in the latest release of Terraform v0.8.2, but this feature has been merged into the latest master of Terraform just a few days ago.
https://github.com/hashicorp/terraform/pull/10986
It is also listed in CHANGELOG of the next release v0.8.3, so it will be available soon.

Resources