Skip to content

Commit

Permalink
Merge pull request hitachienergy#1045 from seriva/fix/wilk-fixes
Browse files Browse the repository at this point in the history
- Added missing template for disk_size_gb storage_os_disk (hitachienergy#1043)
- Add ability to add subsciptionId to sp.yml on Azure (hitachienergy#1044)
- Added Epicli binary and python decencies/components.
- Updated documentation about sp.yml to show usage of " for values that have YAML schema characters.
  • Loading branch information
seriva committed Mar 23, 2020
2 parents 9122a6c + 7f67cce commit 739b782
Show file tree
Hide file tree
Showing 7 changed files with 469 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG-0.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
- [#987](https://github.com/epiphany-platform/epiphany/issues/987) - Add verbosity levels for Terraform and Ansible
- [#656](https://github.com/epiphany-platform/epiphany/issues/656) - Add logrotation to kafka by size
- [#1016](https://github.com/epiphany-platform/epiphany/issues/1016) - Disable verify , backup and recovery as they are not fully implemented
- [#1044](https://github.com/epiphany-platform/epiphany/issues/1044) - Add ability to add subscriptionId to sp.yml on Azure

### Fixed

- [#624](https://github.com/epiphany-platform/epiphany/issues/624) - Don't run epicli as root in container
- [#966](https://github.com/epiphany-platform/epiphany/issues/966) - Ubuntu builds get stuck on 'Create epirepo repository' task waiting for user input in offline mode
- [#1043](https://github.com/epiphany-platform/epiphany/issues/1043) - For vm template on Azure disk_size_gb is missing in storage_os_disk
20 changes: 14 additions & 6 deletions core/src/epicli/cli/engine/terraform/TerraformRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,37 @@ def azure_login(self):
subscription = apiproxy.login_account()
apiproxy.set_active_subscribtion(subscription['id'])
else:
# Service principle
# Service principal
sp_file = os.path.join(get_terraform_path(self.cluster_model.specification.name), SP_FILE_NAME)
if not os.path.exists(sp_file):
# If no service principle exists or is defined we created one and for that we need to login using an account
# If no service principal exists or is defined we created one and for that we need to login using an account
subscription = apiproxy.login_account()
apiproxy.set_active_subscribtion(subscription['id'])

# Create the service principle
# Create the service principal, for now we use the default subscription
self.logger.info('Creating service principal')
cluster_name = self.cluster_model.specification.name.lower()
cluster_prefix = self.cluster_model.specification.prefix.lower()
resource_group_name = resource_name(cluster_prefix, cluster_name, 'rg')
sp = apiproxy.create_sp(resource_group_name, subscription['id'])
sp['subscriptionId'] = subscription['id']
save_sp(sp, self.cluster_model.specification.name)
else:
self.logger.info('Using service principal from file')
sp = load_yaml_file(sp_file)

# Login as SP.
# Login as SP and get the default subscription.
subscription = apiproxy.login_sp(sp)

# Setup environment variables for Terraform when working with Azure and service principal.
self.new_env['ARM_SUBSCRIPTION_ID'] = subscription[0]['id']
if 'subscriptionId' in sp:
# Set active subscription if sp contains it.
apiproxy.set_active_subscribtion(sp['subscriptionId'])
self.new_env['ARM_SUBSCRIPTION_ID'] = sp['subscriptionId']
else:
# No subscriptionId in sp.yml so use the default one from Azure SP login.
self.new_env['ARM_SUBSCRIPTION_ID'] = subscription[0]['id']

# Set other environment variables for Terraform when working with Azure and service principal.
self.new_env['ARM_TENANT_ID'] = sp['tenant']
self.new_env['ARM_CLIENT_ID'] = sp['appId']
self.new_env['ARM_CLIENT_SECRET'] = sp['password']
191 changes: 189 additions & 2 deletions core/src/epicli/cli/licenses.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ resource "azurerm_virtual_machine" "{{ specification.name }}" {
name = "{{ specification.name }}-os-disk"
caching = "{{ specification.storage_os_disk.caching }}"
create_option = "{{ specification.storage_os_disk.create_option }}"
disk_size_gb = "{{ specification.storage_os_disk.disk_size_gb }}"
{%- if specification.storage_os_disk.managed != true %}
managed_disk_type = "{{ specification.storage_os_disk.managed_disk_type | lower }}"
{%- else %}
Expand Down
28 changes: 26 additions & 2 deletions core/src/epicli/gen-licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

def get_dependencies_from_requirements() -> Set[str]:
req = []
with open('requirements.txt') as req_file:
with open('.devcontainer/requirements.txt') as req_file:
for line in req_file:
req.append(line.split("==")[0])
return req
Expand Down Expand Up @@ -56,8 +56,10 @@ def get_pkg_data(pkgname: str, pat:str) -> str:
split = home.split('/')
repo = split[len(split)-1]
user = split[len(split)-2]
license_data = json.loads(makeRequest('https://api.github.com/repos/' + user + '/' + repo + '/license', pat).read().decode())
license_url = 'https://api.github.com/repos/' + user + '/' + repo + '/license'
license_data = json.loads(makeRequest(license_url, pat).read().decode())
pkg_data['License'] = license_data['license']['name']
pkg_data['License URL'] = license_url
pkg_data['License repo'] = makeRequest(license_data['download_url'], pat).read().decode()
if license_data['license']['key'] != 'other':
license_text = json.loads(makeRequest(license_data['license']['url'], pat).read().decode())
Expand All @@ -80,6 +82,7 @@ def _main() -> None:
if data != None:
all_deps_data.append(data)

# Write licenses 'cli/licenses.py'
licenses_content = """
# This is a generated file so don`t change this manually.
# To re-generate run 'python gen-licenses.py' from the project root.
Expand All @@ -90,5 +93,26 @@ def _main() -> None:
with open(path, 'w') as file:
file.write(licenses_content)

# Write components table to be pasted into 'COMPONENTS.md'
dependancies_content = """
| Component | Version | Repo/Website | License |
| --------- | ------- | ------------ | ------- |
"""
for dep in all_deps_data:
dep_name = dep['Name']
dep_version = dep['Version']
dep_website = dep['Home-page']
dep_license = dep['License']
if 'License URL' in dep:
dep_license_url = dep['License URL']
dep_line = f'| {dep_name} | {dep_version} | {dep_website} | [{dep_license}]({dep_license_url}) |\n'
else:
dep_line = f'| {dep_name} | {dep_version} | {dep_website} | {dep_license} |\n'
dependancies_content = dependancies_content + dep_line

path = os.path.join(os.path.dirname(__file__), 'DEPENDENCIES.md')
with open(path, 'w') as file:
file.write(dependancies_content)

if __name__ == '__main__':
_main()
Loading

0 comments on commit 739b782

Please sign in to comment.