Atšķirības starp "Hostnet OpenStack Cloud Network API" versijām

No ''Hostnet Wiki''
Pārlēkt uz: navigācija, meklēt
(Jauna lapa: Example with using curl. Once you have these pieces of information, you can pass them into the SDK by replacing {username}, {password} and {projectID} with your info: {username}, {p...)
 
91. rindiņa: 91. rindiņa:
 
}
 
}
 
</source>
 
</source>
 +
 +
Create subnet in network:
 +
<syntaxhighlight lang=bash>
 +
curl -s $NET_ENDPOINT/v2.0/subnets \
 +
  -X POST \
 +
  -H "X-Auth-Token: $OS_TOKEN" \
 +
  -H "Content-Type: application/json" \
 +
  -d '
 +
{ "subnet": {
 +
    "network_id": "90f1f881-a17d-49e6-a948-d9ec16d3f60d",
 +
    "ip_version": 4,
 +
    "cidr": "192.168.199.0/24"
 +
  }
 +
}' | python -m json.tool
 +
</syntaxhighlight>
 +
 +
Response:
 +
<source lang="json">
 +
{
 +
    "subnet": {
 +
        "allocation_pools": [
 +
            {
 +
                "end": "192.168.199.254",
 +
                "start": "192.168.199.2"
 +
            }
 +
        ],
 +
        "cidr": "192.168.199.0/24",
 +
        "created_at": "2017-06-06T15:16:09Z",
 +
        "description": "",
 +
        "dns_nameservers": [],
 +
        "enable_dhcp": true,
 +
        "gateway_ip": "192.168.199.1",
 +
        "host_routes": [],
 +
        "id": "3d4e0fc2-74f5-4abb-94ee-a25ad41518d1",
 +
        "ip_version": 4,
 +
        "ipv6_address_mode": null,
 +
        "ipv6_ra_mode": null,
 +
        "name": "",
 +
        "network_id": "90f1f881-a17d-49e6-a948-d9ec16d3f60d",
 +
        "project_id": "86320c4cde114196a211b49d3ba9c5f3",
 +
        "revision_number": 2,
 +
        "service_types": [],
 +
        "subnetpool_id": null,
 +
        "tenant_id": "86320c4cde114196a211b49d3ba9c5f3",
 +
        "updated_at": "2017-06-06T15:16:09Z"
 +
    }
 +
}
 +
</source>
 +
 +
[[Category:Hostnet OpenStack Cloud]]

Versija, kas saglabāta 2017. gada 6. jūnijs, plkst. 15.18

Example with using curl.

Once you have these pieces of information, you can pass them into the SDK by replacing {username}, {password} and {projectID} with your info:

{username}, {password} below are placeholders, do not enclose '{}' when you replace them with actual credentials.

curl -i \
  -H "Content-Type: application/json" \
  -d '
{ "auth": {
    "identity": {
      "methods": [
        "password"
      ],
      "password": {
        "user": {
          "name": "{username}",
          "domain": {
            "id": "default"
          },
          "password": "{password}"
        }
      }
    },
    "scope": {
      "project": {
        "id": "{projectID}"
      }
    }
  }
}' \
  https://identity.api.cloud.hostnet.lv/v3/auth/tokens
  1. From the resulting, set environment variable as X-Subject-Token value:
export OS_TOKEN="{X-Subject-Token}"
  1. Get network service endpoints:
curl -s -X GET https://identity.api.cloud.hostnet.lv/v3/auth/catalog \
  -H "X-Auth-Token: $OS_TOKEN" | python -m json.tool

Or take endpoint URL from Hostnet OpenStack Cloud API Endpoints

# Set env variable for public compute, image and network endpoints:
export NET_ENDPOINT="{networkURL}"

Create network:

curl -s $NET_ENDPOINT/v2.0/networks \
  -X POST \
  -H "X-Auth-Token: $OS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "network": {"name": "MyNewNetwork"}}' | python -m json.tool

Response:

{
    "network": {
        "admin_state_up": true,
        "availability_zone_hints": [],
        "availability_zones": [],
        "created_at": "2017-06-06T15:10:36Z",
        "description": "",
        "dns_domain": "",
        "id": "90f1f881-a17d-49e6-a948-d9ec16d3f60d",
        "ipv4_address_scope": null,
        "ipv6_address_scope": null,
        "mtu": 1450,
        "name": "MyNewNetwork",
        "port_security_enabled": true,
        "project_id": "86320c4cde114196a211b49d3ba9c5f3",
        "revision_number": 3,
        "router:external": false,
        "shared": false,
        "status": "ACTIVE",
        "subnets": [],
        "tags": [],
        "tenant_id": "86320c4cde114196a211b49d3ba9c5f3",
        "updated_at": "2017-06-06T15:10:36Z"
    }
}

Create subnet in network:

curl -s $NET_ENDPOINT/v2.0/subnets \
  -X POST \
  -H "X-Auth-Token: $OS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '
{ "subnet": {
    "network_id": "90f1f881-a17d-49e6-a948-d9ec16d3f60d",
    "ip_version": 4,
    "cidr": "192.168.199.0/24"
  }
}' | python -m json.tool

Response:

{
    "subnet": {
        "allocation_pools": [
            {
                "end": "192.168.199.254",
                "start": "192.168.199.2"
            }
        ],
        "cidr": "192.168.199.0/24",
        "created_at": "2017-06-06T15:16:09Z",
        "description": "",
        "dns_nameservers": [],
        "enable_dhcp": true,
        "gateway_ip": "192.168.199.1",
        "host_routes": [],
        "id": "3d4e0fc2-74f5-4abb-94ee-a25ad41518d1",
        "ip_version": 4,
        "ipv6_address_mode": null,
        "ipv6_ra_mode": null,
        "name": "",
        "network_id": "90f1f881-a17d-49e6-a948-d9ec16d3f60d",
        "project_id": "86320c4cde114196a211b49d3ba9c5f3",
        "revision_number": 2,
        "service_types": [],
        "subnetpool_id": null,
        "tenant_id": "86320c4cde114196a211b49d3ba9c5f3",
        "updated_at": "2017-06-06T15:16:09Z"
    }
}