def freeprefix(nipap_deamon_ip, account_cb_alias, account_iam_alias, vpc_network, vpc_prefix):
# Lookup nipap daemon password cipher
nipapCfn = dynamodb.Table(os.environ['TAILOR_TABLENAME_NIPAPCFN'])
getNipapCfn = nipapCfn.get_item(
Key={
'nipapAlias': account_cb_alias
}
)
# Decrypt nipap daemon password
nipapDaemonPasswordCipherBlob = getNipapCfn['Item']['nipapDaemonPasswordCipherBlob']
nipapDeamonPassword = bytes(kms.decrypt(CiphertextBlob=b64decode(nipapDaemonPasswordCipherBlob))['Plaintext'])
# Look up free CIDR block
pynipap.xmlrpc_uri = "http://tailor:" + nipapDeamonPassword.rstrip() + "@" + nipap_deamon_ip + ":1337"
a = pynipap.AuthOptions({
'authoritative_source': 'tailor_nipap_client'
})
# Allocate first available
new_prefix = Prefix()
new_prefix.description = account_iam_alias
new_prefix.type = "assignment"
# Save will communicate with the backend and ask for the next available desired prefix size
new_prefix.save({'from-prefix': [vpc_network], 'prefix_length': vpc_prefix})
# Read the assigned prefix from the new_prefix object
print("VPC Cidr is: ", new_prefix.prefix)
return new_prefix.prefix
评论列表
文章目录