forked from redhat-performance/quads
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MockInventoryDriver.py QuadsNativeInventoryDriver.py functions #53
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f558ff9
MockInventoryDriver.py QuadsNativeInventoryDriver.py functions
79e00f3
Inventory functions in libquads.py to use inventory_service
c6114f7
Added hilapi.py
7b20e3a
Cleaned quads.py from unnecessary sys.path.append's
125d2eb
Bug in load_data, write_data for Mock, QuadsNative
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
url: http://127.0.0.1:5000 # the address of HIL server | ||
|
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,107 @@ | ||
# this is a library to conveniently do REST calls to HIL server | ||
|
||
import requests | ||
import sys | ||
import yaml | ||
|
||
def error_check(response): | ||
if response.status_code < 200 or response.status_code >= 300: | ||
sys.exit(response.text) | ||
else: | ||
print(response.text) | ||
return response.json() | ||
|
||
def make_url(*args): | ||
with open("hil.yml", 'r') as stream: | ||
try: | ||
data = yaml.load(stream) | ||
except yaml.YAMLError: | ||
sys.exit("Can't parse hil.yml file.") | ||
url = data.get('url') | ||
if url is None: | ||
sys.exit("Hil url is not specified in hil.yml.") | ||
for arg in args: | ||
url += '/' + arg | ||
return url | ||
|
||
def do_put(url, data={}): | ||
error_check(requests.put(url, data=json.dumps(data))) | ||
|
||
def do_post(url, data={}): | ||
error_check(requests.post(url, data=json.dumps(data))) | ||
|
||
def do_get(url, params=None): | ||
return error_check(requests.get(url, params=params)) | ||
|
||
def do_delete(url): | ||
error_check(requests.delete(url)) | ||
|
||
def network_create_simple(network, project): | ||
if project is None: | ||
project = network | ||
url = make_url('network', network) | ||
do_put(url, data={'owner': project, | ||
'access': project, | ||
'net_id': ""}) | ||
|
||
def network_delete(network): | ||
url = make_url('network', network) | ||
do_delete(url) | ||
|
||
def list_projects(): | ||
url = make_url('projects') | ||
return do_get(url) | ||
|
||
def project_create(project): | ||
url = make_url('project', project) | ||
do_put(url) | ||
|
||
def project_delete(project): | ||
url = make_url('project', project) | ||
do_delete(url) | ||
|
||
def project_connect_node(project, node): | ||
url = make_url('project', project, 'connect_node') | ||
do_post(url, data={'node': node}) | ||
|
||
def project_detach_node(project, node): | ||
url = make_url('project', project, 'detach_node') | ||
do_post(url, data={'node': node}) | ||
|
||
def node_connect_network(node, nic, network, channel='null'): | ||
# use default value nic='nic' | ||
url = make_url('node', node, 'nic', nic, 'connect_network') | ||
do_post(url, data={'network': network, | ||
'channel': channel}) | ||
|
||
def node_detach_network(node, nic, network): | ||
# use default value nic='nic' | ||
url = make_url('node', node, 'nic', nic, 'detach_network') | ||
do_post(url, data={'network': network}) | ||
|
||
def list_nodes(is_free='all'): | ||
if is_free not in ('all', 'free'): | ||
sys.exit("list_nodes should have 'all' or 'free'") | ||
url = make_url('nodes', is_free) | ||
return do_get(url) | ||
|
||
def list_project_nodes(project): | ||
url = make_url('project', project, 'nodes') | ||
return do_get(url) | ||
|
||
def list_project_networks(project): | ||
url = make_url('project', project, 'networks') | ||
return do_get(url) | ||
|
||
def list_networks(): | ||
url = make_url('networks') | ||
return do_get(url) | ||
|
||
def show_network(network): | ||
url = make_url('network', network) | ||
return do_get(url) | ||
|
||
def show_node(node): | ||
url = make_url('node', node) | ||
return do_get(url) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
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,2 @@ | ||
url: http://127.0.0.1:5000 # the address of HIL server | ||
|
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,107 @@ | ||
# this is a library to conveniently do REST calls to HIL server | ||
|
||
import requests | ||
import sys | ||
import yaml | ||
|
||
def error_check(response): | ||
if response.status_code < 200 or response.status_code >= 300: | ||
sys.exit(response.text) | ||
else: | ||
print(response.text) | ||
return response.json() | ||
|
||
def make_url(*args): | ||
with open("hil.yml", 'r') as stream: | ||
try: | ||
data = yaml.load(stream) | ||
except yaml.YAMLError: | ||
sys.exit("Can't parse hil.yml file.") | ||
url = data.get('url') | ||
if url is None: | ||
sys.exit("Hil url is not specified in hil.yml.") | ||
for arg in args: | ||
url += '/' + arg | ||
return url | ||
|
||
def do_put(url, data={}): | ||
error_check(requests.put(url, data=json.dumps(data))) | ||
|
||
def do_post(url, data={}): | ||
error_check(requests.post(url, data=json.dumps(data))) | ||
|
||
def do_get(url, params=None): | ||
return error_check(requests.get(url, params=params)) | ||
|
||
def do_delete(url): | ||
error_check(requests.delete(url)) | ||
|
||
def network_create_simple(network, project): | ||
if project is None: | ||
project = network | ||
url = make_url('network', network) | ||
do_put(url, data={'owner': project, | ||
'access': project, | ||
'net_id': ""}) | ||
|
||
def network_delete(network): | ||
url = make_url('network', network) | ||
do_delete(url) | ||
|
||
def list_projects(): | ||
url = make_url('projects') | ||
return do_get(url) | ||
|
||
def project_create(project): | ||
url = make_url('project', project) | ||
do_put(url) | ||
|
||
def project_delete(project): | ||
url = make_url('project', project) | ||
do_delete(url) | ||
|
||
def project_connect_node(project, node): | ||
url = make_url('project', project, 'connect_node') | ||
do_post(url, data={'node': node}) | ||
|
||
def project_detach_node(project, node): | ||
url = make_url('project', project, 'detach_node') | ||
do_post(url, data={'node': node}) | ||
|
||
def node_connect_network(node, nic, network, channel='null'): | ||
# use default value nic='nic' | ||
url = make_url('node', node, 'nic', nic, 'connect_network') | ||
do_post(url, data={'network': network, | ||
'channel': channel}) | ||
|
||
def node_detach_network(node, nic, network): | ||
# use default value nic='nic' | ||
url = make_url('node', node, 'nic', nic, 'detach_network') | ||
do_post(url, data={'network': network}) | ||
|
||
def list_nodes(is_free='all'): | ||
if is_free not in ('all', 'free'): | ||
sys.exit("list_nodes should have 'all' or 'free'") | ||
url = make_url('nodes', is_free) | ||
return do_get(url) | ||
|
||
def list_project_nodes(project): | ||
url = make_url('project', project, 'nodes') | ||
return do_get(url) | ||
|
||
def list_project_networks(project): | ||
url = make_url('project', project, 'networks') | ||
return do_get(url) | ||
|
||
def list_networks(): | ||
url = make_url('networks') | ||
return do_get(url) | ||
|
||
def show_network(network): | ||
url = make_url('network', network) | ||
return do_get(url) | ||
|
||
def show_node(node): | ||
url = make_url('node', node) | ||
return do_get(url) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vsemp see #54
as we discussed prior, I added this as a parameter to conf/quads.yml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. We discussed that. And I agreed with you. But I don't see it added.
So can we merge this first and then we can move this line anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/BUEC528-HIL-QUADS/quads/pull/54/files#diff-54b53b5e855e4de6cd714db5a7e6a638