Skip to content

Commit b6db855

Browse files
committed
functions to create / delete vDNS records
1 parent 8b6ea75 commit b6db855

File tree

1 file changed

+140
-8
lines changed

1 file changed

+140
-8
lines changed

basic_rest_functions.sh

Lines changed: 140 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,75 @@ function make_ipam_subnet_str(){
267267
echo "$iss"
268268
}
269269

270+
## @fn make_random_ipv4_address()
271+
## @brief Creates random IPv4 address
272+
function make_random_ipv4_address(){
273+
local subnet_prefix=
274+
local c_digit=
275+
local o_digit=
276+
277+
# octet 1
278+
c_digit=`random_dec_digit_max 3`
279+
if [ "$c_digit" != "0" ]
280+
then
281+
subnet_prefix=$subnet_prefix"$c_digit"
282+
fi
283+
o_digit=$c_digit
284+
c_digit=`random_dec_digit_max 3`
285+
if [ "$c_digit" != "0" ] || [ "$o_digit" != "0" ]
286+
then
287+
subnet_prefix=$subnet_prefix"$c_digit"
288+
fi
289+
subnet_prefix=$subnet_prefix"`random_dec_digit_max 6`"
290+
subnet_prefix=$subnet_prefix"."
291+
292+
# octet 2
293+
c_digit=`random_dec_digit_max 3`
294+
if [ "$c_digit" != "0" ]
295+
then
296+
subnet_prefix=$subnet_prefix"$c_digit"
297+
fi
298+
o_digit=$c_digit
299+
c_digit=`random_dec_digit_max 3`
300+
if [ "$c_digit" != "0" ] || [ "$o_digit" != "0" ]
301+
then
302+
subnet_prefix=$subnet_prefix"$c_digit"
303+
fi
304+
subnet_prefix=$subnet_prefix"`random_dec_digit_max 6`"
305+
subnet_prefix=$subnet_prefix"."
306+
307+
# octet 3
308+
c_digit=`random_dec_digit_max 3`
309+
if [ "$c_digit" != "0" ]
310+
then
311+
subnet_prefix=$subnet_prefix"$c_digit"
312+
fi
313+
o_digit=$c_digit
314+
c_digit=`random_dec_digit_max 3`
315+
if [ "$c_digit" != "0" ] || [ "$o_digit" != "0" ]
316+
then
317+
subnet_prefix=$subnet_prefix"$c_digit"
318+
fi
319+
subnet_prefix=$subnet_prefix"`random_dec_digit_max 6`"
320+
subnet_prefix=$subnet_prefix"."
321+
322+
# octet 4
323+
c_digit=`random_dec_digit_max 3`
324+
if [ "$c_digit" != "0" ]
325+
then
326+
subnet_prefix=$subnet_prefix"$c_digit"
327+
fi
328+
o_digit=$c_digit
329+
c_digit=`random_dec_digit_max 3`
330+
if [ "$c_digit" != "0" ] || [ "$o_digit" != "0" ]
331+
then
332+
subnet_prefix=$subnet_prefix"$c_digit"
333+
fi
334+
subnet_prefix=$subnet_prefix"`random_dec_digit_max 6`"
335+
336+
echo "$subnet_prefix"
337+
}
338+
270339
## @fn make_random_ipam_subnet_prefix_ipv4()
271340
## @brief Creates random IPv4 subnet prefix of a given length
272341
function make_random_ipam_subnet_prefix_ipv4(){
@@ -962,6 +1031,42 @@ REQ_MARKER
9621031
execute_post_request "$REQ_STR" "$REQ_URL" >> $MESG_LOG
9631032
}
9641033

