Page tree
Skip to end of metadata
Go to start of metadata

RosettaHUB provides a rich API with almost 1000 public API functions 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 calling the RosettaHUB web services.

Below are some examples of how you can interact with the plaform using Python: Python Examples

Pyhton Examples

Install the Python module zeep

pip install zeep

List all members of a sub-organization

List Users
import zeep
     
platform = zeep.Client('https://api.rosettahub.com/public/PlatformServices?wsdl').service
session = platform.newSession("cpoc.washington", "{PASSWORD}", 0 )
users = platform.cpocGetFederatedUsers(session, False, False, {'organizationName':'WASHINGTON'} );
for user in users:
    print(user.login)

List all cloud accounts

List Cloud Accounts Costs and Budgets
import zeep
     
platform = zeep.Client('https://api.rosettahub.com/public/PlatformServices?wsdl').service
session = platform.newSession("cpoc.washington", "{PASSWORD}", 0 )
accounts = platform.cpocGetFederatedCloudAccounts(session, False, {'organizationName':'WASHINGTON-Researchers', 'cloudId':'aws','includeCustomization':False} );
for account in accounts:
	print(account.login)
    print(account.aggregatedCost)
	print(account.budget)

Set a user's allowed cloud regions

Set cloud regions
import zeep
     
platform = zeep.Client('https://api.rosettahub.com/public/PlatformServices?wsdl').service
session = platform.newSession("cpoc.washington", "{PASSWORD}", 0 )
platform.cpocSetAllowedRegions(session,["jim.educator"],"gcp",["europe-west1","europe-west4"], None)


List all sub-organization administrators, then add a new administrator

Add new administrators
import zeep
    
platform = zeep.Client('https://api.rosettahub.com/public/PlatformServices?wsdl').service
session = platform.newSession("cpoc.washington", "{PASSWORD}", 0 )
orgs = platform.cpocGetFederatedOrganizations(session, False, True, True, {'organizationName':'*Big data*'})
print(orgs[0].organizationManagers)
platform.adminAssignAdminsToOrganization(session, orgs[0].organizationName, ['stuart.robinson'], False,None)

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

Masquerade and list EC2 instances by user
import zeep
import boto3
client = zeep.Client('https://api.rosettahub.com/public/PlatformServices?wsdl')
platform = client.service
session = platform.newSession("{your_login}", "{your_password}", 0 )
users = platform.cpocGetFederatedUsers(session, False, False, False, {'organizationName':'WASHINGTON-Master of Science in Data Science'} , None);
for user in users:
    if user.enabled:
        platform.suMasquerade(session,user.login)  
        try:          
            stsSession=platform.getFederatedIamUserStsSession(session, user.login, 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(session)
Interact with engine
from zeep import Client
 
client = Client('https://api.rosettahub.com/public/PlatformServices?wsdl')
platform = client.service
session = platform.newSession("{YOUR_LOGIN}", "{YOU_PASSWORD}", 0 )
engines = platform.getEngines(session, {'includePrivate':True,'includeShared':True, 'machineInstanceLabel':'*Data Science*' }, None);
   
e=engines[0];
esession=platform.newEngineSession(session, 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);

Plaform Web Services


Engine Web Services


  • No labels