Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikola Tassev committed Jun 24, 2014
0 parents commit fae58d3
Show file tree
Hide file tree
Showing 43 changed files with 4,701 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea/
build/
dist/
conf.json
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Client tool for collecting statistics from multiple accounts #

Create a config file e.g. named `conf.json` with the following contents:

{
"alias_one": {"username": "[email protected]", "password": "secret", "api_endpoint":"https://wdc.cloudsigma.com/api/2.0/"},
"alias_two": {"username": "[email protected]", "password": "secret2", "api_endpoint":"https://wdc.cloudsigma.com/api/2.0/"}
}

Please verify the accounts are pointed to the right cloud location URL. Here is a list of the current cloud location API endpoints:

* https://wdc.cloudsigma.com/api/2.0/
* https://lvs.cloudsigma.com/api/2.0/
* https://zrh.cloudsigma.com/api/2.0/

Then you can invoke the stats collection using the command:

$ cloudsigma_stats conf.json
{
"Metrics": {
"NumberOfVirtualMachines": {
"alias_one": 0,
"alias_two": 0
},
"NumberOfUsedCPUCores": {
"alias_one": 0,
"alias_two": 0
},
"MemoryUsage": {
"alias_one": 0,
"alias_two": 0
},
"NumberOfVMImages": {
"alias_one": 1,
"alias_two": 0
}
},
"Cloud name": "CloudSigma"
}

If the exit code of the command is 0, the standard output will contain a valid JSON output.

If the `cloudsigma_stats` command is executed without parameters, it prints a template for the config file.

If any error occurs (invalid config file, wrong URL, wrong credentials, problem with connection), the command
will exit with non-zero return code and will print an error trace on the standard output.
39 changes: 39 additions & 0 deletions cloudsigma_stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import json
import cloudsigma
import sys


if len(sys.argv) <= 1:
print >>sys.stderr, "Pass the config file as the first argument. \n" \
"Here is an example template for a config file. Please specify account email, password and cloud location:"
print >>sys.stderr, """
{
"alias_one": {"username": "[email protected]", "password": "secret", "api_endpoint":"https://wdc.cloudsigma.com/api/2.0/"},
"alias_two": {"username": "[email protected]", "password": "secret2", "api_endpoint":"https://wdc.cloudsigma.com/api/2.0/"}
}
"""
sys.exit(-1)

users = json.load(open(sys.argv[1], 'r'))

metrics = {
'MemoryUsage': {},
'NumberOfUsedCPUCores': {},
'NumberOfVMImages': {},
'NumberOfVirtualMachines': {},
}

for alias, user in users.iteritems():
started_servers = [server for server in cloudsigma.resource.Server(**user).list_detail() if server['status'] == 'running']
drives = cloudsigma.resource.Drive(**user).list()
metrics['MemoryUsage'][alias] = sum(guest['mem'] for guest in started_servers)
metrics['NumberOfUsedCPUCores'][alias] = sum(guest['smp'] for guest in started_servers)
metrics['NumberOfVirtualMachines'][alias] = len(started_servers)
metrics['NumberOfVMImages'][alias] = len(drives)

dump = {
'Cloud name': 'CloudSigma',
'Metrics': metrics,
}

print json.dumps(dump, indent=True)
17 changes: 17 additions & 0 deletions cloudsigma_stats.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- mode: python -*-
a = Analysis(['cloudsigma_stats.py', 'cloudsigma_stats.spec'],
pathex=['/home/nikola/src/cloudsme_stats'],
hiddenimports=[],
hookspath=None,
runtime_hooks=None)
pyz = PYZ(a.pure)
exe = EXE(pyz,
a.scripts,
a.binaries + [('requests/cacert.pem', '/home/nikola/.virtualenvs/cloudsme_stats/lib/python2.7/site-packages/requests/cacert.pem', 'DATA'), ],
a.zipfiles,
a.datas,
name='cloudsigma_stats',
debug=False,
strip=None,
upx=True,
console=True )
5 changes: 5 additions & 0 deletions pycloudsigma-master/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.pyc
*.swp
build/
dist/
src/cloudsigma.egg-info
1 change: 1 addition & 0 deletions pycloudsigma-master/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include requirements.txt
Loading

0 comments on commit fae58d3

Please sign in to comment.