Hammer CLI and name to id resolution

Hello ! Someone can explain how does name to id resolution work with latest
hammer cli release ?

Currently in my foreman config script i use bash associative arrays to do
this, for example :

declare -A PROXY
declare -A DOMAIN
eval $(hammer -u admin -p changeme --csv proxy list | awk -F "," '/^[0-9]/
{ print "PROXY[""$2""]="$1 }')
eval $(hammer -u admin -p changeme --csv domain list | awk -F "," '/^[0-9]/
{ print "DOMAIN[""$2""]="$1 }')

hammer -u admin -p changeme subnet create --name "PRODUCTION" --network
"192.168.0.0" --mask "255.255.255.0" --gateway "192.168.0.254"
–dns-primary "192.168.1.1" --dns-secondary "192.168.1.2" --from
"192.168.0.1" --to "192.168.0.253" --vlanid "2" --dhcp-id
${PROXY["foreman.mydomain.com"]} --tftp-id ${PROXY["foreman.mydomain.com"]}
–domain-ids
${DOMAIN["mydomain.com"]},${DOMAIN["mydomain2.com"]},${DOMAIN["mydomain3.com"]}

I saw in last changelogs there is a name to id resolution function, i red
documentation provided for it but i don't understand how to use it … any
help plz ?

> Hello ! Someone can explain how does name to id resolution work with
> latest hammer cli release ?
>
> Currently in my foreman config script i use bash associative arrays to
> do this, for example :
>
> declare -A PROXY
> declare -A DOMAIN
> eval $(hammer -u admin -p changeme --csv proxy list | awk -F ","
> '/^[0-9]/ { print "PROXY[""$2""]="$1 }')
> eval $(hammer -u admin -p changeme --csv domain list | awk -F ","
> '/^[0-9]/ { print "DOMAIN[""$2""]="$1 }')
>
> hammer -u admin -p changeme subnet create --name "PRODUCTION"
> --network "192.168.0.0" --mask "255.255.255.0" --gateway
> "192.168.0.254" --dns-primary "192.168.1.1" --dns-secondary
> "192.168.1.2" --from "192.168.0.1" --to "192.168.0.253" --vlanid "2"
> --dhcp-id ${PROXY["foreman.mydomain.com"]} --tftp-id
> ${PROXY["foreman.mydomain.com"]} --domain-ids
> ${DOMAIN["mydomain.com"]},${DOMAIN["mydomain2.com"]},${DOMAIN["mydomain3.com"]}
>
> I saw in last changelogs there is a name to id resolution function, i
> red documentation provided for it but i don't understand how to use it
> … any help plz ?
>
>
Hello,

though there is support for name to id resolution in Hammer, it is not
complete and there are some id-params that are not supported yet.
If you are not sure if name can be used for specific parameter, check
the command's help (-h).

Unfortunately none o the id-params in the subnet commands can use name
alternatives yet, please, file an issue for that if you can.

$ hammer subnet create -h
Usage:
hammer subnet create [OPTIONS]

Options:
–dhcp-id DHCP_ID DHCP Proxy to use within this subnet
–dns-id DNS_ID DNS Proxy to use within this subnet
–dns-primary DNS_PRIMARY Primary DNS for this subnet
–dns-secondary DNS_SECONDARY Secondary DNS for this subnet
–domain-ids DOMAIN_IDS Domains in which this subnet is part
Comma separated list of values.
–from FROM Starting IP Address for IP auto suggestion
–gateway GATEWAY Primary DNS for this subnet
–ipam IPAM Enable IP Address auto suggestion for
this subnet
–mask MASK Netmask for this subnet
–name NAME Subnet name
–network NETWORK Subnet network
–tftp-id TFTP_ID TFTP Proxy to use within this subnet
–to TO Ending IP Address for IP auto suggestion
–vlanid VLANID VLAN ID for this subnet
-h, --help print help

Here is command that has almost full name to id resolution support which
is apparent in the help:

$ hammer hostgroup create -h
Usage:
hammer hostgroup create [OPTIONS]

Options:
–architecture ARCHITECTURE_NAME Architecture name
–architecture-id ARCHITECTURE_ID
–domain DOMAIN_NAME Domain name
–domain-id DOMAIN_ID Numerical ID or domain name
–environment ENVIRONMENT_NAME Environment name
–environment-id ENVIRONMENT_ID
–medium MEDIUM_NAME Medium name
–medium-id MEDIUM_ID
–name NAME
–operatingsystem-id OPERATINGSYSTEM_ID
–parent-id PARENT_ID
–ptable PTABLE_NAME Partition table name
–ptable-id PTABLE_ID
–puppet-ca-proxy PUPPET_CA_PROXY_NAME Name of puppet CA proxy
–puppet-ca-proxy-id PUPPET_CA_PROXY_ID
–puppet-proxy PUPPET_PROXY_NAME Name of puppet proxy
–puppet-proxy-id PUPPET_PROXY_ID
–puppetclass-ids PUPPETCLASS_IDS List of puppetclass ids
Comma separated list of values.
–realm REALM_NAME Name to search by
–realm-id REALM_ID Numerical ID or realm name
–subnet SUBNET_NAME Subnet name
–subnet-id SUBNET_ID
-h, --help print help

To explain in short how it works: hammer checks if it can tell the
resource from the id-parameter name, e.g. architecture-id ->
architecture. If yes it means it will be able to convert the name to id
later and it extends the available parameters (e.g. --architecture
ARCHITECTURE_NAME Architecture name). Then during the excution it
does extra API request for each name parameter to obtain the ids
required by the API.

HTH,

Martin

··· On 09/04/2014 09:37 AM, Alexandre Barth wrote:


You received this message because you are subscribed to the Google
Groups “Foreman users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to foreman-users+unsubscribe@googlegroups.com
mailto:foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com
mailto:foreman-users@googlegroups.com.
Visit this group at http://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.

Ok thank you for your answer, so we can only use name when it is documented
in cli help :slight_smile:

··· Le jeudi 4 septembre 2014 17:16:39 UTC+2, Martin Bačovský a écrit : > > On 09/04/2014 09:37 AM, Alexandre Barth wrote: > > Hello ! Someone can explain how does name to id resolution work with > latest hammer cli release ? > > Currently in my foreman config script i use bash associative arrays to > do this, for example : > > declare -A PROXY > declare -A DOMAIN > eval $(hammer -u admin -p changeme --csv proxy list | awk -F "," > '/^[0-9]/ { print "PROXY[\""$2"\"]="$1 }') > eval $(hammer -u admin -p changeme --csv domain list | awk -F "," > '/^[0-9]/ { print "DOMAIN[\""$2"\"]="$1 }') > > hammer -u admin -p changeme subnet create --name "PRODUCTION" --network > "192.168.0.0" --mask "255.255.255.0" --gateway "192.168.0.254" > --dns-primary "192.168.1.1" --dns-secondary "192.168.1.2" --from > "192.168.0.1" --to "192.168.0.253" --vlanid "2" --dhcp-id ${PROXY[" > foreman.mydomain.com"]} --tftp-id ${PROXY["foreman.mydomain.com"]} > --domain-ids ${DOMAIN["mydomain.com"]},${DOMAIN["mydomain2.com > "]},${DOMAIN["mydomain3.com"]} > > I saw in last changelogs there is a name to id resolution function, i > red documentation provided for it but i don't understand how to use it ... > any help plz ? > > > Hello, > > though there is support for name to id resolution in Hammer, it is not > complete and there are some id-params that are not supported yet. > If you are not sure if name can be used for specific parameter, check the > command's help (-h). > > Unfortunately none o the id-params in the subnet commands can use name > alternatives yet, please, file an issue for that if you can. > > $ hammer subnet create > -h > > Usage: > hammer subnet create [OPTIONS] > > Options: > --dhcp-id DHCP_ID DHCP Proxy to use within this subnet > --dns-id DNS_ID DNS Proxy to use within this subnet > --dns-primary DNS_PRIMARY Primary DNS for this subnet > --dns-secondary DNS_SECONDARY Secondary DNS for this subnet > --domain-ids DOMAIN_IDS Domains in which this subnet is part > Comma separated list of values. > --from FROM Starting IP Address for IP auto suggestion > --gateway GATEWAY Primary DNS for this subnet > --ipam IPAM Enable IP Address auto suggestion for this > subnet > --mask MASK Netmask for this subnet > --name NAME Subnet name > --network NETWORK Subnet network > --tftp-id TFTP_ID TFTP Proxy to use within this subnet > --to TO Ending IP Address for IP auto suggestion > --vlanid VLANID VLAN ID for this subnet > -h, --help print help > > Here is command that has almost full name to id resolution support which > is apparent in the help: > > $ hammer hostgroup create > -h > > Usage: > hammer hostgroup create [OPTIONS] > > Options: > --architecture ARCHITECTURE_NAME Architecture name > --architecture-id ARCHITECTURE_ID > --domain DOMAIN_NAME Domain name > --domain-id DOMAIN_ID Numerical ID or domain name > --environment ENVIRONMENT_NAME Environment name > --environment-id ENVIRONMENT_ID > --medium MEDIUM_NAME Medium name > --medium-id MEDIUM_ID > --name NAME > --operatingsystem-id OPERATINGSYSTEM_ID > --parent-id PARENT_ID > --ptable PTABLE_NAME Partition table name > --ptable-id PTABLE_ID > --puppet-ca-proxy PUPPET_CA_PROXY_NAME Name of puppet CA proxy > --puppet-ca-proxy-id PUPPET_CA_PROXY_ID > --puppet-proxy PUPPET_PROXY_NAME Name of puppet proxy > --puppet-proxy-id PUPPET_PROXY_ID > --puppetclass-ids PUPPETCLASS_IDS List of puppetclass ids > Comma separated list of values. > --realm REALM_NAME Name to search by > --realm-id REALM_ID Numerical ID or realm name > --subnet SUBNET_NAME Subnet name > --subnet-id SUBNET_ID > -h, --help print help > > To explain in short how it works: hammer checks if it can tell the > resource from the id-parameter name, e.g. architecture-id -> architecture. > If yes it means it will be able to convert the name to id later and it > extends the available parameters (e.g. --architecture > ARCHITECTURE_NAME Architecture name). Then during the excution it > does extra API request for each name parameter to obtain the ids required > by the API. > > HTH, > > Martin > > > -- > You received this message because you are subscribed to the Google Groups > "Foreman users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to foreman-user...@googlegroups.com . > To post to this group, send email to forema...@googlegroups.com > . > Visit this group at http://groups.google.com/group/foreman-users. > For more options, visit https://groups.google.com/d/optout. > > >