You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2021/06/14 23:07:40 UTC

[couchdb-infra-cm] branch main updated (8e8cbb5 -> b9750ee)

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb-infra-cm.git.


    from 8e8cbb5  Update .asf.yaml to avoid spamming dev@couchdb mailing list
     new b6d41b4  Finalize configuring power instances
     new b9750ee  Generate Ansible SSH config for Power instance

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 README.md        |  31 ++++++++++++++-
 production       |  17 +++++++++
 ssh.cfg          |   9 +++++
 tools/gen-config | 112 ++++++++++++++++++++++++++++++++++++++++++-------------
 4 files changed, 143 insertions(+), 26 deletions(-)

[couchdb-infra-cm] 01/02: Finalize configuring power instances

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb-infra-cm.git

commit b6d41b48497cc8ddf68f1430d141ca53f7e34e71
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Mon Jun 14 18:37:07 2021 -0400

    Finalize configuring power instances
    
    Configuration API is bit different than the regular VPC instances, so we they
    ended up a separate hard-coded config environment named "power".
---
 README.md        |  34 ++++++++++++++++-
 tools/gen-config | 112 ++++++++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 120 insertions(+), 26 deletions(-)

diff --git a/README.md b/README.md
index 421bbc1..a19e9cd 100644
--- a/README.md
+++ b/README.md
@@ -76,8 +76,20 @@ Running `./tools/gen-config`
 
 Create a `~/.couchdb-infra-cm.cfg` file that contains the following options:
 
-    [ibmcloud]
+    [ibmcloud.<environment>]
     api_key = <REDACTED>
+    api_url = https://us-south.iaas.cloud.ibm.com/v1
+    crn = crn:v1:...
+    instance_id = 123-abc...
+
+
+`<environment>` is a tag used to differentiate multiple environments. It allows
+fetching instances from more than one IBM Cloud accounts. If `api_url` is
+provided, it will be used to fetch VPC instances. By default is uses
+`"https://us-south.iaas.cloud.ibm.com/v1"`. The `crn` field will be added as a
+`CRN: <crn>` header if provided. `instance_id` is used only by the `power`
+environment. (See `Power Instances` section for more details).
+
 
 The `tools/gen-config` script can then be used to generate our `production`
 inventory and `ssh.cfg` configuration:
@@ -115,3 +127,23 @@ I.e.,
 ```bash
 $ ssh -F ssh.cfg couchdb-worker-x86-64-debian-dal-1-01
 ```
+
+
+Power Instances
+---
+
+Power isntances are configured in a special hard-coded `power` environment.
+This name is hard-coded. The `power` environemnt section, besides the
+`api_key`, should contain additional fields:
+
+```ini
+[ibmcloud.power]
+api_key = ...
+api_url = https://lon.power-iaas.cloud.ibm.com/pcloud/v1/cloud-instances/<cloud_instance_id>
+crn = ...
+instance_id = ...
+```
+
+All those might have to be obtained after the instance is provisioned from the
+team which provisioned them.
+
diff --git a/tools/gen-config b/tools/gen-config
index e1e0932..0a6d708 100755
--- a/tools/gen-config
+++ b/tools/gen-config
@@ -17,7 +17,7 @@ import yaml
 #
 ENV = {}
 
-IBM_CLOUD_URL = "https://us-south.iaas.cloud.ibm.com/v1/"
+IBM_CLOUD_URL = "https://us-south.iaas.cloud.ibm.com/v1"
 IAM_URL = "https://iam.cloud.ibm.com/identity/token"
 
 IBM_CLOUD_GENERATION = "2"
@@ -59,7 +59,10 @@ def load_environment():
             "api_generation" : parser.get(section, "api_generation",
                                           fallback=IBM_CLOUD_GENERATION),
             "api_version" : parser.get(section, "api_version",
-                                       fallback=IBM_CLOUD_VERSION)
+                                       fallback=IBM_CLOUD_VERSION),
+            "crn" : parser.get(section, "crn", fallback=None),
+            "instance_id" : parser.get(section, "instance_id",
+                                       fallback=None)
         }
 
 
