批处理应用程序python客户端

azure-batch-apps的Python项目详细描述


该包使azure批处理应用程序客户能够与 使用python的管理api。

此客户端模块设计用于在 现有的批量应用程序服务。 您可以通过Batch Apps Portal上载应用程序映像和云程序集。 有关设置的详细信息,check out this article

许可证

这个项目是由麻省理工学院授权的。 有关详细信息,请参见license.txt或访问http://opensource.org/licenses/MIT

安装

这个包已经用python 2.6、2.7、3.2、3.3和3.4进行了测试

>;gt;pip安装azure批处理应用程序

所需套餐:

文档

该文档由sphinx生成,可以在项目中找到压缩文件。 根。它也是在线的here

发布历史记录

有关更改的完整摘要,请参见changes.txt

  • 2015年7月15日-0.5.2
    • 修正了下载流媒体中的错误
  • 2015-07-09-0.5.1
    • 为无人值守令牌添加了自动刷新功能
    • 块大小的公开配置以改变上载和下载回调频率
  • 2015年7月1日-0.5.0
    • 添加了文件上载和下载的进度回调
    • 为创建池至少删除了3个实例
  • 2015年5月11日-0.4.0
    • 添加了可选的身份验证配置验证
    • 添加了jobSubmission.settings属性
  • 2015-01-13-0.3.0
    • 添加了对批处理应用程序池管理的初步支持
  • 2014年11月26日-0.2.0
    • 更改了文件上载格式
    • 已更改身份验证配置格式
    • 更改的术语:应用程序到作业类型
    • 更改术语:服务主体到无人值守帐户
    • 添加了filecollection.index方法
    • 增加了对配置中缺少auth值的更好处理
  • 2014-11-03-0.1.1
    • 身份验证错误修复
  • 2014年10月28日-0.1.0
    • 测试版

用法

应用程序配置

以便与批处理应用程序中在服务中设置的应用程序交互 帐户,您将需要配置python客户端。

当您第一次实例化配置对象时, 文件将默认创建为:

$HOME/BatchAppsData/batch_apps.ini

单个配置对象表示批处理应用程序帐户中的单个服务。 这意味着每个配置都需要一个端点和客户端ID。

要设置新的作业类型引用,可以将其添加到配置文件中, 以及您希望与之关联的任何自定义参数。

您可以直接编辑文件,也可以通过配置类进行编辑:

from batchapps import Configuration

# These can be retrieved when creating an unattended account in the Batch Apps portal.
# See the authentication section below for more details.
endpoint = 'myservice.batchapps.core.windows.net'
account_details = 'ClientID=xxxxxxxx;TenantID=abcdefg'
account_key = '12345'

cfg = Configuration(log_level='debug', default=True)
cfg.aad_config(account=account_details, key=account_key,
        endpoint=endpoint, unattended=True)

cfg.add_jobtype('my_job_type')

# Set this job type as the current job type
cfg.current_jobtype('my_job_type')

# Set the current job type as the default job type for future jobs
cfg.set_default_jobtype()

# Set up some default parameter values for the current job type
cfg.set('quality', 10)
cfg.set('timeout', 500)

# Save updated configuration to file
cfg.save_config()

认证

模块使用azure活动目录(oauth2的实现)进行身份验证。 BatchApps模块提供了一个帮助程序类来帮助检索AAD令牌 使用请求oauthlib。但是,如果您有一个首选的oauth实现,那么 可以改为使用此进行身份验证。

您可以在 Batch Apps account。这些将在 格式:

Account Id = ClientId=abc;TenantId=xyz
Account Key = ***********************

一旦您有了这些凭据,就可以通过添加 它们可以使用python进行batch_apps.ini配置,如上所述, 或者直接编辑文件:

[Authentication]
endpoint = myservice.batchapps.core.windows.net
unattended_account = ClientID=abc;TenantID=xyz
unattended_key = ***********************

然后您可以使用这些凭据进行身份验证:

from batchapps import AzureOAuth

creds = AzureOAuth.get_unattended_session()

或者,如果你使用D检索令牌的不同aad实现:

from batchapps import Credentials, Configuration
import my_oauth

client_id = "abc"
cfg = Configuration()

aad_token = my_oauth.get_token(client_id)
creds = Credentials(cfg, client_id, token=aad_token)

不久将支持通过登录到web ui进行身份验证。

工作管理

完成作业管理,包括提交、监控和访问输出 通过JobManager类:

from batchapps import AzureOAuth, JobManager
import time

creds = AzureOAuth.get_unattended_session()
mgr = JobManager(creds)

my_job = mgr.create_job("First Job")

# Apply any custom parameters and source files here
my_job.example_parameter = "test123"

# Then submit the job
new_job = my_job.submit()

job_progress = mgr.get_job(url=new_job['link'])

# Let's allow up to 30 minutes for the job to complete
timeout = time.time() + 1800

while time.time() < timeout:

        if job_progress.status is 'Complete':
                job_progress.get_output('c:\\my_download_dir')
                break

        if job_progress.status is 'Error':
                break

        time.sleep(30)
        job_progress.update()

else:
        job_progress.cancel()

文件管理

文件管理,包括将作业源文件和依赖项同步到 云可以使用filemanager类来完成:

from batchapps import AzureOAuth, FileManager

creds = AzureOAuth.get_unattended_session()
mgr = FileManager(creds)

file_collection = mgr.files_from_dir('c:\\my_job_assets')
job_source = mgr.file_from_path('C:\\start_job.bat')
file_collection.add(job_source)

file_collection.upload()

# Check files previously uploaded matching a certain name
mgr.find_files('start_job.bat')

# Retrieve a list of all uploaded files
mgr.list_files()

泳池管理

池管理,包括创建、调整大小和删除池 使用poolmanager类完成。

创建池后,可以向池提交作业。默认情况下, 当一个作业提交而不引用现有的池时,它将 使用将为运行作业创建的自动池,然后 完成时删除:

from batchapps import AzureOAuth, PoolManager

creds = AzureOAuth.get_unattended_session()
mgr = PoolManager(creds)

new_pool = mgr.create_pool(target_size=5)

# Create new job submission, then submit to pool
my_job.pool = new_pool
my_job.submit()

# After job has completed, and we no longer need the pool
pool.delete()

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在表被注释到配置之前获取表的元数据?   java滚动条不会出现在JList上   java JOGL监视器GPU内存   java为什么要使用RecyclerView onDraw延迟   java定制Oppo Reno 2 Z CPH1951(手机型号)的固件(闪存文件)   java自定义线程池执行器   java如何解决发布版本中重复的jar条目[com/安卓/volley/R.class]?   java如何使用Bukkit API触发事件?   java在blazemeter jmeter RTE插件中使用ctrl+w输入   C#/Visual Studio的java JDT等价物   java为什么当maxread值很大而收到的消息数量很小时,卡夫卡消费者会无限期消费?   java游戏2。x:包含模板列表的绑定模型   带压缩的java日志旋转   运行时。exec用java运行程序读取它正在做什么