RosettaHub Web Services

RosettaHUB provides a rich API to interact with the RosettaHUB platform: Platform Web Services and the RosettaHUB engines: Engine Web Services.

Platform web services allow you to perform all cloud governance tasks: manage users, cloud accounts, organizations, groups, budgets, access rights, etc. as well as manage RosettaHUB cloud artefacts (virtual labs, workspaces, formations, engines, machines, clusters, storages, file systems, disks, ssl certificates, domains). IT administrators can create their own applications by using the RosettaHUB web services.

Pyhton Examples

Below are some examples of how you can interact with the platform using Python

List users

List cloud accounts

Get detailed billing

Transfer budget in batch mode

Reverse transfer budget in batch mode

Assign cloud regions to user

Add a new organization manager

List all EC2 instances for an organization

Send R commands to a RosettaHub engine

Install the Python module zeep

pip install zeep

List all members of a sub-organization

import zeep apiKey ="Your-API-Key"; platform = zeep.Client('https://api.rosettahub.com/public/PlatformServices?wsdl').service users = platform.cpocGetFederatedUsers(apiKey, False, False, {'organizationName':'WASHINGTON'} ); for user in users: print(user.login)

List all cloud accounts

import zeep apiKey ="Your-API-Key"; platform = zeep.Client('https://api.rosettahub.com/public/PlatformServices?wsdl').service accounts = platform.cpocGetFederatedCloudAccounts(apiKey, False, {'organizationName':'WASHINGTON-Researchers', 'cloudId':'aws','includeCustomization':False} ); for account in accounts: print(account.login) print(account.aggregatedCost) print(account.budget)

Get detailed billing

You need to be superuser on the root organization.

import zeep apiKey ="Your-API-Key"; platform = zeep.Client('https://api.rosettahub.com/public/PlatformServices?wsdl').service cloudAccounts = platform.getFederatedCloudAccounts(apiKey, False, {'cloudId':'gcp'}) month = 9 year = 2020 detailedBilling = platform.suGetDetailedBilling(apiKey, cloudAccounts[0].rootCloudAccountUid, month, year) print(detailedBilling)

Transfer budget

Transfer $20 to all cloud accounts of users that belong to an organization

import zeep apiKey ="Your-API-Key"; platform = zeep.Client('https://api.rosettahub.com/public/PlatformServices?wsdl').service accounts = platform.cpocGetFederatedCloudAccounts(apiKey, False, {'organizationName':'WASHINGTON-Researchers', 'cloudId':'aws','includeCustomization':False} ); accountIds = []; i=0; for account in accounts: acountIds[i] = account.cloudAccountUid; i = i+1 platform.cpocTansferBudget(apiKey, accountIds, 20, None);

Reverse transfer budget

reverse transfer from users cloud accounts to a manager's cloud account.

The manager needs to have a SUPERUSER role on the organization and to have the right roles to be able to do the reverse transfer. 

import zeep apiKey ="Your-API-Key"; platform = zeep.Client('https://api.rosettahub.com/public/PlatformServices?wsdl').service accounts = platform.cpocGetFederatedCloudAccounts(apiKey, False, {'organizationName':'WASHINGTON-Researchers', 'cloudId':'aws','includeCustomization':False} ); for account in accounts: platform.suReverseTansferBudget(apiKey, [account.cloudAccountUid], account.amountLeft - 0.001, None);

Set a user's allowed cloud regions

import zeep apiKey ="Your-API-Key"; platform = zeep.Client('https://api.rosettahub.com/public/PlatformServices?wsdl').service platform.cpocSetAllowedRegions(apiKey,["emily.williams"],"gcp",["europe-west1","europe-west4"], None)

Add a new organization manager

List all sub-organization managers, then add a new manager

import zeep apiKey ="Your-API-Key"; platform = zeep.Client('https://api.rosettahub.com/public/PlatformServices?wsdl').service orgs = platform.cpocGetFederatedOrganizations(apiKey, False, True, True, {'organizationName':'*Big data*'}) print(orgs[0].organizationManagers) platform.adminAssignAdminsToOrganization(apiKey, orgs[0].organizationName, ['stuart.robinson'], False,None)

List EC2 instances

List all users, masquerade as individual users, retrieve an STS session to access the user AWS account and list all EC2 instances

import zeep import boto3 apiKey ="Your-API-Key"; platform = zeep.Client('https://api.rosettahub.com/public/PlatformServices?wsdl').service users = platform.cpocGetFederatedUsers(apiKey, False, False, False, {'organizationName':'WASHINGTON-Researchers'} , None); for user in users: if user.enabled: platform.suMasquerade(apiKey,user.login) try: stsSession=platform.getFederatedIamUserStsSession(apiKey, 'rh-main', 60*60, None) ; client = boto3.resource( 'ec2', aws_access_key_id=stsSession.stsAccessKeyId, aws_secret_access_key=stsSession.stsSecretAccessKey, aws_session_token=stsSession.sessionToken, region_name='eu-west-1' ) instances = client.instances.all() for instance in instances: print(user.login+' : '+str(instance)) except: print(user.login+' : '+'Failed to create STS') platform.suUnmasquerade("Your-API-Key")

 

Send R commands to a RosettaHub engine

from zeep import Client apiKey ="Your-API-Key"; platform = zeep.Client('https://api.rosettahub.com/public/PlatformServices?wsdl').service engines = platform.getEngines(apiKey, {'includePrivate':True,'includeShared':True, 'machineInstanceLabel':'*Data Science*' }, None); e=engines[0]; esession=platform.newEngineSession(apiKey, None, e.engineUid, [], 0,0, None); kernel=Client(e.url).service; kernel.console(esession, "x=c(5,66,66)", {'process':'R'}, asynch=False); x=kernel.getObject(esession, "x", {'process':'R'}); print(x); kernel.console(esession, "abc=[55,66,66]", {'process':'Python'}, asynch=False); abc=kernel.getObject(esession, "abc", {'process':'Python'}); print(abc);