Not able to update API management isntance using powershell - azure-api-management

Trying to fetch system certificates from API management instance .Then trying to remove the certificate and update the APIM instance .
APIM management instance is in INTERNAL VNET mode.
Set-AzContext -Subscription "xxxx"
$apimservice= Get-AzApiManagement -ResourceGroupName "xxxx" -Name "xxxx"
$apimservice.SystemCertificates
$apimservice.SystemCertificates.Clear()
Set-AzApiManagement -InputObject $apimservice
ERROR:
Set-AzApiManagement : 'SubnetResourceId' does not match expected pattern '^/subscriptions/[^/]*/resourceGroups/[^/]*/
providers/Microsoft.(ClassicNetwork|Network)/virtualNetworks/[^/]*/subnets/[^/]*$'.
At line:8 char:1
+ Set-AzApiManagement -InputObject $apimservice
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzApiManagement], ValidationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ApiManagement.Commands.SetAzureApiManagement

Looking to your script it seems correct.
So far as we have not all the configuration as yours we have tried to reproduce the minimal as we can and it works at our end.
Could you please make sure you are using connect-azaccount before using the set-azcontext .
And try to use the latest module of az PowerShell module as 8.0.
Set-AzApiManagement : 'SubnetResourceId' does not match expected
pattern '^/subscriptions/[^/]/resourceGroups/[^/]/
providers/Microsoft.(ClassicNetwork|Network)/virtualNetworks/[^/]/subnets/[^/]$'.
For the error:-
Make sure that you have correctly added your resource group as mentioned in portal.
For more information please refer the below Links:-
MICROSOFT DOCUMENTATION|Set-AzApiManagement
MS Q&A For Similar error| resourceGroupName' does not match expected pattern'^[-\w._()]+[ & Getting invalid status code conflict while running New-AzRoleAssignment in powershell.

Related

Azure linux VM deployment .json failing with inputting a password for deployment

Apologies in advance I am extremely new to this I am trying to run the following code and don't understand the error when attempting to generate a password for his azuredeploy.json runbook (or whatever its called)
$ az group deployment create --resource-group ProjectSpaghetti --template-uri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/docker-simple-on-ubuntu/azuredeploy.jsonubuntu/azuredeploy.json
This command is implicitly deprecated because command group 'group deployment' is deprecated and will be removed in a future release. Use 'deployment group' instead.
Please provide string value for 'adminUsername' (? for help): luke
Please provide string value for 'dnsNameForPublicIP' (? for help): lasagne
Please provide securestring value for 'adminPasswordOrKey' (? for help):
Deployment failed. Correlation ID: 55abf44d-92e4-4a7f-9c0e-ed7e5353d586. {
"error": {
"code": "InvalidParameter",
"message": "The value of parameter linuxConfiguration.ssh.publicKeys.keyData is invalid.",
"target": "linuxConfiguration.ssh.publicKeys.keyData"
}
}
I assumed because it used the phrase "adminPasswordOrKey" I would be able to use a password of reasonable complexity. Is that not the case? I'm a real newb at this just having a play really.
You see this error because you seemed to have provided a password instead of the default SSH Public key for the adminPasswordOrKey parameter that this template parameter expects.
You could take either of the following steps next:
Pass on the SSH Public key it expects
If you do not already have one, generate a new keypair and pass the contents of the public key as follows:
az group deployment create --resource-group <resource-group-name> --template-uri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/docker-simple-on-ubuntu/azuredeploy.json --parameters adminPasswordOrKey="ssh-rsa AAAAB..."
Specify an alternate authentication mechanism
Override the authenticationType to accept a password instead of a sshPublicKey. Check this blog for a quick walk through.
You could also set your parameters using a parameter file. Check this document for other ways: Deploy resources with ARM templates and Azure CLI

Multiple DevOps REST methods throwing 'command failed with an unexpected error'

I'm having trouble running DevOps API's via 'az rest' The two methods I attempted return the same result
The code snippet I'm working with
$resource = "https://graph.microsoft.com"
$uribase = "https://dev.azure.com/{org}/{project}"
$requestpath = "/_apis/build/builds?api-version=6.0-preview.6"
$uri = $uribase+$requestpath
az rest --uri $uri --headers "Content-Type=application/json" --resource $resource
I've tried several different API versions down to 5.1 but the result is the same. If i remove the --resource parameter it complains about not being able to determine the authentication. Is 'https://graph.microsoft.com' the right resource for this call?
The error returned
> az : Not a json response, outputting to stdout. For binary data suggest use "--output-file" to
write to a file
At line:5 char:1
+ az rest --uri $uri --headers "Content-Type=application/json" --resour ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Not a json resp...write to a file:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
The command failed with an unexpected error. Here is the traceback:
'charmap' codec can't encode character '\u221e' in position 6302: character maps to <undefined>
Traceback (most recent call last):
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-
packages\azure\cli\command_modules\util\custom.py", line 18, in rest_call
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-yh2ypeu1\requests\requests\models.py", line
897, in json
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\json\__init__.py", line 354, in loads
return _default_decoder.decode(s)
....
I've written the output to a file. It's an HTML file that is related to sign in/sign out - nothing obvious from the text, but kindof a clue. As a result, I've been attempting to explicitly login to devops (even though I am logged in via 'az login') like this:
az devops login --organization https://dev.azure.com/{org}
The login hangs every time, I have to shut down powershell to restart. I've rebooted my machine, tried with and without the organization parameter, tried re-logging in via az login which works fine, but I cannot get the devops login command to work.
I'm not sure if the login is the issue or if its something else. Anyone else seen a situation like this? Thoughts on what to try?
I've untangled most of this mess, hopefully someone else will benefit from this.
First, the hang. I never fixed this so it may still be related to the workaround I discuss below.
Fix #1: Instead of passing --resource, I punted on that and pass an authorization token in the header. The "/_apis/build/builds?api-version=6.0-preview.6" now the request method works with this authorization.
Fix #2: I was working with two different REST requests, one retrieves a simple list of builds, the other retrieves a simple list of release definitions. The base url is different for the release definition API requests, it requires 'vsrm.dev.azure.com' (i have no idea why).
$tokeninfo = az account get-access-token | convertfrom-json
$token = $tokeninfo.accessToken
$uribase = "https://vsrm.dev.azure.com/{org}/{project}"
$requestpath = "/_apis/release/definitions?api-version=6.0-preview.4"
$uri = $uribase+$requestpath
$authheader = "Authorization=Bearer " + $token
az rest --uri $uri --headers $authheader
$uribase = "https://dev.azure.com/{org}/{project}"
$requestpath = "/_apis/build/builds?api-version=6.0-preview.6"
$uri = $uribase+$requestpath
$authheader = "Authorization=Bearer " + $token
az rest --uri $uri --headers $authheader
Hope this helps someone out

How can I check if Couchbase 4.0 server was set up with "Index" and "Query" activated (allowing for N1QL)

Related to this 3-year old question.
Is a way to see if the "Index" and "Query" boxes where checked when a Couchbase server was configured?
I am dealing with a Couchbase 4.0 server that someone else configured, and I'm having problems running N1QL-queries, frequently returning "Requested resource not found.".
Any help here is greatly appreciated.
From the UI, you can click on "Server Nodes". Each node in the cluster will have the services listed:
You could also use the REST API to find this information. For instance, if you use the /pools/nodes endpoint, you'll get a list of nodes which contains a property "services", that will list the available services. Here's a snippet of a typical response:
// . . . snip . . .
"nodes": [{
"services": ["index", "kv", "n1ql"],
// . . . snip . . .

Spinnaker Jenkins Integration unable to fetch jobs from Jenkins

We have completed all the steps as described in the hello-spinnaker example below.We have used the AWS spinnaker image to directly configure spinnaker in AWS.
www.spinnaker.io/docs/hello-spinnaker.
I am trying to create a sample pipeline as noted in the above example.But while I create trigger in the first step and select jenkins ,the jobs are not getting populated and am getting below error in browser.
GET http://localhost:8084/v2/builds/Jenkins/jobs 429 (Too Many Requests)
The actual issue looks like while retrofit is trying to map the response from jenkins getjobs into the JobList class its finding an attribute _class in jenkins response xml and which is not present in JobList groovy class.Below is how we tried finding the issue
1)Login to AWS Spinnaker instance
2)Gate service is exposed at port 8084.
curl http://localhost:8084/v2/builds/Jenkins/jobs.
{"failureCause":"retrofit.RetrofitError: 429 Too Many Requests","error":"Too Many Requests","message":"429 Too Many Requests","status":429,"url":"http://localhost:8088/jobs/Jenkins","timestamp":1462793944530}
3)Igor service is exposed at port 8088.
curl http://localhost:8088/jobs/Jenkins
{"fallbackException":"java.lang.UnsupportedOperationException: No fallback available.","failureType":"COMMAND_EXCEPTION","failureCause":"retrofit.converter.ConversionException: org.simpleframework.xml.core.AttributeException: Attribute '_class' does not have a match in class com.netflix.spinnaker.igor.jenkins.client.model.JobList at line 1","error":"Hystrix Failure","message":"jenkins-Jenkins-getJobs failed and no fallback available.","status":429,"timestamp":1462793896853}
When I check in the igor logs,there are few exceptions which are occuring during the getprojects by jenkins poll
Caused by: retrofit.converter.ConversionException: org.simpleframework.xml.core.AttributeException: Attribute '_class' does not have a match in class com.netflix.spinnaker.igor.jenkins.client.model.ProjectsList at line 2
at retrofit.converter.SimpleXMLConverter.fromBody(SimpleXMLConverter.java:38)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:367)
... 39 common frames omitted
Caused by: org.simpleframework.xml.core.AttributeException: Attribute '_class' does not have a match in class com.netflix.spinnaker.igor.jenkins.client.model.ProjectsList at line 2
4)Connect to jenkins and get the jobs as its being done in spinnaker code https://github.com/spinnaker/igor/blob/master/igor-web/src/main/groovy/com/netflix/spinnaker/igor/jenkins/client/JenkinsClient.groovy
resp = requests.get('http://jenkinserverip:8080/api/xml?tree=jobs[name,jobs[name,jobs[name,jobs[name,jobs[name,jobs[name,jobs[name,jobs[name,jobs[name,jobs[name]]]]]]]]]]',auth=('admin','password'))
print resp.text
<hudson _class='hudson.model.Hudson'><job _class='hudson.model.FreeStyleProject'><name>Hello Build</name></job><job _class='hudson.model.FreeStyleProject'><name>Hello Poll</name></job></hudson>
So as the jenkins response is having the _class attribute ,retrofit is throwing an error at this line http://grepcode.com/file/repo1.maven.org/maven2/com.squareup.retrofit/retrofit/1.9.0/retrofit/RestAdapter.java#383
I wanted to see how can we quickly fix this as it looks like some version in compatibility of jenkins.
I'm seeing a similar issue in spinnaker 1.8.5. I had to reformat the jenkins url from myjenkins.server.com:8080 to http://myjenkins.server.com/ and it corrected the issue.
this is a bug around the jenkins api in later version. I believe 2.2 is the last compatible version, we run 1.6 internally.

