id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
155,500 | juju/juju | state/multiwatcher.go | seen | func (sm *storeManager) seen(revno int64) {
for e := sm.all.list.Front(); e != nil; {
next := e.Next()
entry := e.Value.(*entityEntry)
if entry.revno <= revno {
break
}
if entry.creationRevno > revno {
if !entry.removed {
// This is a new entity that hasn't been seen yet,
// so increment the entry's refCount.
entry.refCount++
}
} else if entry.removed {
// This is an entity that we previously saw, but
// has now been removed, so decrement its refCount, removing
// the entity if nothing else is waiting to be notified that it's
// gone.
sm.all.decRef(entry)
}
e = next
}
} | go | func (sm *storeManager) seen(revno int64) {
for e := sm.all.list.Front(); e != nil; {
next := e.Next()
entry := e.Value.(*entityEntry)
if entry.revno <= revno {
break
}
if entry.creationRevno > revno {
if !entry.removed {
// This is a new entity that hasn't been seen yet,
// so increment the entry's refCount.
entry.refCount++
}
} else if entry.removed {
// This is an entity that we previously saw, but
// has now been removed, so decrement its refCount, removing
// the entity if nothing else is waiting to be notified that it's
// gone.
sm.all.decRef(entry)
}
e = next
}
} | [
"func",
"(",
"sm",
"*",
"storeManager",
")",
"seen",
"(",
"revno",
"int64",
")",
"{",
"for",
"e",
":=",
"sm",
".",
"all",
".",
"list",
".",
"Front",
"(",
")",
";",
"e",
"!=",
"nil",
";",
"{",
"next",
":=",
"e",
".",
"Next",
"(",
")",
"\n",
"entry",
":=",
"e",
".",
"Value",
".",
"(",
"*",
"entityEntry",
")",
"\n",
"if",
"entry",
".",
"revno",
"<=",
"revno",
"{",
"break",
"\n",
"}",
"\n",
"if",
"entry",
".",
"creationRevno",
">",
"revno",
"{",
"if",
"!",
"entry",
".",
"removed",
"{",
"// This is a new entity that hasn't been seen yet,",
"// so increment the entry's refCount.",
"entry",
".",
"refCount",
"++",
"\n",
"}",
"\n",
"}",
"else",
"if",
"entry",
".",
"removed",
"{",
"// This is an entity that we previously saw, but",
"// has now been removed, so decrement its refCount, removing",
"// the entity if nothing else is waiting to be notified that it's",
"// gone.",
"sm",
".",
"all",
".",
"decRef",
"(",
"entry",
")",
"\n",
"}",
"\n",
"e",
"=",
"next",
"\n",
"}",
"\n",
"}"
] | // seen states that a Multiwatcher has just been given information about
// all entities newer than the given revno. We assume it has already
// seen all the older entities. | [
"seen",
"states",
"that",
"a",
"Multiwatcher",
"has",
"just",
"been",
"given",
"information",
"about",
"all",
"entities",
"newer",
"than",
"the",
"given",
"revno",
".",
"We",
"assume",
"it",
"has",
"already",
"seen",
"all",
"the",
"older",
"entities",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher.go#L328-L350 |
155,501 | juju/juju | state/multiwatcher.go | leave | func (sm *storeManager) leave(w *Multiwatcher) {
for e := sm.all.list.Front(); e != nil; {
next := e.Next()
entry := e.Value.(*entityEntry)
if entry.creationRevno <= w.revno {
// The watcher has seen this entry.
if entry.removed && entry.revno <= w.revno {
// The entity has been removed and the
// watcher has already been informed of that,
// so its refcount has already been decremented.
e = next
continue
}
sm.all.decRef(entry)
}
e = next
}
} | go | func (sm *storeManager) leave(w *Multiwatcher) {
for e := sm.all.list.Front(); e != nil; {
next := e.Next()
entry := e.Value.(*entityEntry)
if entry.creationRevno <= w.revno {
// The watcher has seen this entry.
if entry.removed && entry.revno <= w.revno {
// The entity has been removed and the
// watcher has already been informed of that,
// so its refcount has already been decremented.
e = next
continue
}
sm.all.decRef(entry)
}
e = next
}
} | [
"func",
"(",
"sm",
"*",
"storeManager",
")",
"leave",
"(",
"w",
"*",
"Multiwatcher",
")",
"{",
"for",
"e",
":=",
"sm",
".",
"all",
".",
"list",
".",
"Front",
"(",
")",
";",
"e",
"!=",
"nil",
";",
"{",
"next",
":=",
"e",
".",
"Next",
"(",
")",
"\n",
"entry",
":=",
"e",
".",
"Value",
".",
"(",
"*",
"entityEntry",
")",
"\n",
"if",
"entry",
".",
"creationRevno",
"<=",
"w",
".",
"revno",
"{",
"// The watcher has seen this entry.",
"if",
"entry",
".",
"removed",
"&&",
"entry",
".",
"revno",
"<=",
"w",
".",
"revno",
"{",
"// The entity has been removed and the",
"// watcher has already been informed of that,",
"// so its refcount has already been decremented.",
"e",
"=",
"next",
"\n",
"continue",
"\n",
"}",
"\n",
"sm",
".",
"all",
".",
"decRef",
"(",
"entry",
")",
"\n",
"}",
"\n",
"e",
"=",
"next",
"\n",
"}",
"\n",
"}"
] | // leave is called when the given watcher leaves. It decrements the reference
// counts of any entities that have been seen by the watcher. | [
"leave",
"is",
"called",
"when",
"the",
"given",
"watcher",
"leaves",
".",
"It",
"decrements",
"the",
"reference",
"counts",
"of",
"any",
"entities",
"that",
"have",
"been",
"seen",
"by",
"the",
"watcher",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher.go#L354-L371 |
155,502 | juju/juju | state/multiwatcher.go | newStore | func newStore() *multiwatcherStore {
return &multiwatcherStore{
entities: make(map[interface{}]*list.Element),
list: list.New(),
}
} | go | func newStore() *multiwatcherStore {
return &multiwatcherStore{
entities: make(map[interface{}]*list.Element),
list: list.New(),
}
} | [
"func",
"newStore",
"(",
")",
"*",
"multiwatcherStore",
"{",
"return",
"&",
"multiwatcherStore",
"{",
"entities",
":",
"make",
"(",
"map",
"[",
"interface",
"{",
"}",
"]",
"*",
"list",
".",
"Element",
")",
",",
"list",
":",
"list",
".",
"New",
"(",
")",
",",
"}",
"\n",
"}"
] | // newStore returns an Store instance holding information about the
// current state of all entities in the model.
// It is only exposed here for testing purposes. | [
"newStore",
"returns",
"an",
"Store",
"instance",
"holding",
"information",
"about",
"the",
"current",
"state",
"of",
"all",
"entities",
"in",
"the",
"model",
".",
"It",
"is",
"only",
"exposed",
"here",
"for",
"testing",
"purposes",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher.go#L413-L418 |
155,503 | juju/juju | state/multiwatcher.go | All | func (a *multiwatcherStore) All() []multiwatcher.EntityInfo {
entities := make([]multiwatcher.EntityInfo, 0, a.list.Len())
for e := a.list.Front(); e != nil; e = e.Next() {
entry := e.Value.(*entityEntry)
if entry.removed {
continue
}
entities = append(entities, entry.info)
}
return entities
} | go | func (a *multiwatcherStore) All() []multiwatcher.EntityInfo {
entities := make([]multiwatcher.EntityInfo, 0, a.list.Len())
for e := a.list.Front(); e != nil; e = e.Next() {
entry := e.Value.(*entityEntry)
if entry.removed {
continue
}
entities = append(entities, entry.info)
}
return entities
} | [
"func",
"(",
"a",
"*",
"multiwatcherStore",
")",
"All",
"(",
")",
"[",
"]",
"multiwatcher",
".",
"EntityInfo",
"{",
"entities",
":=",
"make",
"(",
"[",
"]",
"multiwatcher",
".",
"EntityInfo",
",",
"0",
",",
"a",
".",
"list",
".",
"Len",
"(",
")",
")",
"\n",
"for",
"e",
":=",
"a",
".",
"list",
".",
"Front",
"(",
")",
";",
"e",
"!=",
"nil",
";",
"e",
"=",
"e",
".",
"Next",
"(",
")",
"{",
"entry",
":=",
"e",
".",
"Value",
".",
"(",
"*",
"entityEntry",
")",
"\n",
"if",
"entry",
".",
"removed",
"{",
"continue",
"\n",
"}",
"\n",
"entities",
"=",
"append",
"(",
"entities",
",",
"entry",
".",
"info",
")",
"\n",
"}",
"\n",
"return",
"entities",
"\n",
"}"
] | // All returns all the entities stored in the Store,
// oldest first. It is only exposed for testing purposes. | [
"All",
"returns",
"all",
"the",
"entities",
"stored",
"in",
"the",
"Store",
"oldest",
"first",
".",
"It",
"is",
"only",
"exposed",
"for",
"testing",
"purposes",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher.go#L422-L432 |
155,504 | juju/juju | state/multiwatcher.go | add | func (a *multiwatcherStore) add(id interface{}, info multiwatcher.EntityInfo) {
if _, ok := a.entities[id]; ok {
panic("adding new entry with duplicate id")
}
a.latestRevno++
entry := &entityEntry{
info: info,
revno: a.latestRevno,
creationRevno: a.latestRevno,
}
a.entities[id] = a.list.PushFront(entry)
} | go | func (a *multiwatcherStore) add(id interface{}, info multiwatcher.EntityInfo) {
if _, ok := a.entities[id]; ok {
panic("adding new entry with duplicate id")
}
a.latestRevno++
entry := &entityEntry{
info: info,
revno: a.latestRevno,
creationRevno: a.latestRevno,
}
a.entities[id] = a.list.PushFront(entry)
} | [
"func",
"(",
"a",
"*",
"multiwatcherStore",
")",
"add",
"(",
"id",
"interface",
"{",
"}",
",",
"info",
"multiwatcher",
".",
"EntityInfo",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"a",
".",
"entities",
"[",
"id",
"]",
";",
"ok",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"a",
".",
"latestRevno",
"++",
"\n",
"entry",
":=",
"&",
"entityEntry",
"{",
"info",
":",
"info",
",",
"revno",
":",
"a",
".",
"latestRevno",
",",
"creationRevno",
":",
"a",
".",
"latestRevno",
",",
"}",
"\n",
"a",
".",
"entities",
"[",
"id",
"]",
"=",
"a",
".",
"list",
".",
"PushFront",
"(",
"entry",
")",
"\n",
"}"
] | // add adds a new entity with the given id and associated
// information to the list. | [
"add",
"adds",
"a",
"new",
"entity",
"with",
"the",
"given",
"id",
"and",
"associated",
"information",
"to",
"the",
"list",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher.go#L436-L447 |
155,505 | juju/juju | state/multiwatcher.go | decRef | func (a *multiwatcherStore) decRef(entry *entityEntry) {
if entry.refCount--; entry.refCount > 0 {
return
}
if entry.refCount < 0 {
panic("negative reference count")
}
if !entry.removed {
return
}
id := entry.info.EntityId()
elem, ok := a.entities[id]
if !ok {
panic("delete of non-existent entry")
}
delete(a.entities, id)
a.list.Remove(elem)
} | go | func (a *multiwatcherStore) decRef(entry *entityEntry) {
if entry.refCount--; entry.refCount > 0 {
return
}
if entry.refCount < 0 {
panic("negative reference count")
}
if !entry.removed {
return
}
id := entry.info.EntityId()
elem, ok := a.entities[id]
if !ok {
panic("delete of non-existent entry")
}
delete(a.entities, id)
a.list.Remove(elem)
} | [
"func",
"(",
"a",
"*",
"multiwatcherStore",
")",
"decRef",
"(",
"entry",
"*",
"entityEntry",
")",
"{",
"if",
"entry",
".",
"refCount",
"--",
";",
"entry",
".",
"refCount",
">",
"0",
"{",
"return",
"\n",
"}",
"\n",
"if",
"entry",
".",
"refCount",
"<",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"entry",
".",
"removed",
"{",
"return",
"\n",
"}",
"\n",
"id",
":=",
"entry",
".",
"info",
".",
"EntityId",
"(",
")",
"\n",
"elem",
",",
"ok",
":=",
"a",
".",
"entities",
"[",
"id",
"]",
"\n",
"if",
"!",
"ok",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"delete",
"(",
"a",
".",
"entities",
",",
"id",
")",
"\n",
"a",
".",
"list",
".",
"Remove",
"(",
"elem",
")",
"\n",
"}"
] | // decRef decrements the reference count of an entry within the list,
// deleting it if it becomes zero and the entry is removed. | [
"decRef",
"decrements",
"the",
"reference",
"count",
"of",
"an",
"entry",
"within",
"the",
"list",
"deleting",
"it",
"if",
"it",
"becomes",
"zero",
"and",
"the",
"entry",
"is",
"removed",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher.go#L451-L468 |
155,506 | juju/juju | state/multiwatcher.go | delete | func (a *multiwatcherStore) delete(id multiwatcher.EntityId) {
elem, ok := a.entities[id]
if !ok {
return
}
delete(a.entities, id)
a.list.Remove(elem)
} | go | func (a *multiwatcherStore) delete(id multiwatcher.EntityId) {
elem, ok := a.entities[id]
if !ok {
return
}
delete(a.entities, id)
a.list.Remove(elem)
} | [
"func",
"(",
"a",
"*",
"multiwatcherStore",
")",
"delete",
"(",
"id",
"multiwatcher",
".",
"EntityId",
")",
"{",
"elem",
",",
"ok",
":=",
"a",
".",
"entities",
"[",
"id",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\n",
"}",
"\n",
"delete",
"(",
"a",
".",
"entities",
",",
"id",
")",
"\n",
"a",
".",
"list",
".",
"Remove",
"(",
"elem",
")",
"\n",
"}"
] | // delete deletes the entry with the given info id. | [
"delete",
"deletes",
"the",
"entry",
"with",
"the",
"given",
"info",
"id",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher.go#L471-L478 |
155,507 | juju/juju | state/multiwatcher.go | Remove | func (a *multiwatcherStore) Remove(id multiwatcher.EntityId) {
if elem := a.entities[id]; elem != nil {
entry := elem.Value.(*entityEntry)
if entry.removed {
return
}
a.latestRevno++
if entry.refCount == 0 {
a.delete(id)
return
}
entry.revno = a.latestRevno
entry.removed = true
a.list.MoveToFront(elem)
}
} | go | func (a *multiwatcherStore) Remove(id multiwatcher.EntityId) {
if elem := a.entities[id]; elem != nil {
entry := elem.Value.(*entityEntry)
if entry.removed {
return
}
a.latestRevno++
if entry.refCount == 0 {
a.delete(id)
return
}
entry.revno = a.latestRevno
entry.removed = true
a.list.MoveToFront(elem)
}
} | [
"func",
"(",
"a",
"*",
"multiwatcherStore",
")",
"Remove",
"(",
"id",
"multiwatcher",
".",
"EntityId",
")",
"{",
"if",
"elem",
":=",
"a",
".",
"entities",
"[",
"id",
"]",
";",
"elem",
"!=",
"nil",
"{",
"entry",
":=",
"elem",
".",
"Value",
".",
"(",
"*",
"entityEntry",
")",
"\n",
"if",
"entry",
".",
"removed",
"{",
"return",
"\n",
"}",
"\n",
"a",
".",
"latestRevno",
"++",
"\n",
"if",
"entry",
".",
"refCount",
"==",
"0",
"{",
"a",
".",
"delete",
"(",
"id",
")",
"\n",
"return",
"\n",
"}",
"\n",
"entry",
".",
"revno",
"=",
"a",
".",
"latestRevno",
"\n",
"entry",
".",
"removed",
"=",
"true",
"\n",
"a",
".",
"list",
".",
"MoveToFront",
"(",
"elem",
")",
"\n",
"}",
"\n",
"}"
] | // Remove marks that the entity with the given id has
// been removed from the backing. If nothing has seen the
// entity, then we delete it immediately. | [
"Remove",
"marks",
"that",
"the",
"entity",
"with",
"the",
"given",
"id",
"has",
"been",
"removed",
"from",
"the",
"backing",
".",
"If",
"nothing",
"has",
"seen",
"the",
"entity",
"then",
"we",
"delete",
"it",
"immediately",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher.go#L483-L498 |
155,508 | juju/juju | state/multiwatcher.go | Update | func (a *multiwatcherStore) Update(info multiwatcher.EntityInfo) {
id := info.EntityId()
elem, ok := a.entities[id]
if !ok {
a.add(id, info)
return
}
entry := elem.Value.(*entityEntry)
// Nothing has changed, so change nothing.
// TODO(rog) do the comparison more efficiently.
if reflect.DeepEqual(info, entry.info) {
return
}
// We already know about the entity; update its doc.
a.latestRevno++
entry.revno = a.latestRevno
entry.info = info
// The app might have been removed and re-added.
entry.removed = false
a.list.MoveToFront(elem)
} | go | func (a *multiwatcherStore) Update(info multiwatcher.EntityInfo) {
id := info.EntityId()
elem, ok := a.entities[id]
if !ok {
a.add(id, info)
return
}
entry := elem.Value.(*entityEntry)
// Nothing has changed, so change nothing.
// TODO(rog) do the comparison more efficiently.
if reflect.DeepEqual(info, entry.info) {
return
}
// We already know about the entity; update its doc.
a.latestRevno++
entry.revno = a.latestRevno
entry.info = info
// The app might have been removed and re-added.
entry.removed = false
a.list.MoveToFront(elem)
} | [
"func",
"(",
"a",
"*",
"multiwatcherStore",
")",
"Update",
"(",
"info",
"multiwatcher",
".",
"EntityInfo",
")",
"{",
"id",
":=",
"info",
".",
"EntityId",
"(",
")",
"\n",
"elem",
",",
"ok",
":=",
"a",
".",
"entities",
"[",
"id",
"]",
"\n",
"if",
"!",
"ok",
"{",
"a",
".",
"add",
"(",
"id",
",",
"info",
")",
"\n",
"return",
"\n",
"}",
"\n",
"entry",
":=",
"elem",
".",
"Value",
".",
"(",
"*",
"entityEntry",
")",
"\n",
"// Nothing has changed, so change nothing.",
"// TODO(rog) do the comparison more efficiently.",
"if",
"reflect",
".",
"DeepEqual",
"(",
"info",
",",
"entry",
".",
"info",
")",
"{",
"return",
"\n",
"}",
"\n",
"// We already know about the entity; update its doc.",
"a",
".",
"latestRevno",
"++",
"\n",
"entry",
".",
"revno",
"=",
"a",
".",
"latestRevno",
"\n",
"entry",
".",
"info",
"=",
"info",
"\n",
"// The app might have been removed and re-added.",
"entry",
".",
"removed",
"=",
"false",
"\n",
"a",
".",
"list",
".",
"MoveToFront",
"(",
"elem",
")",
"\n",
"}"
] | // Update updates the information for the given entity. | [
"Update",
"updates",
"the",
"information",
"for",
"the",
"given",
"entity",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher.go#L501-L521 |
155,509 | juju/juju | state/multiwatcher.go | Get | func (a *multiwatcherStore) Get(id multiwatcher.EntityId) multiwatcher.EntityInfo {
e, ok := a.entities[id]
if !ok {
return nil
}
return e.Value.(*entityEntry).info
} | go | func (a *multiwatcherStore) Get(id multiwatcher.EntityId) multiwatcher.EntityInfo {
e, ok := a.entities[id]
if !ok {
return nil
}
return e.Value.(*entityEntry).info
} | [
"func",
"(",
"a",
"*",
"multiwatcherStore",
")",
"Get",
"(",
"id",
"multiwatcher",
".",
"EntityId",
")",
"multiwatcher",
".",
"EntityInfo",
"{",
"e",
",",
"ok",
":=",
"a",
".",
"entities",
"[",
"id",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"e",
".",
"Value",
".",
"(",
"*",
"entityEntry",
")",
".",
"info",
"\n",
"}"
] | // Get returns the stored entity with the given id, or nil if none was found.
// The contents of the returned entity MUST not be changed. | [
"Get",
"returns",
"the",
"stored",
"entity",
"with",
"the",
"given",
"id",
"or",
"nil",
"if",
"none",
"was",
"found",
".",
"The",
"contents",
"of",
"the",
"returned",
"entity",
"MUST",
"not",
"be",
"changed",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher.go#L525-L531 |
155,510 | juju/juju | state/multiwatcher.go | ChangesSince | func (a *multiwatcherStore) ChangesSince(revno int64) []multiwatcher.Delta {
e := a.list.Front()
n := 0
for ; e != nil; e = e.Next() {
entry := e.Value.(*entityEntry)
if entry.revno <= revno {
break
}
n++
}
if e != nil {
// We've found an element that we've already seen.
e = e.Prev()
} else {
// We haven't seen any elements, so we want all of them.
e = a.list.Back()
n++
}
changes := make([]multiwatcher.Delta, 0, n)
for ; e != nil; e = e.Prev() {
entry := e.Value.(*entityEntry)
if entry.removed && entry.creationRevno > revno {
// Don't include entries that have been created
// and removed since the revno.
continue
}
changes = append(changes, multiwatcher.Delta{
Removed: entry.removed,
Entity: entry.info,
})
}
return changes
} | go | func (a *multiwatcherStore) ChangesSince(revno int64) []multiwatcher.Delta {
e := a.list.Front()
n := 0
for ; e != nil; e = e.Next() {
entry := e.Value.(*entityEntry)
if entry.revno <= revno {
break
}
n++
}
if e != nil {
// We've found an element that we've already seen.
e = e.Prev()
} else {
// We haven't seen any elements, so we want all of them.
e = a.list.Back()
n++
}
changes := make([]multiwatcher.Delta, 0, n)
for ; e != nil; e = e.Prev() {
entry := e.Value.(*entityEntry)
if entry.removed && entry.creationRevno > revno {
// Don't include entries that have been created
// and removed since the revno.
continue
}
changes = append(changes, multiwatcher.Delta{
Removed: entry.removed,
Entity: entry.info,
})
}
return changes
} | [
"func",
"(",
"a",
"*",
"multiwatcherStore",
")",
"ChangesSince",
"(",
"revno",
"int64",
")",
"[",
"]",
"multiwatcher",
".",
"Delta",
"{",
"e",
":=",
"a",
".",
"list",
".",
"Front",
"(",
")",
"\n",
"n",
":=",
"0",
"\n",
"for",
";",
"e",
"!=",
"nil",
";",
"e",
"=",
"e",
".",
"Next",
"(",
")",
"{",
"entry",
":=",
"e",
".",
"Value",
".",
"(",
"*",
"entityEntry",
")",
"\n",
"if",
"entry",
".",
"revno",
"<=",
"revno",
"{",
"break",
"\n",
"}",
"\n",
"n",
"++",
"\n",
"}",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"// We've found an element that we've already seen.",
"e",
"=",
"e",
".",
"Prev",
"(",
")",
"\n",
"}",
"else",
"{",
"// We haven't seen any elements, so we want all of them.",
"e",
"=",
"a",
".",
"list",
".",
"Back",
"(",
")",
"\n",
"n",
"++",
"\n",
"}",
"\n",
"changes",
":=",
"make",
"(",
"[",
"]",
"multiwatcher",
".",
"Delta",
",",
"0",
",",
"n",
")",
"\n",
"for",
";",
"e",
"!=",
"nil",
";",
"e",
"=",
"e",
".",
"Prev",
"(",
")",
"{",
"entry",
":=",
"e",
".",
"Value",
".",
"(",
"*",
"entityEntry",
")",
"\n",
"if",
"entry",
".",
"removed",
"&&",
"entry",
".",
"creationRevno",
">",
"revno",
"{",
"// Don't include entries that have been created",
"// and removed since the revno.",
"continue",
"\n",
"}",
"\n",
"changes",
"=",
"append",
"(",
"changes",
",",
"multiwatcher",
".",
"Delta",
"{",
"Removed",
":",
"entry",
".",
"removed",
",",
"Entity",
":",
"entry",
".",
"info",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"changes",
"\n",
"}"
] | // ChangesSince returns any changes that have occurred since
// the given revno, oldest first. | [
"ChangesSince",
"returns",
"any",
"changes",
"that",
"have",
"occurred",
"since",
"the",
"given",
"revno",
"oldest",
"first",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/multiwatcher.go#L535-L567 |
155,511 | juju/juju | provider/oracle/provider.go | PrepareConfig | func (e EnvironProvider) PrepareConfig(args environs.PrepareConfigParams) (*config.Config, error) {
if err := e.validateCloudSpec(args.Cloud); err != nil {
return nil, errors.Annotatef(err, "validating cloud spec")
}
// Set the default block-storage source.
attrs := make(map[string]interface{})
if _, ok := args.Config.StorageDefaultBlockSource(); !ok {
attrs[config.StorageDefaultBlockSourceKey] = oracleStorageProviderType
}
if len(attrs) == 0 {
return args.Config, nil
}
return args.Config.Apply(attrs)
} | go | func (e EnvironProvider) PrepareConfig(args environs.PrepareConfigParams) (*config.Config, error) {
if err := e.validateCloudSpec(args.Cloud); err != nil {
return nil, errors.Annotatef(err, "validating cloud spec")
}
// Set the default block-storage source.
attrs := make(map[string]interface{})
if _, ok := args.Config.StorageDefaultBlockSource(); !ok {
attrs[config.StorageDefaultBlockSourceKey] = oracleStorageProviderType
}
if len(attrs) == 0 {
return args.Config, nil
}
return args.Config.Apply(attrs)
} | [
"func",
"(",
"e",
"EnvironProvider",
")",
"PrepareConfig",
"(",
"args",
"environs",
".",
"PrepareConfigParams",
")",
"(",
"*",
"config",
".",
"Config",
",",
"error",
")",
"{",
"if",
"err",
":=",
"e",
".",
"validateCloudSpec",
"(",
"args",
".",
"Cloud",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// Set the default block-storage source.",
"attrs",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"args",
".",
"Config",
".",
"StorageDefaultBlockSource",
"(",
")",
";",
"!",
"ok",
"{",
"attrs",
"[",
"config",
".",
"StorageDefaultBlockSourceKey",
"]",
"=",
"oracleStorageProviderType",
"\n",
"}",
"\n",
"if",
"len",
"(",
"attrs",
")",
"==",
"0",
"{",
"return",
"args",
".",
"Config",
",",
"nil",
"\n",
"}",
"\n",
"return",
"args",
".",
"Config",
".",
"Apply",
"(",
"attrs",
")",
"\n",
"}"
] | // PrepareConfig is defined on the environs.EnvironProvider interface. | [
"PrepareConfig",
"is",
"defined",
"on",
"the",
"environs",
".",
"EnvironProvider",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/provider.go#L42-L55 |
155,512 | juju/juju | provider/oracle/provider.go | validateCloudSpec | func (e EnvironProvider) validateCloudSpec(spec environs.CloudSpec) error {
if err := spec.Validate(); err != nil {
return errors.Trace(err)
}
if spec.Credential == nil {
return errors.NotValidf("missing credentials")
}
// validate the authentication type
if authType := spec.Credential.AuthType(); authType != cloud.UserPassAuthType {
return errors.NotSupportedf("%q auth-type ", authType)
}
if _, ok := spec.Credential.Attributes()["identity-domain"]; !ok {
return errors.NotFoundf("identity-domain in the credentials")
}
return nil
} | go | func (e EnvironProvider) validateCloudSpec(spec environs.CloudSpec) error {
if err := spec.Validate(); err != nil {
return errors.Trace(err)
}
if spec.Credential == nil {
return errors.NotValidf("missing credentials")
}
// validate the authentication type
if authType := spec.Credential.AuthType(); authType != cloud.UserPassAuthType {
return errors.NotSupportedf("%q auth-type ", authType)
}
if _, ok := spec.Credential.Attributes()["identity-domain"]; !ok {
return errors.NotFoundf("identity-domain in the credentials")
}
return nil
} | [
"func",
"(",
"e",
"EnvironProvider",
")",
"validateCloudSpec",
"(",
"spec",
"environs",
".",
"CloudSpec",
")",
"error",
"{",
"if",
"err",
":=",
"spec",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"spec",
".",
"Credential",
"==",
"nil",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// validate the authentication type",
"if",
"authType",
":=",
"spec",
".",
"Credential",
".",
"AuthType",
"(",
")",
";",
"authType",
"!=",
"cloud",
".",
"UserPassAuthType",
"{",
"return",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
",",
"authType",
")",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"ok",
":=",
"spec",
".",
"Credential",
".",
"Attributes",
"(",
")",
"[",
"\"",
"\"",
"]",
";",
"!",
"ok",
"{",
"return",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // validateCloudSpec validates the given configuration against the oracle cloud spec | [
"validateCloudSpec",
"validates",
"the",
"given",
"configuration",
"against",
"the",
"oracle",
"cloud",
"spec"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/provider.go#L58-L76 |
155,513 | juju/juju | provider/oracle/provider.go | Open | func (e *EnvironProvider) Open(params environs.OpenParams) (environs.Environ, error) {
logger.Debugf("opening model %q", params.Config.Name())
if err := e.validateCloudSpec(params.Cloud); err != nil {
return nil, errors.Annotatef(err, "validating cloud spec")
}
cli, err := oci.NewClient(oci.Config{
Username: params.Cloud.Credential.Attributes()["username"],
Password: params.Cloud.Credential.Attributes()["password"],
Endpoint: params.Cloud.Endpoint,
Identify: params.Cloud.Credential.Attributes()["identity-domain"],
})
if err != nil {
return nil, errors.Trace(err)
}
if err = cli.Authenticate(); err != nil {
return nil, errors.Trace(err)
}
return NewOracleEnviron(e, params, cli, clock.WallClock)
} | go | func (e *EnvironProvider) Open(params environs.OpenParams) (environs.Environ, error) {
logger.Debugf("opening model %q", params.Config.Name())
if err := e.validateCloudSpec(params.Cloud); err != nil {
return nil, errors.Annotatef(err, "validating cloud spec")
}
cli, err := oci.NewClient(oci.Config{
Username: params.Cloud.Credential.Attributes()["username"],
Password: params.Cloud.Credential.Attributes()["password"],
Endpoint: params.Cloud.Endpoint,
Identify: params.Cloud.Credential.Attributes()["identity-domain"],
})
if err != nil {
return nil, errors.Trace(err)
}
if err = cli.Authenticate(); err != nil {
return nil, errors.Trace(err)
}
return NewOracleEnviron(e, params, cli, clock.WallClock)
} | [
"func",
"(",
"e",
"*",
"EnvironProvider",
")",
"Open",
"(",
"params",
"environs",
".",
"OpenParams",
")",
"(",
"environs",
".",
"Environ",
",",
"error",
")",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"params",
".",
"Config",
".",
"Name",
"(",
")",
")",
"\n",
"if",
"err",
":=",
"e",
".",
"validateCloudSpec",
"(",
"params",
".",
"Cloud",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"cli",
",",
"err",
":=",
"oci",
".",
"NewClient",
"(",
"oci",
".",
"Config",
"{",
"Username",
":",
"params",
".",
"Cloud",
".",
"Credential",
".",
"Attributes",
"(",
")",
"[",
"\"",
"\"",
"]",
",",
"Password",
":",
"params",
".",
"Cloud",
".",
"Credential",
".",
"Attributes",
"(",
")",
"[",
"\"",
"\"",
"]",
",",
"Endpoint",
":",
"params",
".",
"Cloud",
".",
"Endpoint",
",",
"Identify",
":",
"params",
".",
"Cloud",
".",
"Credential",
".",
"Attributes",
"(",
")",
"[",
"\"",
"\"",
"]",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"cli",
".",
"Authenticate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"NewOracleEnviron",
"(",
"e",
",",
"params",
",",
"cli",
",",
"clock",
".",
"WallClock",
")",
"\n",
"}"
] | // Open is defined on the environs.EnvironProvider interface. | [
"Open",
"is",
"defined",
"on",
"the",
"environs",
".",
"EnvironProvider",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/provider.go#L84-L105 |
155,514 | juju/juju | provider/oracle/provider.go | Validate | func (e EnvironProvider) Validate(cfg, old *config.Config) (valid *config.Config, err error) {
if err := config.Validate(cfg, old); err != nil {
return nil, err
}
newAttrs, err := cfg.ValidateUnknownAttrs(
schema.Fields{}, schema.Defaults{},
)
if err != nil {
return nil, err
}
return cfg.Apply(newAttrs)
} | go | func (e EnvironProvider) Validate(cfg, old *config.Config) (valid *config.Config, err error) {
if err := config.Validate(cfg, old); err != nil {
return nil, err
}
newAttrs, err := cfg.ValidateUnknownAttrs(
schema.Fields{}, schema.Defaults{},
)
if err != nil {
return nil, err
}
return cfg.Apply(newAttrs)
} | [
"func",
"(",
"e",
"EnvironProvider",
")",
"Validate",
"(",
"cfg",
",",
"old",
"*",
"config",
".",
"Config",
")",
"(",
"valid",
"*",
"config",
".",
"Config",
",",
"err",
"error",
")",
"{",
"if",
"err",
":=",
"config",
".",
"Validate",
"(",
"cfg",
",",
"old",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"newAttrs",
",",
"err",
":=",
"cfg",
".",
"ValidateUnknownAttrs",
"(",
"schema",
".",
"Fields",
"{",
"}",
",",
"schema",
".",
"Defaults",
"{",
"}",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"cfg",
".",
"Apply",
"(",
"newAttrs",
")",
"\n",
"}"
] | // Validate is defined on the config.Validator interface. | [
"Validate",
"is",
"defined",
"on",
"the",
"config",
".",
"Validator",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/provider.go#L108-L120 |
155,515 | juju/juju | provider/oracle/provider.go | FinalizeCredential | func (e EnvironProvider) FinalizeCredential(
cfx environs.FinalizeCredentialContext,
params environs.FinalizeCredentialParams,
) (*cloud.Credential, error) {
return ¶ms.Credential, nil
} | go | func (e EnvironProvider) FinalizeCredential(
cfx environs.FinalizeCredentialContext,
params environs.FinalizeCredentialParams,
) (*cloud.Credential, error) {
return ¶ms.Credential, nil
} | [
"func",
"(",
"e",
"EnvironProvider",
")",
"FinalizeCredential",
"(",
"cfx",
"environs",
".",
"FinalizeCredentialContext",
",",
"params",
"environs",
".",
"FinalizeCredentialParams",
",",
")",
"(",
"*",
"cloud",
".",
"Credential",
",",
"error",
")",
"{",
"return",
"&",
"params",
".",
"Credential",
",",
"nil",
"\n",
"}"
] | // FinalizeCredential is defined on the environs.ProviderCredentials interface. | [
"FinalizeCredential",
"is",
"defined",
"on",
"the",
"environs",
".",
"ProviderCredentials",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oracle/provider.go#L150-L156 |
155,516 | juju/juju | cmd/juju/commands/main.go | Main | func Main(args []string) int {
return main{
execCommand: exec.Command,
}.Run(args)
} | go | func Main(args []string) int {
return main{
execCommand: exec.Command,
}.Run(args)
} | [
"func",
"Main",
"(",
"args",
"[",
"]",
"string",
")",
"int",
"{",
"return",
"main",
"{",
"execCommand",
":",
"exec",
".",
"Command",
",",
"}",
".",
"Run",
"(",
"args",
")",
"\n",
"}"
] | // Main registers subcommands for the juju executable, and hands over control
// to the cmd package. This function is not redundant with main, because it
// provides an entry point for testing with arbitrary command line arguments.
// This function returns the exit code, for main to pass to os.Exit. | [
"Main",
"registers",
"subcommands",
"for",
"the",
"juju",
"executable",
"and",
"hands",
"over",
"control",
"to",
"the",
"cmd",
"package",
".",
"This",
"function",
"is",
"not",
"redundant",
"with",
"main",
"because",
"it",
"provides",
"an",
"entry",
"point",
"for",
"testing",
"with",
"arbitrary",
"command",
"line",
"arguments",
".",
"This",
"function",
"returns",
"the",
"exit",
"code",
"for",
"main",
"to",
"pass",
"to",
"os",
".",
"Exit",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/commands/main.go#L86-L90 |
155,517 | juju/juju | cmd/juju/commands/main.go | Run | func (m main) Run(args []string) int {
ctx, err := cmd.DefaultContext()
if err != nil {
cmd.WriteError(os.Stderr, err)
return 2
}
// note that this has to come before we init the juju home directory,
// since it relies on detecting the lack of said directory.
newInstall := m.maybeWarnJuju1x()
if err = juju.InitJujuXDGDataHome(); err != nil {
cmd.WriteError(ctx.Stderr, err)
return 2
}
if err := installProxy(); err != nil {
cmd.WriteError(ctx.Stderr, err)
return 2
}
if newInstall {
fmt.Fprintf(ctx.Stderr, "Since Juju %v is being run for the first time, downloading latest cloud information.\n", jujuversion.Current.Major)
updateCmd := cloud.NewUpdatePublicCloudsCommand()
if err := updateCmd.Run(ctx); err != nil {
cmd.WriteError(ctx.Stderr, err)
}
}
for i := range x {
x[i] ^= 255
}
if len(args) == 2 {
if args[1] == string(x[0:2]) {
os.Stdout.Write(x[9:])
return 0
}
if args[1] == string(x[2:9]) {
os.Stdout.Write(model.ExtractCert())
return 0
}
}
jcmd := NewJujuCommand(ctx)
return cmd.Main(jcmd, ctx, args[1:])
} | go | func (m main) Run(args []string) int {
ctx, err := cmd.DefaultContext()
if err != nil {
cmd.WriteError(os.Stderr, err)
return 2
}
// note that this has to come before we init the juju home directory,
// since it relies on detecting the lack of said directory.
newInstall := m.maybeWarnJuju1x()
if err = juju.InitJujuXDGDataHome(); err != nil {
cmd.WriteError(ctx.Stderr, err)
return 2
}
if err := installProxy(); err != nil {
cmd.WriteError(ctx.Stderr, err)
return 2
}
if newInstall {
fmt.Fprintf(ctx.Stderr, "Since Juju %v is being run for the first time, downloading latest cloud information.\n", jujuversion.Current.Major)
updateCmd := cloud.NewUpdatePublicCloudsCommand()
if err := updateCmd.Run(ctx); err != nil {
cmd.WriteError(ctx.Stderr, err)
}
}
for i := range x {
x[i] ^= 255
}
if len(args) == 2 {
if args[1] == string(x[0:2]) {
os.Stdout.Write(x[9:])
return 0
}
if args[1] == string(x[2:9]) {
os.Stdout.Write(model.ExtractCert())
return 0
}
}
jcmd := NewJujuCommand(ctx)
return cmd.Main(jcmd, ctx, args[1:])
} | [
"func",
"(",
"m",
"main",
")",
"Run",
"(",
"args",
"[",
"]",
"string",
")",
"int",
"{",
"ctx",
",",
"err",
":=",
"cmd",
".",
"DefaultContext",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"cmd",
".",
"WriteError",
"(",
"os",
".",
"Stderr",
",",
"err",
")",
"\n",
"return",
"2",
"\n",
"}",
"\n\n",
"// note that this has to come before we init the juju home directory,",
"// since it relies on detecting the lack of said directory.",
"newInstall",
":=",
"m",
".",
"maybeWarnJuju1x",
"(",
")",
"\n\n",
"if",
"err",
"=",
"juju",
".",
"InitJujuXDGDataHome",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"cmd",
".",
"WriteError",
"(",
"ctx",
".",
"Stderr",
",",
"err",
")",
"\n",
"return",
"2",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"installProxy",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"cmd",
".",
"WriteError",
"(",
"ctx",
".",
"Stderr",
",",
"err",
")",
"\n",
"return",
"2",
"\n",
"}",
"\n\n",
"if",
"newInstall",
"{",
"fmt",
".",
"Fprintf",
"(",
"ctx",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
",",
"jujuversion",
".",
"Current",
".",
"Major",
")",
"\n",
"updateCmd",
":=",
"cloud",
".",
"NewUpdatePublicCloudsCommand",
"(",
")",
"\n",
"if",
"err",
":=",
"updateCmd",
".",
"Run",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"cmd",
".",
"WriteError",
"(",
"ctx",
".",
"Stderr",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"range",
"x",
"{",
"x",
"[",
"i",
"]",
"^=",
"255",
"\n",
"}",
"\n",
"if",
"len",
"(",
"args",
")",
"==",
"2",
"{",
"if",
"args",
"[",
"1",
"]",
"==",
"string",
"(",
"x",
"[",
"0",
":",
"2",
"]",
")",
"{",
"os",
".",
"Stdout",
".",
"Write",
"(",
"x",
"[",
"9",
":",
"]",
")",
"\n",
"return",
"0",
"\n",
"}",
"\n",
"if",
"args",
"[",
"1",
"]",
"==",
"string",
"(",
"x",
"[",
"2",
":",
"9",
"]",
")",
"{",
"os",
".",
"Stdout",
".",
"Write",
"(",
"model",
".",
"ExtractCert",
"(",
")",
")",
"\n",
"return",
"0",
"\n",
"}",
"\n",
"}",
"\n\n",
"jcmd",
":=",
"NewJujuCommand",
"(",
"ctx",
")",
"\n",
"return",
"cmd",
".",
"Main",
"(",
"jcmd",
",",
"ctx",
",",
"args",
"[",
"1",
":",
"]",
")",
"\n",
"}"
] | // Run is the main entry point for the juju client. | [
"Run",
"is",
"the",
"main",
"entry",
"point",
"for",
"the",
"juju",
"client",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/commands/main.go#L99-L144 |
155,518 | juju/juju | apiserver/authentication/user.go | Authenticate | func (u *UserAuthenticator) Authenticate(
entityFinder EntityFinder, tag names.Tag, req params.LoginRequest,
) (state.Entity, error) {
userTag, ok := tag.(names.UserTag)
if !ok {
return nil, errors.Errorf("invalid request")
}
if req.Credentials == "" && userTag.IsLocal() {
return u.authenticateMacaroons(entityFinder, userTag, req)
}
return u.AgentAuthenticator.Authenticate(entityFinder, tag, req)
} | go | func (u *UserAuthenticator) Authenticate(
entityFinder EntityFinder, tag names.Tag, req params.LoginRequest,
) (state.Entity, error) {
userTag, ok := tag.(names.UserTag)
if !ok {
return nil, errors.Errorf("invalid request")
}
if req.Credentials == "" && userTag.IsLocal() {
return u.authenticateMacaroons(entityFinder, userTag, req)
}
return u.AgentAuthenticator.Authenticate(entityFinder, tag, req)
} | [
"func",
"(",
"u",
"*",
"UserAuthenticator",
")",
"Authenticate",
"(",
"entityFinder",
"EntityFinder",
",",
"tag",
"names",
".",
"Tag",
",",
"req",
"params",
".",
"LoginRequest",
",",
")",
"(",
"state",
".",
"Entity",
",",
"error",
")",
"{",
"userTag",
",",
"ok",
":=",
"tag",
".",
"(",
"names",
".",
"UserTag",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"req",
".",
"Credentials",
"==",
"\"",
"\"",
"&&",
"userTag",
".",
"IsLocal",
"(",
")",
"{",
"return",
"u",
".",
"authenticateMacaroons",
"(",
"entityFinder",
",",
"userTag",
",",
"req",
")",
"\n",
"}",
"\n",
"return",
"u",
".",
"AgentAuthenticator",
".",
"Authenticate",
"(",
"entityFinder",
",",
"tag",
",",
"req",
")",
"\n",
"}"
] | // Authenticate authenticates the entity with the specified tag, and returns an
// error on authentication failure.
//
// If and only if no password is supplied, then Authenticate will check for any
// valid macaroons. Otherwise, password authentication will be performed. | [
"Authenticate",
"authenticates",
"the",
"entity",
"with",
"the",
"specified",
"tag",
"and",
"returns",
"an",
"error",
"on",
"authentication",
"failure",
".",
"If",
"and",
"only",
"if",
"no",
"password",
"is",
"supplied",
"then",
"Authenticate",
"will",
"check",
"for",
"any",
"valid",
"macaroons",
".",
"Otherwise",
"password",
"authentication",
"will",
"be",
"performed",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/authentication/user.go#L67-L78 |
155,519 | juju/juju | provider/azure/internal/useragent/useragent.go | UpdateClient | func UpdateClient(client *autorest.Client) {
if client.UserAgent == "" {
client.UserAgent = JujuPrefix()
} else {
client.UserAgent = JujuPrefix() + " " + client.UserAgent
}
} | go | func UpdateClient(client *autorest.Client) {
if client.UserAgent == "" {
client.UserAgent = JujuPrefix()
} else {
client.UserAgent = JujuPrefix() + " " + client.UserAgent
}
} | [
"func",
"UpdateClient",
"(",
"client",
"*",
"autorest",
".",
"Client",
")",
"{",
"if",
"client",
".",
"UserAgent",
"==",
"\"",
"\"",
"{",
"client",
".",
"UserAgent",
"=",
"JujuPrefix",
"(",
")",
"\n",
"}",
"else",
"{",
"client",
".",
"UserAgent",
"=",
"JujuPrefix",
"(",
")",
"+",
"\"",
"\"",
"+",
"client",
".",
"UserAgent",
"\n",
"}",
"\n",
"}"
] | // UpdateClient updates the UserAgent field of the given autorest.Client. | [
"UpdateClient",
"updates",
"the",
"UserAgent",
"field",
"of",
"the",
"given",
"autorest",
".",
"Client",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/internal/useragent/useragent.go#L18-L24 |
155,520 | juju/juju | cmd/jujud/agent/caasoperator.go | NewCaasOperatorAgent | func NewCaasOperatorAgent(ctx *cmd.Context, bufferedLogger *logsender.BufferedLogWriter) (*CaasOperatorAgent, error) {
prometheusRegistry, err := newPrometheusRegistry()
if err != nil {
return nil, errors.Trace(err)
}
return &CaasOperatorAgent{
AgentConf: NewAgentConf(""),
configChangedVal: voyeur.NewValue(true),
ctx: ctx,
dead: make(chan struct{}),
bufferedLogger: bufferedLogger,
prometheusRegistry: prometheusRegistry,
preUpgradeSteps: upgrades.PreUpgradeSteps,
}, nil
} | go | func NewCaasOperatorAgent(ctx *cmd.Context, bufferedLogger *logsender.BufferedLogWriter) (*CaasOperatorAgent, error) {
prometheusRegistry, err := newPrometheusRegistry()
if err != nil {
return nil, errors.Trace(err)
}
return &CaasOperatorAgent{
AgentConf: NewAgentConf(""),
configChangedVal: voyeur.NewValue(true),
ctx: ctx,
dead: make(chan struct{}),
bufferedLogger: bufferedLogger,
prometheusRegistry: prometheusRegistry,
preUpgradeSteps: upgrades.PreUpgradeSteps,
}, nil
} | [
"func",
"NewCaasOperatorAgent",
"(",
"ctx",
"*",
"cmd",
".",
"Context",
",",
"bufferedLogger",
"*",
"logsender",
".",
"BufferedLogWriter",
")",
"(",
"*",
"CaasOperatorAgent",
",",
"error",
")",
"{",
"prometheusRegistry",
",",
"err",
":=",
"newPrometheusRegistry",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"CaasOperatorAgent",
"{",
"AgentConf",
":",
"NewAgentConf",
"(",
"\"",
"\"",
")",
",",
"configChangedVal",
":",
"voyeur",
".",
"NewValue",
"(",
"true",
")",
",",
"ctx",
":",
"ctx",
",",
"dead",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"bufferedLogger",
":",
"bufferedLogger",
",",
"prometheusRegistry",
":",
"prometheusRegistry",
",",
"preUpgradeSteps",
":",
"upgrades",
".",
"PreUpgradeSteps",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewCaasOperatorAgent creates a new CAASOperatorAgent instance properly initialized. | [
"NewCaasOperatorAgent",
"creates",
"a",
"new",
"CAASOperatorAgent",
"instance",
"properly",
"initialized",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/agent/caasoperator.go#L69-L83 |
155,521 | juju/juju | cmd/jujud/agent/caasoperator.go | maybeCopyAgentConfig | func (op *CaasOperatorAgent) maybeCopyAgentConfig() error {
err := op.ReadConfig(op.Tag().String())
if err == nil {
return nil
}
if !os.IsNotExist(errors.Cause(err)) {
logger.Errorf("reading initial agent config file: %v", err)
return errors.Trace(err)
}
templateFile := filepath.Join(agent.Dir(op.DataDir(), op.Tag()), caasprovider.TemplateFileNameAgentConf)
if err := copyFile(agent.ConfigPath(op.DataDir(), op.Tag()), templateFile); err != nil {
logger.Errorf("copying agent config file template: %v", err)
return errors.Trace(err)
}
return op.ReadConfig(op.Tag().String())
} | go | func (op *CaasOperatorAgent) maybeCopyAgentConfig() error {
err := op.ReadConfig(op.Tag().String())
if err == nil {
return nil
}
if !os.IsNotExist(errors.Cause(err)) {
logger.Errorf("reading initial agent config file: %v", err)
return errors.Trace(err)
}
templateFile := filepath.Join(agent.Dir(op.DataDir(), op.Tag()), caasprovider.TemplateFileNameAgentConf)
if err := copyFile(agent.ConfigPath(op.DataDir(), op.Tag()), templateFile); err != nil {
logger.Errorf("copying agent config file template: %v", err)
return errors.Trace(err)
}
return op.ReadConfig(op.Tag().String())
} | [
"func",
"(",
"op",
"*",
"CaasOperatorAgent",
")",
"maybeCopyAgentConfig",
"(",
")",
"error",
"{",
"err",
":=",
"op",
".",
"ReadConfig",
"(",
"op",
".",
"Tag",
"(",
")",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"!",
"os",
".",
"IsNotExist",
"(",
"errors",
".",
"Cause",
"(",
"err",
")",
")",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"templateFile",
":=",
"filepath",
".",
"Join",
"(",
"agent",
".",
"Dir",
"(",
"op",
".",
"DataDir",
"(",
")",
",",
"op",
".",
"Tag",
"(",
")",
")",
",",
"caasprovider",
".",
"TemplateFileNameAgentConf",
")",
"\n",
"if",
"err",
":=",
"copyFile",
"(",
"agent",
".",
"ConfigPath",
"(",
"op",
".",
"DataDir",
"(",
")",
",",
"op",
".",
"Tag",
"(",
")",
")",
",",
"templateFile",
")",
";",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"op",
".",
"ReadConfig",
"(",
"op",
".",
"Tag",
"(",
")",
".",
"String",
"(",
")",
")",
"\n",
"}"
] | // maybeCopyAgentConfig copies the read-only agent config template
// to the writeable agent config file if the file doesn't yet exist. | [
"maybeCopyAgentConfig",
"copies",
"the",
"read",
"-",
"only",
"agent",
"config",
"template",
"to",
"the",
"writeable",
"agent",
"config",
"file",
"if",
"the",
"file",
"doesn",
"t",
"yet",
"exist",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/agent/caasoperator.go#L138-L153 |
155,522 | juju/juju | cmd/jujud/agent/caasoperator.go | Workers | func (op *CaasOperatorAgent) Workers() (worker.Worker, error) {
updateAgentConfLogging := func(loggingConfig string) error {
return op.AgentConf.ChangeConfig(func(setter agent.ConfigSetter) error {
setter.SetLoggingConfig(loggingConfig)
return nil
})
}
agentConfig := op.AgentConf.CurrentConfig()
manifolds := CaasOperatorManifolds(caasoperator.ManifoldsConfig{
Agent: agent.APIHostPortsSetter{op},
AgentConfigChanged: op.configChangedVal,
Clock: clock.WallClock,
LogSource: op.bufferedLogger.Logs(),
UpdateLoggerConfig: updateAgentConfLogging,
PrometheusRegisterer: op.prometheusRegistry,
LeadershipGuarantee: 15 * time.Second,
PreUpgradeSteps: op.preUpgradeSteps,
UpgradeStepsLock: op.upgradeComplete,
ValidateMigration: op.validateMigration,
MachineLock: op.machineLock,
PreviousAgentVersion: agentConfig.UpgradedToVersion(),
})
engine, err := dependency.NewEngine(dependencyEngineConfig())
if err != nil {
return nil, err
}
if err := dependency.Install(engine, manifolds); err != nil {
if err := worker.Stop(engine); err != nil {
logger.Errorf("while stopping engine with bad manifolds: %v", err)
}
return nil, err
}
if err := startIntrospection(introspectionConfig{
Agent: op,
Engine: engine,
MachineLock: op.machineLock,
NewSocketName: DefaultIntrospectionSocketName,
PrometheusGatherer: op.prometheusRegistry,
WorkerFunc: introspection.NewWorker,
}); err != nil {
// If the introspection worker failed to start, we just log error
// but continue. It is very unlikely to happen in the real world
// as the only issue is connecting to the abstract domain socket
// and the agent is controlled by by the OS to only have one.
logger.Errorf("failed to start introspection worker: %v", err)
}
return engine, nil
} | go | func (op *CaasOperatorAgent) Workers() (worker.Worker, error) {
updateAgentConfLogging := func(loggingConfig string) error {
return op.AgentConf.ChangeConfig(func(setter agent.ConfigSetter) error {
setter.SetLoggingConfig(loggingConfig)
return nil
})
}
agentConfig := op.AgentConf.CurrentConfig()
manifolds := CaasOperatorManifolds(caasoperator.ManifoldsConfig{
Agent: agent.APIHostPortsSetter{op},
AgentConfigChanged: op.configChangedVal,
Clock: clock.WallClock,
LogSource: op.bufferedLogger.Logs(),
UpdateLoggerConfig: updateAgentConfLogging,
PrometheusRegisterer: op.prometheusRegistry,
LeadershipGuarantee: 15 * time.Second,
PreUpgradeSteps: op.preUpgradeSteps,
UpgradeStepsLock: op.upgradeComplete,
ValidateMigration: op.validateMigration,
MachineLock: op.machineLock,
PreviousAgentVersion: agentConfig.UpgradedToVersion(),
})
engine, err := dependency.NewEngine(dependencyEngineConfig())
if err != nil {
return nil, err
}
if err := dependency.Install(engine, manifolds); err != nil {
if err := worker.Stop(engine); err != nil {
logger.Errorf("while stopping engine with bad manifolds: %v", err)
}
return nil, err
}
if err := startIntrospection(introspectionConfig{
Agent: op,
Engine: engine,
MachineLock: op.machineLock,
NewSocketName: DefaultIntrospectionSocketName,
PrometheusGatherer: op.prometheusRegistry,
WorkerFunc: introspection.NewWorker,
}); err != nil {
// If the introspection worker failed to start, we just log error
// but continue. It is very unlikely to happen in the real world
// as the only issue is connecting to the abstract domain socket
// and the agent is controlled by by the OS to only have one.
logger.Errorf("failed to start introspection worker: %v", err)
}
return engine, nil
} | [
"func",
"(",
"op",
"*",
"CaasOperatorAgent",
")",
"Workers",
"(",
")",
"(",
"worker",
".",
"Worker",
",",
"error",
")",
"{",
"updateAgentConfLogging",
":=",
"func",
"(",
"loggingConfig",
"string",
")",
"error",
"{",
"return",
"op",
".",
"AgentConf",
".",
"ChangeConfig",
"(",
"func",
"(",
"setter",
"agent",
".",
"ConfigSetter",
")",
"error",
"{",
"setter",
".",
"SetLoggingConfig",
"(",
"loggingConfig",
")",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"}",
"\n\n",
"agentConfig",
":=",
"op",
".",
"AgentConf",
".",
"CurrentConfig",
"(",
")",
"\n",
"manifolds",
":=",
"CaasOperatorManifolds",
"(",
"caasoperator",
".",
"ManifoldsConfig",
"{",
"Agent",
":",
"agent",
".",
"APIHostPortsSetter",
"{",
"op",
"}",
",",
"AgentConfigChanged",
":",
"op",
".",
"configChangedVal",
",",
"Clock",
":",
"clock",
".",
"WallClock",
",",
"LogSource",
":",
"op",
".",
"bufferedLogger",
".",
"Logs",
"(",
")",
",",
"UpdateLoggerConfig",
":",
"updateAgentConfLogging",
",",
"PrometheusRegisterer",
":",
"op",
".",
"prometheusRegistry",
",",
"LeadershipGuarantee",
":",
"15",
"*",
"time",
".",
"Second",
",",
"PreUpgradeSteps",
":",
"op",
".",
"preUpgradeSteps",
",",
"UpgradeStepsLock",
":",
"op",
".",
"upgradeComplete",
",",
"ValidateMigration",
":",
"op",
".",
"validateMigration",
",",
"MachineLock",
":",
"op",
".",
"machineLock",
",",
"PreviousAgentVersion",
":",
"agentConfig",
".",
"UpgradedToVersion",
"(",
")",
",",
"}",
")",
"\n\n",
"engine",
",",
"err",
":=",
"dependency",
".",
"NewEngine",
"(",
"dependencyEngineConfig",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"dependency",
".",
"Install",
"(",
"engine",
",",
"manifolds",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"err",
":=",
"worker",
".",
"Stop",
"(",
"engine",
")",
";",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"startIntrospection",
"(",
"introspectionConfig",
"{",
"Agent",
":",
"op",
",",
"Engine",
":",
"engine",
",",
"MachineLock",
":",
"op",
".",
"machineLock",
",",
"NewSocketName",
":",
"DefaultIntrospectionSocketName",
",",
"PrometheusGatherer",
":",
"op",
".",
"prometheusRegistry",
",",
"WorkerFunc",
":",
"introspection",
".",
"NewWorker",
",",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"// If the introspection worker failed to start, we just log error",
"// but continue. It is very unlikely to happen in the real world",
"// as the only issue is connecting to the abstract domain socket",
"// and the agent is controlled by by the OS to only have one.",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"engine",
",",
"nil",
"\n",
"}"
] | // Workers returns a dependency.Engine running the operator's responsibilities. | [
"Workers",
"returns",
"a",
"dependency",
".",
"Engine",
"running",
"the",
"operator",
"s",
"responsibilities",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/agent/caasoperator.go#L203-L252 |
155,523 | juju/juju | cmd/jujud/agent/caasoperator.go | ChangeConfig | func (op *CaasOperatorAgent) ChangeConfig(mutate agent.ConfigMutator) error {
err := op.AgentConf.ChangeConfig(mutate)
op.configChangedVal.Set(true)
return errors.Trace(err)
} | go | func (op *CaasOperatorAgent) ChangeConfig(mutate agent.ConfigMutator) error {
err := op.AgentConf.ChangeConfig(mutate)
op.configChangedVal.Set(true)
return errors.Trace(err)
} | [
"func",
"(",
"op",
"*",
"CaasOperatorAgent",
")",
"ChangeConfig",
"(",
"mutate",
"agent",
".",
"ConfigMutator",
")",
"error",
"{",
"err",
":=",
"op",
".",
"AgentConf",
".",
"ChangeConfig",
"(",
"mutate",
")",
"\n",
"op",
".",
"configChangedVal",
".",
"Set",
"(",
"true",
")",
"\n",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}"
] | // ChangeConfig implements Agent. | [
"ChangeConfig",
"implements",
"Agent",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/agent/caasoperator.go#L260-L264 |
155,524 | juju/juju | cmd/jujud/agent/checkconnection.go | ConnectAsAgent | func ConnectAsAgent(a agent.Agent) (io.Closer, error) {
return apicaller.ScaryConnect(a, api.Open)
} | go | func ConnectAsAgent(a agent.Agent) (io.Closer, error) {
return apicaller.ScaryConnect(a, api.Open)
} | [
"func",
"ConnectAsAgent",
"(",
"a",
"agent",
".",
"Agent",
")",
"(",
"io",
".",
"Closer",
",",
"error",
")",
"{",
"return",
"apicaller",
".",
"ScaryConnect",
"(",
"a",
",",
"api",
".",
"Open",
")",
"\n",
"}"
] | // ConnectAsAgent really connects to the API specified in the agent
// config. It's extracted so tests can pass something else in. | [
"ConnectAsAgent",
"really",
"connects",
"to",
"the",
"API",
"specified",
"in",
"the",
"agent",
"config",
".",
"It",
"s",
"extracted",
"so",
"tests",
"can",
"pass",
"something",
"else",
"in",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/agent/checkconnection.go#L25-L27 |
155,525 | juju/juju | cmd/jujud/agent/checkconnection.go | NewCheckConnectionCommand | func NewCheckConnectionCommand(config AgentConf, connect ConnectFunc) cmd.Command {
return &checkConnectionCommand{
config: config,
connect: connect,
}
} | go | func NewCheckConnectionCommand(config AgentConf, connect ConnectFunc) cmd.Command {
return &checkConnectionCommand{
config: config,
connect: connect,
}
} | [
"func",
"NewCheckConnectionCommand",
"(",
"config",
"AgentConf",
",",
"connect",
"ConnectFunc",
")",
"cmd",
".",
"Command",
"{",
"return",
"&",
"checkConnectionCommand",
"{",
"config",
":",
"config",
",",
"connect",
":",
"connect",
",",
"}",
"\n",
"}"
] | // NewCheckConnectionCommand returns a command that will test
// connecting to the API with details from the agent's config. | [
"NewCheckConnectionCommand",
"returns",
"a",
"command",
"that",
"will",
"test",
"connecting",
"to",
"the",
"API",
"with",
"details",
"from",
"the",
"agent",
"s",
"config",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/agent/checkconnection.go#L38-L43 |
155,526 | juju/juju | worker/meterstatus/isolated.go | NewIsolatedStatusWorker | func NewIsolatedStatusWorker(cfg IsolatedConfig) (worker.Worker, error) {
if err := cfg.Validate(); err != nil {
return nil, errors.Trace(err)
}
w := &isolatedStatusWorker{
config: cfg,
}
w.tomb.Go(w.loop)
return w, nil
} | go | func NewIsolatedStatusWorker(cfg IsolatedConfig) (worker.Worker, error) {
if err := cfg.Validate(); err != nil {
return nil, errors.Trace(err)
}
w := &isolatedStatusWorker{
config: cfg,
}
w.tomb.Go(w.loop)
return w, nil
} | [
"func",
"NewIsolatedStatusWorker",
"(",
"cfg",
"IsolatedConfig",
")",
"(",
"worker",
".",
"Worker",
",",
"error",
")",
"{",
"if",
"err",
":=",
"cfg",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"w",
":=",
"&",
"isolatedStatusWorker",
"{",
"config",
":",
"cfg",
",",
"}",
"\n",
"w",
".",
"tomb",
".",
"Go",
"(",
"w",
".",
"loop",
")",
"\n",
"return",
"w",
",",
"nil",
"\n",
"}"
] | // NewIsolatedStatusWorker creates a new status worker that runs without an API connection. | [
"NewIsolatedStatusWorker",
"creates",
"a",
"new",
"status",
"worker",
"that",
"runs",
"without",
"an",
"API",
"connection",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/meterstatus/isolated.go#L84-L93 |
155,527 | juju/juju | state/model.go | ParseModelType | func ParseModelType(raw string) (ModelType, error) {
for _, typ := range []ModelType{ModelTypeIAAS, ModelTypeCAAS} {
if raw == string(typ) {
return typ, nil
}
}
return "", errors.NotValidf("model type %v", raw)
} | go | func ParseModelType(raw string) (ModelType, error) {
for _, typ := range []ModelType{ModelTypeIAAS, ModelTypeCAAS} {
if raw == string(typ) {
return typ, nil
}
}
return "", errors.NotValidf("model type %v", raw)
} | [
"func",
"ParseModelType",
"(",
"raw",
"string",
")",
"(",
"ModelType",
",",
"error",
")",
"{",
"for",
"_",
",",
"typ",
":=",
"range",
"[",
"]",
"ModelType",
"{",
"ModelTypeIAAS",
",",
"ModelTypeCAAS",
"}",
"{",
"if",
"raw",
"==",
"string",
"(",
"typ",
")",
"{",
"return",
"typ",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
",",
"raw",
")",
"\n",
"}"
] | // ParseModelType turns a valid model type string into a ModelType
// constant. | [
"ParseModelType",
"turns",
"a",
"valid",
"model",
"type",
"string",
"into",
"a",
"ModelType",
"constant",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L48-L55 |
155,528 | juju/juju | state/model.go | String | func (l slaLevel) String() string {
if l == slaNone {
l = SLAUnsupported
}
return string(l)
} | go | func (l slaLevel) String() string {
if l == slaNone {
l = SLAUnsupported
}
return string(l)
} | [
"func",
"(",
"l",
"slaLevel",
")",
"String",
"(",
")",
"string",
"{",
"if",
"l",
"==",
"slaNone",
"{",
"l",
"=",
"SLAUnsupported",
"\n",
"}",
"\n",
"return",
"string",
"(",
"l",
")",
"\n",
"}"
] | // String implements fmt.Stringer returning the string representation of an
// SLALevel. | [
"String",
"implements",
"fmt",
".",
"Stringer",
"returning",
"the",
"string",
"representation",
"of",
"an",
"SLALevel",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L131-L136 |
155,529 | juju/juju | state/model.go | newSLALevel | func newSLALevel(level string) (slaLevel, error) {
l := slaLevel(level)
if l == slaNone {
l = SLAUnsupported
}
switch l {
case SLAUnsupported, SLAEssential, SLAStandard, SLAAdvanced:
return l, nil
}
return l, errors.NotValidf("SLA level %q", level)
} | go | func newSLALevel(level string) (slaLevel, error) {
l := slaLevel(level)
if l == slaNone {
l = SLAUnsupported
}
switch l {
case SLAUnsupported, SLAEssential, SLAStandard, SLAAdvanced:
return l, nil
}
return l, errors.NotValidf("SLA level %q", level)
} | [
"func",
"newSLALevel",
"(",
"level",
"string",
")",
"(",
"slaLevel",
",",
"error",
")",
"{",
"l",
":=",
"slaLevel",
"(",
"level",
")",
"\n",
"if",
"l",
"==",
"slaNone",
"{",
"l",
"=",
"SLAUnsupported",
"\n",
"}",
"\n",
"switch",
"l",
"{",
"case",
"SLAUnsupported",
",",
"SLAEssential",
",",
"SLAStandard",
",",
"SLAAdvanced",
":",
"return",
"l",
",",
"nil",
"\n",
"}",
"\n",
"return",
"l",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
",",
"level",
")",
"\n",
"}"
] | // newSLALevel returns a new SLA level from a string representation. | [
"newSLALevel",
"returns",
"a",
"new",
"SLA",
"level",
"from",
"a",
"string",
"representation",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L139-L149 |
155,530 | juju/juju | state/model.go | filteredModelUUIDs | func (st *State) filteredModelUUIDs(filter bson.D) ([]string, error) {
models, closer := st.db().GetCollection(modelsC)
defer closer()
var docs []bson.M
err := models.Find(filter).Sort("name", "owner").Select(bson.M{"_id": 1}).All(&docs)
if err != nil {
return nil, err
}
out := make([]string, len(docs))
for i, doc := range docs {
out[i] = doc["_id"].(string)
}
return out, nil
} | go | func (st *State) filteredModelUUIDs(filter bson.D) ([]string, error) {
models, closer := st.db().GetCollection(modelsC)
defer closer()
var docs []bson.M
err := models.Find(filter).Sort("name", "owner").Select(bson.M{"_id": 1}).All(&docs)
if err != nil {
return nil, err
}
out := make([]string, len(docs))
for i, doc := range docs {
out[i] = doc["_id"].(string)
}
return out, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"filteredModelUUIDs",
"(",
"filter",
"bson",
".",
"D",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"models",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"modelsC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"var",
"docs",
"[",
"]",
"bson",
".",
"M",
"\n",
"err",
":=",
"models",
".",
"Find",
"(",
"filter",
")",
".",
"Sort",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
".",
"Select",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"1",
"}",
")",
".",
"All",
"(",
"&",
"docs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"out",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"docs",
")",
")",
"\n",
"for",
"i",
",",
"doc",
":=",
"range",
"docs",
"{",
"out",
"[",
"i",
"]",
"=",
"doc",
"[",
"\"",
"\"",
"]",
".",
"(",
"string",
")",
"\n",
"}",
"\n",
"return",
"out",
",",
"nil",
"\n",
"}"
] | // filteredModelUUIDs returns all model uuids that match the filter. | [
"filteredModelUUIDs",
"returns",
"all",
"model",
"uuids",
"that",
"match",
"the",
"filter",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L213-L227 |
155,531 | juju/juju | state/model.go | ModelExists | func (st *State) ModelExists(uuid string) (bool, error) {
models, closer := st.db().GetCollection(modelsC)
defer closer()
count, err := models.FindId(uuid).Count()
if err != nil {
return false, errors.Annotate(err, "querying model")
}
return count > 0, nil
} | go | func (st *State) ModelExists(uuid string) (bool, error) {
models, closer := st.db().GetCollection(modelsC)
defer closer()
count, err := models.FindId(uuid).Count()
if err != nil {
return false, errors.Annotate(err, "querying model")
}
return count > 0, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"ModelExists",
"(",
"uuid",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"models",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"modelsC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"count",
",",
"err",
":=",
"models",
".",
"FindId",
"(",
"uuid",
")",
".",
"Count",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"count",
">",
"0",
",",
"nil",
"\n",
"}"
] | // ModelExists returns true if a model with the supplied UUID exists. | [
"ModelExists",
"returns",
"true",
"if",
"a",
"model",
"with",
"the",
"supplied",
"UUID",
"exists",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L230-L239 |
155,532 | juju/juju | state/model.go | Validate | func (m ModelArgs) Validate() error {
if m.Type == modelTypeNone {
return errors.NotValidf("empty Type")
}
if m.Config == nil {
return errors.NotValidf("nil Config")
}
if !names.IsValidCloud(m.CloudName) {
return errors.NotValidf("Cloud Name %q", m.CloudName)
}
if m.Owner == (names.UserTag{}) {
return errors.NotValidf("empty Owner")
}
if m.StorageProviderRegistry == nil {
return errors.NotValidf("nil StorageProviderRegistry")
}
switch m.MigrationMode {
case MigrationModeNone, MigrationModeImporting:
default:
return errors.NotValidf("initial migration mode %q", m.MigrationMode)
}
return nil
} | go | func (m ModelArgs) Validate() error {
if m.Type == modelTypeNone {
return errors.NotValidf("empty Type")
}
if m.Config == nil {
return errors.NotValidf("nil Config")
}
if !names.IsValidCloud(m.CloudName) {
return errors.NotValidf("Cloud Name %q", m.CloudName)
}
if m.Owner == (names.UserTag{}) {
return errors.NotValidf("empty Owner")
}
if m.StorageProviderRegistry == nil {
return errors.NotValidf("nil StorageProviderRegistry")
}
switch m.MigrationMode {
case MigrationModeNone, MigrationModeImporting:
default:
return errors.NotValidf("initial migration mode %q", m.MigrationMode)
}
return nil
} | [
"func",
"(",
"m",
"ModelArgs",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"m",
".",
"Type",
"==",
"modelTypeNone",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"m",
".",
"Config",
"==",
"nil",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"names",
".",
"IsValidCloud",
"(",
"m",
".",
"CloudName",
")",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
",",
"m",
".",
"CloudName",
")",
"\n",
"}",
"\n",
"if",
"m",
".",
"Owner",
"==",
"(",
"names",
".",
"UserTag",
"{",
"}",
")",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"m",
".",
"StorageProviderRegistry",
"==",
"nil",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"switch",
"m",
".",
"MigrationMode",
"{",
"case",
"MigrationModeNone",
",",
"MigrationModeImporting",
":",
"default",
":",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
",",
"m",
".",
"MigrationMode",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Validate validates the ModelArgs. | [
"Validate",
"validates",
"the",
"ModelArgs",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L279-L301 |
155,533 | juju/juju | state/model.go | validateCloudRegion | func validateCloudRegion(cloud jujucloud.Cloud, regionName string) (txn.Op, error) {
// Ensure that the cloud region is valid, or if one is not specified,
// that the cloud does not support regions.
assertCloudRegionOp := txn.Op{
C: cloudsC,
Id: cloud.Name,
}
if regionName != "" {
region, err := jujucloud.RegionByName(cloud.Regions, regionName)
if err != nil {
return txn.Op{}, errors.Trace(err)
}
assertCloudRegionOp.Assert = bson.D{
{"regions." + utils.EscapeKey(region.Name), bson.D{{"$exists", true}}},
}
} else {
if len(cloud.Regions) > 0 {
return txn.Op{}, errors.NotValidf("missing CloudRegion")
}
assertCloudRegionOp.Assert = bson.D{
{"regions", bson.D{{"$exists", false}}},
}
}
return assertCloudRegionOp, nil
} | go | func validateCloudRegion(cloud jujucloud.Cloud, regionName string) (txn.Op, error) {
// Ensure that the cloud region is valid, or if one is not specified,
// that the cloud does not support regions.
assertCloudRegionOp := txn.Op{
C: cloudsC,
Id: cloud.Name,
}
if regionName != "" {
region, err := jujucloud.RegionByName(cloud.Regions, regionName)
if err != nil {
return txn.Op{}, errors.Trace(err)
}
assertCloudRegionOp.Assert = bson.D{
{"regions." + utils.EscapeKey(region.Name), bson.D{{"$exists", true}}},
}
} else {
if len(cloud.Regions) > 0 {
return txn.Op{}, errors.NotValidf("missing CloudRegion")
}
assertCloudRegionOp.Assert = bson.D{
{"regions", bson.D{{"$exists", false}}},
}
}
return assertCloudRegionOp, nil
} | [
"func",
"validateCloudRegion",
"(",
"cloud",
"jujucloud",
".",
"Cloud",
",",
"regionName",
"string",
")",
"(",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"// Ensure that the cloud region is valid, or if one is not specified,",
"// that the cloud does not support regions.",
"assertCloudRegionOp",
":=",
"txn",
".",
"Op",
"{",
"C",
":",
"cloudsC",
",",
"Id",
":",
"cloud",
".",
"Name",
",",
"}",
"\n",
"if",
"regionName",
"!=",
"\"",
"\"",
"{",
"region",
",",
"err",
":=",
"jujucloud",
".",
"RegionByName",
"(",
"cloud",
".",
"Regions",
",",
"regionName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"txn",
".",
"Op",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"assertCloudRegionOp",
".",
"Assert",
"=",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
"+",
"utils",
".",
"EscapeKey",
"(",
"region",
".",
"Name",
")",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"true",
"}",
"}",
"}",
",",
"}",
"\n",
"}",
"else",
"{",
"if",
"len",
"(",
"cloud",
".",
"Regions",
")",
">",
"0",
"{",
"return",
"txn",
".",
"Op",
"{",
"}",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"assertCloudRegionOp",
".",
"Assert",
"=",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"false",
"}",
"}",
"}",
",",
"}",
"\n",
"}",
"\n",
"return",
"assertCloudRegionOp",
",",
"nil",
"\n",
"}"
] | // validateCloudRegion validates the given region name against the
// provided Cloud definition, and returns a txn.Op to include in a
// transaction to assert the same. | [
"validateCloudRegion",
"validates",
"the",
"given",
"region",
"name",
"against",
"the",
"provided",
"Cloud",
"definition",
"and",
"returns",
"a",
"txn",
".",
"Op",
"to",
"include",
"in",
"a",
"transaction",
"to",
"assert",
"the",
"same",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L470-L494 |
155,534 | juju/juju | state/model.go | validateCloudCredential | func validateCloudCredential(
cloud jujucloud.Cloud,
cloudCredentials map[string]Credential,
cloudCredential names.CloudCredentialTag,
) (txn.Op, error) {
if cloudCredential != (names.CloudCredentialTag{}) {
if cloudCredential.Cloud().Id() != cloud.Name {
return txn.Op{}, errors.NotValidf("credential %q", cloudCredential.Id())
}
var found bool
for tag := range cloudCredentials {
if tag == cloudCredential.Id() {
found = true
break
}
}
if !found {
return txn.Op{}, errors.NotFoundf("credential %q", cloudCredential.Id())
}
// NOTE(axw) if we add ACLs for credentials,
// we'll need to check access here. The map
// we check above contains only the credentials
// that the model owner has access to.
return txn.Op{
C: cloudCredentialsC,
Id: cloudCredentialDocID(cloudCredential),
Assert: txn.DocExists,
}, nil
}
var hasEmptyAuth bool
for _, authType := range cloud.AuthTypes {
if authType != jujucloud.EmptyAuthType {
continue
}
hasEmptyAuth = true
break
}
if !hasEmptyAuth {
return txn.Op{}, errors.NotValidf("missing CloudCredential")
}
return txn.Op{
C: cloudsC,
Id: cloud.Name,
Assert: bson.D{{"auth-types", string(jujucloud.EmptyAuthType)}},
}, nil
} | go | func validateCloudCredential(
cloud jujucloud.Cloud,
cloudCredentials map[string]Credential,
cloudCredential names.CloudCredentialTag,
) (txn.Op, error) {
if cloudCredential != (names.CloudCredentialTag{}) {
if cloudCredential.Cloud().Id() != cloud.Name {
return txn.Op{}, errors.NotValidf("credential %q", cloudCredential.Id())
}
var found bool
for tag := range cloudCredentials {
if tag == cloudCredential.Id() {
found = true
break
}
}
if !found {
return txn.Op{}, errors.NotFoundf("credential %q", cloudCredential.Id())
}
// NOTE(axw) if we add ACLs for credentials,
// we'll need to check access here. The map
// we check above contains only the credentials
// that the model owner has access to.
return txn.Op{
C: cloudCredentialsC,
Id: cloudCredentialDocID(cloudCredential),
Assert: txn.DocExists,
}, nil
}
var hasEmptyAuth bool
for _, authType := range cloud.AuthTypes {
if authType != jujucloud.EmptyAuthType {
continue
}
hasEmptyAuth = true
break
}
if !hasEmptyAuth {
return txn.Op{}, errors.NotValidf("missing CloudCredential")
}
return txn.Op{
C: cloudsC,
Id: cloud.Name,
Assert: bson.D{{"auth-types", string(jujucloud.EmptyAuthType)}},
}, nil
} | [
"func",
"validateCloudCredential",
"(",
"cloud",
"jujucloud",
".",
"Cloud",
",",
"cloudCredentials",
"map",
"[",
"string",
"]",
"Credential",
",",
"cloudCredential",
"names",
".",
"CloudCredentialTag",
",",
")",
"(",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"if",
"cloudCredential",
"!=",
"(",
"names",
".",
"CloudCredentialTag",
"{",
"}",
")",
"{",
"if",
"cloudCredential",
".",
"Cloud",
"(",
")",
".",
"Id",
"(",
")",
"!=",
"cloud",
".",
"Name",
"{",
"return",
"txn",
".",
"Op",
"{",
"}",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
",",
"cloudCredential",
".",
"Id",
"(",
")",
")",
"\n",
"}",
"\n",
"var",
"found",
"bool",
"\n",
"for",
"tag",
":=",
"range",
"cloudCredentials",
"{",
"if",
"tag",
"==",
"cloudCredential",
".",
"Id",
"(",
")",
"{",
"found",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"found",
"{",
"return",
"txn",
".",
"Op",
"{",
"}",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"cloudCredential",
".",
"Id",
"(",
")",
")",
"\n",
"}",
"\n",
"// NOTE(axw) if we add ACLs for credentials,",
"// we'll need to check access here. The map",
"// we check above contains only the credentials",
"// that the model owner has access to.",
"return",
"txn",
".",
"Op",
"{",
"C",
":",
"cloudCredentialsC",
",",
"Id",
":",
"cloudCredentialDocID",
"(",
"cloudCredential",
")",
",",
"Assert",
":",
"txn",
".",
"DocExists",
",",
"}",
",",
"nil",
"\n",
"}",
"\n",
"var",
"hasEmptyAuth",
"bool",
"\n",
"for",
"_",
",",
"authType",
":=",
"range",
"cloud",
".",
"AuthTypes",
"{",
"if",
"authType",
"!=",
"jujucloud",
".",
"EmptyAuthType",
"{",
"continue",
"\n",
"}",
"\n",
"hasEmptyAuth",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"if",
"!",
"hasEmptyAuth",
"{",
"return",
"txn",
".",
"Op",
"{",
"}",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"txn",
".",
"Op",
"{",
"C",
":",
"cloudsC",
",",
"Id",
":",
"cloud",
".",
"Name",
",",
"Assert",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"string",
"(",
"jujucloud",
".",
"EmptyAuthType",
")",
"}",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // validateCloudCredential validates the given cloud credential
// name against the provided cloud definition and credentials,
// and returns a txn.Op to include in a transaction to assert the
// same. A user is supplied, for which access to the credential
// will be asserted. | [
"validateCloudCredential",
"validates",
"the",
"given",
"cloud",
"credential",
"name",
"against",
"the",
"provided",
"cloud",
"definition",
"and",
"credentials",
"and",
"returns",
"a",
"txn",
".",
"Op",
"to",
"include",
"in",
"a",
"transaction",
"to",
"assert",
"the",
"same",
".",
"A",
"user",
"is",
"supplied",
"for",
"which",
"access",
"to",
"the",
"credential",
"will",
"be",
"asserted",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L501-L546 |
155,535 | juju/juju | state/model.go | ModelTag | func (m *Model) ModelTag() names.ModelTag {
return names.NewModelTag(m.doc.UUID)
} | go | func (m *Model) ModelTag() names.ModelTag {
return names.NewModelTag(m.doc.UUID)
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"ModelTag",
"(",
")",
"names",
".",
"ModelTag",
"{",
"return",
"names",
".",
"NewModelTag",
"(",
"m",
".",
"doc",
".",
"UUID",
")",
"\n",
"}"
] | // ModelTag is the concrete model tag for this model. | [
"ModelTag",
"is",
"the",
"concrete",
"model",
"tag",
"for",
"this",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L556-L558 |
155,536 | juju/juju | state/model.go | ControllerTag | func (m *Model) ControllerTag() names.ControllerTag {
return names.NewControllerTag(m.doc.ControllerUUID)
} | go | func (m *Model) ControllerTag() names.ControllerTag {
return names.NewControllerTag(m.doc.ControllerUUID)
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"ControllerTag",
"(",
")",
"names",
".",
"ControllerTag",
"{",
"return",
"names",
".",
"NewControllerTag",
"(",
"m",
".",
"doc",
".",
"ControllerUUID",
")",
"\n",
"}"
] | // ControllerTag is the tag for the controller that the model is
// running within. | [
"ControllerTag",
"is",
"the",
"tag",
"for",
"the",
"controller",
"that",
"the",
"model",
"is",
"running",
"within",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L562-L564 |
155,537 | juju/juju | state/model.go | CloudCredential | func (m *Model) CloudCredential() (names.CloudCredentialTag, bool) {
if names.IsValidCloudCredential(m.doc.CloudCredential) {
return names.NewCloudCredentialTag(m.doc.CloudCredential), true
}
return names.CloudCredentialTag{}, false
} | go | func (m *Model) CloudCredential() (names.CloudCredentialTag, bool) {
if names.IsValidCloudCredential(m.doc.CloudCredential) {
return names.NewCloudCredentialTag(m.doc.CloudCredential), true
}
return names.CloudCredentialTag{}, false
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"CloudCredential",
"(",
")",
"(",
"names",
".",
"CloudCredentialTag",
",",
"bool",
")",
"{",
"if",
"names",
".",
"IsValidCloudCredential",
"(",
"m",
".",
"doc",
".",
"CloudCredential",
")",
"{",
"return",
"names",
".",
"NewCloudCredentialTag",
"(",
"m",
".",
"doc",
".",
"CloudCredential",
")",
",",
"true",
"\n",
"}",
"\n",
"return",
"names",
".",
"CloudCredentialTag",
"{",
"}",
",",
"false",
"\n",
"}"
] | // CloudCredential returns the tag of the cloud credential used for managing the
// model's cloud resources, and a boolean indicating whether a credential is set. | [
"CloudCredential",
"returns",
"the",
"tag",
"of",
"the",
"cloud",
"credential",
"used",
"for",
"managing",
"the",
"model",
"s",
"cloud",
"resources",
"and",
"a",
"boolean",
"indicating",
"whether",
"a",
"credential",
"is",
"set",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L599-L604 |
155,538 | juju/juju | state/model.go | SetMigrationMode | func (m *Model) SetMigrationMode(mode MigrationMode) error {
ops := []txn.Op{{
C: modelsC,
Id: m.doc.UUID,
Assert: txn.DocExists,
Update: bson.D{{"$set", bson.D{{"migration-mode", mode}}}},
}}
if err := m.st.db().RunTransaction(ops); err != nil {
return errors.Trace(err)
}
return m.Refresh()
} | go | func (m *Model) SetMigrationMode(mode MigrationMode) error {
ops := []txn.Op{{
C: modelsC,
Id: m.doc.UUID,
Assert: txn.DocExists,
Update: bson.D{{"$set", bson.D{{"migration-mode", mode}}}},
}}
if err := m.st.db().RunTransaction(ops); err != nil {
return errors.Trace(err)
}
return m.Refresh()
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"SetMigrationMode",
"(",
"mode",
"MigrationMode",
")",
"error",
"{",
"ops",
":=",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"modelsC",
",",
"Id",
":",
"m",
".",
"doc",
".",
"UUID",
",",
"Assert",
":",
"txn",
".",
"DocExists",
",",
"Update",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"mode",
"}",
"}",
"}",
"}",
",",
"}",
"}",
"\n",
"if",
"err",
":=",
"m",
".",
"st",
".",
"db",
"(",
")",
".",
"RunTransaction",
"(",
"ops",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"m",
".",
"Refresh",
"(",
")",
"\n",
"}"
] | // SetMigrationMode updates the migration mode of the model. | [
"SetMigrationMode",
"updates",
"the",
"migration",
"mode",
"of",
"the",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L612-L623 |
155,539 | juju/juju | state/model.go | Owner | func (m *Model) Owner() names.UserTag {
return names.NewUserTag(m.doc.Owner)
} | go | func (m *Model) Owner() names.UserTag {
return names.NewUserTag(m.doc.Owner)
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"Owner",
"(",
")",
"names",
".",
"UserTag",
"{",
"return",
"names",
".",
"NewUserTag",
"(",
"m",
".",
"doc",
".",
"Owner",
")",
"\n",
"}"
] | // Owner returns tag representing the owner of the model.
// The owner is the user that created the model. | [
"Owner",
"returns",
"tag",
"representing",
"the",
"owner",
"of",
"the",
"model",
".",
"The",
"owner",
"is",
"the",
"user",
"that",
"created",
"the",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L632-L634 |
155,540 | juju/juju | state/model.go | Status | func (m *Model) Status() (status.StatusInfo, error) {
modelStatus, err := getStatus(m.st.db(), m.globalKey(), "model")
if err != nil {
return modelStatus, err
}
return modelStatus, nil
} | go | func (m *Model) Status() (status.StatusInfo, error) {
modelStatus, err := getStatus(m.st.db(), m.globalKey(), "model")
if err != nil {
return modelStatus, err
}
return modelStatus, nil
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"Status",
"(",
")",
"(",
"status",
".",
"StatusInfo",
",",
"error",
")",
"{",
"modelStatus",
",",
"err",
":=",
"getStatus",
"(",
"m",
".",
"st",
".",
"db",
"(",
")",
",",
"m",
".",
"globalKey",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"modelStatus",
",",
"err",
"\n",
"}",
"\n",
"return",
"modelStatus",
",",
"nil",
"\n",
"}"
] | // Status returns the status of the model. | [
"Status",
"returns",
"the",
"status",
"of",
"the",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L637-L643 |
155,541 | juju/juju | state/model.go | localID | func (m *Model) localID(ID string) string {
modelUUID, localID, ok := splitDocID(ID)
if !ok || modelUUID != m.doc.UUID {
return ID
}
return localID
} | go | func (m *Model) localID(ID string) string {
modelUUID, localID, ok := splitDocID(ID)
if !ok || modelUUID != m.doc.UUID {
return ID
}
return localID
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"localID",
"(",
"ID",
"string",
")",
"string",
"{",
"modelUUID",
",",
"localID",
",",
"ok",
":=",
"splitDocID",
"(",
"ID",
")",
"\n",
"if",
"!",
"ok",
"||",
"modelUUID",
"!=",
"m",
".",
"doc",
".",
"UUID",
"{",
"return",
"ID",
"\n",
"}",
"\n",
"return",
"localID",
"\n",
"}"
] | // localID returns the local id value by stripping off the model uuid prefix
// if it is there. | [
"localID",
"returns",
"the",
"local",
"id",
"value",
"by",
"stripping",
"off",
"the",
"model",
"uuid",
"prefix",
"if",
"it",
"is",
"there",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L647-L653 |
155,542 | juju/juju | state/model.go | SetSLA | func (m *Model) SetSLA(level, owner string, credentials []byte) error {
l, err := newSLALevel(level)
if err != nil {
return errors.Trace(err)
}
ops := []txn.Op{{
C: modelsC,
Id: m.doc.UUID,
Update: bson.D{{"$set", bson.D{{"sla", slaDoc{
Level: l,
Owner: owner,
Credentials: credentials,
}}}}},
}}
err = m.st.db().RunTransaction(ops)
if err != nil {
return errors.Trace(err)
}
return m.Refresh()
} | go | func (m *Model) SetSLA(level, owner string, credentials []byte) error {
l, err := newSLALevel(level)
if err != nil {
return errors.Trace(err)
}
ops := []txn.Op{{
C: modelsC,
Id: m.doc.UUID,
Update: bson.D{{"$set", bson.D{{"sla", slaDoc{
Level: l,
Owner: owner,
Credentials: credentials,
}}}}},
}}
err = m.st.db().RunTransaction(ops)
if err != nil {
return errors.Trace(err)
}
return m.Refresh()
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"SetSLA",
"(",
"level",
",",
"owner",
"string",
",",
"credentials",
"[",
"]",
"byte",
")",
"error",
"{",
"l",
",",
"err",
":=",
"newSLALevel",
"(",
"level",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"ops",
":=",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"modelsC",
",",
"Id",
":",
"m",
".",
"doc",
".",
"UUID",
",",
"Update",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"slaDoc",
"{",
"Level",
":",
"l",
",",
"Owner",
":",
"owner",
",",
"Credentials",
":",
"credentials",
",",
"}",
"}",
"}",
"}",
"}",
",",
"}",
"}",
"\n",
"err",
"=",
"m",
".",
"st",
".",
"db",
"(",
")",
".",
"RunTransaction",
"(",
"ops",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"m",
".",
"Refresh",
"(",
")",
"\n",
"}"
] | // SetSLA sets the SLA on the model. | [
"SetSLA",
"sets",
"the",
"SLA",
"on",
"the",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L741-L760 |
155,543 | juju/juju | state/model.go | SetMeterStatus | func (m *Model) SetMeterStatus(status, info string) error {
if _, err := isValidMeterStatusCode(status); err != nil {
return errors.Trace(err)
}
ops := []txn.Op{{
C: modelsC,
Id: m.doc.UUID,
Update: bson.D{{"$set", bson.D{{"meter-status", modelMeterStatusdoc{
Code: status,
Info: info,
}}}}},
}}
err := m.st.db().RunTransaction(ops)
if err != nil {
return errors.Trace(err)
}
return m.Refresh()
} | go | func (m *Model) SetMeterStatus(status, info string) error {
if _, err := isValidMeterStatusCode(status); err != nil {
return errors.Trace(err)
}
ops := []txn.Op{{
C: modelsC,
Id: m.doc.UUID,
Update: bson.D{{"$set", bson.D{{"meter-status", modelMeterStatusdoc{
Code: status,
Info: info,
}}}}},
}}
err := m.st.db().RunTransaction(ops)
if err != nil {
return errors.Trace(err)
}
return m.Refresh()
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"SetMeterStatus",
"(",
"status",
",",
"info",
"string",
")",
"error",
"{",
"if",
"_",
",",
"err",
":=",
"isValidMeterStatusCode",
"(",
"status",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"ops",
":=",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"modelsC",
",",
"Id",
":",
"m",
".",
"doc",
".",
"UUID",
",",
"Update",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"modelMeterStatusdoc",
"{",
"Code",
":",
"status",
",",
"Info",
":",
"info",
",",
"}",
"}",
"}",
"}",
"}",
",",
"}",
"}",
"\n",
"err",
":=",
"m",
".",
"st",
".",
"db",
"(",
")",
".",
"RunTransaction",
"(",
"ops",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"m",
".",
"Refresh",
"(",
")",
"\n",
"}"
] | // SetMeterStatus sets the current meter status for this model. | [
"SetMeterStatus",
"sets",
"the",
"current",
"meter",
"status",
"for",
"this",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L763-L780 |
155,544 | juju/juju | state/model.go | MeterStatus | func (m *Model) MeterStatus() MeterStatus {
ms := m.doc.MeterStatus
return MeterStatus{
Code: MeterStatusFromString(ms.Code),
Info: ms.Info,
}
} | go | func (m *Model) MeterStatus() MeterStatus {
ms := m.doc.MeterStatus
return MeterStatus{
Code: MeterStatusFromString(ms.Code),
Info: ms.Info,
}
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"MeterStatus",
"(",
")",
"MeterStatus",
"{",
"ms",
":=",
"m",
".",
"doc",
".",
"MeterStatus",
"\n",
"return",
"MeterStatus",
"{",
"Code",
":",
"MeterStatusFromString",
"(",
"ms",
".",
"Code",
")",
",",
"Info",
":",
"ms",
".",
"Info",
",",
"}",
"\n",
"}"
] | // MeterStatus returns the current meter status for this model. | [
"MeterStatus",
"returns",
"the",
"current",
"meter",
"status",
"for",
"this",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L783-L789 |
155,545 | juju/juju | state/model.go | SetEnvironVersion | func (m *Model) SetEnvironVersion(v int) error {
mOrig := m
mCopy := *m
m = &mCopy // copy so we can refresh without affecting the original m
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
if err := m.Refresh(); err != nil {
return nil, errors.Trace(err)
}
}
if v < m.doc.EnvironVersion {
return nil, errors.Errorf(
"cannot set environ version to %v, which is less than the current version %v",
v, m.doc.EnvironVersion,
)
}
if v == m.doc.EnvironVersion {
return nil, jujutxn.ErrNoOperations
}
return []txn.Op{{
C: modelsC,
Id: m.doc.UUID,
Assert: bson.D{{"environ-version", m.doc.EnvironVersion}},
Update: bson.D{{"$set", bson.D{{"environ-version", v}}}},
}}, nil
}
if err := m.st.db().Run(buildTxn); err != nil {
return errors.Trace(err)
}
mOrig.doc.EnvironVersion = v
return nil
} | go | func (m *Model) SetEnvironVersion(v int) error {
mOrig := m
mCopy := *m
m = &mCopy // copy so we can refresh without affecting the original m
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
if err := m.Refresh(); err != nil {
return nil, errors.Trace(err)
}
}
if v < m.doc.EnvironVersion {
return nil, errors.Errorf(
"cannot set environ version to %v, which is less than the current version %v",
v, m.doc.EnvironVersion,
)
}
if v == m.doc.EnvironVersion {
return nil, jujutxn.ErrNoOperations
}
return []txn.Op{{
C: modelsC,
Id: m.doc.UUID,
Assert: bson.D{{"environ-version", m.doc.EnvironVersion}},
Update: bson.D{{"$set", bson.D{{"environ-version", v}}}},
}}, nil
}
if err := m.st.db().Run(buildTxn); err != nil {
return errors.Trace(err)
}
mOrig.doc.EnvironVersion = v
return nil
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"SetEnvironVersion",
"(",
"v",
"int",
")",
"error",
"{",
"mOrig",
":=",
"m",
"\n",
"mCopy",
":=",
"*",
"m",
"\n",
"m",
"=",
"&",
"mCopy",
"// copy so we can refresh without affecting the original m",
"\n",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"if",
"attempt",
">",
"0",
"{",
"if",
"err",
":=",
"m",
".",
"Refresh",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"v",
"<",
"m",
".",
"doc",
".",
"EnvironVersion",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
",",
"m",
".",
"doc",
".",
"EnvironVersion",
",",
")",
"\n",
"}",
"\n",
"if",
"v",
"==",
"m",
".",
"doc",
".",
"EnvironVersion",
"{",
"return",
"nil",
",",
"jujutxn",
".",
"ErrNoOperations",
"\n",
"}",
"\n",
"return",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"modelsC",
",",
"Id",
":",
"m",
".",
"doc",
".",
"UUID",
",",
"Assert",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"m",
".",
"doc",
".",
"EnvironVersion",
"}",
"}",
",",
"Update",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"v",
"}",
"}",
"}",
"}",
",",
"}",
"}",
",",
"nil",
"\n",
"}",
"\n",
"if",
"err",
":=",
"m",
".",
"st",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"mOrig",
".",
"doc",
".",
"EnvironVersion",
"=",
"v",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetEnvironVersion sets the model's current environ version. The value
// must be monotonically increasing. | [
"SetEnvironVersion",
"sets",
"the",
"model",
"s",
"current",
"environ",
"version",
".",
"The",
"value",
"must",
"be",
"monotonically",
"increasing",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L802-L833 |
155,546 | juju/juju | state/model.go | AllUnits | func (m *Model) AllUnits() ([]*Unit, error) {
coll, closer := m.st.db().GetCollection(unitsC)
defer closer()
docs := []unitDoc{}
err := coll.Find(nil).All(&docs)
if err != nil {
return nil, errors.Annotate(err, "cannot get all units for model")
}
var units []*Unit
for i := range docs {
units = append(units, newUnit(m.st, m.Type(), &docs[i]))
}
return units, nil
} | go | func (m *Model) AllUnits() ([]*Unit, error) {
coll, closer := m.st.db().GetCollection(unitsC)
defer closer()
docs := []unitDoc{}
err := coll.Find(nil).All(&docs)
if err != nil {
return nil, errors.Annotate(err, "cannot get all units for model")
}
var units []*Unit
for i := range docs {
units = append(units, newUnit(m.st, m.Type(), &docs[i]))
}
return units, nil
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"AllUnits",
"(",
")",
"(",
"[",
"]",
"*",
"Unit",
",",
"error",
")",
"{",
"coll",
",",
"closer",
":=",
"m",
".",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"unitsC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"docs",
":=",
"[",
"]",
"unitDoc",
"{",
"}",
"\n",
"err",
":=",
"coll",
".",
"Find",
"(",
"nil",
")",
".",
"All",
"(",
"&",
"docs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"units",
"[",
"]",
"*",
"Unit",
"\n",
"for",
"i",
":=",
"range",
"docs",
"{",
"units",
"=",
"append",
"(",
"units",
",",
"newUnit",
"(",
"m",
".",
"st",
",",
"m",
".",
"Type",
"(",
")",
",",
"&",
"docs",
"[",
"i",
"]",
")",
")",
"\n",
"}",
"\n",
"return",
"units",
",",
"nil",
"\n",
"}"
] | // AllUnits returns all units for a model, for all applications. | [
"AllUnits",
"returns",
"all",
"units",
"for",
"a",
"model",
"for",
"all",
"applications",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L855-L869 |
155,547 | juju/juju | state/model.go | AllEndpointBindings | func (m *Model) AllEndpointBindings() ([]ApplicationEndpointBindings, error) {
endpointBindings, closer := m.st.db().GetCollection(endpointBindingsC)
defer closer()
var docs []endpointBindingsDoc
err := endpointBindings.Find(nil).All(&docs)
if err != nil {
return nil, errors.Annotatef(err, "cannot get endpoint bindings")
}
var appEndpointBindings []ApplicationEndpointBindings
for _, doc := range docs {
var applicationName string
applicationKey := m.localID(doc.DocID)
// for each application deployed we have an instance of ApplicationEndpointBindings struct
if strings.HasPrefix(applicationKey, "a#") {
applicationName = applicationKey[2:]
} else {
return nil, errors.NotValidf("application key %v", applicationKey)
}
endpointBindings := ApplicationEndpointBindings{
AppName: applicationName,
Bindings: doc.Bindings,
}
appEndpointBindings = append(appEndpointBindings, endpointBindings)
}
return appEndpointBindings, nil
} | go | func (m *Model) AllEndpointBindings() ([]ApplicationEndpointBindings, error) {
endpointBindings, closer := m.st.db().GetCollection(endpointBindingsC)
defer closer()
var docs []endpointBindingsDoc
err := endpointBindings.Find(nil).All(&docs)
if err != nil {
return nil, errors.Annotatef(err, "cannot get endpoint bindings")
}
var appEndpointBindings []ApplicationEndpointBindings
for _, doc := range docs {
var applicationName string
applicationKey := m.localID(doc.DocID)
// for each application deployed we have an instance of ApplicationEndpointBindings struct
if strings.HasPrefix(applicationKey, "a#") {
applicationName = applicationKey[2:]
} else {
return nil, errors.NotValidf("application key %v", applicationKey)
}
endpointBindings := ApplicationEndpointBindings{
AppName: applicationName,
Bindings: doc.Bindings,
}
appEndpointBindings = append(appEndpointBindings, endpointBindings)
}
return appEndpointBindings, nil
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"AllEndpointBindings",
"(",
")",
"(",
"[",
"]",
"ApplicationEndpointBindings",
",",
"error",
")",
"{",
"endpointBindings",
",",
"closer",
":=",
"m",
".",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"endpointBindingsC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"var",
"docs",
"[",
"]",
"endpointBindingsDoc",
"\n",
"err",
":=",
"endpointBindings",
".",
"Find",
"(",
"nil",
")",
".",
"All",
"(",
"&",
"docs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"appEndpointBindings",
"[",
"]",
"ApplicationEndpointBindings",
"\n",
"for",
"_",
",",
"doc",
":=",
"range",
"docs",
"{",
"var",
"applicationName",
"string",
"\n",
"applicationKey",
":=",
"m",
".",
"localID",
"(",
"doc",
".",
"DocID",
")",
"\n",
"// for each application deployed we have an instance of ApplicationEndpointBindings struct",
"if",
"strings",
".",
"HasPrefix",
"(",
"applicationKey",
",",
"\"",
"\"",
")",
"{",
"applicationName",
"=",
"applicationKey",
"[",
"2",
":",
"]",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
",",
"applicationKey",
")",
"\n",
"}",
"\n",
"endpointBindings",
":=",
"ApplicationEndpointBindings",
"{",
"AppName",
":",
"applicationName",
",",
"Bindings",
":",
"doc",
".",
"Bindings",
",",
"}",
"\n\n",
"appEndpointBindings",
"=",
"append",
"(",
"appEndpointBindings",
",",
"endpointBindings",
")",
"\n",
"}",
"\n",
"return",
"appEndpointBindings",
",",
"nil",
"\n",
"}"
] | // AllEndpointBindings returns all endpoint->space bindings for every application | [
"AllEndpointBindings",
"returns",
"all",
"endpoint",
"-",
">",
"space",
"bindings",
"for",
"every",
"application"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L878-L906 |
155,548 | juju/juju | state/model.go | Users | func (m *Model) Users() ([]permission.UserAccess, error) {
coll, closer := m.st.db().GetCollection(modelUsersC)
defer closer()
var userDocs []userAccessDoc
err := coll.Find(nil).All(&userDocs)
if err != nil {
return nil, errors.Trace(err)
}
var modelUsers []permission.UserAccess
for _, doc := range userDocs {
// check if the User belonging to this model user has
// been deleted, in this case we should not return it.
userTag := names.NewUserTag(doc.UserName)
if userTag.IsLocal() {
_, err := m.st.User(userTag)
if err != nil {
if _, ok := err.(DeletedUserError); !ok {
// We ignore deleted users for now. So if it is not a
// DeletedUserError we return the error.
return nil, errors.Trace(err)
}
continue
}
}
mu, err := NewModelUserAccess(m.st, doc)
if err != nil {
return nil, errors.Trace(err)
}
modelUsers = append(modelUsers, mu)
}
return modelUsers, nil
} | go | func (m *Model) Users() ([]permission.UserAccess, error) {
coll, closer := m.st.db().GetCollection(modelUsersC)
defer closer()
var userDocs []userAccessDoc
err := coll.Find(nil).All(&userDocs)
if err != nil {
return nil, errors.Trace(err)
}
var modelUsers []permission.UserAccess
for _, doc := range userDocs {
// check if the User belonging to this model user has
// been deleted, in this case we should not return it.
userTag := names.NewUserTag(doc.UserName)
if userTag.IsLocal() {
_, err := m.st.User(userTag)
if err != nil {
if _, ok := err.(DeletedUserError); !ok {
// We ignore deleted users for now. So if it is not a
// DeletedUserError we return the error.
return nil, errors.Trace(err)
}
continue
}
}
mu, err := NewModelUserAccess(m.st, doc)
if err != nil {
return nil, errors.Trace(err)
}
modelUsers = append(modelUsers, mu)
}
return modelUsers, nil
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"Users",
"(",
")",
"(",
"[",
"]",
"permission",
".",
"UserAccess",
",",
"error",
")",
"{",
"coll",
",",
"closer",
":=",
"m",
".",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"modelUsersC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"var",
"userDocs",
"[",
"]",
"userAccessDoc",
"\n",
"err",
":=",
"coll",
".",
"Find",
"(",
"nil",
")",
".",
"All",
"(",
"&",
"userDocs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"var",
"modelUsers",
"[",
"]",
"permission",
".",
"UserAccess",
"\n",
"for",
"_",
",",
"doc",
":=",
"range",
"userDocs",
"{",
"// check if the User belonging to this model user has",
"// been deleted, in this case we should not return it.",
"userTag",
":=",
"names",
".",
"NewUserTag",
"(",
"doc",
".",
"UserName",
")",
"\n",
"if",
"userTag",
".",
"IsLocal",
"(",
")",
"{",
"_",
",",
"err",
":=",
"m",
".",
"st",
".",
"User",
"(",
"userTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"DeletedUserError",
")",
";",
"!",
"ok",
"{",
"// We ignore deleted users for now. So if it is not a",
"// DeletedUserError we return the error.",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"mu",
",",
"err",
":=",
"NewModelUserAccess",
"(",
"m",
".",
"st",
",",
"doc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"modelUsers",
"=",
"append",
"(",
"modelUsers",
",",
"mu",
")",
"\n",
"}",
"\n\n",
"return",
"modelUsers",
",",
"nil",
"\n",
"}"
] | // Users returns a slice of all users for this model. | [
"Users",
"returns",
"a",
"slice",
"of",
"all",
"users",
"for",
"this",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L909-L943 |
155,549 | juju/juju | state/model.go | IsControllerModel | func (m *Model) IsControllerModel() bool {
return m.st.controllerModelTag.Id() == m.doc.UUID
} | go | func (m *Model) IsControllerModel() bool {
return m.st.controllerModelTag.Id() == m.doc.UUID
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"IsControllerModel",
"(",
")",
"bool",
"{",
"return",
"m",
".",
"st",
".",
"controllerModelTag",
".",
"Id",
"(",
")",
"==",
"m",
".",
"doc",
".",
"UUID",
"\n",
"}"
] | // IsControllerModel returns a boolean indicating whether
// this model is responsible for running a controller. | [
"IsControllerModel",
"returns",
"a",
"boolean",
"indicating",
"whether",
"this",
"model",
"is",
"responsible",
"for",
"running",
"a",
"controller",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L947-L949 |
155,550 | juju/juju | state/model.go | Destroy | func (m *Model) Destroy(args DestroyModelParams) (err error) {
defer errors.DeferredAnnotatef(&err, "failed to destroy model")
buildTxn := func(attempt int) ([]txn.Op, error) {
// On the first attempt, we assume memory state is recent
// enough to try using...
if attempt != 0 {
// ...but on subsequent attempts, we read fresh environ
// state from the DB. Note that we do *not* refresh the
// original `m` itself, as detailed in doc/hacking-state.txt
if attempt == 1 {
mCopy := *m
m = &mCopy
}
if err := m.Refresh(); err != nil {
return nil, errors.Trace(err)
}
}
ops, err := m.destroyOps(args, false, false)
if err == errModelNotAlive {
return nil, jujutxn.ErrNoOperations
} else if err != nil {
return nil, errors.Trace(err)
}
return ops, nil
}
return m.st.db().Run(buildTxn)
} | go | func (m *Model) Destroy(args DestroyModelParams) (err error) {
defer errors.DeferredAnnotatef(&err, "failed to destroy model")
buildTxn := func(attempt int) ([]txn.Op, error) {
// On the first attempt, we assume memory state is recent
// enough to try using...
if attempt != 0 {
// ...but on subsequent attempts, we read fresh environ
// state from the DB. Note that we do *not* refresh the
// original `m` itself, as detailed in doc/hacking-state.txt
if attempt == 1 {
mCopy := *m
m = &mCopy
}
if err := m.Refresh(); err != nil {
return nil, errors.Trace(err)
}
}
ops, err := m.destroyOps(args, false, false)
if err == errModelNotAlive {
return nil, jujutxn.ErrNoOperations
} else if err != nil {
return nil, errors.Trace(err)
}
return ops, nil
}
return m.st.db().Run(buildTxn)
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"Destroy",
"(",
"args",
"DestroyModelParams",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
")",
"\n\n",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"// On the first attempt, we assume memory state is recent",
"// enough to try using...",
"if",
"attempt",
"!=",
"0",
"{",
"// ...but on subsequent attempts, we read fresh environ",
"// state from the DB. Note that we do *not* refresh the",
"// original `m` itself, as detailed in doc/hacking-state.txt",
"if",
"attempt",
"==",
"1",
"{",
"mCopy",
":=",
"*",
"m",
"\n",
"m",
"=",
"&",
"mCopy",
"\n",
"}",
"\n",
"if",
"err",
":=",
"m",
".",
"Refresh",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"ops",
",",
"err",
":=",
"m",
".",
"destroyOps",
"(",
"args",
",",
"false",
",",
"false",
")",
"\n",
"if",
"err",
"==",
"errModelNotAlive",
"{",
"return",
"nil",
",",
"jujutxn",
".",
"ErrNoOperations",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"ops",
",",
"nil",
"\n",
"}",
"\n",
"return",
"m",
".",
"st",
".",
"db",
"(",
")",
".",
"Run",
"(",
"buildTxn",
")",
"\n",
"}"
] | // Destroy sets the models's lifecycle to Dying, preventing
// addition of applications or machines to state. If called on
// an empty hosted model, the lifecycle will be advanced
// straight to Dead. | [
"Destroy",
"sets",
"the",
"models",
"s",
"lifecycle",
"to",
"Dying",
"preventing",
"addition",
"of",
"applications",
"or",
"machines",
"to",
"state",
".",
"If",
"called",
"on",
"an",
"empty",
"hosted",
"model",
"the",
"lifecycle",
"will",
"be",
"advanced",
"straight",
"to",
"Dead",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L996-L1024 |
155,551 | juju/juju | state/model.go | IsHasHostedModelsError | func IsHasHostedModelsError(err error) bool {
_, ok := errors.Cause(err).(hasHostedModelsError)
return ok
} | go | func IsHasHostedModelsError(err error) bool {
_, ok := errors.Cause(err).(hasHostedModelsError)
return ok
} | [
"func",
"IsHasHostedModelsError",
"(",
"err",
"error",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"errors",
".",
"Cause",
"(",
"err",
")",
".",
"(",
"hasHostedModelsError",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // IsHasHostedModelsError reports whether or not the given error
// was caused by an attempt to destroy the controller model while
// it contained non-empty hosted models, without specifying that
// they should also be destroyed. | [
"IsHasHostedModelsError",
"reports",
"whether",
"or",
"not",
"the",
"given",
"error",
"was",
"caused",
"by",
"an",
"attempt",
"to",
"destroy",
"the",
"controller",
"model",
"while",
"it",
"contained",
"non",
"-",
"empty",
"hosted",
"models",
"without",
"specifying",
"that",
"they",
"should",
"also",
"be",
"destroyed",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L1044-L1047 |
155,552 | juju/juju | state/model.go | IsModelNotEmptyError | func IsModelNotEmptyError(err error) bool {
_, ok := errors.Cause(err).(modelNotEmptyError)
return ok
} | go | func IsModelNotEmptyError(err error) bool {
_, ok := errors.Cause(err).(modelNotEmptyError)
return ok
} | [
"func",
"IsModelNotEmptyError",
"(",
"err",
"error",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"errors",
".",
"Cause",
"(",
"err",
")",
".",
"(",
"modelNotEmptyError",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // IsModelNotEmptyError reports whether or not the given error was caused
// due to an operation requiring a model to be empty, where the model is
// non-empty. | [
"IsModelNotEmptyError",
"reports",
"whether",
"or",
"not",
"the",
"given",
"error",
"was",
"caused",
"due",
"to",
"an",
"operation",
"requiring",
"a",
"model",
"to",
"be",
"empty",
"where",
"the",
"model",
"is",
"non",
"-",
"empty",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L1100-L1103 |
155,553 | juju/juju | state/model.go | getEntityRefs | func (m *Model) getEntityRefs() (*modelEntityRefsDoc, error) {
modelEntityRefs, closer := m.st.db().GetCollection(modelEntityRefsC)
defer closer()
var doc modelEntityRefsDoc
if err := modelEntityRefs.FindId(m.UUID()).One(&doc); err != nil {
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("entity references doc for model %s", m.UUID())
}
return nil, errors.Annotatef(err, "getting entity references for model %s", m.UUID())
}
return &doc, nil
} | go | func (m *Model) getEntityRefs() (*modelEntityRefsDoc, error) {
modelEntityRefs, closer := m.st.db().GetCollection(modelEntityRefsC)
defer closer()
var doc modelEntityRefsDoc
if err := modelEntityRefs.FindId(m.UUID()).One(&doc); err != nil {
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("entity references doc for model %s", m.UUID())
}
return nil, errors.Annotatef(err, "getting entity references for model %s", m.UUID())
}
return &doc, nil
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"getEntityRefs",
"(",
")",
"(",
"*",
"modelEntityRefsDoc",
",",
"error",
")",
"{",
"modelEntityRefs",
",",
"closer",
":=",
"m",
".",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"modelEntityRefsC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"var",
"doc",
"modelEntityRefsDoc",
"\n",
"if",
"err",
":=",
"modelEntityRefs",
".",
"FindId",
"(",
"m",
".",
"UUID",
"(",
")",
")",
".",
"One",
"(",
"&",
"doc",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"mgo",
".",
"ErrNotFound",
"{",
"return",
"nil",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"m",
".",
"UUID",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"m",
".",
"UUID",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"&",
"doc",
",",
"nil",
"\n",
"}"
] | // getEntityRefs reads the current model entity refs document for the model. | [
"getEntityRefs",
"reads",
"the",
"current",
"model",
"entity",
"refs",
"document",
"for",
"the",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L1332-L1344 |
155,554 | juju/juju | state/model.go | checkModelEntityRefsEmpty | func checkModelEntityRefsEmpty(doc *modelEntityRefsDoc) ([]txn.Op, error) {
// These errors could be potentially swallowed as we re-try to destroy model.
// Let's, at least, log them for observation.
err := modelNotEmptyError{
machines: len(doc.Machines),
applications: len(doc.Applications),
volumes: len(doc.Volumes),
filesystems: len(doc.Filesystems),
}
if err != (modelNotEmptyError{}) {
return nil, err
}
isEmpty := func(attribute string) bson.DocElem {
// We consider it empty if the array has no entries, or if the attribute doesn't exist
return bson.DocElem{
"$or", []bson.M{{
attribute: bson.M{"$exists": false},
}, {
attribute: bson.M{"$size": 0},
}},
}
}
return []txn.Op{{
C: modelEntityRefsC,
Id: doc.UUID,
Assert: bson.D{
isEmpty("machines"),
isEmpty("applications"),
isEmpty("volumes"),
isEmpty("filesystems"),
},
}}, nil
} | go | func checkModelEntityRefsEmpty(doc *modelEntityRefsDoc) ([]txn.Op, error) {
// These errors could be potentially swallowed as we re-try to destroy model.
// Let's, at least, log them for observation.
err := modelNotEmptyError{
machines: len(doc.Machines),
applications: len(doc.Applications),
volumes: len(doc.Volumes),
filesystems: len(doc.Filesystems),
}
if err != (modelNotEmptyError{}) {
return nil, err
}
isEmpty := func(attribute string) bson.DocElem {
// We consider it empty if the array has no entries, or if the attribute doesn't exist
return bson.DocElem{
"$or", []bson.M{{
attribute: bson.M{"$exists": false},
}, {
attribute: bson.M{"$size": 0},
}},
}
}
return []txn.Op{{
C: modelEntityRefsC,
Id: doc.UUID,
Assert: bson.D{
isEmpty("machines"),
isEmpty("applications"),
isEmpty("volumes"),
isEmpty("filesystems"),
},
}}, nil
} | [
"func",
"checkModelEntityRefsEmpty",
"(",
"doc",
"*",
"modelEntityRefsDoc",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"// These errors could be potentially swallowed as we re-try to destroy model.",
"// Let's, at least, log them for observation.",
"err",
":=",
"modelNotEmptyError",
"{",
"machines",
":",
"len",
"(",
"doc",
".",
"Machines",
")",
",",
"applications",
":",
"len",
"(",
"doc",
".",
"Applications",
")",
",",
"volumes",
":",
"len",
"(",
"doc",
".",
"Volumes",
")",
",",
"filesystems",
":",
"len",
"(",
"doc",
".",
"Filesystems",
")",
",",
"}",
"\n",
"if",
"err",
"!=",
"(",
"modelNotEmptyError",
"{",
"}",
")",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"isEmpty",
":=",
"func",
"(",
"attribute",
"string",
")",
"bson",
".",
"DocElem",
"{",
"// We consider it empty if the array has no entries, or if the attribute doesn't exist",
"return",
"bson",
".",
"DocElem",
"{",
"\"",
"\"",
",",
"[",
"]",
"bson",
".",
"M",
"{",
"{",
"attribute",
":",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"false",
"}",
",",
"}",
",",
"{",
"attribute",
":",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"0",
"}",
",",
"}",
"}",
",",
"}",
"\n",
"}",
"\n\n",
"return",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"modelEntityRefsC",
",",
"Id",
":",
"doc",
".",
"UUID",
",",
"Assert",
":",
"bson",
".",
"D",
"{",
"isEmpty",
"(",
"\"",
"\"",
")",
",",
"isEmpty",
"(",
"\"",
"\"",
")",
",",
"isEmpty",
"(",
"\"",
"\"",
")",
",",
"isEmpty",
"(",
"\"",
"\"",
")",
",",
"}",
",",
"}",
"}",
",",
"nil",
"\n",
"}"
] | // checkModelEntityRefsEmpty checks that the model is empty of any entities
// that may require external resource cleanup. If the model is not empty,
// then an error will be returned; otherwise txn.Ops are returned to assert
// the continued emptiness. | [
"checkModelEntityRefsEmpty",
"checks",
"that",
"the",
"model",
"is",
"empty",
"of",
"any",
"entities",
"that",
"may",
"require",
"external",
"resource",
"cleanup",
".",
"If",
"the",
"model",
"is",
"not",
"empty",
"then",
"an",
"error",
"will",
"be",
"returned",
";",
"otherwise",
"txn",
".",
"Ops",
"are",
"returned",
"to",
"assert",
"the",
"continued",
"emptiness",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L1356-L1390 |
155,555 | juju/juju | state/model.go | checkModelEntityRefsNoPersistentStorage | func checkModelEntityRefsNoPersistentStorage(
db Database, doc *modelEntityRefsDoc,
) ([]txn.Op, error) {
for _, volumeId := range doc.Volumes {
volumeTag := names.NewVolumeTag(volumeId)
detachable, err := isDetachableVolumeTag(db, volumeTag)
if err != nil {
return nil, errors.Trace(err)
}
if detachable {
return nil, hasPersistentStorageError{}
}
}
for _, filesystemId := range doc.Filesystems {
filesystemTag := names.NewFilesystemTag(filesystemId)
detachable, err := isDetachableFilesystemTag(db, filesystemTag)
if err != nil {
return nil, errors.Trace(err)
}
if detachable {
return nil, hasPersistentStorageError{}
}
}
return noNewStorageModelEntityRefs(doc), nil
} | go | func checkModelEntityRefsNoPersistentStorage(
db Database, doc *modelEntityRefsDoc,
) ([]txn.Op, error) {
for _, volumeId := range doc.Volumes {
volumeTag := names.NewVolumeTag(volumeId)
detachable, err := isDetachableVolumeTag(db, volumeTag)
if err != nil {
return nil, errors.Trace(err)
}
if detachable {
return nil, hasPersistentStorageError{}
}
}
for _, filesystemId := range doc.Filesystems {
filesystemTag := names.NewFilesystemTag(filesystemId)
detachable, err := isDetachableFilesystemTag(db, filesystemTag)
if err != nil {
return nil, errors.Trace(err)
}
if detachable {
return nil, hasPersistentStorageError{}
}
}
return noNewStorageModelEntityRefs(doc), nil
} | [
"func",
"checkModelEntityRefsNoPersistentStorage",
"(",
"db",
"Database",
",",
"doc",
"*",
"modelEntityRefsDoc",
",",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"for",
"_",
",",
"volumeId",
":=",
"range",
"doc",
".",
"Volumes",
"{",
"volumeTag",
":=",
"names",
".",
"NewVolumeTag",
"(",
"volumeId",
")",
"\n",
"detachable",
",",
"err",
":=",
"isDetachableVolumeTag",
"(",
"db",
",",
"volumeTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"detachable",
"{",
"return",
"nil",
",",
"hasPersistentStorageError",
"{",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"filesystemId",
":=",
"range",
"doc",
".",
"Filesystems",
"{",
"filesystemTag",
":=",
"names",
".",
"NewFilesystemTag",
"(",
"filesystemId",
")",
"\n",
"detachable",
",",
"err",
":=",
"isDetachableFilesystemTag",
"(",
"db",
",",
"filesystemTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"detachable",
"{",
"return",
"nil",
",",
"hasPersistentStorageError",
"{",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"noNewStorageModelEntityRefs",
"(",
"doc",
")",
",",
"nil",
"\n",
"}"
] | // checkModelEntityRefsNoPersistentStorage checks that there is no
// persistent storage in the model. If there is, then an error of
// type hasPersistentStorageError is returned. If there is not,
// txn.Ops are returned to assert the same. | [
"checkModelEntityRefsNoPersistentStorage",
"checks",
"that",
"there",
"is",
"no",
"persistent",
"storage",
"in",
"the",
"model",
".",
"If",
"there",
"is",
"then",
"an",
"error",
"of",
"type",
"hasPersistentStorageError",
"is",
"returned",
".",
"If",
"there",
"is",
"not",
"txn",
".",
"Ops",
"are",
"returned",
"to",
"assert",
"the",
"same",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L1396-L1420 |
155,556 | juju/juju | state/model.go | checkModelEntityRefsAllReleasableStorage | func checkModelEntityRefsAllReleasableStorage(sb *storageBackend, doc *modelEntityRefsDoc) ([]txn.Op, error) {
for _, volumeId := range doc.Volumes {
volumeTag := names.NewVolumeTag(volumeId)
volume, err := getVolumeByTag(sb.mb, volumeTag)
if err != nil {
return nil, errors.Trace(err)
}
if !volume.Detachable() {
continue
}
if err := checkStoragePoolReleasable(sb, volume.pool()); err != nil {
return nil, errors.Annotatef(err,
"cannot release %s", names.ReadableString(volumeTag),
)
}
}
for _, filesystemId := range doc.Filesystems {
filesystemTag := names.NewFilesystemTag(filesystemId)
filesystem, err := getFilesystemByTag(sb.mb, filesystemTag)
if err != nil {
return nil, errors.Trace(err)
}
if !filesystem.Detachable() {
continue
}
if err := checkStoragePoolReleasable(sb, filesystem.pool()); err != nil {
return nil, errors.Annotatef(err,
"cannot release %s", names.ReadableString(filesystemTag),
)
}
}
return noNewStorageModelEntityRefs(doc), nil
} | go | func checkModelEntityRefsAllReleasableStorage(sb *storageBackend, doc *modelEntityRefsDoc) ([]txn.Op, error) {
for _, volumeId := range doc.Volumes {
volumeTag := names.NewVolumeTag(volumeId)
volume, err := getVolumeByTag(sb.mb, volumeTag)
if err != nil {
return nil, errors.Trace(err)
}
if !volume.Detachable() {
continue
}
if err := checkStoragePoolReleasable(sb, volume.pool()); err != nil {
return nil, errors.Annotatef(err,
"cannot release %s", names.ReadableString(volumeTag),
)
}
}
for _, filesystemId := range doc.Filesystems {
filesystemTag := names.NewFilesystemTag(filesystemId)
filesystem, err := getFilesystemByTag(sb.mb, filesystemTag)
if err != nil {
return nil, errors.Trace(err)
}
if !filesystem.Detachable() {
continue
}
if err := checkStoragePoolReleasable(sb, filesystem.pool()); err != nil {
return nil, errors.Annotatef(err,
"cannot release %s", names.ReadableString(filesystemTag),
)
}
}
return noNewStorageModelEntityRefs(doc), nil
} | [
"func",
"checkModelEntityRefsAllReleasableStorage",
"(",
"sb",
"*",
"storageBackend",
",",
"doc",
"*",
"modelEntityRefsDoc",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"for",
"_",
",",
"volumeId",
":=",
"range",
"doc",
".",
"Volumes",
"{",
"volumeTag",
":=",
"names",
".",
"NewVolumeTag",
"(",
"volumeId",
")",
"\n",
"volume",
",",
"err",
":=",
"getVolumeByTag",
"(",
"sb",
".",
"mb",
",",
"volumeTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"!",
"volume",
".",
"Detachable",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"err",
":=",
"checkStoragePoolReleasable",
"(",
"sb",
",",
"volume",
".",
"pool",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"names",
".",
"ReadableString",
"(",
"volumeTag",
")",
",",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"filesystemId",
":=",
"range",
"doc",
".",
"Filesystems",
"{",
"filesystemTag",
":=",
"names",
".",
"NewFilesystemTag",
"(",
"filesystemId",
")",
"\n",
"filesystem",
",",
"err",
":=",
"getFilesystemByTag",
"(",
"sb",
".",
"mb",
",",
"filesystemTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"!",
"filesystem",
".",
"Detachable",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"err",
":=",
"checkStoragePoolReleasable",
"(",
"sb",
",",
"filesystem",
".",
"pool",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"names",
".",
"ReadableString",
"(",
"filesystemTag",
")",
",",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"noNewStorageModelEntityRefs",
"(",
"doc",
")",
",",
"nil",
"\n",
"}"
] | // checkModelEntityRefsAllReleasableStorage checks that there all
// persistent storage in the model is releasable. If it is, then
// txn.Ops are returned to assert the same; if it is not, then an
// error is returned. | [
"checkModelEntityRefsAllReleasableStorage",
"checks",
"that",
"there",
"all",
"persistent",
"storage",
"in",
"the",
"model",
"is",
"releasable",
".",
"If",
"it",
"is",
"then",
"txn",
".",
"Ops",
"are",
"returned",
"to",
"assert",
"the",
"same",
";",
"if",
"it",
"is",
"not",
"then",
"an",
"error",
"is",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L1426-L1458 |
155,557 | juju/juju | state/model.go | createModelOp | func createModelOp(
modelType ModelType,
owner names.UserTag,
name, uuid, controllerUUID, cloudName, cloudRegion string,
cloudCredential names.CloudCredentialTag,
migrationMode MigrationMode,
environVersion int,
) txn.Op {
doc := &modelDoc{
Type: modelType,
UUID: uuid,
Name: name,
Life: Alive,
Owner: owner.Id(),
ControllerUUID: controllerUUID,
MigrationMode: migrationMode,
EnvironVersion: environVersion,
Cloud: cloudName,
CloudRegion: cloudRegion,
CloudCredential: cloudCredential.Id(),
}
return txn.Op{
C: modelsC,
Id: uuid,
Assert: txn.DocMissing,
Insert: doc,
}
} | go | func createModelOp(
modelType ModelType,
owner names.UserTag,
name, uuid, controllerUUID, cloudName, cloudRegion string,
cloudCredential names.CloudCredentialTag,
migrationMode MigrationMode,
environVersion int,
) txn.Op {
doc := &modelDoc{
Type: modelType,
UUID: uuid,
Name: name,
Life: Alive,
Owner: owner.Id(),
ControllerUUID: controllerUUID,
MigrationMode: migrationMode,
EnvironVersion: environVersion,
Cloud: cloudName,
CloudRegion: cloudRegion,
CloudCredential: cloudCredential.Id(),
}
return txn.Op{
C: modelsC,
Id: uuid,
Assert: txn.DocMissing,
Insert: doc,
}
} | [
"func",
"createModelOp",
"(",
"modelType",
"ModelType",
",",
"owner",
"names",
".",
"UserTag",
",",
"name",
",",
"uuid",
",",
"controllerUUID",
",",
"cloudName",
",",
"cloudRegion",
"string",
",",
"cloudCredential",
"names",
".",
"CloudCredentialTag",
",",
"migrationMode",
"MigrationMode",
",",
"environVersion",
"int",
",",
")",
"txn",
".",
"Op",
"{",
"doc",
":=",
"&",
"modelDoc",
"{",
"Type",
":",
"modelType",
",",
"UUID",
":",
"uuid",
",",
"Name",
":",
"name",
",",
"Life",
":",
"Alive",
",",
"Owner",
":",
"owner",
".",
"Id",
"(",
")",
",",
"ControllerUUID",
":",
"controllerUUID",
",",
"MigrationMode",
":",
"migrationMode",
",",
"EnvironVersion",
":",
"environVersion",
",",
"Cloud",
":",
"cloudName",
",",
"CloudRegion",
":",
"cloudRegion",
",",
"CloudCredential",
":",
"cloudCredential",
".",
"Id",
"(",
")",
",",
"}",
"\n",
"return",
"txn",
".",
"Op",
"{",
"C",
":",
"modelsC",
",",
"Id",
":",
"uuid",
",",
"Assert",
":",
"txn",
".",
"DocMissing",
",",
"Insert",
":",
"doc",
",",
"}",
"\n",
"}"
] | // createModelOp returns the operation needed to create
// an model document with the given name and UUID. | [
"createModelOp",
"returns",
"the",
"operation",
"needed",
"to",
"create",
"an",
"model",
"document",
"with",
"the",
"given",
"name",
"and",
"UUID",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L1544-L1571 |
155,558 | juju/juju | state/model.go | createUniqueOwnerModelNameOp | func createUniqueOwnerModelNameOp(qualifier string, modelName string) txn.Op {
return txn.Op{
C: usermodelnameC,
Id: userModelNameIndex(qualifier, modelName),
Assert: txn.DocMissing,
Insert: bson.M{},
}
} | go | func createUniqueOwnerModelNameOp(qualifier string, modelName string) txn.Op {
return txn.Op{
C: usermodelnameC,
Id: userModelNameIndex(qualifier, modelName),
Assert: txn.DocMissing,
Insert: bson.M{},
}
} | [
"func",
"createUniqueOwnerModelNameOp",
"(",
"qualifier",
"string",
",",
"modelName",
"string",
")",
"txn",
".",
"Op",
"{",
"return",
"txn",
".",
"Op",
"{",
"C",
":",
"usermodelnameC",
",",
"Id",
":",
"userModelNameIndex",
"(",
"qualifier",
",",
"modelName",
")",
",",
"Assert",
":",
"txn",
".",
"DocMissing",
",",
"Insert",
":",
"bson",
".",
"M",
"{",
"}",
",",
"}",
"\n",
"}"
] | // createUniqueOwnerModelNameOp returns the operation needed to create
// an usermodelnameC document with the given qualifier and model name. | [
"createUniqueOwnerModelNameOp",
"returns",
"the",
"operation",
"needed",
"to",
"create",
"an",
"usermodelnameC",
"document",
"with",
"the",
"given",
"qualifier",
"and",
"model",
"name",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L1630-L1637 |
155,559 | juju/juju | state/model.go | assertModelActiveOp | func assertModelActiveOp(modelUUID string) txn.Op {
return txn.Op{
C: modelsC,
Id: modelUUID,
Assert: append(isAliveDoc, bson.DocElem{"migration-mode", MigrationModeNone}),
}
} | go | func assertModelActiveOp(modelUUID string) txn.Op {
return txn.Op{
C: modelsC,
Id: modelUUID,
Assert: append(isAliveDoc, bson.DocElem{"migration-mode", MigrationModeNone}),
}
} | [
"func",
"assertModelActiveOp",
"(",
"modelUUID",
"string",
")",
"txn",
".",
"Op",
"{",
"return",
"txn",
".",
"Op",
"{",
"C",
":",
"modelsC",
",",
"Id",
":",
"modelUUID",
",",
"Assert",
":",
"append",
"(",
"isAliveDoc",
",",
"bson",
".",
"DocElem",
"{",
"\"",
"\"",
",",
"MigrationModeNone",
"}",
")",
",",
"}",
"\n",
"}"
] | // assertModelActiveOp returns a txn.Op that asserts the given
// model UUID refers to an Alive model. | [
"assertModelActiveOp",
"returns",
"a",
"txn",
".",
"Op",
"that",
"asserts",
"the",
"given",
"model",
"UUID",
"refers",
"to",
"an",
"Alive",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/model.go#L1646-L1652 |
155,560 | juju/juju | cmd/juju/application/consume.go | Run | func (c *consumeCommand) Run(ctx *cmd.Context) error {
accountDetails, err := c.CurrentAccountDetails()
if err != nil {
return errors.Trace(err)
}
url, err := crossmodel.ParseOfferURL(c.remoteApplication)
if err != nil {
return errors.Trace(err)
}
if url.HasEndpoint() {
return errors.Errorf("remote offer %q shouldn't include endpoint", c.remoteApplication)
}
if url.User == "" {
url.User = accountDetails.User
c.remoteApplication = url.Path()
}
sourceClient, err := c.getSourceAPI(url)
if err != nil {
return errors.Trace(err)
}
defer sourceClient.Close()
consumeDetails, err := sourceClient.GetConsumeDetails(url.AsLocal().String())
if err != nil {
return errors.Trace(err)
}
// Parse the offer details URL and add the source controller so
// things like status can show the original source of the offer.
offerURL, err := crossmodel.ParseOfferURL(consumeDetails.Offer.OfferURL)
if err != nil {
return errors.Trace(err)
}
offerURL.Source = url.Source
consumeDetails.Offer.OfferURL = offerURL.String()
targetClient, err := c.getTargetAPI()
if err != nil {
return errors.Trace(err)
}
defer targetClient.Close()
arg := crossmodel.ConsumeApplicationArgs{
Offer: *consumeDetails.Offer,
ApplicationAlias: c.applicationAlias,
Macaroon: consumeDetails.Macaroon,
}
if consumeDetails.ControllerInfo != nil {
controllerTag, err := names.ParseControllerTag(consumeDetails.ControllerInfo.ControllerTag)
if err != nil {
return errors.Trace(err)
}
arg.ControllerInfo = &crossmodel.ControllerInfo{
ControllerTag: controllerTag,
Alias: consumeDetails.ControllerInfo.Alias,
Addrs: consumeDetails.ControllerInfo.Addrs,
CACert: consumeDetails.ControllerInfo.CACert,
}
}
localName, err := targetClient.Consume(arg)
if err != nil {
return errors.Trace(err)
}
ctx.Infof("Added %s as %s", c.remoteApplication, localName)
return nil
} | go | func (c *consumeCommand) Run(ctx *cmd.Context) error {
accountDetails, err := c.CurrentAccountDetails()
if err != nil {
return errors.Trace(err)
}
url, err := crossmodel.ParseOfferURL(c.remoteApplication)
if err != nil {
return errors.Trace(err)
}
if url.HasEndpoint() {
return errors.Errorf("remote offer %q shouldn't include endpoint", c.remoteApplication)
}
if url.User == "" {
url.User = accountDetails.User
c.remoteApplication = url.Path()
}
sourceClient, err := c.getSourceAPI(url)
if err != nil {
return errors.Trace(err)
}
defer sourceClient.Close()
consumeDetails, err := sourceClient.GetConsumeDetails(url.AsLocal().String())
if err != nil {
return errors.Trace(err)
}
// Parse the offer details URL and add the source controller so
// things like status can show the original source of the offer.
offerURL, err := crossmodel.ParseOfferURL(consumeDetails.Offer.OfferURL)
if err != nil {
return errors.Trace(err)
}
offerURL.Source = url.Source
consumeDetails.Offer.OfferURL = offerURL.String()
targetClient, err := c.getTargetAPI()
if err != nil {
return errors.Trace(err)
}
defer targetClient.Close()
arg := crossmodel.ConsumeApplicationArgs{
Offer: *consumeDetails.Offer,
ApplicationAlias: c.applicationAlias,
Macaroon: consumeDetails.Macaroon,
}
if consumeDetails.ControllerInfo != nil {
controllerTag, err := names.ParseControllerTag(consumeDetails.ControllerInfo.ControllerTag)
if err != nil {
return errors.Trace(err)
}
arg.ControllerInfo = &crossmodel.ControllerInfo{
ControllerTag: controllerTag,
Alias: consumeDetails.ControllerInfo.Alias,
Addrs: consumeDetails.ControllerInfo.Addrs,
CACert: consumeDetails.ControllerInfo.CACert,
}
}
localName, err := targetClient.Consume(arg)
if err != nil {
return errors.Trace(err)
}
ctx.Infof("Added %s as %s", c.remoteApplication, localName)
return nil
} | [
"func",
"(",
"c",
"*",
"consumeCommand",
")",
"Run",
"(",
"ctx",
"*",
"cmd",
".",
"Context",
")",
"error",
"{",
"accountDetails",
",",
"err",
":=",
"c",
".",
"CurrentAccountDetails",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"url",
",",
"err",
":=",
"crossmodel",
".",
"ParseOfferURL",
"(",
"c",
".",
"remoteApplication",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"url",
".",
"HasEndpoint",
"(",
")",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"c",
".",
"remoteApplication",
")",
"\n",
"}",
"\n",
"if",
"url",
".",
"User",
"==",
"\"",
"\"",
"{",
"url",
".",
"User",
"=",
"accountDetails",
".",
"User",
"\n",
"c",
".",
"remoteApplication",
"=",
"url",
".",
"Path",
"(",
")",
"\n",
"}",
"\n",
"sourceClient",
",",
"err",
":=",
"c",
".",
"getSourceAPI",
"(",
"url",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"defer",
"sourceClient",
".",
"Close",
"(",
")",
"\n\n",
"consumeDetails",
",",
"err",
":=",
"sourceClient",
".",
"GetConsumeDetails",
"(",
"url",
".",
"AsLocal",
"(",
")",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// Parse the offer details URL and add the source controller so",
"// things like status can show the original source of the offer.",
"offerURL",
",",
"err",
":=",
"crossmodel",
".",
"ParseOfferURL",
"(",
"consumeDetails",
".",
"Offer",
".",
"OfferURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"offerURL",
".",
"Source",
"=",
"url",
".",
"Source",
"\n",
"consumeDetails",
".",
"Offer",
".",
"OfferURL",
"=",
"offerURL",
".",
"String",
"(",
")",
"\n\n",
"targetClient",
",",
"err",
":=",
"c",
".",
"getTargetAPI",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"defer",
"targetClient",
".",
"Close",
"(",
")",
"\n\n",
"arg",
":=",
"crossmodel",
".",
"ConsumeApplicationArgs",
"{",
"Offer",
":",
"*",
"consumeDetails",
".",
"Offer",
",",
"ApplicationAlias",
":",
"c",
".",
"applicationAlias",
",",
"Macaroon",
":",
"consumeDetails",
".",
"Macaroon",
",",
"}",
"\n",
"if",
"consumeDetails",
".",
"ControllerInfo",
"!=",
"nil",
"{",
"controllerTag",
",",
"err",
":=",
"names",
".",
"ParseControllerTag",
"(",
"consumeDetails",
".",
"ControllerInfo",
".",
"ControllerTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"arg",
".",
"ControllerInfo",
"=",
"&",
"crossmodel",
".",
"ControllerInfo",
"{",
"ControllerTag",
":",
"controllerTag",
",",
"Alias",
":",
"consumeDetails",
".",
"ControllerInfo",
".",
"Alias",
",",
"Addrs",
":",
"consumeDetails",
".",
"ControllerInfo",
".",
"Addrs",
",",
"CACert",
":",
"consumeDetails",
".",
"ControllerInfo",
".",
"CACert",
",",
"}",
"\n",
"}",
"\n",
"localName",
",",
"err",
":=",
"targetClient",
".",
"Consume",
"(",
"arg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"ctx",
".",
"Infof",
"(",
"\"",
"\"",
",",
"c",
".",
"remoteApplication",
",",
"localName",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Run adds the requested remote offer to the model. Implements
// cmd.Command. | [
"Run",
"adds",
"the",
"requested",
"remote",
"offer",
"to",
"the",
"model",
".",
"Implements",
"cmd",
".",
"Command",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/application/consume.go#L113-L177 |
155,561 | juju/juju | worker/uniter/runner/debug/server.go | MatchHook | func (s *ServerSession) MatchHook(hookName string) bool {
return s.hooks.IsEmpty() || s.hooks.Contains(hookName)
} | go | func (s *ServerSession) MatchHook(hookName string) bool {
return s.hooks.IsEmpty() || s.hooks.Contains(hookName)
} | [
"func",
"(",
"s",
"*",
"ServerSession",
")",
"MatchHook",
"(",
"hookName",
"string",
")",
"bool",
"{",
"return",
"s",
".",
"hooks",
".",
"IsEmpty",
"(",
")",
"||",
"s",
".",
"hooks",
".",
"Contains",
"(",
"hookName",
")",
"\n",
"}"
] | // MatchHook returns true if the specified hook name matches
// the hook specified by the debug-hooks client. | [
"MatchHook",
"returns",
"true",
"if",
"the",
"specified",
"hook",
"name",
"matches",
"the",
"hook",
"specified",
"by",
"the",
"debug",
"-",
"hooks",
"client",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/debug/server.go#L31-L33 |
155,562 | juju/juju | worker/uniter/runner/debug/server.go | RunHook | func (s *ServerSession) RunHook(hookName, charmDir string, env []string) error {
debugDir, err := ioutil.TempDir("", "juju-debug-hooks-")
if err != nil {
return errors.Trace(err)
}
defer os.RemoveAll(debugDir)
if err := s.writeDebugFiles(debugDir); err != nil {
return errors.Trace(err)
}
env = utils.Setenv(env, "JUJU_HOOK_NAME="+hookName)
env = utils.Setenv(env, "JUJU_DEBUG="+debugDir)
cmd := exec.Command("/bin/bash", "-s")
cmd.Env = env
cmd.Dir = charmDir
cmd.Stdin = bytes.NewBufferString(debugHooksServerScript)
if s.output != nil {
cmd.Stdout = s.output
cmd.Stderr = s.output
}
if err := cmd.Start(); err != nil {
return err
}
go func(proc *os.Process) {
// Wait for the SSH client to exit (i.e. release the flock),
// then kill the server hook process in case the client
// exited uncleanly.
waitClientExit(s)
proc.Kill()
}(cmd.Process)
return cmd.Wait()
} | go | func (s *ServerSession) RunHook(hookName, charmDir string, env []string) error {
debugDir, err := ioutil.TempDir("", "juju-debug-hooks-")
if err != nil {
return errors.Trace(err)
}
defer os.RemoveAll(debugDir)
if err := s.writeDebugFiles(debugDir); err != nil {
return errors.Trace(err)
}
env = utils.Setenv(env, "JUJU_HOOK_NAME="+hookName)
env = utils.Setenv(env, "JUJU_DEBUG="+debugDir)
cmd := exec.Command("/bin/bash", "-s")
cmd.Env = env
cmd.Dir = charmDir
cmd.Stdin = bytes.NewBufferString(debugHooksServerScript)
if s.output != nil {
cmd.Stdout = s.output
cmd.Stderr = s.output
}
if err := cmd.Start(); err != nil {
return err
}
go func(proc *os.Process) {
// Wait for the SSH client to exit (i.e. release the flock),
// then kill the server hook process in case the client
// exited uncleanly.
waitClientExit(s)
proc.Kill()
}(cmd.Process)
return cmd.Wait()
} | [
"func",
"(",
"s",
"*",
"ServerSession",
")",
"RunHook",
"(",
"hookName",
",",
"charmDir",
"string",
",",
"env",
"[",
"]",
"string",
")",
"error",
"{",
"debugDir",
",",
"err",
":=",
"ioutil",
".",
"TempDir",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"defer",
"os",
".",
"RemoveAll",
"(",
"debugDir",
")",
"\n",
"if",
"err",
":=",
"s",
".",
"writeDebugFiles",
"(",
"debugDir",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"env",
"=",
"utils",
".",
"Setenv",
"(",
"env",
",",
"\"",
"\"",
"+",
"hookName",
")",
"\n",
"env",
"=",
"utils",
".",
"Setenv",
"(",
"env",
",",
"\"",
"\"",
"+",
"debugDir",
")",
"\n\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"cmd",
".",
"Env",
"=",
"env",
"\n",
"cmd",
".",
"Dir",
"=",
"charmDir",
"\n",
"cmd",
".",
"Stdin",
"=",
"bytes",
".",
"NewBufferString",
"(",
"debugHooksServerScript",
")",
"\n",
"if",
"s",
".",
"output",
"!=",
"nil",
"{",
"cmd",
".",
"Stdout",
"=",
"s",
".",
"output",
"\n",
"cmd",
".",
"Stderr",
"=",
"s",
".",
"output",
"\n",
"}",
"\n",
"if",
"err",
":=",
"cmd",
".",
"Start",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"go",
"func",
"(",
"proc",
"*",
"os",
".",
"Process",
")",
"{",
"// Wait for the SSH client to exit (i.e. release the flock),",
"// then kill the server hook process in case the client",
"// exited uncleanly.",
"waitClientExit",
"(",
"s",
")",
"\n",
"proc",
".",
"Kill",
"(",
")",
"\n",
"}",
"(",
"cmd",
".",
"Process",
")",
"\n",
"return",
"cmd",
".",
"Wait",
"(",
")",
"\n",
"}"
] | // RunHook "runs" the hook with the specified name via debug-hooks. | [
"RunHook",
"runs",
"the",
"hook",
"with",
"the",
"specified",
"name",
"via",
"debug",
"-",
"hooks",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/debug/server.go#L43-L75 |
155,563 | juju/juju | worker/uniter/runner/debug/server.go | FindSession | func (c *HooksContext) FindSession() (*ServerSession, error) {
cmd := exec.Command("tmux", "has-session", "-t", c.tmuxSessionName())
out, err := cmd.CombinedOutput()
if err != nil {
if len(out) != 0 {
return nil, errors.New(string(out))
} else {
return nil, err
}
}
// Parse the debug-hooks file for an optional hook name.
data, err := ioutil.ReadFile(c.ClientFileLock())
if err != nil {
return nil, err
}
var args hookArgs
err = goyaml.Unmarshal(data, &args)
if err != nil {
return nil, err
}
hooks := set.NewStrings(args.Hooks...)
session := &ServerSession{HooksContext: c, hooks: hooks}
return session, nil
} | go | func (c *HooksContext) FindSession() (*ServerSession, error) {
cmd := exec.Command("tmux", "has-session", "-t", c.tmuxSessionName())
out, err := cmd.CombinedOutput()
if err != nil {
if len(out) != 0 {
return nil, errors.New(string(out))
} else {
return nil, err
}
}
// Parse the debug-hooks file for an optional hook name.
data, err := ioutil.ReadFile(c.ClientFileLock())
if err != nil {
return nil, err
}
var args hookArgs
err = goyaml.Unmarshal(data, &args)
if err != nil {
return nil, err
}
hooks := set.NewStrings(args.Hooks...)
session := &ServerSession{HooksContext: c, hooks: hooks}
return session, nil
} | [
"func",
"(",
"c",
"*",
"HooksContext",
")",
"FindSession",
"(",
")",
"(",
"*",
"ServerSession",
",",
"error",
")",
"{",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"c",
".",
"tmuxSessionName",
"(",
")",
")",
"\n",
"out",
",",
"err",
":=",
"cmd",
".",
"CombinedOutput",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len",
"(",
"out",
")",
"!=",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"string",
"(",
"out",
")",
")",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"// Parse the debug-hooks file for an optional hook name.",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"c",
".",
"ClientFileLock",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"args",
"hookArgs",
"\n",
"err",
"=",
"goyaml",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"args",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"hooks",
":=",
"set",
".",
"NewStrings",
"(",
"args",
".",
"Hooks",
"...",
")",
"\n",
"session",
":=",
"&",
"ServerSession",
"{",
"HooksContext",
":",
"c",
",",
"hooks",
":",
"hooks",
"}",
"\n",
"return",
"session",
",",
"nil",
"\n",
"}"
] | // FindSession attempts to find a debug hooks session for the unit specified
// in the context, and returns a new ServerSession structure for it. | [
"FindSession",
"attempts",
"to",
"find",
"a",
"debug",
"hooks",
"session",
"for",
"the",
"unit",
"specified",
"in",
"the",
"context",
"and",
"returns",
"a",
"new",
"ServerSession",
"structure",
"for",
"it",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runner/debug/server.go#L110-L133 |
155,564 | juju/juju | environs/manual/sshprovisioner/sshprovisioner.go | gatherMachineParams | func gatherMachineParams(hostname string) (*params.AddMachineParams, error) {
// Generate a unique nonce for the machine.
uuid, err := utils.NewUUID()
if err != nil {
return nil, err
}
addr, err := manual.HostAddress(hostname)
if err != nil {
return nil, errors.Annotatef(err, "failed to compute public address for %q", hostname)
}
provisioned, err := checkProvisioned(hostname)
if err != nil {
return nil, errors.Annotatef(err, "error checking if provisioned")
}
if provisioned {
return nil, manual.ErrProvisioned
}
hc, series, err := DetectSeriesAndHardwareCharacteristics(hostname)
if err != nil {
return nil, errors.Annotatef(err, "error detecting linux hardware characteristics")
}
// There will never be a corresponding "instance" that any provider
// knows about. This is fine, and works well with the provisioner
// task. The provisioner task will happily remove any and all dead
// machines from state, but will ignore the associated instance ID
// if it isn't one that the environment provider knows about.
instanceId := instance.Id(manual.ManualInstancePrefix + hostname)
nonce := fmt.Sprintf("%s:%s", instanceId, uuid.String())
machineParams := ¶ms.AddMachineParams{
Series: series,
HardwareCharacteristics: hc,
InstanceId: instanceId,
Nonce: nonce,
Addrs: params.FromNetworkAddresses(addr),
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
}
return machineParams, nil
} | go | func gatherMachineParams(hostname string) (*params.AddMachineParams, error) {
// Generate a unique nonce for the machine.
uuid, err := utils.NewUUID()
if err != nil {
return nil, err
}
addr, err := manual.HostAddress(hostname)
if err != nil {
return nil, errors.Annotatef(err, "failed to compute public address for %q", hostname)
}
provisioned, err := checkProvisioned(hostname)
if err != nil {
return nil, errors.Annotatef(err, "error checking if provisioned")
}
if provisioned {
return nil, manual.ErrProvisioned
}
hc, series, err := DetectSeriesAndHardwareCharacteristics(hostname)
if err != nil {
return nil, errors.Annotatef(err, "error detecting linux hardware characteristics")
}
// There will never be a corresponding "instance" that any provider
// knows about. This is fine, and works well with the provisioner
// task. The provisioner task will happily remove any and all dead
// machines from state, but will ignore the associated instance ID
// if it isn't one that the environment provider knows about.
instanceId := instance.Id(manual.ManualInstancePrefix + hostname)
nonce := fmt.Sprintf("%s:%s", instanceId, uuid.String())
machineParams := ¶ms.AddMachineParams{
Series: series,
HardwareCharacteristics: hc,
InstanceId: instanceId,
Nonce: nonce,
Addrs: params.FromNetworkAddresses(addr),
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
}
return machineParams, nil
} | [
"func",
"gatherMachineParams",
"(",
"hostname",
"string",
")",
"(",
"*",
"params",
".",
"AddMachineParams",
",",
"error",
")",
"{",
"// Generate a unique nonce for the machine.",
"uuid",
",",
"err",
":=",
"utils",
".",
"NewUUID",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"addr",
",",
"err",
":=",
"manual",
".",
"HostAddress",
"(",
"hostname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"hostname",
")",
"\n",
"}",
"\n\n",
"provisioned",
",",
"err",
":=",
"checkProvisioned",
"(",
"hostname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"provisioned",
"{",
"return",
"nil",
",",
"manual",
".",
"ErrProvisioned",
"\n",
"}",
"\n\n",
"hc",
",",
"series",
",",
"err",
":=",
"DetectSeriesAndHardwareCharacteristics",
"(",
"hostname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// There will never be a corresponding \"instance\" that any provider",
"// knows about. This is fine, and works well with the provisioner",
"// task. The provisioner task will happily remove any and all dead",
"// machines from state, but will ignore the associated instance ID",
"// if it isn't one that the environment provider knows about.",
"instanceId",
":=",
"instance",
".",
"Id",
"(",
"manual",
".",
"ManualInstancePrefix",
"+",
"hostname",
")",
"\n",
"nonce",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"instanceId",
",",
"uuid",
".",
"String",
"(",
")",
")",
"\n",
"machineParams",
":=",
"&",
"params",
".",
"AddMachineParams",
"{",
"Series",
":",
"series",
",",
"HardwareCharacteristics",
":",
"hc",
",",
"InstanceId",
":",
"instanceId",
",",
"Nonce",
":",
"nonce",
",",
"Addrs",
":",
"params",
".",
"FromNetworkAddresses",
"(",
"addr",
")",
",",
"Jobs",
":",
"[",
"]",
"multiwatcher",
".",
"MachineJob",
"{",
"multiwatcher",
".",
"JobHostUnits",
"}",
",",
"}",
"\n",
"return",
"machineParams",
",",
"nil",
"\n",
"}"
] | // gatherMachineParams collects all the information we know about the machine
// we are about to provision. It will SSH into that machine as the ubuntu user.
// The hostname supplied should not include a username.
// If we can, we will reverse lookup the hostname by its IP address, and use
// the DNS resolved name, rather than the name that was supplied | [
"gatherMachineParams",
"collects",
"all",
"the",
"information",
"we",
"know",
"about",
"the",
"machine",
"we",
"are",
"about",
"to",
"provision",
".",
"It",
"will",
"SSH",
"into",
"that",
"machine",
"as",
"the",
"ubuntu",
"user",
".",
"The",
"hostname",
"supplied",
"should",
"not",
"include",
"a",
"username",
".",
"If",
"we",
"can",
"we",
"will",
"reverse",
"lookup",
"the",
"hostname",
"by",
"its",
"IP",
"address",
"and",
"use",
"the",
"DNS",
"resolved",
"name",
"rather",
"than",
"the",
"name",
"that",
"was",
"supplied"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/manual/sshprovisioner/sshprovisioner.go#L213-L255 |
155,565 | juju/juju | environs/manual/sshprovisioner/sshprovisioner.go | ProvisioningScript | func ProvisioningScript(icfg *instancecfg.InstanceConfig) (string, error) {
cloudcfg, err := cloudinit.New(icfg.Series)
if err != nil {
return "", errors.Annotate(err, "error generating cloud-config")
}
cloudcfg.SetSystemUpdate(icfg.EnableOSRefreshUpdate)
cloudcfg.SetSystemUpgrade(icfg.EnableOSUpgrade)
udata, err := cloudconfig.NewUserdataConfig(icfg, cloudcfg)
if err != nil {
return "", errors.Annotate(err, "error generating cloud-config")
}
if err := udata.ConfigureJuju(); err != nil {
return "", errors.Annotate(err, "error generating cloud-config")
}
configScript, err := cloudcfg.RenderScript()
if err != nil {
return "", errors.Annotate(err, "error converting cloud-config to script")
}
var buf bytes.Buffer
// Always remove the cloud-init-output.log file first, if it exists.
fmt.Fprintf(&buf, "rm -f %s\n", utils.ShQuote(icfg.CloudInitOutputLog))
// If something goes wrong, dump cloud-init-output.log to stderr.
buf.WriteString(shell.DumpFileOnErrorScript(icfg.CloudInitOutputLog))
buf.WriteString(configScript)
return buf.String(), nil
} | go | func ProvisioningScript(icfg *instancecfg.InstanceConfig) (string, error) {
cloudcfg, err := cloudinit.New(icfg.Series)
if err != nil {
return "", errors.Annotate(err, "error generating cloud-config")
}
cloudcfg.SetSystemUpdate(icfg.EnableOSRefreshUpdate)
cloudcfg.SetSystemUpgrade(icfg.EnableOSUpgrade)
udata, err := cloudconfig.NewUserdataConfig(icfg, cloudcfg)
if err != nil {
return "", errors.Annotate(err, "error generating cloud-config")
}
if err := udata.ConfigureJuju(); err != nil {
return "", errors.Annotate(err, "error generating cloud-config")
}
configScript, err := cloudcfg.RenderScript()
if err != nil {
return "", errors.Annotate(err, "error converting cloud-config to script")
}
var buf bytes.Buffer
// Always remove the cloud-init-output.log file first, if it exists.
fmt.Fprintf(&buf, "rm -f %s\n", utils.ShQuote(icfg.CloudInitOutputLog))
// If something goes wrong, dump cloud-init-output.log to stderr.
buf.WriteString(shell.DumpFileOnErrorScript(icfg.CloudInitOutputLog))
buf.WriteString(configScript)
return buf.String(), nil
} | [
"func",
"ProvisioningScript",
"(",
"icfg",
"*",
"instancecfg",
".",
"InstanceConfig",
")",
"(",
"string",
",",
"error",
")",
"{",
"cloudcfg",
",",
"err",
":=",
"cloudinit",
".",
"New",
"(",
"icfg",
".",
"Series",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"cloudcfg",
".",
"SetSystemUpdate",
"(",
"icfg",
".",
"EnableOSRefreshUpdate",
")",
"\n",
"cloudcfg",
".",
"SetSystemUpgrade",
"(",
"icfg",
".",
"EnableOSUpgrade",
")",
"\n\n",
"udata",
",",
"err",
":=",
"cloudconfig",
".",
"NewUserdataConfig",
"(",
"icfg",
",",
"cloudcfg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"udata",
".",
"ConfigureJuju",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"configScript",
",",
"err",
":=",
"cloudcfg",
".",
"RenderScript",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"// Always remove the cloud-init-output.log file first, if it exists.",
"fmt",
".",
"Fprintf",
"(",
"&",
"buf",
",",
"\"",
"\\n",
"\"",
",",
"utils",
".",
"ShQuote",
"(",
"icfg",
".",
"CloudInitOutputLog",
")",
")",
"\n",
"// If something goes wrong, dump cloud-init-output.log to stderr.",
"buf",
".",
"WriteString",
"(",
"shell",
".",
"DumpFileOnErrorScript",
"(",
"icfg",
".",
"CloudInitOutputLog",
")",
")",
"\n",
"buf",
".",
"WriteString",
"(",
"configScript",
")",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
",",
"nil",
"\n",
"}"
] | // ProvisioningScript generates a bash script that can be
// executed on a remote host to carry out the cloud-init
// configuration. | [
"ProvisioningScript",
"generates",
"a",
"bash",
"script",
"that",
"can",
"be",
"executed",
"on",
"a",
"remote",
"host",
"to",
"carry",
"out",
"the",
"cloud",
"-",
"init",
"configuration",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/manual/sshprovisioner/sshprovisioner.go#L268-L296 |
155,566 | juju/juju | cmd/juju/crossmodel/remove.go | NewRemoveOfferCommand | func NewRemoveOfferCommand() cmd.Command {
removeCmd := &removeCommand{}
removeCmd.newAPIFunc = func(controllerName string) (RemoveAPI, error) {
return removeCmd.NewApplicationOffersAPI(controllerName)
}
return modelcmd.WrapController(removeCmd)
} | go | func NewRemoveOfferCommand() cmd.Command {
removeCmd := &removeCommand{}
removeCmd.newAPIFunc = func(controllerName string) (RemoveAPI, error) {
return removeCmd.NewApplicationOffersAPI(controllerName)
}
return modelcmd.WrapController(removeCmd)
} | [
"func",
"NewRemoveOfferCommand",
"(",
")",
"cmd",
".",
"Command",
"{",
"removeCmd",
":=",
"&",
"removeCommand",
"{",
"}",
"\n",
"removeCmd",
".",
"newAPIFunc",
"=",
"func",
"(",
"controllerName",
"string",
")",
"(",
"RemoveAPI",
",",
"error",
")",
"{",
"return",
"removeCmd",
".",
"NewApplicationOffersAPI",
"(",
"controllerName",
")",
"\n",
"}",
"\n",
"return",
"modelcmd",
".",
"WrapController",
"(",
"removeCmd",
")",
"\n",
"}"
] | // NewRemoveOfferCommand returns a command used to remove a specified offer. | [
"NewRemoveOfferCommand",
"returns",
"a",
"command",
"used",
"to",
"remove",
"a",
"specified",
"offer",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/crossmodel/remove.go#L23-L29 |
155,567 | juju/juju | cmd/juju/crossmodel/remove.go | NewApplicationOffersAPI | func (c *removeCommand) NewApplicationOffersAPI(controllerName string) (*applicationoffers.Client, error) {
root, err := c.CommandBase.NewAPIRoot(c.ClientStore(), controllerName, "")
if err != nil {
return nil, err
}
return applicationoffers.NewClient(root), nil
} | go | func (c *removeCommand) NewApplicationOffersAPI(controllerName string) (*applicationoffers.Client, error) {
root, err := c.CommandBase.NewAPIRoot(c.ClientStore(), controllerName, "")
if err != nil {
return nil, err
}
return applicationoffers.NewClient(root), nil
} | [
"func",
"(",
"c",
"*",
"removeCommand",
")",
"NewApplicationOffersAPI",
"(",
"controllerName",
"string",
")",
"(",
"*",
"applicationoffers",
".",
"Client",
",",
"error",
")",
"{",
"root",
",",
"err",
":=",
"c",
".",
"CommandBase",
".",
"NewAPIRoot",
"(",
"c",
".",
"ClientStore",
"(",
")",
",",
"controllerName",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"applicationoffers",
".",
"NewClient",
"(",
"root",
")",
",",
"nil",
"\n",
"}"
] | // NewApplicationOffersAPI returns an application offers api. | [
"NewApplicationOffersAPI",
"returns",
"an",
"application",
"offers",
"api",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/crossmodel/remove.go#L97-L103 |
155,568 | juju/juju | cmd/juju/block/protection.go | getBlockAPI | func getBlockAPI(c newAPIRoot) (*apiblock.Client, error) {
root, err := c.NewAPIRoot()
if err != nil {
return nil, err
}
return apiblock.NewClient(root), nil
} | go | func getBlockAPI(c newAPIRoot) (*apiblock.Client, error) {
root, err := c.NewAPIRoot()
if err != nil {
return nil, err
}
return apiblock.NewClient(root), nil
} | [
"func",
"getBlockAPI",
"(",
"c",
"newAPIRoot",
")",
"(",
"*",
"apiblock",
".",
"Client",
",",
"error",
")",
"{",
"root",
",",
"err",
":=",
"c",
".",
"NewAPIRoot",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"apiblock",
".",
"NewClient",
"(",
"root",
")",
",",
"nil",
"\n",
"}"
] | // getBlockAPI returns a block api for block manipulation. | [
"getBlockAPI",
"returns",
"a",
"block",
"api",
"for",
"block",
"manipulation",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/block/protection.go#L58-L64 |
155,569 | juju/juju | cmd/juju/block/protection.go | ProcessBlockedError | func ProcessBlockedError(err error, block Block) error {
if err == nil {
return nil
}
if params.IsCodeOperationBlocked(err) {
msg := fmt.Sprintf("%v\n%v", err, blockedMessages[block])
logger.Infof(msg)
return errors.Errorf(msg)
}
return err
} | go | func ProcessBlockedError(err error, block Block) error {
if err == nil {
return nil
}
if params.IsCodeOperationBlocked(err) {
msg := fmt.Sprintf("%v\n%v", err, blockedMessages[block])
logger.Infof(msg)
return errors.Errorf(msg)
}
return err
} | [
"func",
"ProcessBlockedError",
"(",
"err",
"error",
",",
"block",
"Block",
")",
"error",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"params",
".",
"IsCodeOperationBlocked",
"(",
"err",
")",
"{",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
",",
"blockedMessages",
"[",
"block",
"]",
")",
"\n",
"logger",
".",
"Infof",
"(",
"msg",
")",
"\n",
"return",
"errors",
".",
"Errorf",
"(",
"msg",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // ProcessBlockedError ensures that correct and user-friendly message is
// displayed to the user based on the block type. | [
"ProcessBlockedError",
"ensures",
"that",
"correct",
"and",
"user",
"-",
"friendly",
"message",
"is",
"displayed",
"to",
"the",
"user",
"based",
"on",
"the",
"block",
"type",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/block/protection.go#L91-L101 |
155,570 | juju/juju | environs/tools/marshal.go | MarshalToolsMetadataJSON | func MarshalToolsMetadataJSON(metadata map[string][]*ToolsMetadata, updated time.Time) (index, legacyIndex []byte, products map[string][]byte, err error) {
if index, legacyIndex, err = marshalToolsMetadataIndexJSON(metadata, updated); err != nil {
return nil, nil, nil, err
}
if products, err = MarshalToolsMetadataProductsJSON(metadata, updated); err != nil {
return nil, nil, nil, err
}
return index, legacyIndex, products, err
} | go | func MarshalToolsMetadataJSON(metadata map[string][]*ToolsMetadata, updated time.Time) (index, legacyIndex []byte, products map[string][]byte, err error) {
if index, legacyIndex, err = marshalToolsMetadataIndexJSON(metadata, updated); err != nil {
return nil, nil, nil, err
}
if products, err = MarshalToolsMetadataProductsJSON(metadata, updated); err != nil {
return nil, nil, nil, err
}
return index, legacyIndex, products, err
} | [
"func",
"MarshalToolsMetadataJSON",
"(",
"metadata",
"map",
"[",
"string",
"]",
"[",
"]",
"*",
"ToolsMetadata",
",",
"updated",
"time",
".",
"Time",
")",
"(",
"index",
",",
"legacyIndex",
"[",
"]",
"byte",
",",
"products",
"map",
"[",
"string",
"]",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"if",
"index",
",",
"legacyIndex",
",",
"err",
"=",
"marshalToolsMetadataIndexJSON",
"(",
"metadata",
",",
"updated",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"products",
",",
"err",
"=",
"MarshalToolsMetadataProductsJSON",
"(",
"metadata",
",",
"updated",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"index",
",",
"legacyIndex",
",",
"products",
",",
"err",
"\n",
"}"
] | // MarshalToolsMetadataJSON marshals tools metadata to index and products JSON.
// updated is the time at which the JSON file was updated. | [
"MarshalToolsMetadataJSON",
"marshals",
"tools",
"metadata",
"to",
"index",
"and",
"products",
"JSON",
".",
"updated",
"is",
"the",
"time",
"at",
"which",
"the",
"JSON",
"file",
"was",
"updated",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/tools/marshal.go#L32-L40 |
155,571 | juju/juju | environs/tools/marshal.go | marshalToolsMetadataIndexJSON | func marshalToolsMetadataIndexJSON(streamMetadata map[string][]*ToolsMetadata, updated time.Time) (out, outlegacy []byte, err error) {
var indices simplestreams.Indices
indices.Updated = updated.Format(time.RFC1123Z)
indices.Format = simplestreams.IndexFormat
indices.Indexes = make(map[string]*simplestreams.IndexMetadata, len(streamMetadata))
var indicesLegacy simplestreams.Indices
indicesLegacy.Updated = updated.Format(time.RFC1123Z)
indicesLegacy.Format = simplestreams.IndexFormat
for stream, metadata := range streamMetadata {
var productIds []string
for _, t := range metadata {
id, err := t.productId()
if err != nil {
if series.IsUnknownSeriesVersionError(err) {
logger.Infof("ignoring tools metadata with unknown series %q", t.Release)
continue
}
return nil, nil, err
}
productIds = append(productIds, id)
}
indexMetadata := &simplestreams.IndexMetadata{
Updated: indices.Updated,
Format: simplestreams.ProductFormat,
DataType: ContentDownload,
ProductsFilePath: ProductMetadataPath(stream),
ProductIds: set.NewStrings(productIds...).SortedValues(),
}
indices.Indexes[ToolsContentId(stream)] = indexMetadata
if stream == ReleasedStream {
indicesLegacy.Indexes = make(map[string]*simplestreams.IndexMetadata, 1)
indicesLegacy.Indexes[ToolsContentId(stream)] = indexMetadata
}
}
out, err = json.MarshalIndent(&indices, "", " ")
if len(indicesLegacy.Indexes) == 0 {
return out, nil, err
}
outlegacy, err = json.MarshalIndent(&indicesLegacy, "", " ")
if err != nil {
return nil, nil, err
}
return out, outlegacy, nil
} | go | func marshalToolsMetadataIndexJSON(streamMetadata map[string][]*ToolsMetadata, updated time.Time) (out, outlegacy []byte, err error) {
var indices simplestreams.Indices
indices.Updated = updated.Format(time.RFC1123Z)
indices.Format = simplestreams.IndexFormat
indices.Indexes = make(map[string]*simplestreams.IndexMetadata, len(streamMetadata))
var indicesLegacy simplestreams.Indices
indicesLegacy.Updated = updated.Format(time.RFC1123Z)
indicesLegacy.Format = simplestreams.IndexFormat
for stream, metadata := range streamMetadata {
var productIds []string
for _, t := range metadata {
id, err := t.productId()
if err != nil {
if series.IsUnknownSeriesVersionError(err) {
logger.Infof("ignoring tools metadata with unknown series %q", t.Release)
continue
}
return nil, nil, err
}
productIds = append(productIds, id)
}
indexMetadata := &simplestreams.IndexMetadata{
Updated: indices.Updated,
Format: simplestreams.ProductFormat,
DataType: ContentDownload,
ProductsFilePath: ProductMetadataPath(stream),
ProductIds: set.NewStrings(productIds...).SortedValues(),
}
indices.Indexes[ToolsContentId(stream)] = indexMetadata
if stream == ReleasedStream {
indicesLegacy.Indexes = make(map[string]*simplestreams.IndexMetadata, 1)
indicesLegacy.Indexes[ToolsContentId(stream)] = indexMetadata
}
}
out, err = json.MarshalIndent(&indices, "", " ")
if len(indicesLegacy.Indexes) == 0 {
return out, nil, err
}
outlegacy, err = json.MarshalIndent(&indicesLegacy, "", " ")
if err != nil {
return nil, nil, err
}
return out, outlegacy, nil
} | [
"func",
"marshalToolsMetadataIndexJSON",
"(",
"streamMetadata",
"map",
"[",
"string",
"]",
"[",
"]",
"*",
"ToolsMetadata",
",",
"updated",
"time",
".",
"Time",
")",
"(",
"out",
",",
"outlegacy",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"var",
"indices",
"simplestreams",
".",
"Indices",
"\n",
"indices",
".",
"Updated",
"=",
"updated",
".",
"Format",
"(",
"time",
".",
"RFC1123Z",
")",
"\n",
"indices",
".",
"Format",
"=",
"simplestreams",
".",
"IndexFormat",
"\n",
"indices",
".",
"Indexes",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"simplestreams",
".",
"IndexMetadata",
",",
"len",
"(",
"streamMetadata",
")",
")",
"\n\n",
"var",
"indicesLegacy",
"simplestreams",
".",
"Indices",
"\n",
"indicesLegacy",
".",
"Updated",
"=",
"updated",
".",
"Format",
"(",
"time",
".",
"RFC1123Z",
")",
"\n",
"indicesLegacy",
".",
"Format",
"=",
"simplestreams",
".",
"IndexFormat",
"\n\n",
"for",
"stream",
",",
"metadata",
":=",
"range",
"streamMetadata",
"{",
"var",
"productIds",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"t",
":=",
"range",
"metadata",
"{",
"id",
",",
"err",
":=",
"t",
".",
"productId",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"series",
".",
"IsUnknownSeriesVersionError",
"(",
"err",
")",
"{",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"t",
".",
"Release",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"productIds",
"=",
"append",
"(",
"productIds",
",",
"id",
")",
"\n",
"}",
"\n",
"indexMetadata",
":=",
"&",
"simplestreams",
".",
"IndexMetadata",
"{",
"Updated",
":",
"indices",
".",
"Updated",
",",
"Format",
":",
"simplestreams",
".",
"ProductFormat",
",",
"DataType",
":",
"ContentDownload",
",",
"ProductsFilePath",
":",
"ProductMetadataPath",
"(",
"stream",
")",
",",
"ProductIds",
":",
"set",
".",
"NewStrings",
"(",
"productIds",
"...",
")",
".",
"SortedValues",
"(",
")",
",",
"}",
"\n",
"indices",
".",
"Indexes",
"[",
"ToolsContentId",
"(",
"stream",
")",
"]",
"=",
"indexMetadata",
"\n",
"if",
"stream",
"==",
"ReleasedStream",
"{",
"indicesLegacy",
".",
"Indexes",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"simplestreams",
".",
"IndexMetadata",
",",
"1",
")",
"\n",
"indicesLegacy",
".",
"Indexes",
"[",
"ToolsContentId",
"(",
"stream",
")",
"]",
"=",
"indexMetadata",
"\n",
"}",
"\n",
"}",
"\n",
"out",
",",
"err",
"=",
"json",
".",
"MarshalIndent",
"(",
"&",
"indices",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"indicesLegacy",
".",
"Indexes",
")",
"==",
"0",
"{",
"return",
"out",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"outlegacy",
",",
"err",
"=",
"json",
".",
"MarshalIndent",
"(",
"&",
"indicesLegacy",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"out",
",",
"outlegacy",
",",
"nil",
"\n",
"}"
] | // marshalToolsMetadataIndexJSON marshals tools metadata to index JSON.
// updated is the time at which the JSON file was updated. | [
"marshalToolsMetadataIndexJSON",
"marshals",
"tools",
"metadata",
"to",
"index",
"JSON",
".",
"updated",
"is",
"the",
"time",
"at",
"which",
"the",
"JSON",
"file",
"was",
"updated",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/tools/marshal.go#L44-L89 |
155,572 | juju/juju | environs/tools/marshal.go | MarshalToolsMetadataProductsJSON | func MarshalToolsMetadataProductsJSON(
streamMetadata map[string][]*ToolsMetadata, updated time.Time,
) (out map[string][]byte, err error) {
out = make(map[string][]byte, len(streamMetadata))
for stream, metadata := range streamMetadata {
var cloud simplestreams.CloudMetadata
cloud.Updated = updated.Format(time.RFC1123Z)
cloud.Format = simplestreams.ProductFormat
cloud.ContentId = ToolsContentId(stream)
cloud.Products = make(map[string]simplestreams.MetadataCatalog)
itemsversion := updated.Format("20060102") // YYYYMMDD
for _, t := range metadata {
id, err := t.productId()
if err != nil {
if series.IsUnknownSeriesVersionError(err) {
continue
}
return nil, err
}
itemid := fmt.Sprintf("%s-%s-%s", t.Version, t.Release, t.Arch)
if catalog, ok := cloud.Products[id]; ok {
catalog.Items[itemsversion].Items[itemid] = t
} else {
catalog = simplestreams.MetadataCatalog{
Arch: t.Arch,
Version: t.Version,
Items: map[string]*simplestreams.ItemCollection{
itemsversion: {
Items: map[string]interface{}{itemid: t},
},
},
}
cloud.Products[id] = catalog
}
}
if out[stream], err = json.MarshalIndent(&cloud, "", " "); err != nil {
return nil, err
}
}
return out, nil
} | go | func MarshalToolsMetadataProductsJSON(
streamMetadata map[string][]*ToolsMetadata, updated time.Time,
) (out map[string][]byte, err error) {
out = make(map[string][]byte, len(streamMetadata))
for stream, metadata := range streamMetadata {
var cloud simplestreams.CloudMetadata
cloud.Updated = updated.Format(time.RFC1123Z)
cloud.Format = simplestreams.ProductFormat
cloud.ContentId = ToolsContentId(stream)
cloud.Products = make(map[string]simplestreams.MetadataCatalog)
itemsversion := updated.Format("20060102") // YYYYMMDD
for _, t := range metadata {
id, err := t.productId()
if err != nil {
if series.IsUnknownSeriesVersionError(err) {
continue
}
return nil, err
}
itemid := fmt.Sprintf("%s-%s-%s", t.Version, t.Release, t.Arch)
if catalog, ok := cloud.Products[id]; ok {
catalog.Items[itemsversion].Items[itemid] = t
} else {
catalog = simplestreams.MetadataCatalog{
Arch: t.Arch,
Version: t.Version,
Items: map[string]*simplestreams.ItemCollection{
itemsversion: {
Items: map[string]interface{}{itemid: t},
},
},
}
cloud.Products[id] = catalog
}
}
if out[stream], err = json.MarshalIndent(&cloud, "", " "); err != nil {
return nil, err
}
}
return out, nil
} | [
"func",
"MarshalToolsMetadataProductsJSON",
"(",
"streamMetadata",
"map",
"[",
"string",
"]",
"[",
"]",
"*",
"ToolsMetadata",
",",
"updated",
"time",
".",
"Time",
",",
")",
"(",
"out",
"map",
"[",
"string",
"]",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"out",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"byte",
",",
"len",
"(",
"streamMetadata",
")",
")",
"\n",
"for",
"stream",
",",
"metadata",
":=",
"range",
"streamMetadata",
"{",
"var",
"cloud",
"simplestreams",
".",
"CloudMetadata",
"\n",
"cloud",
".",
"Updated",
"=",
"updated",
".",
"Format",
"(",
"time",
".",
"RFC1123Z",
")",
"\n",
"cloud",
".",
"Format",
"=",
"simplestreams",
".",
"ProductFormat",
"\n",
"cloud",
".",
"ContentId",
"=",
"ToolsContentId",
"(",
"stream",
")",
"\n",
"cloud",
".",
"Products",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"simplestreams",
".",
"MetadataCatalog",
")",
"\n",
"itemsversion",
":=",
"updated",
".",
"Format",
"(",
"\"",
"\"",
")",
"// YYYYMMDD",
"\n",
"for",
"_",
",",
"t",
":=",
"range",
"metadata",
"{",
"id",
",",
"err",
":=",
"t",
".",
"productId",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"series",
".",
"IsUnknownSeriesVersionError",
"(",
"err",
")",
"{",
"continue",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"itemid",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Version",
",",
"t",
".",
"Release",
",",
"t",
".",
"Arch",
")",
"\n",
"if",
"catalog",
",",
"ok",
":=",
"cloud",
".",
"Products",
"[",
"id",
"]",
";",
"ok",
"{",
"catalog",
".",
"Items",
"[",
"itemsversion",
"]",
".",
"Items",
"[",
"itemid",
"]",
"=",
"t",
"\n",
"}",
"else",
"{",
"catalog",
"=",
"simplestreams",
".",
"MetadataCatalog",
"{",
"Arch",
":",
"t",
".",
"Arch",
",",
"Version",
":",
"t",
".",
"Version",
",",
"Items",
":",
"map",
"[",
"string",
"]",
"*",
"simplestreams",
".",
"ItemCollection",
"{",
"itemsversion",
":",
"{",
"Items",
":",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"itemid",
":",
"t",
"}",
",",
"}",
",",
"}",
",",
"}",
"\n",
"cloud",
".",
"Products",
"[",
"id",
"]",
"=",
"catalog",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"out",
"[",
"stream",
"]",
",",
"err",
"=",
"json",
".",
"MarshalIndent",
"(",
"&",
"cloud",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"out",
",",
"nil",
"\n",
"}"
] | // MarshalToolsMetadataProductsJSON marshals tools metadata to products JSON.
// updated is the time at which the JSON file was updated. | [
"MarshalToolsMetadataProductsJSON",
"marshals",
"tools",
"metadata",
"to",
"products",
"JSON",
".",
"updated",
"is",
"the",
"time",
"at",
"which",
"the",
"JSON",
"file",
"was",
"updated",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/tools/marshal.go#L93-L134 |
155,573 | juju/juju | cmd/juju/controller/unregister.go | NewUnregisterCommand | func NewUnregisterCommand(store jujuclient.ClientStore) cmd.Command {
if store == nil {
panic("valid store must be specified")
}
cmd := &unregisterCommand{store: store}
return modelcmd.WrapBase(cmd)
} | go | func NewUnregisterCommand(store jujuclient.ClientStore) cmd.Command {
if store == nil {
panic("valid store must be specified")
}
cmd := &unregisterCommand{store: store}
return modelcmd.WrapBase(cmd)
} | [
"func",
"NewUnregisterCommand",
"(",
"store",
"jujuclient",
".",
"ClientStore",
")",
"cmd",
".",
"Command",
"{",
"if",
"store",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"cmd",
":=",
"&",
"unregisterCommand",
"{",
"store",
":",
"store",
"}",
"\n",
"return",
"modelcmd",
".",
"WrapBase",
"(",
"cmd",
")",
"\n",
"}"
] | // NewUnregisterCommand returns a command to allow the user to unregister a controller. | [
"NewUnregisterCommand",
"returns",
"a",
"command",
"to",
"allow",
"the",
"user",
"to",
"unregister",
"a",
"controller",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/controller/unregister.go#L19-L25 |
155,574 | juju/juju | cmd/juju/controller/unregister.go | Info | func (c *unregisterCommand) Info() *cmd.Info {
return jujucmd.Info(&cmd.Info{
Name: "unregister",
Args: "<controller name>",
Purpose: "Unregisters a Juju controller.",
Doc: usageUnregisterDetails,
})
} | go | func (c *unregisterCommand) Info() *cmd.Info {
return jujucmd.Info(&cmd.Info{
Name: "unregister",
Args: "<controller name>",
Purpose: "Unregisters a Juju controller.",
Doc: usageUnregisterDetails,
})
} | [
"func",
"(",
"c",
"*",
"unregisterCommand",
")",
"Info",
"(",
")",
"*",
"cmd",
".",
"Info",
"{",
"return",
"jujucmd",
".",
"Info",
"(",
"&",
"cmd",
".",
"Info",
"{",
"Name",
":",
"\"",
"\"",
",",
"Args",
":",
"\"",
"\"",
",",
"Purpose",
":",
"\"",
"\"",
",",
"Doc",
":",
"usageUnregisterDetails",
",",
"}",
")",
"\n",
"}"
] | // Info implements Command.Info
// `unregister` may seem generic as a command, but aligns with `register`. | [
"Info",
"implements",
"Command",
".",
"Info",
"unregister",
"may",
"seem",
"generic",
"as",
"a",
"command",
"but",
"aligns",
"with",
"register",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/controller/unregister.go#L52-L59 |
155,575 | juju/juju | core/presence/presence.go | Disable | func (r *recorder) Disable() {
r.mu.Lock()
defer r.mu.Unlock()
r.enabled = false
r.entries = nil
} | go | func (r *recorder) Disable() {
r.mu.Lock()
defer r.mu.Unlock()
r.enabled = false
r.entries = nil
} | [
"func",
"(",
"r",
"*",
"recorder",
")",
"Disable",
"(",
")",
"{",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"r",
".",
"enabled",
"=",
"false",
"\n",
"r",
".",
"entries",
"=",
"nil",
"\n",
"}"
] | // Disable implements Recorder. | [
"Disable",
"implements",
"Recorder",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/presence/presence.go#L173-L178 |
155,576 | juju/juju | core/presence/presence.go | Enable | func (r *recorder) Enable() {
r.mu.Lock()
defer r.mu.Unlock()
r.enabled = true
} | go | func (r *recorder) Enable() {
r.mu.Lock()
defer r.mu.Unlock()
r.enabled = true
} | [
"func",
"(",
"r",
"*",
"recorder",
")",
"Enable",
"(",
")",
"{",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"r",
".",
"enabled",
"=",
"true",
"\n\n",
"}"
] | // Enable implements Recorder. | [
"Enable",
"implements",
"Recorder",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/presence/presence.go#L181-L186 |
155,577 | juju/juju | core/presence/presence.go | IsEnabled | func (r *recorder) IsEnabled() bool {
r.mu.Lock()
defer r.mu.Unlock()
return r.enabled
} | go | func (r *recorder) IsEnabled() bool {
r.mu.Lock()
defer r.mu.Unlock()
return r.enabled
} | [
"func",
"(",
"r",
"*",
"recorder",
")",
"IsEnabled",
"(",
")",
"bool",
"{",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"r",
".",
"enabled",
"\n",
"}"
] | // IsEnabled implements Recorder. | [
"IsEnabled",
"implements",
"Recorder",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/presence/presence.go#L189-L193 |
155,578 | juju/juju | core/presence/presence.go | Connect | func (r *recorder) Connect(server, model, agent string, id uint64, controllerAgent bool, userData string) {
r.mu.Lock()
defer r.mu.Unlock()
if !r.enabled {
return
}
pos := r.findIndex(server, id)
if pos == -1 {
r.entries = append(r.entries, Value{
Model: model,
Server: server,
Agent: agent,
ControllerAgent: controllerAgent,
ConnectionID: id,
Status: Alive,
UserData: userData,
LastSeen: r.clock.Now(),
})
} else {
// Need to access the value in the array, not a copy of it.
r.entries[pos].Status = Alive
r.entries[pos].LastSeen = r.clock.Now()
}
} | go | func (r *recorder) Connect(server, model, agent string, id uint64, controllerAgent bool, userData string) {
r.mu.Lock()
defer r.mu.Unlock()
if !r.enabled {
return
}
pos := r.findIndex(server, id)
if pos == -1 {
r.entries = append(r.entries, Value{
Model: model,
Server: server,
Agent: agent,
ControllerAgent: controllerAgent,
ConnectionID: id,
Status: Alive,
UserData: userData,
LastSeen: r.clock.Now(),
})
} else {
// Need to access the value in the array, not a copy of it.
r.entries[pos].Status = Alive
r.entries[pos].LastSeen = r.clock.Now()
}
} | [
"func",
"(",
"r",
"*",
"recorder",
")",
"Connect",
"(",
"server",
",",
"model",
",",
"agent",
"string",
",",
"id",
"uint64",
",",
"controllerAgent",
"bool",
",",
"userData",
"string",
")",
"{",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"r",
".",
"enabled",
"{",
"return",
"\n",
"}",
"\n\n",
"pos",
":=",
"r",
".",
"findIndex",
"(",
"server",
",",
"id",
")",
"\n",
"if",
"pos",
"==",
"-",
"1",
"{",
"r",
".",
"entries",
"=",
"append",
"(",
"r",
".",
"entries",
",",
"Value",
"{",
"Model",
":",
"model",
",",
"Server",
":",
"server",
",",
"Agent",
":",
"agent",
",",
"ControllerAgent",
":",
"controllerAgent",
",",
"ConnectionID",
":",
"id",
",",
"Status",
":",
"Alive",
",",
"UserData",
":",
"userData",
",",
"LastSeen",
":",
"r",
".",
"clock",
".",
"Now",
"(",
")",
",",
"}",
")",
"\n",
"}",
"else",
"{",
"// Need to access the value in the array, not a copy of it.",
"r",
".",
"entries",
"[",
"pos",
"]",
".",
"Status",
"=",
"Alive",
"\n",
"r",
".",
"entries",
"[",
"pos",
"]",
".",
"LastSeen",
"=",
"r",
".",
"clock",
".",
"Now",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Connect implements Recorder. | [
"Connect",
"implements",
"Recorder",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/presence/presence.go#L205-L229 |
155,579 | juju/juju | core/presence/presence.go | Disconnect | func (r *recorder) Disconnect(server string, id uint64) {
r.mu.Lock()
defer r.mu.Unlock()
if !r.enabled {
return
}
if pos := r.findIndex(server, id); pos >= 0 {
if pos == 0 {
r.entries = r.entries[1:]
} else {
r.entries = append(r.entries[0:pos], r.entries[pos+1:]...)
}
}
} | go | func (r *recorder) Disconnect(server string, id uint64) {
r.mu.Lock()
defer r.mu.Unlock()
if !r.enabled {
return
}
if pos := r.findIndex(server, id); pos >= 0 {
if pos == 0 {
r.entries = r.entries[1:]
} else {
r.entries = append(r.entries[0:pos], r.entries[pos+1:]...)
}
}
} | [
"func",
"(",
"r",
"*",
"recorder",
")",
"Disconnect",
"(",
"server",
"string",
",",
"id",
"uint64",
")",
"{",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"r",
".",
"enabled",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"pos",
":=",
"r",
".",
"findIndex",
"(",
"server",
",",
"id",
")",
";",
"pos",
">=",
"0",
"{",
"if",
"pos",
"==",
"0",
"{",
"r",
".",
"entries",
"=",
"r",
".",
"entries",
"[",
"1",
":",
"]",
"\n",
"}",
"else",
"{",
"r",
".",
"entries",
"=",
"append",
"(",
"r",
".",
"entries",
"[",
"0",
":",
"pos",
"]",
",",
"r",
".",
"entries",
"[",
"pos",
"+",
"1",
":",
"]",
"...",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Disconnect implements Recorder. | [
"Disconnect",
"implements",
"Recorder",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/presence/presence.go#L232-L246 |
155,580 | juju/juju | core/presence/presence.go | Activity | func (r *recorder) Activity(server string, id uint64) {
r.mu.Lock()
defer r.mu.Unlock()
if !r.enabled {
return
}
if pos := r.findIndex(server, id); pos >= 0 {
r.entries[pos].LastSeen = r.clock.Now()
}
} | go | func (r *recorder) Activity(server string, id uint64) {
r.mu.Lock()
defer r.mu.Unlock()
if !r.enabled {
return
}
if pos := r.findIndex(server, id); pos >= 0 {
r.entries[pos].LastSeen = r.clock.Now()
}
} | [
"func",
"(",
"r",
"*",
"recorder",
")",
"Activity",
"(",
"server",
"string",
",",
"id",
"uint64",
")",
"{",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"r",
".",
"enabled",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"pos",
":=",
"r",
".",
"findIndex",
"(",
"server",
",",
"id",
")",
";",
"pos",
">=",
"0",
"{",
"r",
".",
"entries",
"[",
"pos",
"]",
".",
"LastSeen",
"=",
"r",
".",
"clock",
".",
"Now",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Activity implements Recorder. | [
"Activity",
"implements",
"Recorder",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/presence/presence.go#L249-L259 |
155,581 | juju/juju | core/presence/presence.go | ServerDown | func (r *recorder) ServerDown(server string) {
r.mu.Lock()
defer r.mu.Unlock()
if !r.enabled {
return
}
for i, value := range r.entries {
if value.Server == server {
r.entries[i].Status = Missing
}
}
} | go | func (r *recorder) ServerDown(server string) {
r.mu.Lock()
defer r.mu.Unlock()
if !r.enabled {
return
}
for i, value := range r.entries {
if value.Server == server {
r.entries[i].Status = Missing
}
}
} | [
"func",
"(",
"r",
"*",
"recorder",
")",
"ServerDown",
"(",
"server",
"string",
")",
"{",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"r",
".",
"enabled",
"{",
"return",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"value",
":=",
"range",
"r",
".",
"entries",
"{",
"if",
"value",
".",
"Server",
"==",
"server",
"{",
"r",
".",
"entries",
"[",
"i",
"]",
".",
"Status",
"=",
"Missing",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // ServerDown implements Recorder. | [
"ServerDown",
"implements",
"Recorder",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/presence/presence.go#L262-L274 |
155,582 | juju/juju | core/presence/presence.go | UpdateServer | func (r *recorder) UpdateServer(server string, connections []Value) error {
r.mu.Lock()
defer r.mu.Unlock()
if !r.enabled {
return errors.New("recorder not enabled")
}
entries := make([]Value, 0, len(r.entries))
for _, value := range r.entries {
if value.Server != server {
entries = append(entries, value)
}
}
for _, value := range connections {
if value.Server != server {
return errors.Errorf("connection server mismatch, got %q expected %q", value.Server, server)
}
value.Status = Alive
value.LastSeen = r.clock.Now()
entries = append(entries, value)
}
r.entries = entries
return nil
} | go | func (r *recorder) UpdateServer(server string, connections []Value) error {
r.mu.Lock()
defer r.mu.Unlock()
if !r.enabled {
return errors.New("recorder not enabled")
}
entries := make([]Value, 0, len(r.entries))
for _, value := range r.entries {
if value.Server != server {
entries = append(entries, value)
}
}
for _, value := range connections {
if value.Server != server {
return errors.Errorf("connection server mismatch, got %q expected %q", value.Server, server)
}
value.Status = Alive
value.LastSeen = r.clock.Now()
entries = append(entries, value)
}
r.entries = entries
return nil
} | [
"func",
"(",
"r",
"*",
"recorder",
")",
"UpdateServer",
"(",
"server",
"string",
",",
"connections",
"[",
"]",
"Value",
")",
"error",
"{",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"r",
".",
"enabled",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"entries",
":=",
"make",
"(",
"[",
"]",
"Value",
",",
"0",
",",
"len",
"(",
"r",
".",
"entries",
")",
")",
"\n",
"for",
"_",
",",
"value",
":=",
"range",
"r",
".",
"entries",
"{",
"if",
"value",
".",
"Server",
"!=",
"server",
"{",
"entries",
"=",
"append",
"(",
"entries",
",",
"value",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"value",
":=",
"range",
"connections",
"{",
"if",
"value",
".",
"Server",
"!=",
"server",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"value",
".",
"Server",
",",
"server",
")",
"\n",
"}",
"\n",
"value",
".",
"Status",
"=",
"Alive",
"\n",
"value",
".",
"LastSeen",
"=",
"r",
".",
"clock",
".",
"Now",
"(",
")",
"\n",
"entries",
"=",
"append",
"(",
"entries",
",",
"value",
")",
"\n",
"}",
"\n\n",
"r",
".",
"entries",
"=",
"entries",
"\n",
"return",
"nil",
"\n",
"}"
] | // UpdateServer implements Recorder. | [
"UpdateServer",
"implements",
"Recorder",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/presence/presence.go#L277-L302 |
155,583 | juju/juju | core/presence/presence.go | Connections | func (r *recorder) Connections() Connections {
r.mu.Lock()
defer r.mu.Unlock()
entries := make([]Value, len(r.entries))
copy(entries, r.entries)
return &connections{values: entries}
} | go | func (r *recorder) Connections() Connections {
r.mu.Lock()
defer r.mu.Unlock()
entries := make([]Value, len(r.entries))
copy(entries, r.entries)
return &connections{values: entries}
} | [
"func",
"(",
"r",
"*",
"recorder",
")",
"Connections",
"(",
")",
"Connections",
"{",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"entries",
":=",
"make",
"(",
"[",
"]",
"Value",
",",
"len",
"(",
"r",
".",
"entries",
")",
")",
"\n",
"copy",
"(",
"entries",
",",
"r",
".",
"entries",
")",
"\n",
"return",
"&",
"connections",
"{",
"values",
":",
"entries",
"}",
"\n",
"}"
] | // Connections implements Recorder. | [
"Connections",
"implements",
"Recorder",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/presence/presence.go#L305-L312 |
155,584 | juju/juju | core/presence/presence.go | ForModel | func (c *connections) ForModel(model string) Connections {
var values []Value
for _, value := range c.values {
if value.Model == model {
values = append(values, value)
}
}
return &connections{model: model, values: values}
} | go | func (c *connections) ForModel(model string) Connections {
var values []Value
for _, value := range c.values {
if value.Model == model {
values = append(values, value)
}
}
return &connections{model: model, values: values}
} | [
"func",
"(",
"c",
"*",
"connections",
")",
"ForModel",
"(",
"model",
"string",
")",
"Connections",
"{",
"var",
"values",
"[",
"]",
"Value",
"\n",
"for",
"_",
",",
"value",
":=",
"range",
"c",
".",
"values",
"{",
"if",
"value",
".",
"Model",
"==",
"model",
"{",
"values",
"=",
"append",
"(",
"values",
",",
"value",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"&",
"connections",
"{",
"model",
":",
"model",
",",
"values",
":",
"values",
"}",
"\n",
"}"
] | // ForModel implements Connections. | [
"ForModel",
"implements",
"Connections",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/presence/presence.go#L315-L323 |
155,585 | juju/juju | core/presence/presence.go | ForServer | func (c *connections) ForServer(server string) Connections {
var values []Value
for _, value := range c.values {
if value.Server == server {
values = append(values, value)
}
}
return &connections{model: c.model, values: values}
} | go | func (c *connections) ForServer(server string) Connections {
var values []Value
for _, value := range c.values {
if value.Server == server {
values = append(values, value)
}
}
return &connections{model: c.model, values: values}
} | [
"func",
"(",
"c",
"*",
"connections",
")",
"ForServer",
"(",
"server",
"string",
")",
"Connections",
"{",
"var",
"values",
"[",
"]",
"Value",
"\n",
"for",
"_",
",",
"value",
":=",
"range",
"c",
".",
"values",
"{",
"if",
"value",
".",
"Server",
"==",
"server",
"{",
"values",
"=",
"append",
"(",
"values",
",",
"value",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"&",
"connections",
"{",
"model",
":",
"c",
".",
"model",
",",
"values",
":",
"values",
"}",
"\n",
"}"
] | // ForServer implements Connections. | [
"ForServer",
"implements",
"Connections",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/presence/presence.go#L326-L334 |
155,586 | juju/juju | core/presence/presence.go | ForAgent | func (c *connections) ForAgent(agent string) Connections {
var values []Value
for _, value := range c.values {
if value.Agent == agent {
values = append(values, value)
}
}
return &connections{model: c.model, values: values}
} | go | func (c *connections) ForAgent(agent string) Connections {
var values []Value
for _, value := range c.values {
if value.Agent == agent {
values = append(values, value)
}
}
return &connections{model: c.model, values: values}
} | [
"func",
"(",
"c",
"*",
"connections",
")",
"ForAgent",
"(",
"agent",
"string",
")",
"Connections",
"{",
"var",
"values",
"[",
"]",
"Value",
"\n",
"for",
"_",
",",
"value",
":=",
"range",
"c",
".",
"values",
"{",
"if",
"value",
".",
"Agent",
"==",
"agent",
"{",
"values",
"=",
"append",
"(",
"values",
",",
"value",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"&",
"connections",
"{",
"model",
":",
"c",
".",
"model",
",",
"values",
":",
"values",
"}",
"\n",
"}"
] | // ForAgent implements Connections. | [
"ForAgent",
"implements",
"Connections",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/presence/presence.go#L337-L345 |
155,587 | juju/juju | core/presence/presence.go | Models | func (c *connections) Models() []string {
models := set.NewStrings()
for _, value := range c.values {
models.Add(value.Model)
}
return models.Values()
} | go | func (c *connections) Models() []string {
models := set.NewStrings()
for _, value := range c.values {
models.Add(value.Model)
}
return models.Values()
} | [
"func",
"(",
"c",
"*",
"connections",
")",
"Models",
"(",
")",
"[",
"]",
"string",
"{",
"models",
":=",
"set",
".",
"NewStrings",
"(",
")",
"\n",
"for",
"_",
",",
"value",
":=",
"range",
"c",
".",
"values",
"{",
"models",
".",
"Add",
"(",
"value",
".",
"Model",
")",
"\n",
"}",
"\n",
"return",
"models",
".",
"Values",
"(",
")",
"\n",
"}"
] | // Models implements Connections. | [
"Models",
"implements",
"Connections",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/presence/presence.go#L353-L359 |
155,588 | juju/juju | core/presence/presence.go | Servers | func (c *connections) Servers() []string {
servers := set.NewStrings()
for _, value := range c.values {
servers.Add(value.Server)
}
return servers.Values()
} | go | func (c *connections) Servers() []string {
servers := set.NewStrings()
for _, value := range c.values {
servers.Add(value.Server)
}
return servers.Values()
} | [
"func",
"(",
"c",
"*",
"connections",
")",
"Servers",
"(",
")",
"[",
"]",
"string",
"{",
"servers",
":=",
"set",
".",
"NewStrings",
"(",
")",
"\n",
"for",
"_",
",",
"value",
":=",
"range",
"c",
".",
"values",
"{",
"servers",
".",
"Add",
"(",
"value",
".",
"Server",
")",
"\n",
"}",
"\n",
"return",
"servers",
".",
"Values",
"(",
")",
"\n",
"}"
] | // Servers implements Connections. | [
"Servers",
"implements",
"Connections",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/presence/presence.go#L362-L368 |
155,589 | juju/juju | core/presence/presence.go | Agents | func (c *connections) Agents() []string {
agents := set.NewStrings()
for _, value := range c.values {
agents.Add(value.Agent)
}
return agents.Values()
} | go | func (c *connections) Agents() []string {
agents := set.NewStrings()
for _, value := range c.values {
agents.Add(value.Agent)
}
return agents.Values()
} | [
"func",
"(",
"c",
"*",
"connections",
")",
"Agents",
"(",
")",
"[",
"]",
"string",
"{",
"agents",
":=",
"set",
".",
"NewStrings",
"(",
")",
"\n",
"for",
"_",
",",
"value",
":=",
"range",
"c",
".",
"values",
"{",
"agents",
".",
"Add",
"(",
"value",
".",
"Agent",
")",
"\n",
"}",
"\n",
"return",
"agents",
".",
"Values",
"(",
")",
"\n",
"}"
] | // Agents implements Connections. | [
"Agents",
"implements",
"Connections",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/presence/presence.go#L371-L377 |
155,590 | juju/juju | core/presence/presence.go | AgentStatus | func (c *connections) AgentStatus(agent string) (Status, error) {
if c.model == "" {
return Unknown, errors.New("connections not limited to a model, agent ambiguous")
}
result := Unknown
for _, value := range c.values {
if value.Agent == agent && !value.ControllerAgent {
if value.Status > result {
result = value.Status
}
}
}
return result, nil
} | go | func (c *connections) AgentStatus(agent string) (Status, error) {
if c.model == "" {
return Unknown, errors.New("connections not limited to a model, agent ambiguous")
}
result := Unknown
for _, value := range c.values {
if value.Agent == agent && !value.ControllerAgent {
if value.Status > result {
result = value.Status
}
}
}
return result, nil
} | [
"func",
"(",
"c",
"*",
"connections",
")",
"AgentStatus",
"(",
"agent",
"string",
")",
"(",
"Status",
",",
"error",
")",
"{",
"if",
"c",
".",
"model",
"==",
"\"",
"\"",
"{",
"return",
"Unknown",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"result",
":=",
"Unknown",
"\n",
"for",
"_",
",",
"value",
":=",
"range",
"c",
".",
"values",
"{",
"if",
"value",
".",
"Agent",
"==",
"agent",
"&&",
"!",
"value",
".",
"ControllerAgent",
"{",
"if",
"value",
".",
"Status",
">",
"result",
"{",
"result",
"=",
"value",
".",
"Status",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // AgentStatus implements Connections. | [
"AgentStatus",
"implements",
"Connections",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/presence/presence.go#L380-L393 |
155,591 | juju/juju | provider/cloudsigma/environ.go | SetConfig | func (env *environ) SetConfig(cfg *config.Config) error {
env.lock.Lock()
defer env.lock.Unlock()
ecfg, err := validateConfig(cfg, env.ecfg)
if err != nil {
return errors.Trace(err)
}
env.ecfg = ecfg
return nil
} | go | func (env *environ) SetConfig(cfg *config.Config) error {
env.lock.Lock()
defer env.lock.Unlock()
ecfg, err := validateConfig(cfg, env.ecfg)
if err != nil {
return errors.Trace(err)
}
env.ecfg = ecfg
return nil
} | [
"func",
"(",
"env",
"*",
"environ",
")",
"SetConfig",
"(",
"cfg",
"*",
"config",
".",
"Config",
")",
"error",
"{",
"env",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"env",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"ecfg",
",",
"err",
":=",
"validateConfig",
"(",
"cfg",
",",
"env",
".",
"ecfg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"env",
".",
"ecfg",
"=",
"ecfg",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // SetConfig updates the Environ's configuration.
//
// Calls to SetConfig do not affect the configuration of values previously obtained
// from Storage. | [
"SetConfig",
"updates",
"the",
"Environ",
"s",
"configuration",
".",
"Calls",
"to",
"SetConfig",
"do",
"not",
"affect",
"the",
"configuration",
"of",
"values",
"previously",
"obtained",
"from",
"Storage",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/cloudsigma/environ.go#L48-L59 |
155,592 | juju/juju | provider/cloudsigma/environ.go | ControllerInstances | func (e *environ) ControllerInstances(ctx context.ProviderCallContext, controllerUUID string) ([]instance.Id, error) {
return e.client.getControllerIds()
} | go | func (e *environ) ControllerInstances(ctx context.ProviderCallContext, controllerUUID string) ([]instance.Id, error) {
return e.client.getControllerIds()
} | [
"func",
"(",
"e",
"*",
"environ",
")",
"ControllerInstances",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"controllerUUID",
"string",
")",
"(",
"[",
"]",
"instance",
".",
"Id",
",",
"error",
")",
"{",
"return",
"e",
".",
"client",
".",
"getControllerIds",
"(",
")",
"\n",
"}"
] | // ControllerInstances is part of the Environ interface. | [
"ControllerInstances",
"is",
"part",
"of",
"the",
"Environ",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/cloudsigma/environ.go#L98-L100 |
155,593 | juju/juju | provider/cloudsigma/environ.go | Destroy | func (env *environ) Destroy(ctx context.ProviderCallContext) error {
// You can probably ignore this method; the common implementation should work.
return common.Destroy(env, ctx)
} | go | func (env *environ) Destroy(ctx context.ProviderCallContext) error {
// You can probably ignore this method; the common implementation should work.
return common.Destroy(env, ctx)
} | [
"func",
"(",
"env",
"*",
"environ",
")",
"Destroy",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
")",
"error",
"{",
"// You can probably ignore this method; the common implementation should work.",
"return",
"common",
".",
"Destroy",
"(",
"env",
",",
"ctx",
")",
"\n",
"}"
] | // Destroy shuts down all known machines and destroys the
// rest of the environment. Note that on some providers,
// very recently started instances may not be destroyed
// because they are not yet visible.
//
// When Destroy has been called, any Environ referring to the
// same remote environment may become invalid | [
"Destroy",
"shuts",
"down",
"all",
"known",
"machines",
"and",
"destroys",
"the",
"rest",
"of",
"the",
"environment",
".",
"Note",
"that",
"on",
"some",
"providers",
"very",
"recently",
"started",
"instances",
"may",
"not",
"be",
"destroyed",
"because",
"they",
"are",
"not",
"yet",
"visible",
".",
"When",
"Destroy",
"has",
"been",
"called",
"any",
"Environ",
"referring",
"to",
"the",
"same",
"remote",
"environment",
"may",
"become",
"invalid"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/cloudsigma/environ.go#L115-L118 |
155,594 | juju/juju | provider/common/instance_configurator.go | NewSshInstanceConfigurator | func NewSshInstanceConfigurator(host string) InstanceConfigurator {
options := ssh.Options{}
options.SetIdentities("/var/lib/juju/system-identity")
// Disable host key checking. We're not sending any sensitive data
// across, and we don't have access to the host's keys from here.
//
// TODO(axw) 2017-12-07 #1732665
// Stop using SSH, instead manage iptables on the machine
// itself. This will also provide firewalling for MAAS and
// LXD machines.
options.SetStrictHostKeyChecking(ssh.StrictHostChecksNo)
options.SetKnownHostsFile(os.DevNull)
return &sshInstanceConfigurator{
client: ssh.DefaultClient,
host: "ubuntu@" + host,
options: &options,
}
} | go | func NewSshInstanceConfigurator(host string) InstanceConfigurator {
options := ssh.Options{}
options.SetIdentities("/var/lib/juju/system-identity")
// Disable host key checking. We're not sending any sensitive data
// across, and we don't have access to the host's keys from here.
//
// TODO(axw) 2017-12-07 #1732665
// Stop using SSH, instead manage iptables on the machine
// itself. This will also provide firewalling for MAAS and
// LXD machines.
options.SetStrictHostKeyChecking(ssh.StrictHostChecksNo)
options.SetKnownHostsFile(os.DevNull)
return &sshInstanceConfigurator{
client: ssh.DefaultClient,
host: "ubuntu@" + host,
options: &options,
}
} | [
"func",
"NewSshInstanceConfigurator",
"(",
"host",
"string",
")",
"InstanceConfigurator",
"{",
"options",
":=",
"ssh",
".",
"Options",
"{",
"}",
"\n",
"options",
".",
"SetIdentities",
"(",
"\"",
"\"",
")",
"\n\n",
"// Disable host key checking. We're not sending any sensitive data",
"// across, and we don't have access to the host's keys from here.",
"//",
"// TODO(axw) 2017-12-07 #1732665",
"// Stop using SSH, instead manage iptables on the machine",
"// itself. This will also provide firewalling for MAAS and",
"// LXD machines.",
"options",
".",
"SetStrictHostKeyChecking",
"(",
"ssh",
".",
"StrictHostChecksNo",
")",
"\n",
"options",
".",
"SetKnownHostsFile",
"(",
"os",
".",
"DevNull",
")",
"\n\n",
"return",
"&",
"sshInstanceConfigurator",
"{",
"client",
":",
"ssh",
".",
"DefaultClient",
",",
"host",
":",
"\"",
"\"",
"+",
"host",
",",
"options",
":",
"&",
"options",
",",
"}",
"\n",
"}"
] | // NewSshInstanceConfigurator creates new sshInstanceConfigurator. | [
"NewSshInstanceConfigurator",
"creates",
"new",
"sshInstanceConfigurator",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/instance_configurator.go#L46-L65 |
155,595 | juju/juju | provider/common/instance_configurator.go | DropAllPorts | func (c *sshInstanceConfigurator) DropAllPorts(exceptPorts []int, addr string) error {
cmds := []string{
iptables.DropCommand{DestinationAddress: addr}.Render(),
}
for _, port := range exceptPorts {
cmds = append(cmds, iptables.AcceptInternalCommand{
Protocol: "tcp",
DestinationAddress: addr,
DestinationPort: port,
}.Render())
}
output, err := c.runCommand(strings.Join(cmds, "\n"))
if err != nil {
return errors.Errorf("failed to drop all ports: %s", output)
}
logger.Tracef("drop all ports output: %s", output)
return nil
} | go | func (c *sshInstanceConfigurator) DropAllPorts(exceptPorts []int, addr string) error {
cmds := []string{
iptables.DropCommand{DestinationAddress: addr}.Render(),
}
for _, port := range exceptPorts {
cmds = append(cmds, iptables.AcceptInternalCommand{
Protocol: "tcp",
DestinationAddress: addr,
DestinationPort: port,
}.Render())
}
output, err := c.runCommand(strings.Join(cmds, "\n"))
if err != nil {
return errors.Errorf("failed to drop all ports: %s", output)
}
logger.Tracef("drop all ports output: %s", output)
return nil
} | [
"func",
"(",
"c",
"*",
"sshInstanceConfigurator",
")",
"DropAllPorts",
"(",
"exceptPorts",
"[",
"]",
"int",
",",
"addr",
"string",
")",
"error",
"{",
"cmds",
":=",
"[",
"]",
"string",
"{",
"iptables",
".",
"DropCommand",
"{",
"DestinationAddress",
":",
"addr",
"}",
".",
"Render",
"(",
")",
",",
"}",
"\n",
"for",
"_",
",",
"port",
":=",
"range",
"exceptPorts",
"{",
"cmds",
"=",
"append",
"(",
"cmds",
",",
"iptables",
".",
"AcceptInternalCommand",
"{",
"Protocol",
":",
"\"",
"\"",
",",
"DestinationAddress",
":",
"addr",
",",
"DestinationPort",
":",
"port",
",",
"}",
".",
"Render",
"(",
")",
")",
"\n",
"}",
"\n\n",
"output",
",",
"err",
":=",
"c",
".",
"runCommand",
"(",
"strings",
".",
"Join",
"(",
"cmds",
",",
"\"",
"\\n",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"output",
")",
"\n",
"}",
"\n",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"output",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // DropAllPorts implements InstanceConfigurator interface. | [
"DropAllPorts",
"implements",
"InstanceConfigurator",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/instance_configurator.go#L78-L96 |
155,596 | juju/juju | provider/common/instance_configurator.go | ConfigureExternalIpAddressCommands | func ConfigureExternalIpAddressCommands(apiPort int) []string {
commands := []string{
`printf 'auto eth1\niface eth1 inet dhcp' | sudo tee -a /etc/network/interfaces.d/eth1.cfg`,
"sudo ifup eth1",
iptables.DropCommand{Interface: "eth1"}.Render(),
}
if apiPort > 0 {
commands = append(commands, iptables.AcceptInternalCommand{
Protocol: "tcp",
DestinationPort: apiPort,
}.Render())
}
return commands
} | go | func ConfigureExternalIpAddressCommands(apiPort int) []string {
commands := []string{
`printf 'auto eth1\niface eth1 inet dhcp' | sudo tee -a /etc/network/interfaces.d/eth1.cfg`,
"sudo ifup eth1",
iptables.DropCommand{Interface: "eth1"}.Render(),
}
if apiPort > 0 {
commands = append(commands, iptables.AcceptInternalCommand{
Protocol: "tcp",
DestinationPort: apiPort,
}.Render())
}
return commands
} | [
"func",
"ConfigureExternalIpAddressCommands",
"(",
"apiPort",
"int",
")",
"[",
"]",
"string",
"{",
"commands",
":=",
"[",
"]",
"string",
"{",
"`printf 'auto eth1\\niface eth1 inet dhcp' | sudo tee -a /etc/network/interfaces.d/eth1.cfg`",
",",
"\"",
"\"",
",",
"iptables",
".",
"DropCommand",
"{",
"Interface",
":",
"\"",
"\"",
"}",
".",
"Render",
"(",
")",
",",
"}",
"\n",
"if",
"apiPort",
">",
"0",
"{",
"commands",
"=",
"append",
"(",
"commands",
",",
"iptables",
".",
"AcceptInternalCommand",
"{",
"Protocol",
":",
"\"",
"\"",
",",
"DestinationPort",
":",
"apiPort",
",",
"}",
".",
"Render",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"commands",
"\n",
"}"
] | // ConfigureExternalIpAddressCommands returns the commands to run to configure
// the external IP address | [
"ConfigureExternalIpAddressCommands",
"returns",
"the",
"commands",
"to",
"run",
"to",
"configure",
"the",
"external",
"IP",
"address"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/instance_configurator.go#L100-L113 |
155,597 | juju/juju | provider/common/instance_configurator.go | ConfigureExternalIpAddress | func (c *sshInstanceConfigurator) ConfigureExternalIpAddress(apiPort int) error {
cmds := ConfigureExternalIpAddressCommands(apiPort)
output, err := c.runCommand(strings.Join(cmds, "\n"))
if err != nil {
return errors.Errorf("failed to drop all ports: %s", output)
}
if err != nil {
return errors.Errorf("failed to allocate external IP address: %s", output)
}
logger.Tracef("configure external ip address output: %s", output)
return nil
} | go | func (c *sshInstanceConfigurator) ConfigureExternalIpAddress(apiPort int) error {
cmds := ConfigureExternalIpAddressCommands(apiPort)
output, err := c.runCommand(strings.Join(cmds, "\n"))
if err != nil {
return errors.Errorf("failed to drop all ports: %s", output)
}
if err != nil {
return errors.Errorf("failed to allocate external IP address: %s", output)
}
logger.Tracef("configure external ip address output: %s", output)
return nil
} | [
"func",
"(",
"c",
"*",
"sshInstanceConfigurator",
")",
"ConfigureExternalIpAddress",
"(",
"apiPort",
"int",
")",
"error",
"{",
"cmds",
":=",
"ConfigureExternalIpAddressCommands",
"(",
"apiPort",
")",
"\n",
"output",
",",
"err",
":=",
"c",
".",
"runCommand",
"(",
"strings",
".",
"Join",
"(",
"cmds",
",",
"\"",
"\\n",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"output",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"output",
")",
"\n",
"}",
"\n",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"output",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // ConfigureExternalIpAddress implements InstanceConfigurator interface. | [
"ConfigureExternalIpAddress",
"implements",
"InstanceConfigurator",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/instance_configurator.go#L116-L127 |
155,598 | juju/juju | provider/common/instance_configurator.go | ChangeIngressRules | func (c *sshInstanceConfigurator) ChangeIngressRules(ipAddress string, insert bool, rules []network.IngressRule) error {
var cmds []string
for _, rule := range rules {
cmds = append(cmds, iptables.IngressRuleCommand{
Rule: rule,
DestinationAddress: ipAddress,
Delete: !insert,
}.Render())
}
output, err := c.runCommand(strings.Join(cmds, "\n"))
if err != nil {
return errors.Errorf("failed to configure ports on external network: %s", output)
}
logger.Tracef("change ports output: %s", output)
return nil
} | go | func (c *sshInstanceConfigurator) ChangeIngressRules(ipAddress string, insert bool, rules []network.IngressRule) error {
var cmds []string
for _, rule := range rules {
cmds = append(cmds, iptables.IngressRuleCommand{
Rule: rule,
DestinationAddress: ipAddress,
Delete: !insert,
}.Render())
}
output, err := c.runCommand(strings.Join(cmds, "\n"))
if err != nil {
return errors.Errorf("failed to configure ports on external network: %s", output)
}
logger.Tracef("change ports output: %s", output)
return nil
} | [
"func",
"(",
"c",
"*",
"sshInstanceConfigurator",
")",
"ChangeIngressRules",
"(",
"ipAddress",
"string",
",",
"insert",
"bool",
",",
"rules",
"[",
"]",
"network",
".",
"IngressRule",
")",
"error",
"{",
"var",
"cmds",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"rule",
":=",
"range",
"rules",
"{",
"cmds",
"=",
"append",
"(",
"cmds",
",",
"iptables",
".",
"IngressRuleCommand",
"{",
"Rule",
":",
"rule",
",",
"DestinationAddress",
":",
"ipAddress",
",",
"Delete",
":",
"!",
"insert",
",",
"}",
".",
"Render",
"(",
")",
")",
"\n",
"}",
"\n\n",
"output",
",",
"err",
":=",
"c",
".",
"runCommand",
"(",
"strings",
".",
"Join",
"(",
"cmds",
",",
"\"",
"\\n",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"output",
")",
"\n",
"}",
"\n",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"output",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // ChangeIngressRules implements InstanceConfigurator interface. | [
"ChangeIngressRules",
"implements",
"InstanceConfigurator",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/instance_configurator.go#L130-L146 |
155,599 | juju/juju | provider/common/instance_configurator.go | FindIngressRules | func (c *sshInstanceConfigurator) FindIngressRules() ([]network.IngressRule, error) {
output, err := c.runCommand("sudo iptables -L INPUT -n")
if err != nil {
return nil, errors.Errorf("failed to list open ports: %s", output)
}
logger.Tracef("find open ports output: %s", output)
return iptables.ParseIngressRules(strings.NewReader(output))
} | go | func (c *sshInstanceConfigurator) FindIngressRules() ([]network.IngressRule, error) {
output, err := c.runCommand("sudo iptables -L INPUT -n")
if err != nil {
return nil, errors.Errorf("failed to list open ports: %s", output)
}
logger.Tracef("find open ports output: %s", output)
return iptables.ParseIngressRules(strings.NewReader(output))
} | [
"func",
"(",
"c",
"*",
"sshInstanceConfigurator",
")",
"FindIngressRules",
"(",
")",
"(",
"[",
"]",
"network",
".",
"IngressRule",
",",
"error",
")",
"{",
"output",
",",
"err",
":=",
"c",
".",
"runCommand",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"output",
")",
"\n",
"}",
"\n",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"output",
")",
"\n",
"return",
"iptables",
".",
"ParseIngressRules",
"(",
"strings",
".",
"NewReader",
"(",
"output",
")",
")",
"\n",
"}"
] | // FindIngressRules implements InstanceConfigurator interface. | [
"FindIngressRules",
"implements",
"InstanceConfigurator",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/common/instance_configurator.go#L149-L156 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.