I'm making a connection to a remote SAS Workspace Server using IOM Bridge:
import win32com.client
objFactory = win32com.client.Dispatch("SASObjectManager.ObjectFactoryMulti2")
objServerDef = win32com.client.Dispatch("SASObjectManager.ServerDef")
objServerDef.MachineDNSName = "servername"
objServerDef.Port = 8591 # workspace server port
objServerDef.Protocol = 2 # 2 = IOM protocol
objServerDef.BridgeSecurityPackage = "Username/Password"
objServerDef.ClassIdentifier = "workspace server id"
objSAS = objFactory.CreateObjectByServer("SASApp", True, objServerDef, "uid", "pw")
program = "ods listing;proc means data=sashelp.cars mean mode min max; run;"
objSAS.LanguageService.Submit(program)
_list = objSAS.LanguageService.FlushList(999999)
print(_list)
log = objSAS.LanguageService.FlushLog(999999)
print(log)
objSAS.Close()
It work fine. But I cant seem to find the right attribut for CreateObjectByServer, when trying with a Stored Process Server (when I change 'Port' and 'ClassIdentifier'):
import win32com.client
objFactory = win32com.client.Dispatch("SASObjectManager.ObjectFactoryMulti2")
objServerDef = win32com.client.Dispatch("SASObjectManager.ServerDef")
objServerDef.MachineDNSName = "servername"
objServerDef.Port = 8601 # stored process server port
objServerDef.Protocol = 2 # 2 = IOM protocol
objServerDef.BridgeSecurityPackage = "Username/Password"
objServerDef.ClassIdentifier = "stp server id"
objSAS = objFactory.CreateObjectByServer("SASApp", True, objServerDef, "uid", "pw")
objSAS.StoredProcessService.Repository("path", "stp", "params")
_list = objSAS.LanguageService.FlushList(999999)
print(_list)
log = objSAS.LanguageService.FlushLog(999999)
print(log)
objSAS.Close()
When trying the above I get:
AttributeError: CreateObjectByServer.StoredProcessService
I cant seem to find much documentation IOM to Stored Process Servers. Anyone got any suggestions?
Related
This is the code I'm using to turn the pypresence on:
from pypresence import Presence
import time
start = int(time.time())
client_id = "XXXXXXXXXXXXXXXX"
RPC = Presence(client_id, pipe=0, loop=None, handler=None)
RPC.connect()
while True:
RPC.update(
details = "▬▬▬▬▬▬▬▬▬▬",
state = "All Systems Operational.",
large_image = "xxx_logo_rpc_v2",
large_text = "exe is running!",
small_image = "xx_green_circle_rpc_v2",
small_text = "Online",
start = start,
buttons = [{"label": "🌐XX 🌐", "url": "https://xx/"}, {"label": "xxxx", "url": "https://xxxx8"}]
)
time.sleep(60)
This is the code I'm trying to use to turn it off:
from pypresence import Presence
import os
client_id = "XXXXXXXXXXXXXX"
RPC = Presence(client_id, pipe=0, loop=None, handler=None)
RPC.clear(pid=os.getpid())
RPC.close()
The problem is that it shows me this error:
File "C:\Users\Foxii\AppData\Local\Programs\Python\Python310\lib\site- packages\pypresence\baseclient.py",
line 96, in send_data assert self.sock_writer is not None, "You must connect your client before sending events!" AssertionError: You must connect your client before sending events!
Well, the client seems to be connected when I run it with my custom Tkinter GUI but when I try to run the code to close it, it shows me that error.
I am trying to create a file in an ESP32 named "PassWord" containing a password, using Micropython Serial. The code below works with a "hardwired" password, but I would like to be able to send the contents of a variable that was typed in by the user. The sending script is running in Win10 using Python 3.7.9
import serial
import time
def Send(s):
ser.write((s +'\r\n').encode())
time.sleep(.3)
z = ser.read(ser.in_waiting)
portx = "COM6"
bps = 115200
timex = 5
ser = serial.Serial(portx,bps,timeout=timex)
Send("f = open('Password,'w')")
Send("f.write('MyPassWord\\n')")
Send("f.close()")
You could do something like this. Just made this as an exaggerated example so you can learn. You could put this whole thing into the send function input if you wanted.
import serial
import time
MyPassWord = "This is the password"
def Send(s):
ser.write((s +'\r\n').encode())
time.sleep(.3)
z = ser.read(ser.in_waiting)
portx = "COM6"
bps = 115200
timex = 5
ser = serial.Serial(portx,bps,timeout=timex)
StringToSend = """f.write('""" + MyPassWord+ """\\n')"""
Send("f = open('Password,'w')")
Send(StringToSend)
Send("f.close()")
Some time ago I was working to rotate the password of the administrator#vsphere.local user in the Vcenter, but there isn't a lot of information about how to do that with Python. I did with LDAP protocol, I just want to create this to future references if someone need it.
import ldap
import os
import sys
vcenter = "the_IP_OR_Host_Name_of_the_VC"
ad_server = "ldap://"+vcenter
userAccount = 'Administrator'
ad_dn = "cn="+userAccount+",cn=users,dc=vsphere,dc=local"
username = 'CPMS_Test#vsphere.local'
old_pwd = 'The_Actual_PAss_of_Administrator'
new_pwd = 'New_Pass_of_the_Account'
# Lets initialize the LDAP, in our case is the same VC
l = ldap.initialize(ad_server)
#LDAP settings, Im not using SSL, but you can use it
l.protocol_version = ldap.VERSION3
l.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_DEMAND)
l.set_option(ldap.OPT_X_TLS_NEWCTX, 0)
l.simple_bind_s(ad_dn.format(username), old_pwd)
#lets run the update of the pass
password_value_old = old_pwd.encode("utf-8")
password_value = new_pwd.encode("utf-8")
mod_list = [
(ldap.MOD_DELETE, 'userpassword', [password_value_old]),
(ldap.MOD_ADD, 'userpassword', [password_value]),
]
result = l.modify_s(ad_dn.format(username), mod_list)
print(result.info)
How to efficiently and correctly manage processes with python. I want to run commands like:
/etc/init.d/daemon stop
service daemon start
systemctl restart daemon
Is there any python module available for this?
Any help will be highly appreciated.
I found a way using systemd dbus interface. Here is the code:
import dbus
import subprocess
import os
import sys
import time
SYSTEMD_BUSNAME = 'org.freedesktop.systemd1'
SYSTEMD_PATH = '/org/freedesktop/systemd1'
SYSTEMD_MANAGER_INTERFACE = 'org.freedesktop.systemd1.Manager'
SYSTEMD_UNIT_INTERFACE = 'org.freedesktop.systemd1.Unit'
bus = dbus.SystemBus()
proxy = bus.get_object('org.freedesktop.PolicyKit1', '/org/freedesktop/PolicyKit1/Authority')
authority = dbus.Interface(proxy, dbus_interface='org.freedesktop.PolicyKit1.Authority')
system_bus_name = bus.get_unique_name()
subject = ('system-bus-name', {'name' : system_bus_name})
action_id = 'org.freedesktop.systemd1.manage-units'
details = {}
flags = 1 # AllowUserInteraction flag
cancellation_id = '' # No cancellation id
result = authority.CheckAuthorization(subject, action_id, details, flags, cancellation_id)
if result[1] != 0:
sys.exit("Need administrative privilege")
systemd_object = bus.get_object(SYSTEMD_BUSNAME, SYSTEMD_PATH)
systemd_manager = dbus.Interface(systemd_object, SYSTEMD_MANAGER_INTERFACE)
unit = systemd_manager.GetUnit('cups.service')
unit_object = bus.get_object(SYSTEMD_BUSNAME, unit)
#unit_interface = dbus.Interface(unit_object, SYSTEMD_UNIT_INTERFACE)
#unit_interface.Stop('replace')
systemd_manager.StartUnit('cups.service', 'replace')
while list(systemd_manager.ListJobs()):
time.sleep(2)
print 'there are pending jobs, lets wait for them to finish.'
prop_unit = dbus.Interface(unit_object, 'org.freedesktop.DBus.Properties')
active_state = prop_unit.Get('org.freedesktop.systemd1.Unit', 'ActiveState')
sub_state = prop_unit.Get('org.freedesktop.systemd1.Unit', 'SubState')
print active_state, sub_state
Below is the code I think should be used to modify the network adapter IP of an ethernet adapter for a windows VM while cloning a VM from a template using pyvmomi and virtual center. It doesn't work, the VM clones but the network adapter is not modified. I only seem to be finding examples that assume there are no adapters at all and creating new ones. I could use some help figuring out what I'm doing wrong:
def clone_vm(
content, template, vm_name, si, ip,
datacenter_name, vm_folder, datastore_name,
cluster_name, resource_pool, power_on):
"""
Clone a VM from a template/VM, datacenter_name, vm_folder, datastore_name
cluster_name, resource_pool, and power_on are all optional.
"""
# if none git the first one
datacenter = get_obj(content, [vim.Datacenter], datacenter_name)
if vm_folder:
destfolder = get_obj(content, [vim.Folder], vm_folder)
else:
destfolder = datacenter.vmFolder
if datastore_name:
datastore = get_obj(content, [vim.Datastore], datastore_name)
else:
datastore = get_obj(
content, [vim.Datastore], template.datastore[0].info.name)
# if None, get the first one
cluster = get_obj(content, [vim.ClusterComputeResource], cluster_name)
if resource_pool:
resource_pool = get_obj(content, [vim.ResourcePool], resource_pool)
else:
resource_pool = cluster.resourcePool
# set relospec
relospec = vim.vm.RelocateSpec()
relospec.datastore = datastore
relospec.pool = resource_pool
deviceToChange = None
for device in template.config.hardware.device:
if isinstance(device, vim.vm.device.VirtualEthernetCard):
deviceToChange = device
#guest NIC settings
nic = vim.vm.device.VirtualDeviceSpec()
nic.operation = vim.vm.device.VirtualDeviceSpec.Operation.edit # or add to make a new one
nic.device = deviceToChange
nic.device.wakeOnLanEnabled = True
nic.device.addressType = 'assigned' #mac address assigned by virtual center
nic.device.key = 4000 # 4000 seems to be the value to use for a vmxnet3 device
# nic.device.deviceInfo = vim.Description()
# nic.device.deviceInfo.label = "Network Adapter"
# nic.device.deviceInfo.summary = "summary text here"
#"adapter map" no idea wtf this is
guest_map = vim.vm.customization.AdapterMapping()
guest_map.adapter = vim.vm.customization.IPSettings()
guest_map.adapter.ip = vim.vm.customization.FixedIp()
guest_map.adapter.ip.ipAddress = str(ip)
guest_map.adapter.subnetMask = str(subnet)
guest_map.adapter.gateway = str(gateway)
# DNS settings
globalip = vim.vm.customization.GlobalIPSettings()
globalip.dnsServerList = dns
# globalip.dnsSuffixList = ip_settings[0]['domain'] #do I need this? I don't think so
# Hostname settings
ident = vim.vm.customization.Sysprep()
ident.guiUnattended = vim.vm.customization.GuiUnattended()
ident.guiUnattended.autoLogon = False #the machine does not auto-logon
ident.guiUnattended.password = vim.vm.customization.Password()
ident.guiUnattended.password.value = vm_password
ident.guiUnattended.password.plainText = True #the password passed over is not encrypted
ident.userData = vim.vm.customization.UserData()
ident.userData.fullName = "Derek Chadwell"
ident.userData.orgName = "NetApp"
ident.userData.computerName = vim.vm.customization.FixedName()
ident.userData.computerName.name = vm_name
ident.identification = vim.vm.customization.Identification()
# create spec to change host IP address
customspec = vim.vm.customization.Specification()
customspec.nicSettingMap = [guest_map]
customspec.globalIPSettings = globalip
customspec.identity = ident
# VM config spec
vmconf = vim.vm.ConfigSpec()
#vmconf.numCPUs = deploy_settings['cpus']
#vmconf.memoryMB = deploy_settings['mem']
#vmconf.cpuHotAddEnabled = True
#vmconf.memoryHotAddEnabled = True
vmconf.deviceChange = [nic]
clonespec = vim.vm.CloneSpec()
clonespec.location = relospec
clonespec.config = vmconf
clonespec.customization = customspec
clonespec.powerOn = power_on
clonespec.template = False
print "cloning VM..."
task = template.Clone(folder=destfolder, name=vm_name, spec=clonespec)
wait_for_task(task)