|
1 | 1 | #!/usr/bin/env python |
2 | 2 |
|
3 | | - |
4 | | -# |
5 | 3 | # Copyright (c) 2015-2017 Nest Labs, Inc. |
6 | 4 | # All rights reserved. |
7 | 5 | # |
|
21 | 19 | # |
22 | 20 | # @file |
23 | 21 | # Implements generate register service cmd which is used to service provisioning |
| 22 | +# Note: "openweave-core/src/test-apps/happy/test-templates/generated" |
| 23 | +# needs to be added to PYTHONPATH |
24 | 24 |
|
25 | 25 | import json |
26 | | -import os |
27 | | -import requests |
28 | | -import shutil |
29 | | -import sys |
30 | | -import tarfile |
31 | | -import time |
32 | | - |
| 26 | +from httplib import HTTPSConnection |
33 | 27 | import grpc |
34 | 28 | from grpc.framework.interfaces.face.face import ExpirationError |
35 | | -from httplib import HTTPSConnection |
| 29 | +import time |
| 30 | +import nestlabs.gateway.v2.gateway_api_pb2 as gateway_api_pb2 |
| 31 | +import nestlabs.gateway.v2.gateway_api_pb2_grpc as gateway_api_pb2_grpc |
36 | 32 |
|
37 | 33 | options = {} |
38 | 34 | options["tier"] = None |
|
43 | 39 | def option(): |
44 | 40 | return options.copy() |
45 | 41 |
|
46 | | - |
47 | | -default_schema_branch = 'develop' |
48 | 42 | apigw_fmt = 'apigw01.weave01.iad02.{tier}.nestlabs.com' |
49 | 43 | apigw_siac_fmt = '{siac_name}.unstable.nestlabs.com' |
50 | 44 |
|
51 | | -phoenix_mirror_url = 'http://device-automation.nestlabs.com/phoenix-schema/python' |
52 | | - |
53 | | -python_local = os.path.expanduser('~/.python-local') |
54 | | -phoenix_cache = os.path.join(python_local, 'phoenix') |
55 | | - |
56 | | - |
57 | | -def get_phoenix_hash(branch): |
58 | | - url = '{}/{}/__latest__'.format(phoenix_mirror_url, branch) |
59 | | - response = requests.get(url) |
60 | | - response.raise_for_status() |
61 | | - return response.text.rstrip() |
62 | | - |
63 | | -_phoenix_proto_cache = dict() |
64 | | - |
65 | | - |
66 | | -def get_phoenix_proto_dir(branch): |
67 | | - if branch in _phoenix_proto_cache: |
68 | | - return _phoenix_proto_cache.get(branch) |
69 | | - |
70 | | - latest_hash = get_phoenix_hash(branch) |
71 | | - tarball_dir = os.path.join(phoenix_cache, branch) |
72 | | - tarball_path = os.path.join(tarball_dir, '{}.tar.gz'.format(latest_hash)) |
73 | | - extract_dir = os.path.join(tarball_dir, latest_hash) |
74 | | - phoenix_dir = os.path.join(extract_dir, 'phoenix') |
75 | | - if not os.path.exists(extract_dir): |
76 | | - os.makedirs(extract_dir) |
77 | | - |
78 | | - if not os.path.exists(tarball_path): |
79 | | - url = '{}/{}/{}.tar.gz'.format(phoenix_mirror_url, branch, latest_hash) |
80 | | - response = requests.get(url, stream=True) |
81 | | - response.raise_for_status() |
82 | | - with open(tarball_path, 'wb') as tarball_file: |
83 | | - print type(response.raw) |
84 | | - shutil.copyfileobj(response.raw, tarball_file) |
85 | | - |
86 | | - if not os.path.exists(phoenix_dir): |
87 | | - with tarfile.open(tarball_path) as tar: |
88 | | - for member in tar.getmembers(): |
89 | | - if not member.isdir(): |
90 | | - tar.extract(member.path, path=extract_dir) |
91 | | - |
92 | | - _phoenix_proto_cache[branch] = phoenix_dir |
93 | | - return phoenix_dir |
94 | | - |
95 | | - |
96 | | -def use_phoenix_schema(branch): |
97 | | - sys.path.insert(0, get_phoenix_proto_dir(branch)) |
98 | | - |
99 | 45 |
|
100 | 46 | class ServiceClient(object): |
| 47 | + """ |
| 48 | + Gets basic account information from Service |
| 49 | + Args: |
| 50 | + tier (str): tier of the service |
| 51 | + username (str): Account email/username |
| 52 | + password (str): Account password |
| 53 | + token (str): Account access token |
| 54 | + """ |
101 | 55 |
|
102 | | - def __init__(self, tier, username, password, token, |
103 | | - schema_branch=default_schema_branch): |
| 56 | + def __init__(self, tier, username, password, token): |
104 | 57 | self.tier = tier |
105 | 58 | self.username = username |
106 | 59 | self.password = password |
107 | 60 |
|
108 | | - use_phoenix_schema(schema_branch) |
109 | | - import nestlabs.gateway.v2.gateway_api_pb2 as gateway_api_pb2 |
110 | | - import nestlabs.gateway.v2.gateway_api_pb2_grpc as gateway_api_pb2_grpc |
111 | 61 | self.gateway_api_pb2 = gateway_api_pb2 |
112 | 62 | self.gateway_api_pb2_grpc = gateway_api_pb2_grpc |
113 | 63 |
|
|
0 commit comments