Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Note

All sample code in this section is written in Python using the Amazon Boto AWS API client library.


Before pre-provisioning and launching Infoblox vNIOS for AWS instances, ensure that you have completed the following:

  • Configure the AWS API Proxy based on your deployment, as described in Setting Up the Infoblox AWS API Proxy;
  • For CLI operations, configure an Amazon API client system to work with your API Proxy, as described in Setting Up an API Client;
  • Obtain and install pool licenses and create license pools on the Grid Master. (For information on license pools and dynamic licensing, see the Infoblox NIOS Documentation.) To obtain your pool licenses, consult your Infoblox Sales representative.

The following examples rely on the following two declarations:

vpc_conn = boto.vpc.connect_to_region("eu-west-1", port=8787,validate_certs=False)

ec2_conn = boto.ec2.connect_to_region("eu-west-1", port=8787)

The first declaration initializes a connection object in Python for the AWS VPC API endpoint. The second declaration
initializes a connection object to the AWS EC2 API endpoint.

Creating New VPC with Specific Tenant and Network View

This example shows the recommended API Client process to set the AWS VPC's DHCP options to specify a Infoblox vNIOS for AWS instance as the DNS server. This ensures that the NIOS Grid is the management for the VPC's DNS domain.
The network view must already be created in NIOS.
You use the CreateVpc workflow to define a new virtual private cloud. In the sample python script, you can issue the following sample directives:

## Create a VPC with an explicit CIDR in a specified network view

## Network view MUST exist in NIOS

cidr_and_exts = '10.69.69.0/24#X-IB-Network-View=My-network'

vpc = vpc_conn.create_vpc(cidr_block=cidr_and_exts)

print 'VPC ID: %s, State: %s' % (vpc.id, vpc.state)

The following example adds another Infoblox extension to specify the tenant for the new virtual private cloud.

## Create a VPC with CIDR in a network view under a specified Tenant

## Maximum sizes for VPCs under Amazon are /16

cidr_and_exts = '10.60.60.0/24#X-IB-Network-View=My-network#X-IB-Tenant-ID=Tenant-1'

vpc = vpc_conn.create_vpc(cidr_block=cidr_and_exts)

print 'VPC ID: %s, State: %s' % (vpc.id, vpc.state)

##The vpc_id is the value Amazon passes to NIOS.

Creating New Subnet in VPC with no Extensible Attributes

You use the CreateSubnet workflow to create a new Subnet in an Amazon VPC. The following example is relatively straightforward, without use of any Infoblox extensions to search or define EA values:

## Create a Subnet under a VPC with the next available subnet range in the VPC

cidr_and_exts = 'next-available-network/28'

## THE NEXT-AVAILABLE-NETWORK argument is not native to AWS.

## Without NIOS, this won't work.

The next example shows how you can pass an explicit prefix value to create the new subnet.

## or pass explicitly - which AWS DOES support) cird_and_exts - '10.10.1.1/26'

subnet = vpc_conn.create_subnet(vpc_id=vpc.id, cidr_block=cidr_and_exts)

print 'Subnet ID: %s, State: %s' % (subnet.id, subnet.state)

Adjust the CIDR and prefix values to suit your requirements.

The subnet.id value is passed to NIOS, and is used for other operations including creating new instances as described in the following section.

Creating New Instance in EA-Selected Subnet

The following script segment calls an Amazon virtual machine shape ID and refers to the AWS subnet for the VPC created in the previous section, Creating New Subnet in VPC with no Extensible Attributes.
You use the Run Instances workflow to define a new virtual private cloud, combined with Infoblox extensions built into the API query request.

## Start a t2.micro VM instance in AWS on the subnet

## created above, with the next available IP address on the subnet.

## REQUIRES A VPC AND A SUBNET

reservation = ec2_conn.run_instances(

"ami-7f0ae93b",

subnet_id = subnet.id,

## THIS subnet.id value is passed from the prior subnet script.

instance_type="t2.micro")

inst = reservation.instances[0]

print 'Started instance %s with private IP address %s, status: %s' %\

(inst.id, inst.private_ip_address, inst._state.name)

The IP for the new instance is automatically selected by NIOS from the subnet you previously created.
The next usage example includes the following:

  • Use of an Extensible Attribute to select the VPC subnet in which to provision the VM;
  • Specifying an FQDN for the Host record.

## Start a VM instance in AWS on the subnet created above, with the next available IP

## address on the subnet, using the specific AWS VM shape,

## and create a DNS record with the specified host name.


## The DNS zone corp100.com must be created manually using a subnet search by EA.

reservation = ec2_conn.run_instances(

"ami-7f0ae93b",

subnet_id = 'None#X-IB-EA-EQ-Subnet-ID=172.16.0.0'

'#X-IB-Host-Name=myvm3.corp100.com',

instance_type="t2.micro")

inst = reservation.instances[0]

print 'Started instance %s with private IP address %s, status: %s' %\

(inst.id, inst.private_ip_address, inst._state.name)

Allocating and Associating an Amazon Elastic IP

This short script segment allocates an Amazon Elastic IP to be used for an instance. The Elastic IP always needs to have a Host name (X-IB-Host-Name) and the Infoblox Network View extension (X-IB-Network-View).


## stringing together two extensions

domain_ext = 'vpc#X-IB-Host-Name=myvm-pub.corp100.com#X-IB-Network-View=My-network'

eip = ec2_conn.allocate_address(domain=domain_ext)

print eip

Before associating an Elastic IP, the VPC needs to be attached to an AWS internet gateway. This is a one-time manual step that is done in the AWS console and cannot be performed through the API.

## alloc-id will be logged in /tmp/boto.log for a successful

## allocate_address all. Not shown in the shell. You have to grab it from the log file

## or from the AWS console.

alloc_id = ''

assoc_id = ec2_conn.associate_address(instance_id=inst.id,

## Created in the previous process

public_ip=eip, allocation_id=alloc_id,

private_ip_address=inst.private_ip_address)

Afterwards, in the DNS view, you will see the Elastic IP in NIOS.

  • No labels