@@ -78,6 +81,8 @@ def load_iam_tokens():
         body = resp.json()
         token = body["token_type"] + " " + body["access_token"]
         sess.headers["Authorization"] = token
+        for hk, hv in env_headers(env).items():
+            sess.headers[hk] = hv
         SESS[env] = sess
 
 
@@ -88,8 +93,10 @@ def init():
 
 def list_instances():
     for env in ENV:
-        yield from list_x86_instances(env)
-        #yield from list_power_instances(env)
+        if env != "power":
+            yield from list_x86_instances(env)
+        if env == "power":
+            yield from list_power_instances(env)
 
 
 def list_x86_instances(env):
@@ -107,25 +114,35 @@ def list_x86_instances(env):
 
 
 def list_power_instances(env):
-    url = ENV[env]["api_url"] + "/pvmInstances"
+    # It's really just one instance but to keep up with the shape of the rest
+    # of the code emit it as a generated item
+    if not ENV[env]["instance_id"]:
+        Exception("Power instances require an 'instance_id' setting")
+
+    instance_id = ENV[env]["instance_id"]
+    url = ENV[env]["api_url"] + "/pvm-instances/" + instance_id
     sess = SESS[env]
-    while url:
-        resp = sess.get(url, params=params(env))
-        body = resp.json()
-        for instance in body["instances"]:
-            interface_url = instance["primary_network_interface"]["href"]
-            resp = sess.get(interface_url, params=params(env))
-            instance["primary_network_interface"] = resp.json()
-            yield instance
-        url = body.get("next")
+    resp = sess.get(url, params=params(env))
+    instance = resp.json()
+    instance["name"] = instance["serverName"]
+    yield instance
+
 
 
 def params(env):
-    return {
-        "version": ENV[env]["api_version"],
-        "generation" : ENV[env]["api_generation"],
-        "limit": 100
-    }
+    params = {"limit": 100}
+    if ENV[env].get("api_version"):
+        params["version"] = ENV[env]["api_version"]
+    if ENV[env].get("api_generation"):
+        params["generation"] = ENV[env]["api_generation"]
+    return params
+
+
+def env_headers(env):
+    headers = {}
+    if ENV[env].get("crn"):
+        headers["crn"] = ENV[env]["crn"]
+    return headers
 
 
 def load_bastion(bastions, instance):
@@ -200,6 +217,38 @@ def load_ci_agent(ci_agents, instance):
     }
 
 
+def load_power_ci_agent(ci_agents, instance):
+    if instance["status"] != "ACTIVE":
+        return
+
+    name = instance["name"]
+    if name in ci_agents:
+        print(f"Duplicate ci_agent found {name}")
+        exit(2)
+
+    ci_agents[name] = {
+        "instance": {
+            "id": instance["pvmInstanceID"],
+            "name": instance["serverName"],
+            "created_at": instance["creationDate"],
+            "profile": instance["procType"],
+            "vpc" : instance["sysType"],
+            "zone": instance["placementGroup"],
+            "subnet" : None
+        },
+        "ip_addrs": {
+            "bastion": None,
+            "public": instance["addresses"][0]["externalIP"],
+            "private": instance["addresses"][0]["ip"]
+        },
+        "system": {
+            "arch": "power",
+            "num_cpu": instance["virtualCores"]["assigned"],
+            "ram": instance["memory"]
+        }
+    }
+
+
 def get_private_ip(instance):
     ip = instance["primary_network_interface"]["primary_ipv4_address"]
     if ip:
@@ -220,6 +269,9 @@ def assign_bastions(bastions, ci_agents):
         assert subnet not in subnets
         subnets[subnet] = ip_addr
     for (host, ci_agent) in ci_agents.items():
+        if ci_agent["system"]["arch"] == "power":
+            # Power systems use an external IP without bastions
+            continue
         subnet = ci_agent["instance"]["subnet"]
         assert subnet in subnets
         ci_agent["ip_addrs"]["bastion"] = subnets[subnet]
@@ -273,12 +325,20 @@ def write_ssh_cfg(filename, bastions, ci_agents):
             entry = bastion_tmpl.format(**args)
             handle.write(entry)
         for host, info in sorted(ci_agents.items()):
-            args = {
-                "host": host,
-                "ip_addr": info["ip_addrs"]["private"],
-                "bastion_ip": info["ip_addrs"]["bastion"]
-            }
-            entry = ci_agent_tmpl.format(**args)
+            if info["system"]["arch"] == "power":
+                # Power systems use an external IP directly
+                args = {
+                    "host": host,
+                    "ip_addr": info["ip_addrs"]["public"]
+                }
+                entry = bastion_tmpl.format(**args)
+            else:
+                args = {
+                    "host": host,
+                    "ip_addr": info["ip_addrs"]["private"],
+                    "bastion_ip": info["ip_addrs"]["bastion"]
+                }
+                entry = ci_agent_tmpl.format(**args)
             handle.write(entry)
 
 
@@ -314,6 +374,8 @@ def main():
             load_bastion(bastions, instance)
         elif instance["name"].startswith("couchdb-worker"):
             load_ci_agent(ci_agents, instance)
+        elif instance["name"].startswith("couchdb-ci"):
+            load_power_ci_agent(ci_agents, instance)
 
     assign_bastions(bastions, ci_agents)
 

[couchdb-infra-cm] 02/02: Generate Ansible SSH config for Power instance

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb-infra-cm.git

commit b9750eef881100e92d9ccbf6cf3aa52192756afa
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Mon Jun 14 19:04:13 2021 -0400

    Generate Ansible SSH config for Power instance
---
 README.md  |  9 +++------
 production | 17 +++++++++++++++++
 ssh.cfg    |  9 +++++++++
 3 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md
index a19e9cd..11719a2 100644
--- a/README.md
+++ b/README.md
@@ -132,9 +132,9 @@ $ ssh -F ssh.cfg couchdb-worker-x86-64-debian-dal-1-01
 Power Instances
 ---
 
-Power isntances are configured in a special hard-coded `power` environment.
-This name is hard-coded. The `power` environemnt section, besides the
-`api_key`, should contain additional fields:
+Power isntances are configured in a special hard-coded `power` environment. The
+`power` environemnt section, besides the `api_key`, should contain additional
+required fields:
 
 ```ini
 [ibmcloud.power]
@@ -144,6 +144,3 @@ crn = ...
 instance_id = ...
 ```
 
-All those might have to be obtained after the instance is provisioned from the
-team which provisioned them.
-
diff --git a/production b/production
index 896ab1c..01109fd 100644
--- a/production
+++ b/production
@@ -20,6 +20,23 @@ all:
             ram: 4
     ci_agents:
       hosts:
+        couchdb-ci:
+          instance:
+            created_at: '2021-06-08T17:10:52.000Z'
+            id: 95088258-0fa4-4f3e-af56-abe57d647780
+            name: couchdb-ci
+            profile: shared
+            subnet: null
+            vpc: s922
+            zone: none
+          ip_addrs:
+            bastion: null
+            private: 192.168.150.155
+            public: 158.175.161.155
+          system:
+            arch: power
+            num_cpu: 2
+            ram: 16
         couchdb-worker-x86-64-debian-dal-1-01:
           instance:
             created_at: '2020-12-04T17:37:42Z'
diff --git a/ssh.cfg b/ssh.cfg
index 3a596c5..6c451d9 100644
--- a/ssh.cfg
+++ b/ssh.cfg
@@ -7,6 +7,15 @@ Host couchdb-bastion-x86-64-debian-dal-1-01
   ControlPath /tmp/ansible-%r@%h:%p
   ControlPersist 30m
 
+Host couchdb-ci
+  Hostname 158.175.161.155
+  User root
+  ForwardAgent yes
+  StrictHostKeyChecking no
+  ControlMaster auto
+  ControlPath /tmp/ansible-%r@%h:%p
+  ControlPersist 30m
+
 Host couchdb-worker-x86-64-debian-dal-1-01
   Hostname 10.240.0.16
   User root