def create_proxy_user(module, session): zfb_proxy_user = module.params['zfb_proxy_user'] zfb_constants = module.params['zfb_constants'] # Create proxy user if not present cspenterprise = VSPK.NUEnterprise() cspenterprise.id = session.me.enterprise_id csp_users = cspenterprise.users.get() lst_users = [usr.user_name for usr in csp_users] if zfb_constants['proxy_user'] not in lst_users: proxy_user = VSPK.NUUser(first_name=zfb_proxy_user['firstName'], last_name=zfb_proxy_user['lastName'], user_name=zfb_constants['proxy_user'], email=zfb_proxy_user['email'], password=zfb_proxy_user['password']) cspenterprise.create_child(proxy_user) csprootuser = VSPK.NUUser(id=session.me.id) csprootuser.fetch() # Add proxy user to root group csprootgroup = cspenterprise.groups.get_first(filter="name ==\ 'Root Group'") csprootgroup.assign([proxy_user, csprootuser], VSPK.NUUser)
def main(args): vsd_ip = str(args['--vsd']) api_url = "https://" + vsd_ip + ":8443" try: session = vsdk.NUVSDSession(username=username, password=password, enterprise=login_enterprise, api_url=api_url) session.start() csproot = session.user except: print("ERROR: Could not establish connection to VSD API") sys.exit(1) enterprise_name = str(args['--enterprise']) enterprise_filter_str = 'name == "' + enterprise_name + '"' enterprise = csproot.enterprises.get_first(filter=enterprise_filter_str) if enterprise == None: print("ERROR: Could not find enterprise with name " + enterprise_name) sys.exit(1) #Get NSG object based on Name nsg_name = str(args['--nsg-name']) nsg_filter_str = 'name == "' + nsg_name + '"' nsg = enterprise.ns_gateways.get_first(filter=nsg_filter_str) if nsg == None: print("ERROR: Could not find NSG with name " + nsg_name) sys.exit(1) if nsg.bootstrap_status == "ACTIVE" or nsg.bootstrap_status == "CERTIFICATE_SIGNED": print( "ERROR: NSG is already in a state where a URL can't be extracted") sys.exit(1) bootstraps = nsg.bootstraps.get() bootstrap = bootstraps[0] if bootstrap.installer_id == None: #print("Installer ID not defined ") existing_user = enterprise.users.get_first(filter="dummy") #print(str(existing_user.to_dict())) if existing_user == None: new_user = vsdk.NUUser(email="*****@*****.**", first_name="dummy", last_name="dummy", user_name="dummy", password="******", mobileNumber="+32444444444") enterprise.create_child(new_user) bootstrap.installer_id = new_user.id bootstrap.save() else: bootstrap.installer_id = existing_user.id bootstrap.save() #Starting the AMQP Client to capture the event t = threading.Thread(target=ampqWorker, args=( username, password, login_enterprise, vsd_ip, )) t.start() #Sleep 1s before triggering the NOTIFY event time.sleep(1) #Create job object to trigger notify_nsg_registration job = vsdk.NUJob(command="NOTIFY_NSG_REGISTRATION") #Trigger Job on NSG object nsg.create_child(job)
def users_get(self, filter=None, order_by=None, group_by=None, page=None, page_size=None, query_parameters=None, commit=True, callback=None, **kwargs): group_by = [] if group_by is None else group_by return [vsdk.NUUser(id='user-id'), vsdk.NUUser(id='user-id-2')]