Adding SQL Server registered servers in Powershell

I am attempting to use Powershell v2 to add registered servers in SQL Server Management Studio 2008.
So far I have the following outline
add-pssnapin SqlServerProviderSnapin100
add-pssnapin SqlServerCmdletSnapin100
##get-pssnapin
sl "SQLSERVER:\SQLRegistration\Database Engine Server Group"
new-item SERVERNAME\INSTANCENAME -itemtype registration -Value "server=SERVERNAME\INSTANCENAME;integrated security=false;User Id=SA;Password=foofoo"
The problem I have is with the registered server friendly name. We require slashes in it as we have named instances with the same names on different servers.
Regardless of what I try I get the following error message.
The type is not a known type for the
file system. Only "file" and
"directory" can be specified
I have tried enclosing in quotes, using grave as an escape character. None of which works for me.
Cheers
David
You need to use the encode-sqlname cmdlet which is part of the SqlServerCmdletSnapin100. Here's an example:
New-Item $(Encode-Sqlname "SERVERNAME\INSTANCENAME") -itemtype registration -Value “server=MyServer;integrated security=true”
I have a couple of blog posts about registering servers here also:
http://sev17.com/2008/12/registering-sql-servers-in-2000-em-2005-ssms-and-2008-ssms/
and here
http://sev17.com/2009/01/dynamically-register-sql-instances-in-sql-server-management-studio-2008/