我有很多Azure管理API使用下面的代码,除了GetRole for Virtual Machines.这是api调用的文档:https://msdn.microsoft.com/en-us/library/azure/jj157193.aspx
这是我试图执行的代码:
static void Main(string[] args)
{
Program p = new Program();
p.MakeRequest();
}
public void MakeRequest()
{
string strThumbprint = "{thumbprint}";
X509Certificate2 certificate = GetStoreCertificate(strThumbprint);
string strRequestURI = "https://management.core.windows.net/{subscription}/services/hostedservices/{cloud-service}/deployments/{deployment}/roles/{rolename}";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(strRequestURI);
request.ClientCertificates.Add(certificate);
request.ContentType = "application/xml";
request.Headers.Add("x-ms-version", "2015-04-01");
try
{
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Console.WriteLine("Status Code: " + response.StatusCode.ToString());
Stream receiveStream = response.GetResponseStream();
Encoding encode = Encoding.GetEncoding("utf-8");
StreamReader readStream = new StreamReader(receiveStream, encode);
Console.WriteLine(readStream.ReadToEnd());
response.Close();
}
catch(Exception ex)
{
Console.WriteLine("Error: " + …Run Code Online (Sandbox Code Playgroud) 我尝试了3种没有结果的方法:
var context = new AuthenticationContext($"https://login.windows.net/{tenantId}");
var result = context.AcquireToken("https://management.core.windows.net/", clientId, new Uri(redirectUri));Run Code Online (Sandbox Code Playgroud)
,但它失败,但例外:
Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException was unhandled
Message: An unhandled exception of type 'Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException' occurred in Microsoft.IdentityModel.Clients.ActiveDirectory.dll
Additional information: AADSTS90014: The request body must contain the following parameter: 'client_secret or client_assertion'.
Trace ID: aa2d6962-5aea-4f8e-bed4-9e83c7631887
Correlation ID: f7f1a61e-1720-4243-96fa-cff182150931
Run Code Online (Sandbox Code Playgroud)
var context = new AuthenticationContext($"https://login.windows.net/{tenantId}");
var result = context.AcquireToken("https://management.core.windows.net/", new ClientCredential(clientId, clientSecret));Run Code Online (Sandbox Code Playgroud)
其中clientSecret是我的应用程序的秘密应用程序密钥.此版本返回一个令牌,但使用此令牌的请求将返回403 Forbidden:服务器无法验证请求.验证证书是否有效并与此订阅相关联.
var context = new AuthenticationContext(string.Format("https://login.windows.net/{0}", tenantId));
// …Run Code Online (Sandbox Code Playgroud) c# authentication azure azure-active-directory azure-management-api
我构建了一个Web应用程序,它对Azure Rest API进行查询并创建资源(WebApp,2个MySQL数据库,添加主机名,添加SSL证书......)
所有这些查询都转到:https: //management.azure.com/subscriptions/ {subscriptionId}/resourceGroups/{resourceGroup}/....
经过几次查询后,我得到了"429 - 请求太多".
Management API有哪些限制?我的帐户不在免费试用版中.
好像我只能赚10左右......
谢谢
我曾经将Azure资源管理为一个旧的预览版本.身份验证的工作方式如下:
// Authorize
this.AuthenticationResult = this.Authorize();
this.Credentials = new TokenCloudCredentials(config.SubscriptionId, this.AuthenticationResult.AccessToken);
this.ResourceManagement = new ResourceManagementClient(this.Credentials, new Uri(config.ManagementBaseUrl));
Run Code Online (Sandbox Code Playgroud)
那将弹出和交互式用户登录窗口.我想用新的流畅的nuget包(Microsoft.Azure.Management.Fluent version="1.0.0")做同样的事情
Azure.Authenticate(???)
Run Code Online (Sandbox Code Playgroud)
这似乎是身份验证方法的最佳文档:https://github.com/Azure/azure-sdk-for-net/blob/Fluent/AUTH.md
但它只涵盖了将硬盘上存储凭据的选项,我希望避免这些选项.因此,无论用户使用我的程序,都需要登录.
总结:如何使用最新的Azure管理API使用交互式用户登录进行身份验证?
c# azure azure-management azure-management-api azure-resource-manager
我想为自己创建一个启动/停止 Azure VM 机器人。我想要做的是有一个 slack/telegram bot,它可以通过命令 /start/stop 侦听消息并启动/停止我的 VM。我应该使用什么 REST api 命令来做到这一点?
需要什么:
C#中调用azure管理API来启动释放虚拟机的一些示例代码
我可以获得 API 方法参数值的一些参考(例如订阅 ID、资源 ID 等)。
还
我已经阅读了这个问题,但它并没有帮助我理解如何处理授权以及从哪里获取这些参数。
我正在使用 C# 语言创建该机器人。
我正在尝试通过API将诊断扩展安装到现有的Azure云服务中.Cloud Service已分配保留的IP.在使用ChangeConfigurationBySlot执行此操作时,我收到" 在部署更新或升级期间无法添加,删除或更改保留的IP ".有谁知道让这个工作的诀窍?这是API中的错过还是我做错了什么?
这是相关的代码段:
var dep = client.Deployments.GetBySlot(resource.ServiceName, DeploymentSlot.Production);
var serviceConfig = XElement.Parse(dep.Configuration, LoadOptions.SetBaseUri);
var config = new DeploymentChangeConfigurationParameters(serviceConfig.ToString())
{
ExtendedProperties = dep.ExtendedProperties,
Mode = DeploymentChangeConfigurationMode.Auto,
TreatWarningsAsError = false,
Configuration = serviceConfig.ToString(),
ExtensionConfiguration = new ExtensionConfiguration
{
AllRoles = new List<ExtensionConfiguration.Extension>(),
NamedRoles = extensionConfig
}
};
var result = client.Deployments.ChangeConfigurationBySlot(resource.ServiceName, DeploymentSlot.Production, config);
Run Code Online (Sandbox Code Playgroud)
以下是云服务配置的相关部分
<ServiceConfiguration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" serviceName="IS.Admin.Azure" osFamily="4" osVersion="*" schemaVersion="2014-06.2.4" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
<Role name="IS.Admin">
…
</Role>
<NetworkConfiguration>
<VirtualNetworkSite name="is-prod" />
<AddressAssignments>
<InstanceAddress roleName="IS.Admin">
<Subnets>
<Subnet name="Subnet-1" …Run Code Online (Sandbox Code Playgroud) azure azure-cloud-services azure-management azure-management-api
上下文
/// - Azure
/// - Azure Resource Management
/// https://msdn.microsoft.com/en-us/library/azure/dn578292.aspx
///
/// - Azure Resource Manager Template Language
/// https://msdn.microsoft.com/en-us/library/azure/dn835138.aspx
///
/// - Azure Resource Manager Template Language functions and expressions
/// - Azure Resource Manager Template Language function:
/// resourceId('resourceNamespace/resourceType','resourceName')
///
/// - Powershell
/// - Azure PowerShell
/// - Azure PowerShell Resource Manager Mode (Switch-AzureMode AzureResourceManager)
/// - Azure PowerShell CmdLet: New-AzureResourceGroup
///
Run Code Online (Sandbox Code Playgroud)
模板中的这一行(请参阅下面的完整模板)
"sourceDatabaseId": "[resourceId('Microsoft.Sql/servers/databases', 'TestDB')]"
运行PowerShell New-AzureResourceGroup CmdLet 时出现此错误:
PS … powershell json azure azure-management-api azure-resource-manager
每个Azure存储帐户的卷限制为200 TB(200 TB).这听起来真的很大但是如果你将文件存储在每个25兆字节的blob存储中,那么你可以存储大约四百万个文件,这很不错但不是无法用尽的.
我想制作一些代码,定期检查我使用了多少空间并发出警报.
如何以编程方式查找我已在存储帐户中消耗了多少空间?
您能帮我解决两个非常简单和明显的问题:
有 2 个用于 Azure 资源管理的 nuget 包:
这些 nuget 软件包究竟有何不同以及何时使用哪一个?