Quick App Delivery Based on Resource Orchestration and Ansible over a Typical Network - Alibaba Cloud Developer Forums: Cloud Discussion Forums

Assistant Engineer
Assistant Engineer
  • UID621
  • Fans1
  • Follows0
  • Posts55

Quick App Delivery Based on Resource Orchestration and Ansible over a Typical Network

More Posted time:Sep 21, 2016 17:10 PM
Over a typical network, app delivery does not require other resources such as VPC and VSwitch, which are required by if app delivery is implemented in the VPC environment. App delivery over a typical network requires only ECS and public IP addresses. However, these two delivery modes share the same procedure and steps. The following section provides an example of setting up a Redis cluster to show how to quickly deliver apps over a typical network.
Quickly settings up a Redis cluster over a typical network based on the ROS API and Ansible
Before setting up the cluster, install ROS SDK and Ansible on the master node.
The following describes how to quickly set up a Redis cluster with one master node and two slave nodes based on the ROS API and Ansible over a typical network.
To improve Redis cluster availability, the HA solution Sentinel is deployed when the cluster is set up. The solution enables the cluster to automatically implement failovers.
Construct a resource environment.
Define a resource stack template. Because a typical network is adopted, you only need to define, in the template, the ECS resources and EIP resources required for building three cloud hosts. In the example, I use "Type": "ALIYUN::ECS::InstanceGroup" in the template to define the ECS resource. For details of the resource stack template, refer to the create_instancegroup_template.py file in the attachment.
After the template is defined, edit Python code and call the ROS API based on the template to set up a resource environment. Note that public IP address allocation parameters must be added when the parameters are transferred. The following shows the Python file used to call the ROS API: create_stack_instancegroup.py:
# invoke CreateStackRequest to create InstanceGroup stack

from aliyunsdkcore.client import AcsClient
from aliyunsdkros.request.v20150901 import CreateStacksRequest
import create_instancegroup_template
import json

# define stack creation timeout(minutes)
create_timeout = 60

# define func to create stack
def create_stack(stack_name, ak_id, ak_secret, region_id):
    print('invoke CreateStackRequest to create instances...')
    client = AcsClient(ak_id, ak_secret, region_id)
    req = CreateStacksRequest.CreateStacksRequest()
    req.set_headers({'x-acs-region-id': region_id})

    template = create_instancegroup_template.generate_template(io_optimized='optimized', network_type='classic', image_id='centos6u5_64_40G_cloudinit_20160427.raw', instance_password='******', instance_min_amount=3, system_disk_category='cloud_ssd', instance_max_amount=3, allocate_public_ip='true', instance_type='ecs.n1.small')

    create_stack_body = '''
        "Name": "%s",
        "TimeoutMins": %d,
        "Template": %s
    ''' % (stack_name, create_timeout, template)
    # get response
    response = client.get_response(req)

    # deal response
    if 201 == response[0]:
        parameters = json.loads(response[-1])
        print('Create stack succeccfully!!!')
        return parameters
        print('Unexpected errors: status=%d, error=%s' % (response[0], response[-1]))
        return None

After the ROS API is called successfully, you can log in to the ROS console to view the resource stack being created.
Create an inventory and obtain a playbook.
For details, refer to the VPC environment description.
Execute the playbook to quickly deploy apps.
For details, refer to the VPC environment description.
The attachment contains all the code files for setting up a Redis cluster over a typical network. The following figure shows the resource topology of a Redis cluster set up over a classic network: