-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v2.0.3 - support for dedicated hosts and scale storage (#10)
* v2.0.3 - support for dedicated hosts and scale storage
- Loading branch information
1 parent
90c52c5
commit a7f418f
Showing
35 changed files
with
2,341 additions
and
497 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import requests | ||
import json | ||
import argparse | ||
|
||
TOKEN_URL = "https://iam.cloud.ibm.com/identity/token" | ||
BASE_CLOUD_URL = "https://{region}.iaas.cloud.ibm.com" | ||
|
||
|
||
def get_access_token(api_key): | ||
headers = { | ||
'content-type': 'application/x-www-form-urlencoded', | ||
'accept': 'application/json', | ||
} | ||
body = { | ||
"grant_type": "urn:ibm:params:oauth:grant-type:apikey", | ||
"apikey": api_key | ||
} | ||
try: | ||
res_token = requests.post(url=TOKEN_URL, headers=headers, data=body) | ||
res_token.raise_for_status() | ||
return json.loads(res_token.content) | ||
except (requests.ConnectionError, requests.HTTPError) as err: | ||
raise err | ||
|
||
|
||
def delete_security_group_rule(region, access_token, security_group_id, security_group_rule_id): | ||
url = f"{BASE_CLOUD_URL.format(region=region)}/v1/security_groups/{security_group_id}/rules/{security_group_rule_id}" | ||
params = ( | ||
('version', '2021-12-14'), | ||
('generation', '2'), | ||
) | ||
headers = { | ||
"Authorization": f"Bearer {access_token}" | ||
} | ||
response = requests.delete(url=url, params=params, headers=headers) | ||
response.raise_for_status() | ||
return response.status_code | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description='Optional app description') | ||
parser.add_argument('--region', type=str, dest='region', | ||
help='ibmcloud region', required=True) | ||
parser.add_argument('--apikey', type=str, dest='apikey', | ||
help='ibmcloud apikey', required=True) | ||
parser.add_argument('--sg_id', type=str, dest='sg_id', | ||
help='security group id', required=True) | ||
parser.add_argument('--sg_rule_id', type=str, dest='sg_rule_id', | ||
help="security_group_rule_id", required=True) | ||
args = parser.parse_args() | ||
|
||
res = get_access_token(args.apikey) | ||
delete_security_group_rule(region=args.region, access_token=res.get("access_token"), | ||
security_group_id=args.sg_id, | ||
security_group_rule_id=args.sg_rule_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
################################################### | ||
# Copyright (C) IBM Corp. 2022 All Rights Reserved. | ||
# Licensed under the Apache License v2.0 | ||
################################################### | ||
/* | ||
Creates TCP specific security group rule. | ||
*/ | ||
terraform { | ||
required_providers { | ||
ibm = { | ||
source = "IBM-Cloud/ibm" | ||
} | ||
} | ||
} | ||
|
||
variable "security_group_id" {} | ||
variable "sg_direction" {} | ||
variable "remote_ip_addr" {} | ||
|
||
resource "ibm_is_security_group_rule" "itself" { | ||
count = length(var.remote_ip_addr) | ||
group = var.security_group_id | ||
direction = var.sg_direction | ||
remote = var.remote_ip_addr[count.index] | ||
|
||
tcp { | ||
port_min = 22 | ||
port_max = 22 | ||
} | ||
} | ||
|
||
output "security_rule_id" { | ||
value = ibm_is_security_group_rule.itself[*].rule_id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
################################################### | ||
# Copyright (C) IBM Corp. 2022 All Rights Reserved. | ||
# Licensed under the Apache License v2.0 | ||
################################################### | ||
|
||
variable "login_ip" {} | ||
variable "bastion_ssh_private_key" {} | ||
variable "compute_instances_by_ip" {} | ||
variable "scale_mount_point" {} | ||
|
||
|
||
locals { | ||
cloud_playbook_path = format("%s/%s", "${path.module}/ansible_playbook/", "add_permission.yml") | ||
inventory_file_path = format("%s", "${path.module}/ansible_playbook/inventory_file") | ||
compute_instances_ip = join(",",jsondecode(var.compute_instances_by_ip)) | ||
vsi_ip = format("%s\n%s", "[add_permission]", replace(local.compute_instances_ip, ",", "\n" )) | ||
} | ||
|
||
resource "local_file" "inventory" { | ||
content = local.vsi_ip | ||
filename = "${path.module}/ansible_playbook/inventory_file" | ||
} | ||
|
||
|
||
resource "null_resource" "call_add_permission_mountpoint_playbook" { | ||
connection { | ||
bastion_host = var.login_ip | ||
user = "root" | ||
host = "0.0.0.0" | ||
private_key = file(var.bastion_ssh_private_key) | ||
} | ||
|
||
provisioner "ansible" { | ||
plays { | ||
playbook { | ||
file_path = local.cloud_playbook_path | ||
} | ||
inventory_file = local.inventory_file_path | ||
verbose = true | ||
extra_vars = { | ||
"ansible_python_interpreter" : "/usr/bin/python3", | ||
"scale_cluster_definition_path" : local.inventory_file_path | ||
"mount_point": var.scale_mount_point | ||
"user_name": "lsfadmin" | ||
} | ||
} | ||
ansible_ssh_settings { | ||
insecure_no_strict_host_key_checking = true | ||
insecure_bastion_no_strict_host_key_checking = false | ||
connect_timeout_seconds = 90 | ||
user_known_hosts_file = "" | ||
bastion_user_known_hosts_file = "" | ||
} | ||
} | ||
depends_on = [local_file.inventory] | ||
triggers = { | ||
build = timestamp() | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
resources/scale_common/add_permission/ansible_playbook/add_permission.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
- hosts: add_permission | ||
|
||
tasks: | ||
- name: Add lsfadmin allow rights | ||
shell: chown {{ user_name }} {{ mount_point }} |
Oops, something went wrong.