Skip to content

Commit

Permalink
Merge pull request #56 from themaxbelov/instance-only
Browse files Browse the repository at this point in the history
Support creating instance only
  • Loading branch information
ToxicWar authored Apr 25, 2018
2 parents 0463007 + e8c18ce commit 0e1e549
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ pip install apsconnectcli
### Python releases before 2.7.9 (like CentOS 7.2)
CentOS 7.2 provide outdated Python 2.7.5 release, so you'll need an additional step to make it work properly:

1. First install backport of ssl.match_hostname()
1. Update the setuptools package
```
pip install -U setuptools
```
1. Install backport of ssl.match_hostname()
```
pip install -U backports.ssl-match-hostname
```
Expand All @@ -27,11 +31,6 @@ CentOS 7.2 provide outdated Python 2.7.5 release, so you'll need an additional s
pip install -U apsconnectcli
```

If you get an error message mentioning `invalid environment marker` upgrade the `setuptools` package before installing apsconnect-cli:
```
pip install -U apsconnectcli
```

### How to setup a kubernetes cluster
[Read a good step-by-step instruction by JetStack team](https://github.com/jetstack/kube-lego/tree/master/examples/nginx)

Expand Down Expand Up @@ -104,8 +103,8 @@ Connector backend - https://xxx

```
apsconnect install-frontend --source SOURCE --oauth-key OAUTH_KEY --oauth-secret OAUTH_SECRET \
--backend-url BACKEND_URL [--settings-file SETTINGS_FILE] \
[--network = proxy ] [--hub-id HUB_ID]
--backend-url BACKEND_URL [--settings SETTINGS_FILE] \
[--network = proxy] [--hub-id HUB_ID] [--instance-only = false]
```
```
⇒ apsconnect install-frontend package.aps.zip application-3-v1-687fd3e99eb 639a0c2bf3ab461aaf74a5c622d1fa34 --backend-url http://127.197.49.26/
Expand All @@ -117,6 +116,14 @@ Service template "connector" created with id=16 [ok]
Limits for Service template "16" are applied [ok]
```

The `--settings` parameter is normally not required, it should point to a file containing data in JSON format that will be mixed in to application instance create API request.
Can be used to provide custom application instance global settings.

Use `--instance-only` flag if you wish to skip resource types and service templates creation.

**WARNING** Due to limitations of Operations Automation API importing large (more than a few megabytes) packages from local source might fail.
Use HTTP link as source for such packages.

## Misc

#### Check utility version
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8.4
1.8.5
7 changes: 5 additions & 2 deletions apsconnectcli/apsconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def install_backend(self, name, image, config_file, hostname, healthcheck_path=N
print("[Success]")

def install_frontend(self, source, oauth_key, oauth_secret, backend_url, settings=None,
network='proxy', hub_id=None):
network='proxy', hub_id=None, instance_only=False):
""" Install connector-frontend in Odin Automation Hub, --source can be http(s):// or
filepath"""

Expand All @@ -270,7 +270,7 @@ def install_frontend(self, source, oauth_key, oauth_secret, backend_url, setting
settings = json.load(open(settings)) if settings else {}
hub = Hub()

package = Package(source)
package = Package(source, instance_only=instance_only)
print("Importing connector {} {}-{}".format(package.connector_id,
package.version,
package.release))
Expand All @@ -283,6 +283,9 @@ def install_frontend(self, source, oauth_key, oauth_secret, backend_url, setting
settings, network, hub_id)
print("Application instance creation completed [ok]")

if instance_only:
return

# Create resource types
resource_types = hub.create_rts(package, application_id, instance_uuid)
print("Resource types creation completed [ok]")
Expand Down
2 changes: 1 addition & 1 deletion apsconnectcli/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def create_instance(self, package, oauth_key, oauth_secret, backend_url, setting
"Error: {}".format(package.connector_id, r.status_code, err))
sys.exit(1)

return r.json()['app']['aps']['id']
return r.json()['app']['aps']['id'] if not package.instance_only else None

def _create_core_rts(self, package, app_id, instance_uuid):
rt_ids = {}
Expand Down
16 changes: 12 additions & 4 deletions apsconnectcli/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,24 @@ class Package(object):
tempdir = None
filename = None
path = None
instance_only = False

package_body = None
meta_path = None
tenant_schema_path = None
app_schema_path = None
user_service = None
user_service = False

connector_id = None
connector_name = None
version = None
release = None

app_properties = None
tenant_properties = None
app_properties = {}
tenant_properties = {}

def __init__(self, source):
def __init__(self, source, instance_only=False):
self.instance_only = instance_only
with TemporaryDirectory() as tempdir:
self.source = source
self.tempdir = tempdir
Expand Down Expand Up @@ -103,6 +105,9 @@ def is_http(self):
def _extract_files(self):
with zipfile.ZipFile(self.path) as zip_ref:
self.meta_path = zip_ref.extract('APP-META.xml', path=self.tempdir)
if self.instance_only:
return

self.tenant_schema_path = zip_ref.extract('schemas/tenant.schema', self.tempdir)
self.app_schema_path = zip_ref.extract('schemas/app.schema', self.tempdir)

Expand All @@ -127,5 +132,8 @@ def _parse_metadata(self):
url_path = urlparse(self.connector_id).path
self.connector_name = os.path.split(url_path)[-1]

if self.instance_only:
return

self.app_properties = Package._get_properties(self.app_schema_path)
self.tenant_properties = Package._get_properties(self.tenant_schema_path)

0 comments on commit 0e1e549

Please sign in to comment.