1034+
# @fn create_vdns_record()
1035+
# @brief creates a new virtual DNS record.
1036+
function create_vdns_record() {
1037+
local record_name="$1"
1038+
local vdns_name="$2"
1039+
local vdns_record="$3"
1040+
local vdns_fqname="[\"default-domain\",\"$vdns_name\"]"
1041+
local vdns_uuid=`fqname_to_uuid "$vdns_fqname" "virtual-DNS"`
1042+
if [ "$vdns_uuid" = "" ]
1043+
then
1044+
echo "vDNS $vdns_name was not found" >> $MESG_LOG
1045+
return 1
1046+
fi
1047+
local record_fqname=[\"default-domain\",\"$vdns_name\",\"$record_name\"]
1048+
1049+
local REQ_STR=
1050+
read -r -d '' REQ_STR <<- REQ_MARKER
1051+
{
1052+
"virtual-DNS-record": {
1053+
"parent_type": "virtual-DNS",
1054+
"parent_uuid": "$vdns_uuid",
1055+
"fq_name": $record_fqname,
1056+
"virtual_DNS_record_data": {
1057+
$vdns_record
1058+
}
1059+
}
1060+
}
1061+
REQ_MARKER
1062+
1063+
echo $REQ_STR
1064+
local REQ_URL="$REST_ADDRESS/virtual-DNS-records"
1065+
REQ_STR=`echo $REQ_STR`
1066+
echo >> $MESG_LOG
1067+
execute_post_request "$REQ_STR" "$REQ_URL" >> $MESG_LOG
1068+
}
1069+
9651070
# @fn create_ipam()
9661071
# @brief Creates a new IPAM with a given DNS server
9671072
function create_ipam(){
@@ -1155,7 +1260,7 @@ REQ_MARKER
11551260
# Add allowed pair
11561261
function link_vmi_with_aap(){
11571262
local vmi_name=$1
1158-
local new_ip=$2
1263+
local new_prefix=$2
11591264
local pref_len=$3
11601265
local address_mode=$4
11611266

@@ -1173,13 +1278,26 @@ function link_vmi_with_aap(){
11731278
return 1
11741279
fi
11751280

1281+
grep -q "-" <<< "$new_prefix"
1282+
local has_mac=$?
1283+
local mac_cfg_str=
1284+
if [ $has_mac ]
1285+
then
1286+
local mac_len=${new_prefix#*"-"}
1287+
local dash_pos=$(( ${#new_prefix} - ${#mac_len} - 1 ))
1288+
local mac="${new_prefix:0:$dash_pos}"
1289+
local ip_prefix_start=$(( $dash_pos + 1 ))
1290+
new_prefix="${new_prefix:$ip_prefix_start}"
1291+
mac_cfg_str=\"mac\":\"$mac\",
1292+
fi
1293+
11761294
read -r -d '' REQ_STR <<- REQ_MARKER
11771295
{
11781296
"virtual-machine-interface": {
11791297
"virtual_machine_interface_allowed_address_pairs" : {
11801298
"allowed_address_pair" : [
1181-
{"address_mode" : "$address_mode",
1182-
"ip" : {"ip_prefix" : "$new_ip", "ip_prefix_len" : "$pref_len"}}
1299+
{"address_mode" : "$address_mode", $mac_cfg_str
1300+
"ip" : {"ip_prefix" : "$new_prefix", "ip_prefix_len" : "$pref_len"}}
11831301
]
11841302
}
11851303
}
@@ -1763,13 +1881,27 @@ function delete_intf_route_table() {
17631881
}
17641882

17651883
function delete_virtual_dns() {
1766-
local dns_name="$1"
1767-
local dns_fqname="[\"default-domain\",\"$dns_name\"]"
1768-
local dns_uuid=`fqname_to_uuid "$dns_fqname" "virtual-DNS"`
1884+
local vdns_name="$1"
1885+
local vdns_fqname="[\"default-domain\",\"$vdns_name\"]"
1886+
local vdns_uuid=`fqname_to_uuid "$vdns_fqname" "virtual-DNS"`
17691887

1770-
if [ "$dns_uuid" != "" ]
1888+
if [ "$vdns_uuid" != "" ]
1889+
then
1890+
delete_entity "$vdns_uuid" "virtual-DNS"
1891+
fi
1892+
}
1893+
1894+
# @fn delete_vdns_record
1895+
# @brief deletes the specified virtual-DNS-record associated with the
1896+
# specified virtual-DNS
1897+
function delete_vdns_record() {
1898+
local record_name="$1"
1899+
local vdns_name="$2"
1900+
local record_fqname=[\"default-domain\",\"$vdns_name\",\"$record_name\"]
1901+
local record_uuid=`fqname_to_uuid "$record_fqname" "virtual-DNS-record"`
1902+
if [ "$record_uuid" != "" ]
17711903
then
1772-
delete_entity "$dns_uuid" "virtual-DNS"
1904+
delete_entity "$record_uuid" "virtual-DNS-record"
17731905
fi
17741906
}
17751907

0 commit comments

Comments
 (0)