Assign DNS Services

Many applications must be integrated with the DNS services provided by the platform, because their services require some DNS records to function properly. Some services may require a domain zone with multiple DNS records.

In this scenario, we will use a sample application whose resource model requires you to assign a domain zone for every new virtual private server (VPS) and optionally add a collection of DNS records to that zone.

Scenario

To assign DNS services, use a customer’s credentials to go through the following steps:

  1. Create a domain zone using the customer’s subscription.

  2. Create a VPS with a link to the domain zone.

  3. In the domain zone, create DNS records for the VPS.

  4. Bind the VPS with the DNS records.

Source Data

Collect the following data before you start provisioning application resources.

  • A customer’s admin credentials: a customer admin’s security key and secret as described in the Set Up the User’s Credentials section. Within the account, the account administrator must manage the subscribed services.

  • The APS type of the domain zone: use the platform APS type http://parallels.com/aps/types/pa/dns/zone/1.1.

  • The APS type of a generic DNS record - http://parallels.com/aps/types/pa/dns/record/1.0. For a particular record, use, for example:

  • The APS type of the service: http://aps-standard.org/samples/dns1p/vps/1.0.

    Note

    A VPS must have a relationship with the following resources whose APS IDs you must collect before provisioning a VPS:

  • APS ID of the management context that will be related with the VPS:

    GET /aps/2/resources?implementing(http://aps-standard.org/samples/dns1p/context/1.0)
    

    The response must contain only one resource of this type, since this is a singular resource in a subscription:

    HTTP/1.1 200 OK
    
    [
       { "aps": {
             "id": "156608a4-d5bf-4497-85f1-74267930cd69",
             "subscription":"93959b89-365f-46e9-b838-8bb1f445cfa3",
             /* ... */
          },
          /* ... */
       }
    ]
    
  • The APS ID of the subscription that allows an external system to create VPSes - the previous response contains it in the aps.subscription property.

Preliminary Inspection

Before you start creating a new VPS, verify whether there is a VPS with similar properties and whether the respective resource usage did not reach its limit in the subscription.

  • Get a list of all VPSes created by the application:

    GET /aps/2/resources?implementing(http://aps-standard.org/samples/dns1p/vps/1.0)
    
  • Verify that there is no VPS with a similar name to the new VPS:

    GET /aps/2/resources?implementing(http://aps-standard.org/samples/dns1p/vps/1.0),like(name,*VPS-1001*)
    
  • Verify that the vps resource usage did not reach the limit in the subscription. Use the subscription APS ID in the following request:

    GET /aps/2/resources/93959b89-365f-46e9-b838-8bb1f445cfa3/resources
    

    The following response shows that no VPSes out of the allowed 10 are used:

    HTTP/1.1 200 OK
    
    [
       {
          "id": "1000059",
          "title": "DNS - Virtual Server",
          "apsType": "http://aps-standard.org/samples/dns1p/vps/1.0",
          "usage": 0,
          "limit": 10,
          "unit": "unit"
       },
       {
          "id": "1000057",
          "title": "DNS - App REF",
          "apsId": "9c62ec36-1edf-4b23-b313-b5d5594a3fc6",
          "apsType": "http://aps-standard.org/samples/dns1p/cloud/1.0",
          "usage": 1,
          "limit": 1,
          "unit": "unit"
       },
       {
          "id": "1000058",
          "title": "DNS - Management Context",
          "apsId": "156608a4-d5bf-4497-85f1-74267930cd69",
          "apsType": "http://aps-standard.org/samples/dns1p/context/1.0",
          "usage": 1,
          "limit": 1,
          "autoprovisioning": true,
          "unit": "unit"
       }
    ]
    
  • Verify that there is no domain with the name you are going to use, for example:

    GET /aps/2/resources?implementing(http://parallels.com/aps/types/pa/dns/zone/1.1),eq(name,isv1.test)
    

Creating Resources

Create a Domain Zone

Create a domain zone isv1.test by sending the following request with properties declared in the PAHostedDomain APS type:

POST /aps/2/resources
"APS-Subscription-ID": "93959b89-365f-46e9-b838-8bb1f445cfa3"

{
   "aps": {
      "type": "http://parallels.com/aps/types/pa/dns/zone/1.1"
   },
   "name": "isv1.test",
   "hosting": {
      "aps": {
         "link": "weak",
         "id": "93959b89-365f-46e9-b838-8bb1f445cfa3"
      }
   }
}

A typical response looks as follows:

HTTP/1.1 200 OK

{
  "aps": {
    "type": "http://parallels.com/aps/types/pa/dns/zone/1.1",
    "id": "21947ac1-6509-4629-95c3-62151fd65a9d",
    "status": "aps:ready",
    "revision": 4,
    "modified": "2016-10-03T10:15:11Z",
    "subscription": "93959b89-365f-46e9-b838-8bb1f445cfa3",
    "package": {
      "id": "e86ef200-5751-4c2c-b342-e65483ede6d0",
      "href": "/aps/2/packages/e86ef200-5751-4c2c-b342-e65483ede6d0"
    }
  },
  "hosts": [
      "857afca8-cc8e-4067-b3a2-5cbb9a8e3b22"
  ]
  "name": "isv1.test",
  "nameServers": [
      "a.isv1.apsdemo.org"
  ]
  "serviceDescription": "Domain subscription isv1.test",
  "serviceName": "Domains",
  "zone": {
    "TTL": 3600,
    "adminEmail": "isv1@aps.test",
    "expire": 2419200,
    "refresh": 14400,
    "retry": 7200
  },
  "zoneId": 1,
  "account": {
    "aps": {
      "link": "strong",
      "href": "/aps/2/resources/e489cb96-e988-475a-854b-0d0a67a18aed",
      "id": "e489cb96-e988-475a-854b-0d0a67a18aed"
    }
  },
  "hosting": {
      "aps": {
         "link": "weak",
         "href": "/aps/2/resources/93959b89-365f-46e9-b838-8bb1f445cfa3",
         "id": "93959b89-365f-46e9-b838-8bb1f445cfa3"
      }
  },
  "records": {
    "aps": {
      "link": "collection",
      "href": "/aps/2/resources/21947ac1-6509-4629-95c3-62151fd65a9d/records"
    }
  },
  "subdomains": {
    "aps": {
      "link": "collection",
      "href": "/aps/2/resources/21947ac1-6509-4629-95c3-62151fd65a9d/subdomains"
    }
  }
}

Note the aps.id property; you will use it in the next step.

Create a Resource Linked to the Domain Zone

A REST request for creating a new VPS must comply with the vps type investigated earlier. You must specify the required links with the management context and the domain zone, and specify the subscription APS ID in the APS-Subscription-ID header.

POST /aps/2/resources
"APS-Subscription-ID": "c315f4a9-1e00-4458-b3e9-95de5659b3d7"

{
    "aps":{
    "type":"http://aps-standard.org/samples/dns1p/vps/1.0"
    },
    "name":"VPS-1001",
    "state":"Stopped",
    "hardware":{
        "memory": 512,
        "diskspace": 64,
        "CPU":{
         "number": 2
        }
    },
    "platform":{
      "OS":{
          "name":"CentOS",
          "version": 7
        }
    },
   "context":{
      "aps":{
         "href":"aps/2/resources/156608a4-d5bf-4497-85f1-74267930cd69",
         "id":"156608a4-d5bf-4497-85f1-74267930cd69"
      }
   },
   "domain":{
      "aps":{
         "href":"aps/2/resources/21947ac1-6509-4629-95c3-62151fd65a9d",
         "id":"21947ac1-6509-4629-95c3-62151fd65a9d"
      }
   }
}

The response must look similar to:

HTTP/1.1 200 OK

{
  "aps": {
    "type": "http://aps-standard.org/samples/dns1p/vps/1.0",
    "id": "fb205cce-6874-4493-8e05-f404a16aa5b9",
    "status": "aps:ready",
    "revision": 3,
    "modified": "2016-10-03T11:20:59Z",
    "subscription": "93959b89-365f-46e9-b838-8bb1f445cfa3",
    "package": {
      "id": "57e39966-afab-4e5a-aeb4-703def4fd955",
      "href": "/aps/2/packages/57e39966-afab-4e5a-aeb4-703def4fd955"
    }
  },
  "hardware": {
    "CPU": {
      "number": 2
    },
    "diskspace": 64,
    "memory": 512
  },
  "name": "VPS-1001",
  "platform": {
    "OS": {
      "name": "CentOS",
      "version": "7"
    }
  },
  "state": "Stopped",
  "context": {
    "aps": {
      "link": "strong",
      "href": "/aps/2/resources/156608a4-d5bf-4497-85f1-74267930cd69",
      "id": "156608a4-d5bf-4497-85f1-74267930cd69",
      "subscription": "93959b89-365f-46e9-b838-8bb1f445cfa3"
    }
  },
  "domain": {
    "aps": {
      "link": "strong",
      "href": "/aps/2/resources/21947ac1-6509-4629-95c3-62151fd65a9d",
      "id": "21947ac1-6509-4629-95c3-62151fd65a9d",
      "subscription": "93959b89-365f-46e9-b838-8bb1f445cfa3"
    }
  },
  "records": {
    "aps": {
      "link": "collection",
      "href": "/aps/2/resources/fb205cce-6874-4493-8e05-f404a16aa5b9/records"
    }
  }
}

Create a DNS Record

In the isv1.test domain zone, create an A record for the VPS:

POST /aps/2/resources
"APS-Subscription-ID": "93959b89-365f-46e9-b838-8bb1f445cfa3"

{
   "aps": {
      "type":"http://parallels.com/aps/types/pa/dns/record/a/1.0"
   },
   "zone": "isv1.test",
   "source": "vps1001.isv1.test.",
   "address" : "10.10.10.111"
}

A typical response looks as follows:

HTTP/1.1 200 OK

{
   "aps": {
      "type": "http://parallels.com/aps/types/pa/dns/record/a/1.0",
      "id": "d1d3800b-0f4f-48da-86a3-2244085cec5a",
      "status": "aps:ready",
      "revision": 4,
      "modified": "2016-10-03T11:22:24Z",
      "subscription": "93959b89-365f-46e9-b838-8bb1f445cfa3",
      "package": {
         "id": "e86ef200-5751-4c2c-b342-e65483ede6d0",
         "href": "/aps/2/packages/e86ef200-5751-4c2c-b342-e65483ede6d0"
      }
   },
   "RRState": "active",
   "TTL": 0,
   "address": "10.10.10.111",
   "data": "10.10.10.111",
   "recordId": 1,
   "source": "vps1001",
   "sourceFQN": "vps1001.isv1.test.",
   "replacedBy": {
      "aps": {
         "link": "collection",
         "href": "/aps/2/resources/d1d3800b-0f4f-48da-86a3-2244085cec5a/replacedBy"
      }
   },
   "replaces": {
      "aps": {
         "link": "collection",
         "href": "/aps/2/resources/d1d3800b-0f4f-48da-86a3-2244085cec5a/replaces"
      }
   },
   "zone": {
      "aps": {
         "link": "strong",
         "href": "/aps/2/resources/21947ac1-6509-4629-95c3-62151fd65a9d",
         "id": "21947ac1-6509-4629-95c3-62151fd65a9d",
         "subscription": "93959b89-365f-46e9-b838-8bb1f445cfa3"
      }
   }
}

Notice the aps.id property that you will use in the next step.

Conclusion

You have successfully created a resource and assigned to it two DNS resources: a domain zone and a DNS record. Now you can create more resources.

Use the REST requests described in Preliminary Inspection to find the created resources.

On completion of this scenario, you have achieved the business goal of using the DNS services provided by the platform.